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>it.soltec.lightstream_adapters.data.portfolio.PortfolioDemoProvider</adapter_class>
  16.      <param name="config_file">portfolio.conf.properties</param>
  17.    </data_provider>
  19.  </adapters_conf>