diff --git a/CObject b/CObject index 6f43467c7c2e305d695102a151bf9e0c62688752..03fade9153c504ff358a3b5af02c2fee7769461e 100644 --- a/CObject +++ b/CObject @@ -1,7 +1,7 @@ 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 diff --git a/Collection b/Collection index c6939daccaa8f9048bdd34b6433180475df00928..f6e6a357d05ea1e58c237785501848021a47ab5b 100644 --- a/Collection +++ b/Collection @@ -1,7 +1,7 @@ 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()) diff --git a/Session b/Session index 12a7506b9afcc27cf9f97ea6a9f8b65d55e77aa7..ce5ea4bee06811f2a95950ade83a79598f9c2445 100644 --- a/Session +++ b/Session @@ -1,7 +1,10 @@ +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 } diff --git a/Transaction b/Transaction index ffe0d6115b6288609856f7ee65f194e188fd9278..9b1909510049970918fa3582b95731294f7a4969 100644 --- a/Transaction +++ b/Transaction @@ -1,14 +1,16 @@ +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() } } diff --git a/utils/CObjectId b/utils/CObjectId deleted file mode 100644 index 8bde73e3fe66396027abd8bc12679c97603288b9..0000000000000000000000000000000000000000 --- a/utils/CObjectId +++ /dev/null @@ -1,2 +0,0 @@ -// Concordant object unique identifiers -type CObjectId = (CollectionId, String, Type) diff --git a/utils/CObjectUId b/utils/CObjectUId new file mode 100644 index 0000000000000000000000000000000000000000..d383ac442fb9b5c6f724630d02209ccc7c883ab5 --- /dev/null +++ b/utils/CObjectUId @@ -0,0 +1,2 @@ +// Concordant object unique identifiers +type CObjectUId = (CollectionUId, String, Type) diff --git a/utils/ClientId b/utils/ClientId deleted file mode 100644 index a591f0b532ecb2940443966ef212acf68c7b1290..0000000000000000000000000000000000000000 --- a/utils/ClientId +++ /dev/null @@ -1,2 +0,0 @@ -// Client unique identifiers are UUId, they can also be hierarchic -type ClientId = UUId diff --git a/utils/CollectionId b/utils/CollectionUId similarity index 54% rename from utils/CollectionId rename to utils/CollectionUId index 330f9c2fb6052ae742d68acae12c3cdf5f29f702..2d976d2150423e08e26891a30e6e59549959f3b7 100644 --- a/utils/CollectionId +++ b/utils/CollectionUId @@ -1,2 +1,2 @@ // Collection unique identifiers -type CollectionId = String +type CollectionUId = String diff --git a/utils/NotificationHandler b/utils/NotificationHandler index d905e70edc80a33338a38f688df2dd37cf3f908d..0bbb84632385dc71b0b4231e2a4bab0079a7a6c1 100644 --- a/utils/NotificationHandler +++ b/utils/NotificationHandler @@ -1,3 +1,5 @@ +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 diff --git a/utils/OperationId b/utils/OperationId deleted file mode 100644 index 6b954f5b0fc6e6b72bed936b651297525a165dc3..0000000000000000000000000000000000000000 --- a/utils/OperationId +++ /dev/null @@ -1,2 +0,0 @@ -// Operations unique identifiers -type OperationId = (TxnId, Int) diff --git a/utils/OperationUId b/utils/OperationUId new file mode 100644 index 0000000000000000000000000000000000000000..65d77447a2e148072f8d12361c072cbd2e288a41 --- /dev/null +++ b/utils/OperationUId @@ -0,0 +1,2 @@ +// Operations unique identifiers +type OperationUId = (TxnUId, Int) diff --git a/utils/TransactionEnvironment b/utils/TransactionEnvironment new file mode 100644 index 0000000000000000000000000000000000000000..6b2fb108004b49b5ce26864710dd6d4086b42bca --- /dev/null +++ b/utils/TransactionEnvironment @@ -0,0 +1,5 @@ +import c-crdtlin.utils.Environment + +class TransactionEnvironment : Environment { + // TODO: implement this class +} diff --git a/utils/TxnId b/utils/TxnId deleted file mode 100644 index f26285555e8fe694e7717eac458b249559b2a841..0000000000000000000000000000000000000000 --- a/utils/TxnId +++ /dev/null @@ -1,2 +0,0 @@ -// Transaction unique identifiers -type TxnId = (Int, ClientId) diff --git a/utils/TxnUId b/utils/TxnUId new file mode 100644 index 0000000000000000000000000000000000000000..6da51377e48dce0977c82ac59f81fd7ad2184fdd --- /dev/null +++ b/utils/TxnUId @@ -0,0 +1,4 @@ +import c-crdtlib.utils.ClientUId + +// Transaction unique identifiers +type TxnUId = (Int, ClientUId)