Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1dab00e0 authored by Ludovic Le Frioux's avatar Ludovic Le Frioux
Browse files

Better integration of the c-crdtlib

parent 5949c6f6
No related branches found
No related tags found
No related merge requests found
class CObject<T> {
// Concordant object id
private id: CObjectId
// Concordant object unique id
private id: CObjectUId
// Is openned in read only mode
private readOnly: Boolean
......@@ -12,7 +12,7 @@ class CObject<T> {
// Backup for the necapsulated CRDT (used in case of transaction abort)
private txnBackup: DeltaCRDT<T>?
CObject(oid: CObjectId, crdt: DeltaCRDT<T>, readOnly: Boolean) {
CObject(oid: CObjectUId, crdt: DeltaCRDT<T>, readOnly: Boolean) {
this.id = oid
this.crdt = crdt
this.readOnly = readOnly
......
class Collection {
// The collection id
private id: CollectionId
// The collection unique id
private id: CollectionUId
// Is the collection open in read only mode
private readOnly: Boolean
......@@ -9,7 +9,7 @@ class Collection {
// Static boolean used to ensure that only one collection is openned
private static otherOpenned: Boolean = false
Collection(cid: CollectionId, readOnly: Boolean) {
Collection(cid: CollectionUId, readOnly: Boolean) {
if (Collection.otherOpenned == true) throw Exception
Collection.otherOpenned = true
this.id = cid
......@@ -21,7 +21,7 @@ class Collection {
if (this.readOnly AND NOT readOnly) throw Exception
if (NOT Session.currentTransaction == null) throw Exception
oid = CObjectId(this.id, oid, T)
oid = CObjectUId(this.id, oid, T)
if (ActiveSession.cache.contains(oid)) return ActiveSession.cache.get(oid)
crdt, v = SERVICE.getObject(oid, ActiveSession.txnEnv.getState())
......
import c-crdlib.utils.ClientUId
import c-crdtlib.utils.VersionVector
class Session {
// The client id
private cliendId: CliendId
// The client unique id
private cliendUId: CliendUId
// Current consistency level
private consistency: ConsistencyLevel?
......@@ -12,21 +15,21 @@ class Session {
// Current running transaction
private currentTransaction: Transaction?
// Transaction environment should inherit from crdtlib.utils.Environment
// Transaction environment
package txnEnv: TransactionEnvironment
// Map for dirty Concordant objects
package dirtyObjects: Map<CObjectId, CObject>
package dirtyObjects: Map<CObjectUId, CObject>
// Map for the cache of Concordant objects
package cache: Map<CObjectId, CObject>
package cache: Map<CObjectUId, CObject>
// Map for Concordant object handlers management
package handlers: Map<CObjectId, NotificationHandler>
package handlers: Map<CObjectUId, NotificationHandler>
private Session(cid: ClientId) {
this.clientId = cid
this.txnEnv = TransactionEnvironment(this.clientId)
private Session(cid: ClientUId) {
this.clientUId = cid
this.txnEnv = TransactionEnvironment(this.clientUId)
this.dirtyObjects = mutableMapOf()
this.cache = mutableMapOf()
this.handlers = mutableMapOf()
......@@ -38,9 +41,9 @@ class Session {
// c_begin_session
static fun connect(dbName: String, credentials: String): Session {
if (NOT ActiveSession == null) throw Exception
clientId = ClientId()
if (NOT SERVICE.connect(dbName, credentials, clientId)) throw Exception
ActiveSession = Session(clientId)
clientId = ClientUId()
if (NOT SERVICE.connect(dbName, credentials, clientUId)) throw Exception
ActiveSession = Session(clientUId)
retur ActiveSession
}
......@@ -72,7 +75,7 @@ class Session {
}
// c_open_collection_read|write
fun openCollection(cid: CollectionId, readOnly: Boolean): Collection {
fun openCollection(cid: CollectionUId, readOnly: Boolean): Collection {
if (NOT this.currentTransaction == null) throw Exception
return Collection(cid, readOnly)
}
......@@ -86,7 +89,7 @@ class Session {
// c_end_session
fun close() {
if (this.currentTransaction == null) this.currentTransaction.abort()
SERVICE.close(clientId)
SERVICE.close(clientUId)
this.serviceHandler.stop()
ActiveSession = null
}
......
import c-crdtlib.utils.VersionVector
class Transaction {
// Transaction id
private transactionId: TxnId
// Transaction unique id
private transactionUId: TxnUId
// The version vector at which the transaction has started
private begin: VersionVector
Transaction(tid: TxnId, body: TransactionBody) {
Transaction(tid: TxnUId, body: TransactionBody) {
this.begin = ActiveSession.txnEnv.getState()
this.transactionId = ActiveSession.txnEnv.tickTransaction()
this.transactionUId = ActiveSession.txnEnv.tickTransaction()
try {
// call the body function
......@@ -31,12 +33,12 @@ class Transaction {
// c_commit_txn
fun commit() {
SERVICE.beginTransaction(this.transactionId)
SERVICE.beginTransaction(this.transactionUId)
for obj in ActiveSession.dirtyObjects {
SERVICE.pushObject(obj.crdt.getDelta(this.begin))
obj.txnCommit()
}
SERVICE.commitTransaction(this.transactionId)
SERVICE.commitTransaction(this.transactionUId)
ActiveSession.dirtyObjects.clear()
}
}
// Concordant object unique identifiers
type CObjectId = (CollectionId, String, Type)
type CObjectUId = (CollectionUId, String, Type)
// Client unique identifiers are UUId, they can also be hierarchic
type ClientId = UUId
// Collection unique identifiers
type CollectionId = String
type CollectionUId = String
import c-crdtlib.utils.VersionVector
// The notification handler (function) type accepted for c-objects
// Unit == void in Kotlin
type NotificationHandler = (VersionVector, CObjectId) -> Unit
type NotificationHandler = (VersionVector, CObjectUId) -> Unit
// Operations unique identifiers
type OperationId = (TxnId, Int)
type OperationUId = (TxnUId, Int)
import c-crdtlin.utils.Environment
class TransactionEnvironment : Environment {
// TODO: implement this class
}
import c-crdtlib.utils.ClientUId
// Transaction unique identifiers
type TxnId = (Int, ClientId)
type TxnUId = (Int, ClientUId)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment