I want to extract data being updated on one item say item1(itemname & fieldvalue) of a StaticGrid & publish it to textbox
OR
data directly being updated to a textbox
and count the number of updations taking place.
How can I do it?
I want to extract data being updated on one item say item1(itemname & fieldvalue) of a StaticGrid & publish it to textbox
OR
data directly being updated to a textbox
and count the number of updations taking place.
How can I do it?
Hi Priyanka,
You should leverage the addListener method of the Subscription, and give as parameter a custom implementation of SubscriptionListener.
Please note that in your case you just have to implement the onItemUpdate method.
Somthing like this should work in your case:
Regards,Code:var count = 0; ... var mySub = new Subscription(...); mySub.addListener({ onItemUpdate: function(updInfo) { if (updInfo != null) { if ( updInfo.isValueChanged("MY_FIELD") ) { document.getElementById("myText").value = updInfo.getValue("MY_FIELD"); count++; } } } });
Giuseppe
Hey,
So this is what I've done, where "qqq" is the id of my label which is extracting item1 from the static grid - stocksGrid. I just have 1 item in my grid where messages keep updating.
<!-- JavaScript code specific of this application -->
<script type="text/javascript">
var count =0;
require(["js/lsClient","Subscription","StaticGrid"],
function(lsClient,Subscription,StaticGrid) {
var stocksGrid = new StaticGrid("stocks",true);
stocksGrid.setAutoCleanBehavior(true,false);
stocksGrid.addListener({
onVisualUpdate: function(key,info) {
var d = new Date();
count++;
var starttime = 0;
var endtime = 0;
if(count==1)
{
starttime = d.getMilliseconds();
}
else
{
endtime = d.getMilliseconds();
}
if (info != null) {
var arrayofitems = ['ClientMsgCount:',count++,'Time:',endtime-starttime,'Message :',info.So.topicdata];
document.getElementById("qqq").innerHTML =arrayofitems ;
}
var cold = (key.substring(4) % 2 == 1) ? "#eeeeee" : "#ddddee";
info.setAttribute("yellow", cold, "backgroundColor");
}
});
var stockSubscription = new Subscription("MERGE",stocksGrid.extractItemList(), stocksGrid.extractFieldList());
stockSubscription.addListener(stocksGrid);
stockSubscription.setDataAdapter("QUOTE_ADAPTER");
stockSubscription.setRequestedSnapshot("yes");
lsClient.subscribe(stockSubscription);
});
</script>
So, I have set a counter in my java data adapter which reads 29995 messages from a file which it does in 1.6 seconds. But when I send it to the javascript client and set a counter like I have in the script code above, the 2 counters show different number of messages.
My label on my clientpage looks like this:
ClientMsgCount:76, Time:778, Message: AdapterMsgCount:29995,IBM UN EQUITY,3/30/2016 11:48:49 AM,Active,Invalid Security,LAST_PRICE=86.000,BID=86.000,ASK=86.100
Is my javascript client not able to consume all 29995 messages sent by the data adapter? If so, why? I don't understand why both my message counts are different?
Thanks
Do help me out
Priyanka
Last edited by Priyanka; May 27th, 2016 at 11:31 AM.
Hi Priyanka,
The fact that the counter at the client side is far below the expected value can be explained since a subscription in MERGE mode allows the server to merge one or more updates received by the adapter and in practice allows the server to not send all the updates.
Please refer to section "3.2 Data Model and Subscription Modes" of General Concepts document for further details about conflation.
A subscription mode that does not allow conflation is DISTINC mode. So in your case you should switch from MERGE to DISTINCT, otherwise keep MERGE but requiring unfiltered dispatching (section "3.3.4 Filtered and Unfiltered Modes" of the same document).
Furthermore, for a more accurate calculation you should move the count++ inside the if (info != null).
Regards,
Giuseppe
Hey,
Thanks for the help! Meanwhile I figured out something in my adapter and now it counts fine. However, I'm not able to print my updated value into the label in different lines. I can only see the updated current value while debugging in a single line, and I lose the previous values. What can I do about it?
Thank you,
Priyanka
Hi Priyanka,
You should switch from StaticGrid to DynaGrid and from MERGE mode to DISTINCT mode.
But if you want to keep the MERGE mode you still have to use a DynaGrid and specify forceSubscriptionInterpretation:
Otherwise you have to give up our widgets and handling by code the add of all the updates in the DOM.Code:forceSubscriptionInterpretation("UPDATE_IS_KEY");
Regards,
Giuseppe
Hey,
I am trying to extract data directly to the textbox minus any grid. Could you help me out with this please?
Here is a part of my code:
<body>
<br><br>
<div> <td> Light Streamer message:<br>
<textarea id="stock_textarea" style="width:766px;height:200px" data-item="item1" data-field="topicdata"></textarea><br><br>
<script src="js/require.js"></script>
<script src="js/lightstreamer.js"></script>
<script>
//////////////// Connect to current host (or localhost) and configure a StatusWidget
define("js/lsClient",["LightstreamerClient","StatusWidget"],
function(LightstreamerClient,StatusWidget) {
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
// in accordance with the port configuration in the factory lightstreamer_conf.xml
// (although the https port is not open by the factory lightstreamer_conf.xml)
var lsClient = new LightstreamerClient(protocolToUse+"//localhost:"+portToUse,"WELCOME");
lsClient.connectionSharing.enableSharing("DemoComm onConnection", "ATTACH", "CREATE");
lsClient.addListener(new StatusWidget("left", "0px", true));
lsClient.connect();
return lsClient;
});
</script>
<!-- JavaScript code specific of this application -->
<script type="text/javascript">
var count =0;
require(["js/lsClient","Subscription"],
function(lsClient,Subscription) {
var stockSubscription = new Subscription("MERGE","item1","topicdata");
stockSubscription.setDataAdapter("QUOTE_ADAPTER");
stockSubscription.setRequestedSnapshot("yes");
stockSubscription.addListener({
onItemUpdate: function(updInfo) {
var d = new Date();
var starttime = 0;
var endtime = 0;
if(count==1)
{
starttime = d.getMilliseconds();
}
else
{
endtime = d.getMilliseconds();
}
if (updInfo != null) {
if ( updInfo.isValueChanged("topicdata") ) {
var arrayofitems = ['Count:',count++,'Time:',endtime-starttime,'Message :',updInfo.getValue("topicdata")];
document.getElementById("stock_textarea").value =arrayofitems ;
var1= arrayofitems;
console.log(var1);
}
var cold = (key.substring(4) % 2 == 1) ? "#eeeeee" : "#ddddee";
info.setAttribute("yellow", cold, "backgroundColor");
}
}
});
lsClient.subscribe(stockSubscription);
});
</script>
</div>
</body>
So, I get an error lightstreamer.js:360 Uncaught [|IllegalArgumentException|Please specify a valid field list|] How can I fix this issue & where all am I going wrong in my code? Could you please let me know?
Last edited by Priyanka; May 27th, 2016 at 10:10 AM.
Hi Priyanka,
The third parameter of the Subscription's constructor should be an array of Strings.
So, this small change to your code
should do the trick for you.Code:var stockSubscription = new Subscription("MERGE","item1",["topicdata"]);
Regards,
Giuseppe
Hey,
Awesome! It worked. One more query,
I tried the distinct mode & dynagrid but I guess I am still doing something wrong and so I went ahead with the MERGE mode as you saw in the code I sent above.
As in,
I want my result to be this way on the client end inside my textarea:
but, this is how I get itCount:,0,Time:,157,Message :,2.86
Count:,1,Time:,206,Message :,2.87
Count:,2,Time:,304,Message :,2.85
Count:,3,Time:,355,Message :,2.88
Count:,4,Time:,401,Message :,2.89
ie,I get just one message at a time in my textarea instead of all the previous values too. I want all my messages in my textarea one below the other.Count:,3,Time:,355,Message :,2.88
What changes should I do regarding this?
Thanks
Priyanka
Last edited by Priyanka; May 27th, 2016 at 12:04 PM.
Hi Priyanka,
Please, let me recommend again to use a DynaGrid although with the MERGE mode.
Something like this should work in your case:
Regards,Code:<html> <body> <br><br> <div> <td> Light Streamer message:<br> </td> </div> <table> <tr class="tablerow" id="stocks" data-source="lightstreamer" > <td><div data-source="lightstreamer" data-field="topicdata"></div></td> </tr> <table> <script src="js/require.js"></script> <script src="js/lightstreamer.js"></script> <!-- JavaScript code specific of this application --> <script type="text/javascript"> var count =0; require(["js/lsClient","Subscription","DynaGrid"], function(lsClient,Subscription,DynaGrid) { var stockSubscription = new Subscription("MERGE","item2",["topicdata"]); stockSubscription.setDataAdapter("QUOTE_ADAPTER"); stockSubscription.setRequestedSnapshot("yes"); stockSubscription.setRequestedMaxFrequency("unfiltered"); var myGrid = new DynaGrid("stocks",true); myGrid.setAutoCleanBehavior(true,false); myGrid.forceSubscriptionInterpretation("UPDATE_IS_KEY"); myGrid.addListener({ onVisualUpdate: function(key, visualUpdate, domNode) { var d = new Date(); var starttime = 0; var endtime = 0; if(count==1) { starttime = d.getMilliseconds(); } else { endtime = d.getMilliseconds(); } if (visualUpdate != null) { visualUpdate.forEachChangedField(function changedFieldCallback(field, value){ var arrayofitems = ['Count:',count++,'Time:',endtime-starttime,'Message :',visualUpdate.getCellValue("topicdata")]; visualUpdate.setCellValue("topicdata", arrayofitems); var1= arrayofitems; console.log(var1); }); } } }); stockSubscription.addListener(myGrid); lsClient.subscribe(stockSubscription); }); </script> <script> //////////////// Connect to current host (or localhost) and configure a StatusWidget define("js/lsClient",["LightstreamerClient","StatusWidget"], function(LightstreamerClient,StatusWidget) { var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:"; var portToUse = document.location.protocol == "https:" ? "443" : "8080"; // in accordance with the port configuration in the factory lightstreamer_conf.xml // (although the https port is not open by the factory lightstreamer_conf.xml) var lsClient = new LightstreamerClient(protocolToUse+"//localhost:"+portToUse,"WELCOME"); lsClient.connectionSharing.enableSharing("DemoCommonConnection", "ATTACH", "CREATE"); lsClient.addListener(new StatusWidget("left", "0px", true)); lsClient.connect(); return lsClient; }); </script> </body> </html>
Giuseppe
Bookmarks