Mentions légales du service

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

Add more code documentation.

parent 2ad93a2b
No related branches found
No related tags found
No related merge requests found
......@@ -21,31 +21,22 @@ package client
import client.utils.ActiveSession
import client.utils.CObjectUId
import client.utils.CService
import client.utils.OperationUId
import crdtlib.crdt.DeltaCRDT
open class CObject<T> {
/**
* Concordant object unique id
*/
private val id: CObjectUId<T>
/**
* Is openned in read only mode
*/
private val readOnly: Boolean
/**
* Class representing a Concordant object.
* @property id Concordant object unique identifier.
* @property readOnly is object openned in read-only mode.
*/
open class CObject<T>(private val id: CObjectUId<T>, private val readOnly: Boolean) {
/**
* The encapsulated CRDT
* The encapsulated CRDT.
*/
protected var crdt: DeltaCRDT<T>? = null
constructor(oid: CObjectUId<T>, readOnly: Boolean) {
this.id = oid
this.readOnly = readOnly
}
protected fun beforeUpdate(): OperationUId {
if (this.readOnly) throw RuntimeException("CObject has been opened in read-only mode.")
if (ActiveSession == null) RuntimeException("Not active session.")
......@@ -64,6 +55,9 @@ open class CObject<T> {
protected fun afterGetter() {
}
/**
* Closes this object.
*/
fun close() {
}
}
......@@ -23,32 +23,29 @@ import client.utils.CObjectUId
import client.utils.CollectionUId
import client.utils.NotificationHandler
class Collection {
/**
* The collection unique id
*/
private val id: CollectionUId
/**
* This class represents a collection of objects.
* @property id the collection unique identifier.
* @property readOnly is the collection open in read-only mode.
*/
class Collection(private val id: CollectionUId, private val readOnly: Boolean) {
/**
* Is the collection open in read only mode
*/
private val readOnly: Boolean
constructor(cid: CollectionUId, readOnly: Boolean) {
this.id = cid
this.readOnly = readOnly
}
// c_open_read|write<T>
fun <T> open(oid: String, readOnly: Boolean, handler: NotificationHandler<T>): T {
* Opens an object of the collection.
* @param objectId the name of the object.
* @param readOnly is the object open in read-only mode.
* @param handler currently not used.
*/
fun <T> open(objectId: String, readOnly: Boolean, handler: NotificationHandler<T>): T {
if (this.readOnly && !readOnly) throw RuntimeException("Collection has been opened in read-only mode.")
val oid = CObjectUId<T>(this.id, oid)
return CObject<T>(oid, readOnly) as T
val objectUId = CObjectUId<T>(this.id, objectId)
return CObject<T>(objectUId, readOnly) as T
}
// c_close_collection
/**
* Closes this collection.
*/
fun close() {
}
}
......@@ -21,16 +21,20 @@
package client
import client.utils.ActiveSession
import client.utils.CService
import client.utils.CollectionUId
import client.utils.ConsistencyLevel
import crdtlib.utils.ClientUId
import crdtlib.utils.SimpleEnvironment
import crdtlib.utils.VersionVector
/**
* Class representing a client session.
*/
class Session {
/**
* The client unique id
* The client unique identifier
*/
private val clientUId: ClientUId
......@@ -39,32 +43,52 @@ class Session {
*/
public val environment: SimpleEnvironment
private constructor(cid: ClientUId) {
this.clientUId = cid
/**
* Private constructor.
* @param clientUId the client unique identifier.
*/
private constructor(clientUId: ClientUId) {
this.clientUId = clientUId
this.environment = SimpleEnvironment(this.clientUId)
}
// c_pull_XX_view
fun pull(type: ConsistencyLevel) {
// Not yet implemented
throw RuntimeException("Method pull is not yet supported.")
}
// c_pull_XX_view(v)
fun pull(type: ConsistencyLevel, vv: VersionVector) {
// Not yet implemented
throw RuntimeException("Method pull is not yet supported.")
}
// c_open_collection_read|write
fun openCollection(cid: CollectionUId, readOnly: Boolean): Collection {
return Collection(cid, readOnly)
/**
* Opens a given collection with the given read-only mode.
* @param collectionUId the collection unique identifier.
* @param readOnly is read-only mode activated.
* @return the corresponding collection.
*/
fun openCollection(collectionUId: CollectionUId, readOnly: Boolean): Collection {
return Collection(collectionUId, readOnly)
}
// c_end_session
/**
* Closes this session.
*/
fun close() {
CService.close(this.clientUId)
ActiveSession = null
}
companion object {
// c_begin_session
/**
* Connects a client to Concordant platform.
* @param dbName the database name that should be accessed.
* @param credentials the crediantials provided by the client.
* @return the client session to communicate with Concordant.
*/
fun connect(dbName: String, credentials: String): Session {
val clientUId = ClientUId("MY_ID")
if (!CService.connect(dbName, clientUId)) throw RuntimeException("Connection to server failed.")
......
......@@ -20,6 +20,6 @@
package client.utils
/**
* Concordant object unique identifiers
* Concordant object unique identifier.
*/
data class CObjectUId<T>(val cid: CollectionUId, val name: String)
......@@ -21,6 +21,6 @@
package client.utils
/**
* Collection unique identifiers
* Collection unique identifier.
*/
typealias CollectionUId = String
......@@ -20,7 +20,7 @@
package client.utils
/**
* Different types of consistency level provided by the Concordant platform
* Different types of consistency level provided by the Concordant platform.
*/
enum class ConsistencyLevel {
......
......@@ -22,6 +22,6 @@ package client.utils
import client.Session
/**
* Global variable(s)
* Global variable storing a reference to the currently active session.
*/
var ActiveSession: Session? = null
......@@ -22,6 +22,6 @@ package client.utils
import crdtlib.utils.VersionVector
/**
* The notification handler (function) type accepted for c-objects
* The notification handler (function) type used is case of object update.
*/
typealias NotificationHandler<T> = (VersionVector, CObjectUId<T>) -> Unit
......@@ -22,6 +22,6 @@ package client.utils
import crdtlib.utils.Timestamp
/**
* Operations unique identifiers
* Operation unique identifier.
*/
typealias OperationUId = Timestamp
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