Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Mar 2010
    Location
    Madurai
    Posts
    12

    Snapshot Available

    I have a data adapter with the following code inside.

    Code:
    public class SecuritiesDataAdapter implements SmartDataProvider
    {
    ...
             public boolean isSnapshotAvailable(String itemName)
    			throws SubscriptionException {
    		return true;
    	}
    ...
    }
    ------------------------------------------------------------------------------------------------

    In the GWT client I have the following code:
    Code:
    jsonEntries = "xxx yyy zzz" //This is framed automatically based on his subscribed items.
    
    $wnd.pushtable_messages = new $wnd.NonVisualTable(jsonEntries.split(" "), new Array("instancesAndSecurities"), "DISTINCT");
    $wnd.pushtable_messages.setSnapshotRequired(true);
    
    $wnd.pushtable_messages.onItemUpdate = function (pos, updateInfo, itemName) {
    var val = updateInfo.getNewValue("instancesAndSecurities");
    $wnd.jsonUpdatedStaticJS(val);}
    			
    $wnd.page.addTable($wnd.pushtable_messages, "instancesAndSecuritiesTable");
    ------------------------------------------------------------------------------------------------

    Apart from this, I have a feed that is coming from our internal server to LS for all the subscribed items.

    Query:

    Client 1 logs in and subscribes to item "xxx" and he gets feed every 10 seconds with Snapshot set to true

    Client 2 logs in and subscribes to the same item "xxx".

    My understanding is, if Snapshot is set to true, as soon as Client 2 logs in and subscribes to item xxx, he will get the last available feed that has got updated for client 1. After 10 seconds, both client 1 and client 2 will get the next feed.

    If my understanding is correct, I am not able to receive the feed in client 2 immediately. It is coming only after 10 seconds. What might be the issue?

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,089
    Your expectations match the behaviour of MERGE mode.
    As your subscription is in DISTINCT mode, there are a few complications.

    In this case, the snapshot is a recent history of updates and the maximum length must be specified by the Metadata Adapter through getDistinctSnapshotLength.
    You should ensure that it is not 0.
    In case you are using the LiteralBasedProvider the returned length is configured through the "distinct_snapshot_length" parameter directly in adapters.xml.

    If you still see problems, please get the Server log after setting the "LightstreamerLogger.subscriptions", "LightstreamerLogger.preprocessor" and "LightstreamerLogger.pump" categories to DEBUG level.

  3. #3
    Member
    Join Date
    Mar 2010
    Location
    Madurai
    Posts
    12
    Thanks for you response.

    Is my understanding of Snapshot right?

    1. Client Subscribes to LS using Distinct Mode as mentioned in my previous post
    2. In the data adapter we need to set isSnapshotAvailable to true
    3. We need to set getDistinctSnapshotLength to a non-zero value. Can you tell me what exactly the length means? Currently we are sending only one field in the item update, which is a JSON string. Should we give the length of the JSON string?
    4. On doing all the above, LS will maintain the last updated value for each item internally and send it to the new person who is subscribing to the same item. Is my understanding correct? or do we need to update LS Listener asking it to keep the item as a snap shot?

    Should we also do the below? What is the purpose of having IsSnapShot in the smart update method? If I set it to True, no update is coming to any of the client.

    itemEventListener.smartUpdate(itemHandle, data, true);

    I also tried adding: <param name="distinct_snapshot_length">500</param>. It is not working.


    Note: I read most of your materials, I am not able to understand it clearly.

  4. #4
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    3. We need to set getDistinctSnapshotLength to a non-zero value. Can you tell me what exactly the length means? Currently we are sending only one field in the item update, which is a JSON string. Should we give the length of the JSON string?
    the length is the number of updates that will form the snapshot; As a practical example, take a look to our ChatDemo, (unless you're unlucky and the server was just upgraded and restarted) you'll immediately receive 30 messages; that's because the snapshot lenght of that item is set to 30 (note that the client may ask for a shorter snapshot, in our case the client request and the server limit are the same).

    4. On doing all the above, LS will maintain the last updated value for each item internally and send it to the new person who is subscribing to the same item. Is my understanding correct? or do we need to update LS Listener asking it to keep the item as a snap shot?
    The server will mantain and update the snapshot internally while the subscription for that item is active, that's correct.

    Should we also do the below? What is the purpose of having IsSnapShot in the smart update method? If I set it to True, no update is coming to any of the client.
    In case of a distinct subscription, the first client will not receive any data until the server has received from the adapter a complete snapshot. The snapshot is considered complete when the onSnapshotEnd method is called or when one of the smartUpdate is called with the isSnapshot flag as false (so the completeness of the first snapshot is unrelated to the distinct snapshot length)

    Note that Dario's suggestion about tracking in the log the events is still valid.

  5. #5
    Member
    Join Date
    Mar 2010
    Location
    Madurai
    Posts
    12
    For Client 1, I am getting the following entries in the log. The item that I am subscribing is MW#1#1#1:

    16-Dec-10 17:13:38,218 |TRACE|LightstreamerLogger.preprocessor |SERVER POOLED THREAD 1 |No frequency prefilter for item MW#1#1#1
    16-Dec-10 17:13:38,218 |TRACE|LightstreamerLogger.preprocessor |SERVER POOLED THREAD 1 |Snapshot buffer size for DISTINCT item MW#1#1#1 set to 0
    16-Dec-10 17:13:38,218 |TRACE|LightstreamerLogger.subscriptions|SERVER POOLED THREAD 1 |Subscribing item MW#1#1#1 on BrowserToLSToTWS.DEFAULT
    16-Dec-10 17:13:38,218 |DEBUG|LightstreamerLogger.subscriptions|SERVER POOLED THREAD 1 |Manager: com.lightstreamer.c.fb@bc5596

    For Client 2, I am getting like this:
    16-Dec-10 17:14:54,328 |TRACE|LightstreamerLogger.preprocessor |SNAPSHOT POOLED THREAD 1 |Sending DISTINCT snapshot to session Sc1cd7da17bb316adT1451625 for item MW#1#1#1: Snapshot end signal for item MW#1#1#1 on BrowserToLSToTWS.DEFAULT

    The code that I have written:

    Client Side:
    Code:
    $wnd.pushtable_messages = new $wnd.NonVisualTable(jsonEntries.split(" "), new Array("instancesAndSecurities"), "DISTINCT");
    $wnd.pushtable_messages.setSnapshotRequired(true);
    Server Side:
    1. In Meta data data Adapter

    Code:
    public boolean isSnapshotAvailable(String itemName)
    			throws SubscriptionException {
    		return true;
    	}
    
    public int getDistinctSnapshotLength(String item)
    	{
    		return 1;
    	}
    
    itemEventListener.smartUpdate(itemHandle, data, false);
    3. In Adapter.XML:
    <param name="distinct_snapshot_length">1</param>

    Can you please let me know what I have done wrong?

    Note:

    1. I also tried $wnd.pushtable_messages.setSnapshotRequired(1); This is also not working.
    2. For Data Adapter I have implemented:
    Code:
    public class InstancesAndSecuritiesDataAdapter implements SmartDataProvider 
    {
    }
    3. For Meta Data Adapter I have implemented:
    Code:
    public class ActiveTraderMetaData extends LiteralBasedProvider 
    {
    }
    Attached Files Attached Files

  6. #6
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,089
    The "Snapshot buffer size for DISTINCT item MW#1#1#1 set to 0" log line clearly states that the snapshot length is zero, hence no snapshot is kept.

    According to your implementation of getDistinctSnapshotLength, that shouldn't have happened.
    Could you try to trace your getDistinctSnapshotLength implementation and see if it is indeed invoked?

  7. #7
    Member
    Join Date
    Mar 2010
    Location
    Madurai
    Posts
    12
    Yes, you are right, the getDistinctSnapshotLength is not invoked at all...

    How should I invoke this? I thought lightstreamer will invoke this automatically.

    I am using lightstreamer Version 3.5 Update 1428.4

  8. #8
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,089
    In my previous post I didn't notice that,
    but you coded getDistinctSnapshotLength in the Data Adapter (beside isSnapshotAvailable);
    you should rather code it in the Metadata Adapter;
    then, Lightstreamer will invoke it automatically.

    Are you using a custom Metadata Adapter or the ready-made LiteralBasedProvider?
    In the latter case, you don't need to move to a custom Metadata Adapter, as the setting of <param name="distinct_snapshot_length">500</param> should do the trick;
    if it hasn't worked, maybe the syntax is not correct; please ensure that the line is inside the <metadata_provider> element.

  9. #9
    Member
    Join Date
    Mar 2010
    Location
    Madurai
    Posts
    12
    Thanks a lot !!!

    When I moved the getDistinctSnapshotLength to Meta Data adapter. it worked.

 

 

Similar Threads

  1. Snapshot Processing
    By wwatts in forum Client SDKs
    Replies: 3
    Last Post: October 2nd, 2012, 11:40 AM
  2. How to configure snapshot length?
    By LS_Developer in forum General
    Replies: 3
    Last Post: March 14th, 2012, 03:46 PM
  3. Initial snapshot length
    By patilgkk in forum General
    Replies: 5
    Last Post: August 2nd, 2010, 10:04 AM
  4. Snapshot example
    By patilgkk in forum Adapter SDKs
    Replies: 3
    Last Post: June 3rd, 2010, 11:27 AM
  5. Pre-Processor Snapshot vs DataAdapter Snapshot
    By sukhdev in forum Adapter SDKs
    Replies: 3
    Last Post: August 1st, 2007, 09:44 AM

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
  •  
All times are GMT +1. The time now is 10:12 AM.