SessionStorage in Lianja
In Lianja v2.0 we made it dramatically easier to share data in real time between multiple Lianja processes running in parallel.
In HTML5 Web/Mobile there is the concept of 'localStorage' and 'sessionStorage'.
In the Lianja Desktop client 'sessionStorage' is non persistent data that can be shared across multiple concurrent processes e.g. background processes gathering data from instruments or multiple Lianja windows on the desktop.
Access to data in sessionStorage is handled automatically for you so that concurrent reads, updates and removing of data items is atomic.
Lianja uses a shared memory segment to maintain sessionStorage.
Lianja will automatically keep the keys and their values consistent between each running process as you reference the items stored in SessionStorage. If you want to keep complex objects as the values for keys then use JSON_ENCODE() and JSON_DECODE() to handle serialization and deserialization of the objects.
// in the main process App private myobj = object("name" => "Barry", "company" => "Lianja") Lianja.sessionStorage.setItem("myobj", json_encode(myobj) )
// then in another process that needs to read objects from the main App window private myobj = json_decode( Lianja.sessionStorage.getItem("myobj") )
Note that each time you call any of the methods or reference the length property the shared sessionStorage will be automatically kept current for you.
There is a "Sessionstorage size" attribute in App Settings, along with a "Session data changed" delegate and a "Session data changed interval".
Lianja will check for changes in the sessionStorage every #msecs and call the "Session data changed" delegate if any changes in the sessionStorage have been made.
This is fast, as a transaction sequence number is kept as part of the sessionStorage so no deserialization of data is required.
Note: the "Session data changed" delegate can also be set using
Lianja.sessionStorage.dataChanged = cProc
and the "Session data changed interval" using
Lianja.sessionStorage.dataChangedInterval = nInterval
Another interesting use of sessionStorage is the ability to switch between Apps and maintain state or pass data between them.
So, when building a large application which is built out of smaller Apps and each App is built out of pages, you can load Apps using Lianja.openApp("someappname") and in the "Ready" delegate read some data from sessionStorage that was set using Lianja.sessionStorage.setItem("mediate", "some JSON encoded object") in the parent App that loaded "someappname".
This technique also works in the Web/Mobile client which also has Lianja.sessionStorage in the framework.
The following related classes handle custom shared memory access and custom system semaphores.