Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Nov 2006
    Location
    Riyadh
    Posts
    33

    Adding/Removing item in subscribed group

    Hi all,

    I have the following scenario:
    - HTML subscribes to a group item = "List1" using NonVisualTable() and lsPage.addTable()
    - MetaAdapter resolves List1 and returns a list of items (dymanic)

    I'd like to subscribe to a new item in the same table without unsubscribing and subscribing to the previou group item.
    I also would like to unsubscibe a specific item in the same table without unsubscribing and subscribing to the previous group item.

    How an I achive this ?

    Regards,

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan, Italy
    Posts
    517
    There are basically two ways to accomplish what you need.

    FIRST WAY

    When you need fine-grained dynamic subscriptions and unsubscriptions and want to decouple the life cycle of the items, the strategy to choose is to use one different NonVisualTable for each item. In this ways you will only have single-item tables and you will be free to add and remove items without impacting existing subscription.

    Lightstreamer APIs handle this scenario in a very efficient way too.

    This solution implies that you cannot use a group name anymore to subscribe to the items, because you need to give up the concept of group (since items in the same group necessarily share the same life cycle). So you will have to resolve the group through a very traditional request/response call to your web application server (i.e. your web application needs to know the initial list contents).

    SECOND WAY

    You can use so called meta-push through a DynaMetapushTable and COMMAND subscription mode. In this way Lightstreamer Server will push commands to the Client in order to dynamically add and remove rows from a table (in this case the whole table will be an item and each row is identified by a key).

    For a full example of this strategy, with source code, please refer to the Portfolio Demo.

  3. #3
    Senior Member
    Join Date
    Nov 2006
    Location
    Riyadh
    Posts
    33
    Thanks Alex for you prompt answer.

    Can Option 2 be used to push COMMAND messages to specific users ?
    In the sample you provided (portfolio), all users share the same group item.
    In my case, when a user requests to add/remove an item from a group (List.1), only him should be impacted. But it seems to me COMMAND is global, right ?

    Regards

  4. #4
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    Hi,

    You're right, the COMMAND message and in general all updates are sent to all the clients subscribed to the specific item.

    Note that you can - starting from a common name client-side - modify users subscriptions server-side:
    In the MetadataProvider interface there is a method called getItems. You can implement it to customize the items to be subscribed per each user.

    Hope that helps,
    Goodbye.

    PS: you can also implement the customizeUpdate method to customize each update on an user basis. Btw take count of the advices of the JavaDocs.

  5. #5
    Administrator
    Join Date
    Jul 2006
    Location
    Milan, Italy
    Posts
    517

    Lightbulb

    To answer your question from a more general point of view, yes, you can certainly push different commands to different clients. To do this you will either use a different group descriptor for each user or the same group descriptor with the Metadata Adapter expanding it to different items names based on the user identity (see the explanation below). Remember that In COMMAND mode an item defines a whole table (e.g. a set of stocks). This means that if different users must see different table rows, then they should subscribe to different items.

    Example.
    Let's imagine a typical Portoflio subscribed in COMMAND mode. Here are the relevant steps:
    1. [Client] The LightstreamerEngine is created, and the user's credentials are provided through:
      Code javascript:
      1. connection.setUserName(“alex”);
      2. connection.setPassword(“mypassword”);
    2. [Client] You add a Portfolio table template to your page and perform a corresponding subscription in COMMAND mode through an addTable(). The Table constructor will be for example:
      Code javascript:
      1. new DynaMetapushTable("portfolio", "key command stock price qty cval time", "COMMAND")
      This means that the group descriptor is “portfolio”. See DynaMetaPushTable.
    3. [Server] The Metadata Adapter receives this method call:
      Code java:
      1. getItems(“alex”, “portfolio”)
      and it responds with:
      {“alex-portfolio”}
    4. [Server] The Data Adapter receives this method call:
      Code java:
      1. subscribe(“alex-portfolio”, false)
      At this point the Data Adapter queries a DB to retrieve the current content of Alex’s portfolio, getting a list of stocks, quantities, etc.
      The Data Adapter subscribes to any stocks of that list that it is not already subscribed to.
      The Data Adapter subscribes to a topic that delivers any changes in the portfolio content for Alex.
      The Data Adapter delivers the snapshot of Alex’s portfolio (comprised of a series of “ADD” commands).
    5. [Server] Each time the Data Adapter receives an event from the stock-quote feed or from the portfolio-content feed, it consults its internal tables and delivers a command to the client, that can be “ADD”, “UPDATE” or “DELETE”.

 

 

Similar Threads

  1. Adding or Removing Subscriptions
    By subuta in forum Client APIs
    Replies: 4
    Last Post: December 27th, 2011, 04:03 PM
  2. Replies: 2
    Last Post: December 24th, 2010, 08:51 AM
  3. Adding/Removing items dynamically
    By Otake in forum Client APIs
    Replies: 5
    Last Post: December 17th, 2009, 03:15 PM
  4. IG Group's cool applications
    By Alessandro in forum General
    Replies: 6
    Last Post: July 1st, 2008, 03:26 PM
  5. Changing subscribed topic
    By simonef in forum Client APIs
    Replies: 1
    Last Post: June 10th, 2008, 02:47 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 09:05 PM.