The Quickstart Example provides the source code to build very simple and basic client applications, used to test the capability of the Client APIs to connect and receive data from Lightstreamer Server. The examples can be used to familiarize with the Client APIs and as a reference on how to use them, and can be used as a starting point for client application implementations.
This project contains the Java source files of some sample applications, that shows how the Lightstreamer Java SE Client API can be used to connect to Lightstreamer Server.
The Lightstreamer Java SE Client API is used to connect to Lightstreamer, subscribe to available items and to send messages to the server. Automatic reconnections and resubscriptions are offered out-of-the-box by the library itself. All the available methods are non-blocking so they execute fast, network and other time-consuming operations are handled on dedicated threads; methods are synchronized among themselves though, so calling many methods on the same instance from different threads at the same time might still slow down things a bit.
Each source class (excluding the SystemOutClientListener) is an independent application with its own main() method. They generally connect to the server and perform a subscription, printing on the console the incoming Item Updates. Only PortfolioOrderEntry behaves differently, as it just submits a message and closes.
To resume, under src/quickstart you'll find:
SystemOutClientListener.java
is a simple implementation of the ClientListener interface that is used by the other examples. An instance of this class, listening to a LightstreamerClient instance (through the addListener method) will print on the standard output information about the status of the connection.Stocklist.java
is a simple application that subscribes to 15 stocks (MERGE) and prints all the updates on the standard outputPortfolio.java
is very similar to theStocklist.java
example, but, in this case a 2-level subscription, representing a portfolio (COMMAND) is shown. The second level is obtained using the same stock data (MERGE) used by the previous example.Chat.java
is a simple application that subscribes to the chat item (DISTINCT) on a Lightstreamer server and then accepts command from the standard input to send messages, connect/disconnect subscribe/unsubscribe and others making it possible to easily experiment with the APIsPortfolioOrderEntry.java
sends a message representing an order based on the program arguments, waits for the Server response, and prints it; then closes. The effect of the order submission can be seen by running Portfolio.java concurrently.Main.java
utility class for launch through Maven.
To build and install a version of this demo you have two options: either use Maven (or other build tools) to take care of dependencies and building (recommended) or gather the necessary jars yourself and build it manually. For the sake of simplicity only the maven case is detailed here.
In both cases, if you plan to point the examples to your own server, you'll need to install the following adapters (depending on which quickstart example you want to run you might not need them all):
- The CHAT_ROOM (see the Lightstreamer - Basic Chat Demo - Java Adapter).
- The QUOTE_ADAPTER (see the Lightstreamer - Stock-List Demo - Java Adapter)
- The PORTFOLIO_ADAPTER ( see the Lightstreamer - Portfolio Demo - Java Adapter),
Follow the instructions on those projects to get them up and running (in the portfolio case, you'll need the full version).
You can easily build and run this application using Maven through the pom.xml file located in the root folder of this project.As an alternative, you can use an alternative build tool (e.g. Gradle, Ivy, etc.) by converting the provided pom.xml file.
Assuming Maven is installed and available in your path you can build the demo by running
mvn package
You can also run the application with the following command
mvn exec:java -Dexec.args="chat http://push.lightstreamer.com"
the arguments in the above command select the example to run (and must be either "chat", "stocklist", "portfolio", or "orderentry") and the target Lightstreamer server. Only for "orderentry", the command should also specify an item name supported by the Portfolio Data Adapter and a quantity (possibly negative), like in
mvn exec:java -Dexec.args="orderentry http://push.lightstreamer.com item1 100"
- Lightstreamer - Stock-List Demo - Java Adapter
- Lightstreamer - Portfolio Demo - Java Adapter
- Lightstreamer - Chat Demo - Java Adapter
- Lightstreamer - Reusable Metadata Adapters - Java Adapter
- Compatible with Lightstreamer Java SE Client SDK 5.0 or newer.
- For Lightstreamer Server 7.4.0 or newer. Ensure that Java SE Client API is supported by Lightstreamer Server license configuration.
- For a version of this example compatible with Lightstreamer Java Client API version 4.x, please refer to this tag.
- For a version of this example compatible with Lightstreamer Java Client API version 3.x, please refer to this tag.
- For a version of this example compatible with Lightstreamer Java Client API version 2.5.2, please refer to this tag.