Results 1 to 3 of 3

Thread: Using selectors

  1. #1
    Join Date
    Jul 2006
    Milan, Italy

    Using selectors

    A selector is an optional filter applied to the updates pertaining to a table subscribed by a session. The Client can specify a selector string through the setSelector() function. On the server the isSelected() callback method is invoked onto the custom Metadata Adapter for each update to decide whether the current event should be delivered to that session based on the specified selectior string.

    In COMMAND mode, a selector could be used to receive a subset of a table.
    In this example, based on the Portfolio Demo, only one of the stocks in the portfolio, namely "STOCK 04", should be received.

    The last lines of the front-end index.html page may become:
    Code javascript:
    1.   /////////////////////////////////table handler
    2.       var table = new DynaMetapushTable("portfolio", schema, "COMMAND");
    4.       table.setSelector("STOCK 04");
    5.       // the selector name follows a custom convention,
    6.       // that is imposed by the custom Metadata Adapter,
    7.       // because the latter is the only responsible
    8.       // for understanding the selector name
    9.       // and performing the requested selection
    11.       table.setSnapshotRequired(true);
    12.       table.setPushedHtmlEnabled(false);
    13.       table.setClearOnDisconnected(true);
    14.       table.onChangingValues = formatValues;
    15.       table.setMaxDynaRows("unlimited");
    16.       table.setMetapushFields(2, 1);
    17.       table.setMetapushSort(3, direction);
    19.       lsPage.addTable(table, "info");
    On the Server side, the Metadata Adapter has to be extended, so as to support the selector requests. Currently, the Portfolio Demo is not based on a custom Metadata Adapter; instead, it takes advantage of a reusable Metadata Adapter provided by Lightstreamer (the LiteralBasedProvider). So, we need to create and compile a new Metadata Adapter and then to install it into Lightstreamer Server. It can be installed by putting its "jar" file beside the Portfolio Demo's Data Adapter "jar" file, that you found in the package as:

    The new Metadata Adapter source code may be:
    Code java:
    1.     package myPackage;
    3.     import com.lightstreamer.adapters.metadata.LiteralBasedProvider;
    5.     public class myMetadataAdapter extends LiteralBasedProvider {
    7.         public boolean isSelectorAllowed(String user, String item, String selector) {
    8.             if (item.equals("portfolio")) {
    9.                 return true;
    10.             }
    11.             return false;   // the default
    12.         }
    14.         public boolean isSelected(String user, String item, String selector, ItemEvent event) {
    15.             // we expect the selector name
    16.             // to be the name of a stock to be allowed;
    17.             // no other type of selection is supported;
    19.             // Note: the "user" parameter would allow us to perform
    20.             // a selection based on the specific user
    22.             String stockName = event.getValueAsString("stock");
    23.                 // (see the Javadocs for details on the ItemEvent type)
    24.             boolean match = stockName.equals(selector);
    25.             return match;
    26.         }
    27.     }
    In order to use the new Metadata Adapter, the Portfolio Demo's adapter configuration file adapters.xml should also be changed and may become like this:
    Code xml:
    1. <?xml version="1.0"?>
    2.  <adapters_conf id="PORTFOLIO">
    4.    <metadata_provider>
    5.      <adapter_class>myPackage.myMetadataAdapter</adapter_class>
    6.      <!-- the following parameters are still managed
    7.            by superclass (LiteralBasedProvider) code -->
    8.      <param name="search_dir">.</param>
    9.      <param name="max_bandwidth">16</param>
    10.      <param name="max_frequency">5</param>
    11.      <param name="buffer_size">30</param>
    12.    </metadata_provider>
    14.    <data_provider>
    15.      <adapter_class></adapter_class>
    16.      <param name="config_file"></param>
    17.    </data_provider>
    19.  </adapters_conf>

  2. #2
    Join Date
    Aug 2007
    DKI Jaya

    Calling table.setSelector

    Dear All,
    I have several questions about calling setSelector() function.
    1.Can we change the selector parameter set before ?
    2.If we do, should we reregister the table through lspage.AddTable() function ?
    3.After we succesfully change the selector parameter, does the data will be resent from the begining but this time with new selector parameter or the selector will apply to the next messaages received ?

    regards,Dyan Dhanisworo

  3. #3
    Join Date
    Jul 2006
    Hi Dyan,

    (1, 2) The client "setSelector" method only affects the next time an "addTable" is performed. Therefore, if the selector has to change, you have to issue "removeTable", then "setSelector" then "addTable".
    (3) In this phase, the old table contents are cleared from the screen according to the settings for "setClearOnRemove" and "setClearOnAdd". Moreover, upon the new "addTable", the snapshot, if requested, is received restricted to the new selector, as the server-side "isSelected" method is consulted for both snapshot and regular updates.

    See the Table and VisualTable docs for reference.



Similar Threads

  1. Use of Selectors in COMMAND mode
    By Alessandro in forum General
    Replies: 0
    Last Post: February 2nd, 2007, 05:40 PM


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