Results 1 to 8 of 8
  1. #1

    Streaming 2 or more items parallel

    Hi,

    I got this code from the ".NET HelloWorld Example":
    Code:
    while (go)
            {
                IDictionary eventData = new Hashtable();
                eventData["message"] = c % 2 == 0 ? "Hello" : "World";
                eventData["timestamp"] = DateTime.Now.ToString("s");
                _listener.Update("greetings", eventData, false);
                c++;
                Thread.Sleep(1000 + rand.Next(2000));
            }
    In the code above, we can only update 1 item "greetings" at a time, is it right ?

    But i have more than 1, and i want it to be streamed parallely, like the Stock (Stock A and Stock B has different values at a time), can someone tell me how to do this? I thought i must use 1 Thread per item to stream parallely but i'm just a beginner

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    716
    How to model the internal architecture of a Data Adapter depends on several factors, including, maybe the most important, is what kind of the data source is available.

    Anyway, here you can find the implementation of an example in which updates for 30 Items, relating to 30 different stocks, are pushed into Lighstreamer server.

  3. #3
    Quote Originally Posted by giuseppe.corti View Post
    How to model the internal architecture of a Data Adapter depends on several factors, including, maybe the most important, is what kind of the data source is available.

    Anyway, here you can find the implementation of an example in which updates for 30 Items, relating to 30 different stocks, are pushed into Lighstreamer server.
    The example you gave me is too tough, i cant understand all those codes.
    My problem is only how to stream parallely. Lets say, i have one more item "greetings2". Its "message" and "timestamp" completely different from the old "greeting". How can i stream these 2 items parallely. Thats my problem.

  4. #4
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    716
    Please, let me repeat that this depends on the type of data source.
    Yes, you are right, if you have only 2, or few more, Items powered by different sources, for example two distinct socket streams, then the simplest solution is to create two parallel threads which are waiting for the updates to be pushed into Lightstreamer server.

    But please consider that if the number of Items grows up to hundreds or thousands then the solution proposed would become unmanageable and you should re-model the Adapter with an asynchronous management of data feeders.

    Anyway, if you expand a little more on how the Items updates are generated/received I think we can help you better.

  5. #5
    Quote Originally Posted by giuseppe.corti View Post
    Please, let me repeat that this depends on the type of data source.
    Yes, you are right, if you have only 2, or few more, Items powered by different sources, for example two distinct socket streams, then the simplest solution is to create two parallel threads which are waiting for the updates to be pushed into Lightstreamer server.

    But please consider that if the number of Items grows up to hundreds or thousands then the solution proposed would become unmanageable and you should re-model the Adapter with an asynchronous management of data feeders.

    Anyway, if you expand a little more on how the Items updates are generated/received I think we can help you better.
    Okay okay.


    • I have a database (SQL Server 2008) and a table. I have some codes (C#) to insert rows into this table. Random seconds per row.
    • On the web client, i have three Items, which has Status field like: item "A" has status "OK", item "B" has "Warning" ...
    • So whenever the row is inserted into the table (item A, status OK), i want my web show like that too. Similar for item B (When the code randomly insert item B row, Item B will change)


    Im trying to use SqlDependancy to catch the row inserted event. When the event insert is fired, i will select the only one last row of that table and stream the content to Lightstreamer.

    And that's it. I dont know what im doing is right or wrong. Please help me with this.

  6. #6
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    If you have an external source that notifies you of the changes in your data (as, in this case, a "row inserted" event), then the reception of the notification is the right place in which you can invoke "Update".
    As you can see, in this case, you don't have to create your own threads, but you can just lean on the threads used by your external source to issue the notifications.

    The only problem for you is to ensure that, if multiple rows are inserted at once, you will invoke Update once for each new row and in the same order.
    In particular, if you have separated the data in three items, then what is important is that subsequent rows inserted for the same item give rise to invocations of Update in the same order.
    Once you have ensured that, your client will receive the real-time updates correctly.

  7. #7

    Smile

    Quote Originally Posted by DarioCrivelli View Post
    If you have an external source that notifies you of the changes in your data (as, in this case, a "row inserted" event), then the reception of the notification is the right place in which you can invoke "Update".
    As you can see, in this case, you don't have to create your own threads, but you can just lean on the threads used by your external source to issue the notifications.

    The only problem for you is to ensure that, if multiple rows are inserted at once, you will invoke Update once for each new row and in the same order.
    In particular, if you have separated the data in three items, then what is important is that subsequent rows inserted for the same item give rise to invocations of Update in the same order.
    Once you have ensured that, your client will receive the real-time updates correctly.
    Okay never mind, i got this :d . By the way, please help me one more thing. I got the Run method below:
    Code:
    public void Run()
      {    
         go = true;
         int c = 0; 
         Random rand = new Random();
          while (go)      {              
              IDictionary eventData = new Hashtable();
              eventData["message"] = c % 2 == 0 ? "Hello" : "World";       
              eventData["timestamp"] = DateTime.Now.ToString("s");
              _listener.Update("greetings", eventData, false);  
              c++;       
              Thread.Sleep(1000 + rand.Next(2000));      
        }  
    }
    How can i pass some parameters to this method? Coz if i do that, i get stuck the code below
    Code:
    Thread t = new Thread(new ThreadStart(Run));
    t.Start();
    I dont want to hard code like eventData["message"] or listener.update("greetings"). I want something like eventData[string] or listener.update(fieldname) (string and fieldname will be treated as arguments)

    Thanks in advance
    Last edited by vielktus; November 8th, 2013 at 03:27 AM.

  8. #8
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    This is a question for a C# theorist, actually.
    One syntax we happened to use involves delegates, that is, a form like this:
    Code:
    String fld1 = "message";
    String fld2 = "timestamp";
    String it1 = "greetings";
    Thread t = new Thread(new ThreadStart(delegate() {
        go = true;
        int c = 0;
        Random rand = new Random();
        while (go)
        {
            IDictionary eventData = new Hashtable();
            eventData[fld1] = c % 2 == 0 ? "Hello" : "World";
            eventData[fld2] = DateTime.Now.ToString("s");
            _listener.Update(it1, eventData, false);
            c++;
            Thread.Sleep(1000 + rand.Next(2000));
        }
    }));
    
    t.Start();

 

 

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:43 PM.