Results 1 to 10 of 31

Thread: Action script

Hybrid View

  1. #1
    Member
    Join Date
    Jul 2009
    Location
    Zagreb
    Posts
    18

    Action script

    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 )

  2. #2
    Member
    Join Date
    Jul 2009
    Location
    Zagreb
    Posts
    18
    Quote Originally Posted by 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.DataProviderExce ption;
    import com.lightstreamer.interfaces.data.FailureException ;
    import com.lightstreamer.interfaces.data.ItemEventListene r;
    import com.lightstreamer.interfaces.data.SubscriptionExce ption;

    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(debugAl erts);
    lsPage.context.setRemoteAlertsOnClientError(remote Alerts);

    lsPage.onEngineCreation = function(lsEngine) {
    lsEngine.context.setDebugAlertsOnClientError(debug Alerts);
    lsEngine.context.setRemoteAlertsOnClientError(remo teAlerts);

    lsEngine.connection.setLSHost(pushHost);
    lsEngine.connection.setLSPort(pushPort);
    lsEngine.connection.setAdapterName("SIMPLEST");

    lsEngine.changeStatus("STREAMING");
    }

    lsPage.bind();
    lsPage.createEngine("SimplestEng","LS","SHARE_SESS ION");

    ///////////////////////Table configuration



    var table1 = new OverwriteTable(stream, null, "RAW");
    table1.setClearOnDisconnected(true);
    table1.setClearOnRemove(true);
    lsPage.addTable(table1, "table1");



    </script>
    </body>

    </html>

  3. #3
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    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:

    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:


    specifying null so that the table will read the item list from the associated html element(s):



    For javascript debug I advice you to use firefox with the firebug plugin.
    HTH

  4. #4
    Member
    Join Date
    Jul 2009
    Location
    Zagreb
    Posts
    18
    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

  5. #5
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    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

  6. #6
    Member
    Join Date
    Jul 2009
    Location
    Zagreb
    Posts
    18
    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.

 

 

Similar Threads

  1. IE script warning
    By jonasby1 in forum Client SDKs
    Replies: 3
    Last Post: July 27th, 2011, 10:58 AM
  2. Replies: 5
    Last Post: December 23rd, 2010, 09:34 AM
  3. Unresponsive Script
    By vaduganathan in forum Client SDKs
    Replies: 1
    Last Post: March 23rd, 2010, 03:38 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 02:00 PM.