Lightstreamer - Stock-List Demo - Java Adapter
This project includes the resources needed to develop a Data Adapter for the Lighstreamer - Basic Stock-List Demo - HTML Client that is pluggable into Lightstreamer Server.
The Stock-List demos simulate a market data feed and front-end for stock quotes. They show a list of stock symbols and updates prices and other fields displayed on the page in real-time.
The project is comprised of source code and a deployment example.
Dig the Code
The Stock-List Data Adapter is comprised of three Java classes.
Contains the data generation logic (that is, the actual feed simulator). This is a broadcast feed, which delivers all the generated data, with no notion of subscriptions.
Handles the data delivery from the ExternalFeedSimulator to the DemoDataProvider, to better decouple the two classes.
Implements the DataProvider interface to handle the communication with Lightstreamer Kernel. Leverages the ExternalFeedListener to get the data originated by the ExternalFeedSimulator. Injects the received data into Lightstreamer Kernel or filters it out based on the subscriptions/unsubscriptions received from the Kernel.
See the source code comments for further details.
The Metadata Adapter functionalities are absolved by the
LiteralBasedProvider in Lightstreamer - Reusable Metadata Adapters - Java Adapter, a simple full implementation of a Metadata Adapter, already provided by Lightstreamer server.
The Adapter Set Configuration
This Adapter Set is configured and will be referenced by the clients as
adapters.xml file for the Stock-List Demo, should look like:
<?xml version="1.0"?> <!-- Mandatory. Define an Adapter Set and sets its unique ID. --> <adapters_conf id="DEMO"> <!-- Not all configuration options of an Adapter Set are exposed by this file. You can easily expand your configurations using the generic template, `DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml`, as a reference. --> <metadata_provider> <adapter_class>com.lightstreamer.adapters.metadata.LiteralBasedProvider</adapter_class> <!-- Optional. See LiteralBasedProvider javadoc. --> <!-- <param name="max_bandwidth">40</param> <param name="max_frequency">3</param> <param name="buffer_size">30</param> <param name="distinct_snapshot_length">10</param> <param name="prefilter_frequency">5</param> <param name="allowed_users">user123,user456</param> --> <!-- Optional. See LiteralBasedProvider javadoc. --> <param name="item_family_1">item.*</param> <param name="modes_for_item_family_1">MERGE</param> </metadata_provider> <data_provider name="QUOTE_ADAPTER"> <adapter_class>stocklist_demo.adapters.StockQuotesDataAdapter</adapter_class> <!-- Optional for StockQuotesDataAdapter. Configuration file for the Adapter's own logging. Logging is managed through log4j. --> <param name="log_config">adapters_log_conf.xml</param> <param name="log_config_refresh_seconds">10</param> </data_provider> </adapters_conf>
NOTE: not all configuration options of an Adapter Set are exposed by the file suggested above.
You can easily expand your configurations using the generic template,
DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml, as a reference.
Please refer here for more details about Lightstreamer Adapters.
If you want to install a version of the Stock-List Demo in your local Lightstreamer Server, follow these steps:
- Download Lightstreamer Server (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from Lightstreamer Download page, and install it, as explained in the
GETTING_STARTED.TXTfile in the installation home directory.
- Make sure that Lightstreamer Server is not running.
- In the
adaptersfolder of your Lightstreamer Server installation, you may find a
Demofolder, containing some adapters ready-made for several demo including the Stock-List one. If this is the case, you already have a Stock-List Demo Adapter installed and you may stop here. Please note that, in case of Demo folder already installed, the MetaData Adapter jar installed is a mixed one that combines the functionality of several demos. If the Demo folder is not installed, or you have removed it, or you want to install the Stock-List Adapter Set alone, please continue to follow the next steps.
- Get the
deploy.zipfile of the latest release, unzip it, and copy the
StockListfolder into the
adaptersfolder of your Lightstreamer Server installation.
- Launch Lightstreamer Server.
- Test the Adapter, launching the Basic Stock-List Demo - HTML Client listed in Clients Using This Adapter.
To build your own version of
LS_quote_feed_simulator.jar, instead of using the one provided in the
deploy.zip file from the Install section above, follow these steps:
- Download this project.
- Get the
ls-adapter-interface.jarfile from the
/libfolder of the latest Lightstreamer distribution, and copy it into the
- Get the
log4j-1.2.17.jarfile from Apache log4j and copy it into the
- Create the jars
LS_quote_feed_simulator.jarwith commands like these:
> mkdir tmp_classes/feed tmp_classes/adapter > javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar -sourcepath src/src_feed -d tmp_classes/feed src/src_feed/stocklist_demo/feed_simulator/ExternalFeedSimulator.java > jar cvf LS_quote_feed_simulator.jar -C tmp_classes/feed . > javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar;lib/ls-adapter-interface.jar;LS_quote_feed_simulator.jar -sourcepath src/src_adapter -d tmp_classes/adapter src/src_adapter/stocklist_demo/adapters/StockQuotesDataAdapter.java > jar cvf LS_StockListDemo_DataAdapter.jar -C tmp_classes/adapter .
- Copy the just compiled
adapters/Stocklist/libfolder of your Lightstreamer Server installation.
Clients Using This Adapter
- Lightstreamer - Reusable Metadata Adapters - Java Adapter
- Lightstreamer - Portfolio Demo - Java Adapter
The Same Demo Adapter With Other Technologies
Lightstreamer Compatibility Notes
- Compatible with Lightstreamer SDK for Java In-Process Adapters since 6.0
- For a version of this example compatible with Lightstreamer SDK for Java Adapters version 5.1, please refer to this tag.