Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Dec 2008
    Location
    Bangalore
    Posts
    20

    Question Pushing complex data structure

    Hi,

    I had data object that contains attributes as string. I had no trouble in converting it to a map of <String,String> and push it(where key was the attributeName, and value was attributeValue). But now, the data model is going a change, along with the previous attributes now it has a List<Object> where Object it self contains attributes as String. How should I handle this? Is it possible or advisable to have the data model that needs to be pushed in this structure? Please advise.

    A sample scenario is presented below. Class Complex contains List of Phones.

    Code:
    Class Complex{
    String name;
    String id;
    List<Phone> simples;
    }
    Class Phone{
    String phone;
    }
    Thanks,
    Shreyas

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan, Italy
    Posts
    517
    Hi Shreyas,

    If you want to take benefit of the highly efficient delivery mechanisms of Lightstreamer (such as delta delivery and message conflation), you should map any data model you have to a table-based data model. So, in this case, it is up to you to find the right mapping.

    On the other hand, if you don't need optimized delivery, you can use opaque data types. In other words, you can serialize your complex data object into a string (through JSON, XML, or any other technique) and push it as a single field. Your client-side code will do the opposite operation, deserializing the string and getting a full-blown object again.

    Again, consider that by using opaque data types, you actually hide the data model to Lightstreamer, which cannot parse the messages to extract the deltas. So, each message will be delivered "as is" to the client (thus consuming more bandwidth, also due to the overhead of the serialization syntax).

    Regards,
    Alessandro

  3. #3
    Member
    Join Date
    Dec 2008
    Location
    Bangalore
    Posts
    20

    Smile

    Hi Alessandro,

    Thanks for the reply. I get the point.

    Regards,
    Shreyas

  4. #4
    Member
    Join Date
    Feb 2009
    Location
    Pyrmont
    Posts
    25
    Hello,

    I'm attempting to use JSON and a NonVisualTable on the client side - but I seem to be having trouble with including the json.js file (e.g. using http://www.json.org/json.js) with the lightstreamer js files.

    The updates are working as expected when I don't include the json.js file, but the item updates don't seem to be getting picked up when the json.js is included into the page.

    This is the set up I have:

    Code:
    <html>
    
    <head>
    	<title></title>
    	<script src="js/json.js" type="text/javascript"></script>
    	<script src="ls/lscommons.js" type="text/javascript"></script>
    	<script src="ls/lspushpage.js" type="text/javascript"></script>
    </head>
    
    <body>
    <div source="lightstreamer" table="test" item="item-test" field="fieldA" id="fieldA">
    loading...
    </div>
    
    <script>
    
    	var page = new PushPage();
    	page.onEngineCreation = function(engine) {
    		engine.connection.setAdapterName("TEST_ADAPTER");
    		engine.changeStatus("STREAMING");
    	}
    	page.bind();
    	page.createEngine("TestApp", "LS", "SHARE_SESSION");
    
    	var group = ["item-test"];
    	var schema = ["fieldA"];
    	var pushtable = new NonVisualTable(group, schema, "MERGE");
    	pushtable.setSnapshotRequired(true);
    
    	// callback that receives the updates from the Server
    	pushtable.onItemUpdate = function (item, updateInfo) {
    		//alert("update received");
    		if (item == null) {
    			//alert("item is empty");
                            return;
    		}
    		if (updateInfo == null) {
    			//alert("updateInfo is empty");
    			return;
    		}
    		var value = updateInfo.getNewValue("fieldA");
    		var fieldADiv = document.getElementById("fieldA");
    		fieldADiv.innerHTML = value;
                   
                   //todo: retrieve properties from the JSON obejct
    	};
    
    	//add the table to the page
    	page.addTable(pushtable, "test");
    
    </script>
    
    </body>
    </html>
    Is there something else I need to include to allow JSON to be used?

    Many Thanks,

    C

  5. #5
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    the problem with the json.js file is that such library extends the Object's prototype that in turn breaks our code.

    If you use the updated version of the json library (http://www.JSON.org/json2.js ) no conflicts will occur.

    hope that helps.

 

 

Similar Threads

  1. Replies: 1
    Last Post: March 11th, 2010, 03:53 PM
  2. Replies: 0
    Last Post: March 8th, 2010, 10:27 AM
  3. Replies: 4
    Last Post: August 14th, 2009, 03:28 AM
  4. Bandwidth and event pushing
    By churrusco in forum General
    Replies: 10
    Last Post: May 8th, 2007, 02:04 PM

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 04:22 PM.