Cyro
Greetings I'm new here and I have a question. I'm working on application that allows steraming of data between two endpoints. I took example data adapter created by Mone and adapted it to read from file and push the data. (I read one value - double, and cast it to string and do it at regular intervals - values is always different). I managed to do it without errors and all is fine but I'm stuck at making client application that accepts the incoming data and extracts that one value and stores it for use by other part of program that draws a graph from available data. Now I would use the example again supplied by Mone and adapt it a little but don't know even where to start with writing! Can I do it in eclipse or what?
(sry for the noob questions but it is a project in college and I will flunk if I don't complete it and this is my first time using any of this. I'm sort of good in Java but knowledge in javascript or action script or flex and similar things is next to none )
Cyro
nvm the question. I got it to work. BUT when I try
http://localhost:8080/Simplest I just get Loading and nothing moves. I don't know is it actually streaming or not. If you've got a little time here's the code:
Data adapter:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.Map;
import com.lightstreamer.interfaces.data.DataProvider;
import com.lightstreamer.interfaces.data.DataProviderException;
import com.lightstreamer.interfaces.data.FailureException;
import com.lightstreamer.interfaces.data.ItemEventListener;
import com.lightstreamer.interfaces.data.SubscriptionException;
public class Simplest implements DataProvider {
private ItemEventListener listener;
private Map<String, ItemThread> threads = new HashMap<String, ItemThread>();
public void init(Map params, File configDir) throws DataProviderException {
}
public boolean isSnapshotAvailable(String itemName)
throws SubscriptionException {
return false;
}
public void setListener(ItemEventListener listener) {
this.listener = listener;
}
public synchronized void subscribe(String itemName, boolean needsIterator)
throws SubscriptionException, FailureException {
if (itemName.equals("stream")) {
ItemThread it = new ItemThread(itemName);
it.start();
/*ItemThread it = threads.get(itemName);
if (it == null) {
it = new ItemThread(itemName);
it.start();
threads.put(itemName, it);
*/}
}
public synchronized void unsubscribe(String itemName) throws SubscriptionException,
FailureException {
ItemThread it = threads.get(itemName);
if (it != null) {
it.close();
threads.remove(itemName);
}
}
class ItemThread extends Thread {
private final String item;
private volatile boolean go = true;
public ItemThread(String item) {
this.item = item;
}
public void run() {
int i=0;
while(go) {
Map<String,String> data = new HashMap<String,String>();
try {Reader r = new BufferedReader(new FileReader("primjer.txt"));
StreamTokenizer stok = new StreamTokenizer(r);
stok.parseNumbers();
// double sum = 0;
stok.nextToken();
while (stok.ttype != StreamTokenizer.TT_EOF) {
if (stok.ttype == StreamTokenizer.TT_NUMBER)
i++;
if(i%3==2){
data.put("Sljedeca vrijednost:", Double.toString(stok.nval));
listener.update(item, data, false);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
stok.nextToken();
}
catch(Exception e){e.printStackTrace();}
}}
public void close() {
go = false;
}
}
}
Client:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<script language="JavaScript" src="LS/lscommons.js"></script>
<script language="JavaScript" src="LS/lspushpage.js"></script>
</head>
<body>
<h1>Simplest</h1>
<div>
Stream
<span source="lightstreamer" table="table1" item="stream" field="Sljedeca vrijednost:">Loading...</span>
</div>
<script>
/////////////////PushPage Configuration
var lsPage = new PushPage();
var debugAlerts = false;
var remoteAlerts = false;
var pushHost = null;
var pushPort = null;
var useDomain = null;
lsPage.context.setDomain(useDomain);
lsPage.context.setDebugAlertsOnClientError(debugAlerts);
lsPage.context.setRemoteAlertsOnClientError(remoteAlerts);
lsPage.onEngineCreation = function(lsEngine) {
lsEngine.context.setDebugAlertsOnClientError(debugAlerts);
lsEngine.context.setRemoteAlertsOnClientError(remoteAlerts);
lsEngine.connection.setLSHost(pushHost);
lsEngine.connection.setLSPort(pushPort);
lsEngine.connection.setAdapterName("SIMPLEST");
lsEngine.changeStatus("STREAMING");
}
lsPage.bind();
lsPage.createEngine("SimplestEng","LS","SHARE_SESSION");
///////////////////////Table configuration
var table1 = new OverwriteTable(stream, null, "RAW");
table1.setClearOnDisconnected(true);
table1.setClearOnRemove(true);
lsPage.addTable(table1, "table1");
</script>
</body>
</html>
Mone
Hi,
Assuming that field/item/adapter names are correct (check the server log to see if there are errors) I can see only one error:
[syntax="JS"]var table1 = new OverwriteTable(stream, null, "RAW"); [/syntax]
the variable stream is not defined anywhere so that the above call throws an exception. You should substitute it with one of the following:
specifying the list of items to be subscribed:
[syntax="JS"]var table1 = new OverwriteTable(["stream"], null, "RAW"); [/syntax]
specifying null so that the table will read the item list from the associated html element(s):
[syntax="JS"]var table1 = new OverwriteTable(null, null, "RAW"); [/syntax]
For javascript debug I advice you to use firefox with the firebug plugin.
HTH
Cyro
I tryed the line you gave me and nothing new happened. Problem is that server doesn't list any errors, data adapter didn't list any errors before compiling or after for that matter and Evrsoft front page tried to open the page and didn't list any problems. BUT... Field still says loading and nothing moves... I even tried to copy your entire Simplest data adapter and client and that too didn't budge. Just stands there looking pretty. I think that word Loading will forever stay etched in my mind :Smile_Ab:
Mone
did you debug the adapter code? (you can debug it following this guide:
http://www.lightstreamer.com/vb/showthread.php?t=145 )
then try to paste here a snippet from your server log
Cyro
no debugging errors. not one. but still no luck. page can be opened in browser but looks like either data adapter is not streaming OR client is not recieving because I get the page with heading and everything but instead of data I still get Loading.
Mone
Please get a detailed log from the Server, after setting the priorities for the "LightstreamerLogger.subscriptions" and "LightstreamerLogger.pump" categories as DEBUG in the Server log configuration file (LS_HOME/conf/lightstreamer_log_conf.xml) and then paste it here.
Cyro
Is this what you need?
16-srp-09 13:44:56,734 |INFO |LightstreamerLogger.license |main |This is a trial version.
16-srp-09 13:44:58,703 |INFO |LightstreamerLogger.init |main |Lightstreamer Server starting in Vivace edition
16-srp-09 13:44:58,984 |INFO |LightstreamerLogger.init |main |Started HTML Adaptor for JMX on port 6666
16-srp-09 13:44:59,109 |INFO |LightstreamerLogger.init |main |Started JMXMP Connector for JMX on port 9999
16-srp-09 13:44:59,312 |INFO |LightstreamerLogger.init |main |data_provider element without name attribute; using DEFAULT as the default name
16-srp-09 13:44:59,312 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Loading Metadata Adapter SIMPLEST
16-srp-09 13:44:59,328 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 13:44:59,359 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Finished loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 13:44:59,359 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Finished loading Metadata Adapter SIMPLEST
16-srp-09 13:44:59,640 |INFO |LightstreamerLogger.init |main |Pump pool size set by default at 2
16-srp-09 13:44:59,750 |INFO |LightstreamerLogger.init |main |Events pool size set by default at 2
16-srp-09 13:44:59,812 |INFO |LightstreamerLogger.init |main |Lightstreamer Server 3.5 build 1428.4 starting...
16-srp-09 13:45:00,000 |INFO |LightstreamerLogger.init |main |Server "Lightstreamer HTTP Server" listening to *:8080 ...
16-srp-09 13:46:18,718 |INFO |LightstreamerLogger.license |main |This is a trial version.
16-srp-09 13:46:20,125 |INFO |LightstreamerLogger.init |main |Lightstreamer Server starting in Vivace edition
16-srp-09 13:46:20,171 |INFO |LightstreamerLogger.init |main |Started HTML Adaptor for JMX on port 6666
16-srp-09 13:46:20,218 |INFO |LightstreamerLogger.init |main |Started JMXMP Connector for JMX on port 9999
16-srp-09 13:46:20,312 |INFO |LightstreamerLogger.init |main |data_provider element without name attribute; using DEFAULT as the default name
16-srp-09 13:46:20,312 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Loading Metadata Adapter SIMPLEST
16-srp-09 13:46:20,312 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 13:46:20,328 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Finished loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 13:46:20,328 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Finished loading Metadata Adapter SIMPLEST
16-srp-09 13:46:20,390 |INFO |LightstreamerLogger.init |main |Pump pool size set by default at 2
16-srp-09 13:46:20,437 |INFO |LightstreamerLogger.init |main |Events pool size set by default at 2
16-srp-09 13:46:20,453 |INFO |LightstreamerLogger.init |main |Lightstreamer Server 3.5 build 1428.4 starting...
16-srp-09 13:46:20,515 |INFO |LightstreamerLogger.init |main |Server "Lightstreamer HTTP Server" listening to *:8080 ...
16-srp-09 13:47:03,265 |INFO |LightstreamerLogger.init |Thread-12 |Server shutdown requested
16-srp-09 13:47:03,265 |INFO |LightstreamerLogger.init |Thread-12 |Exiting.....
I would dare to say that problem is with client.
Mone
it seems that you've shut down immediately the server
16-srp-09 13:47:03,265 |INFO |LightstreamerLogger.init |Thread-12 |Server shutdown requested
sorry not to mention it, you should start the server, open your page on a browser, wait a little bit and then get the log so that we can see what requests reach the server and how it answers.
Cyro
ok I got the server to send something. Problem indeed was with the client. Here's proof that he is transmitting:
16-srp-09 14:51:19,953 |INFO |LightstreamerLogger.license |main |This is a trial version.
16-srp-09 14:51:21,437 |INFO |LightstreamerLogger.init |main |Lightstreamer Server starting in Vivace edition
16-srp-09 14:51:21,484 |INFO |LightstreamerLogger.init |main |Started HTML Adaptor for JMX on port 6666
16-srp-09 14:51:21,531 |INFO |LightstreamerLogger.init |main |Started JMXMP Connector for JMX on port 9999
16-srp-09 14:51:21,625 |INFO |LightstreamerLogger.init |main |data_provider element without name attribute; using DEFAULT as the default name
16-srp-09 14:51:21,625 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Loading Metadata Adapter SIMPLEST
16-srp-09 14:51:21,625 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 14:51:21,625 |INFO |LightstreamerLogger.init |Init for SIMPLEST.DEFAULT |Finished loading Data Adapter SIMPLEST.DEFAULT
16-srp-09 14:51:21,625 |INFO |LightstreamerLogger.init |Init for SIMPLEST |Finished loading Metadata Adapter SIMPLEST
16-srp-09 14:51:21,687 |INFO |LightstreamerLogger.init |main |Pump pool size set by default at 2
16-srp-09 14:51:21,734 |INFO |LightstreamerLogger.init |main |Events pool size set by default at 2
16-srp-09 14:51:21,750 |INFO |LightstreamerLogger.init |main |Lightstreamer Server 3.5 build 1428.4 starting...
16-srp-09 14:51:21,796 |INFO |LightstreamerLogger.init |main |Server "Lightstreamer HTTP Server" listening to *:8080 ...
16-srp-09 14:51:35,265 |INFO |LightstreamerLogger.requests |SERVER POOLED THREAD 8 |Serving request: /lightstreamer/create_session.js?LS_phase=1702&LS_polling=true&LS_polling_millis=0&LS_idle_millis=30000&LS_client_version=4.3&LS_adapter=SIMPLEST& from 127.0.0.1:1728
16-srp-09 14:51:35,421 |TRACE|LightstreamerLogger.pump |SERVER POOLED THREAD 8 |Pump for session S259eca68b19bc589T5135421 added
16-srp-09 14:51:35,453 |INFO |LightstreamerLogger.requests |SERVER POOLED THREAD 8 |Starting new session: S259eca68b19bc589T5135421 from 127.0.0.1:1728
16-srp-09 14:51:35,484 |INFO |LightstreamerLogger.requests |SERVER POOLED THREAD 2 |Serving request: /lightstreamer/STREAMING_IN_PROGRESS?LS_session=S259eca68b19bc589T5135421&LS_phase=1703& from 127.0.0.1:1733
16-srp-09 14:51:35,500 |INFO |LightstreamerLogger.requests |SERVER POOLED THREAD 2 |Attaching session: S259eca68b19bc589T5135421 from 127.0.0.1:1733
16-srp-09 14:51:37,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 2 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:39,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 1 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:41,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 2 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:43,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 1 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:45,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 2 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:47,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 1 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:49,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 2 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:51,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 1 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:53,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 2 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:51:55,515 |TRACE|LightstreamerLogger.pump |PUMP POOLED THREAD 1 |Sending probe in session S259eca68b19bc589T5135421
16-srp-09 14:53:02,515 |TRACE|LightstreamerLogger.pump |FOR PUMPS PARKING DESTROYER|Pump for session S259eca68b19bc589T5135421 removed
But I still get only loading. Looks like client is not interpreting correctly.
Here is NEW client:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
<script language="JavaScript" src="LS/lscommons.js"></script>
<script language="JavaScript" src="LS/lspushpage.js"></script>
</head>
<body>
<h1>Simplest</h1>
<div id="F|table1|stream|Next|div" class="">loading...</div>
<script>
var page = new PushPage();
page.onEngineCreation = function(engine) {
engine.connection.setAdapterName("SIMPLEST");
engine.changeStatus("STREAMING");
}
page.bind();
page.createEngine("SimplestApp", "LS", "SHARE_SESSION");
var pushtable = new OverwriteTable(stream, null, "DISTINCT");
page.addTable(pushtable, "table1");
</script>
</body>
</html>
And now I get error that there are no elements in table table1
Mone
the server is sending only probes, no data at all. Debug step by step your adapter and check that it is sending the data to its listener.
[SYNTAX="JAVA"][/SYNTAX]
About the client you've two errors now:
you should not change your html to be like this:
[syntax="HTML"]<div id="F|table1|stream|Next|div" class="">loading...</div>[/syntax]
leave it as it was before
[syntax="HTML"]<span source="lightstreamer" table="table1" item="stream" field="Sljedeca vrijednost:">Loading...</span>[/syntax]
and you still have the undefined variable stream in your table constructor:
[syntax="JS"]var pushtable = new OverwriteTable(stream, null, "DISTINCT");[/syntax]
change it as I've shown you on my first post.
Mone
Cyro
looks like subscription method isn't even called!! I've put a breakpoint on every single line of the subscription method. Nothing. I get that trace when I activate page in browser but looks like it doesn't subscribe...
Mone
did you fix the client page? Paste here a server log.
A subscribe on the data adapter for a certain item is called only when a client subscribes to that item. If the client is broken so that it does not subscribes to your item (as in the previous server log) the subscribe on the data adapter is never called
Cyro
I did it. Had a smaaaaaaall but very significiant error. My file reader was not reading well. And subscribe name was different. Now it works and sends data.
Well then, now I have another question. I have to make a graph from data I recieve. It must be in realtime. Can I have your recommendation? Maybe store the recieved data in a buffer or something so I can access it and plot a graph? Mentor suggested I use adobe flex for plotting.
Mone
Hi,
you can follow three paths:
- Plot a graph with html using our ChartTable(doc ), custom code or a third party library
- Pass your data through our FlashBridge(doc ) to a flash application and create your graph there
- Use our Actionscript client (doc ) to receive pushed data directly on your flex application.
HTH
Cyro
I'm digging through the code but have two questions. My adapter changes data very rapidly. Every 0.01 seconds. Can the client plot that recieved data that fast? And second - can CLIENT create timestamp? Like when transmission began - and in two predefined points. Say 30 sec and 60 sec from beggining?
Mone
My adapter changes data very rapidly. Every 0.01 seconds. Can the client plot that recieved data that fast?
It depends on your machine and on the client technology that you choose. Probably for the best performance you should choose the path #3 (see my previous post)
Note that you need a Vivace server to reach such update frequency:
http://www.lightstreamer.com/products.htm
If the update rate is too high for the client you can limit it.
Be sure to read the General Concepts.pdf file available under LS_HOME/DOCS-SDKs to explore all the possibilities.
can CLIENT create timestamp?
what do you mean?
Cyro
ok here's the thing. I'm simulating ECG (electrocardiogram) and I get a set of numbers ranging from -1 to 1. In adapter I send ONLY that value. No timestamp or anything. Value is generated (read from file or outside source) every 0.01 second. I managed to accept the data and I get it. But now I need to plot that line so that we can see how nice our heart beats. The thing is - bandwith is not a problem - since we're using our own servers and network (very powerfull - My college works with Ericsson :Smile_Ag: ) with very high capped bandwith. I got evaluation version of Lightstreamer Vivace. This project I'm working on will be long past done by the time license expires. And when I present the results decision will be made about buying the license.
Anyway I got carried away... I used the source from number 1 in your earlier post and copied the part which uses the graph. Problem is graph recieves two parameters. Timestamp on X axis and price on Y. Y axis is trivial since I just use the value I get but as for X axis I don't have timestamp... And I don't use schema as well. I just get one value so there's no sense in using schema for that. (I changed the range of X axis to 120 seconds since that is the amount of data we have. And Y axis is between -2 and 2 just so we have some breathing space)
Cyro
p.s. I would use Flex since it looks better but I don't even know where to start with it since I'm a total stranger. I understand a little from your example but that's far from anything usable.