-
January 23rd, 2007, 04:50 PM
#1
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:
/////////////////////////////////table handler
var table = new DynaMetapushTable("portfolio", schema, "COMMAND");
table.setSelector("STOCK 04");
// the selector name follows a custom convention,
// that is imposed by the custom Metadata Adapter,
// because the latter is the only responsible
// for understanding the selector name
// and performing the requested selection
table.setSnapshotRequired(true);
table.setPushedHtmlEnabled(false);
table.setClearOnDisconnected(true);
table.onChangingValues = formatValues;
table.setMaxDynaRows("unlimited");
table.setMetapushFields(2, 1);
table.setMetapushSort(3, direction);
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:
package myPackage;
import com.lightstreamer.adapters.metadata.LiteralBasedProvider;
public class myMetadataAdapter extends LiteralBasedProvider {
if (item.equals("portfolio")) {
return true;
}
return false; // the default
}
// we expect the selector name
// to be the name of a stock to be allowed;
// no other type of selection is supported;
// Note: the "user" parameter would allow us to perform
// a selection based on the specific user
String stockName
= event.
getValueAsString("stock");
// (see the Javadocs for details on the ItemEvent type)
boolean match = stockName.equals(selector);
return match;
}
}
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:
<?xml version="1.0"?>
<adapters_conf id="PORTFOLIO">
<metadata_provider>
<adapter_class>myPackage.myMetadataAdapter</adapter_class>
<!-- the following parameters are still managed
by superclass (LiteralBasedProvider) code -->
<param name="search_dir">.</param>
<param name="max_bandwidth">16</param>
<param name="max_frequency">5</param>
<param name="buffer_size">30</param>
</metadata_provider>
<data_provider>
<adapter_class>it.soltec.lightstream_adapters.data.portfolio.PortfolioDemoProvider</adapter_class>
<param name="config_file">portfolio.conf.properties</param>
</data_provider>
</adapters_conf>
-
December 21st, 2007, 03:25 PM
#2
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
-
December 24th, 2007, 09:02 AM
#3
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
-
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
-
Forum Rules
All times are GMT +1. The time now is 04:08 PM.
Bookmarks