Remote Objects
Rotor Database allows devices to work with the same objects by listening to the same path
. When an object has listened, the library says to Rotor server your device is waiting for changes on that path
, so every time any device makes a change on that (object), the differences are calculated and replicated on all devices listening.
Rotor Database works with Java objects.
Listen
listen(database: String, path: String, object: Reference<T>(T::class.java))
method has a simple object lifecycle interface which controls every object state.
onCreate
Called when the object is not created in remote DB yet. The object is defined and synchronized with the server here. This method won’t be called if the object already exists on the server, onChange
method will be called instead
onChanged
Called in two situations, when some device has made changes on the same object and when listen
method is called and the object is cached. Database library pass the object up to date as a parameter.
onUpdate
Called when sync
method is invoked. Differences with the last “fresh” object passed by the library are calculated and sent to the server.
onDestroy
Called when remove
method is invoked. Reference is removed on database too.
progress
Some object updates can become too big, so server slices updates and sends them sequentially. value parameter goes from 0 to 100
Sync
After work with objects, changes must be synchronized with servers. Call sync(path: String)
method to sync it.
Unlisten
Remove listener in the server by calling unlisten(path: String)
.
Remove
Remove reference in the database by calling remove(path: String)
. onDestroy
will be called.