Results 1 to 2 of 2

Thread: [Answers] SessionStorage

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] SessionStorage

    In Lianja v2.0 we have 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 v2.0 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.

    You access sessionstorage from the Lianja system object Lianja.sessionStorage.

    Properties:

    // The number of key/value pairs in sessionStorage
    length

    Methods:

    // These should be quite explanatory
    Lianja.sessionStorage.setItem(key, value)
    value = Lianja.sessionStorage.getItem(key)
    Lianja.sessionStorage.removeItem(key)
    Lianja.sessionStorage.clear()

    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.

    Code:
    // in the main process App
    private myobj = object("name" => "Barry", "company" => "Lianja")
    Lianja.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.



    Indeed, there is a "Session data changed" delegate and a "Session data changed interval" in App Settings.

    Lianja will check for changes in the sessionStorage every #msecs and call the "Section data changed" 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.

    There is also a property called "datachanged" and "datachangedinterval" (in milliseconds) so this can be used by non GUI applications (background worker processes etc).



    In Lianja v2.0 you also have several new classes that handle custom shared memory access and custom system semaphores.

    New "SharedMemory" system class

    Code:
    m_shareddata = createObject("sharedmemory")
    
    // attach will create the shared memory if it does not exist. Args are the "key" and the "size"
    m_shareddata.attach("com.lianja.myshareddata", 64*1024)
    
    // set key/value pairs
    m_shareddata.setItem("mykey", somevalue)
    
    // get value
    m_value = m_shareddata.getItem("mykey")

    New "SystemSemaphore" system class

    Code:
    m_sem = createObject("SystemSemaphore")
    
    // setKey will create the SystemSemahore if it does not exist. 
    m_sem.setKey("com.lianja.mysem")
    
    // acquire exclusive access to a resource across multiple running processes
    m_sem.acquire()
    
    // do something...
    
    // release access to the resource m_sem.release


    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.



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352

  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    Lianja.sessionStorage.setItem("aquivo", "teste")
    Error: Property 'Sessionstorage' undefined
    A:
    This works for me, in desktop and mobile:

    Code:
    var lo = Lianja.sessionStorage;
    lo.setItem("Hank","Fay");
    messageBox(lo.getItem("Hank"));
    Take my code, put it in the Ready of a page

    Case sensitive. sessionStorage is not the same as Sessionstorage in JavaScript.



    SAVE and RESTORE DATASESSION are useful especially in WebViews generated by rsp pages. It was however awkward to nest the saving and restoring properly.
    So in 2.1 I have added two new commands
    PUSH DATASESSION and POP DATASESSION.
    These operate in the same way as SAVE and RESTORE DATASESSION but enable pushing and popping data session state (database, tables, and cursor state)
    up to 256 levels deep.



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/showthread.php?2717-Answers

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us