Skip to content

The provided source code can be used as a starting point to familiarize with the Lightstreamer Java SE Client API

License

Notifications You must be signed in to change notification settings

Lightstreamer/Lightstreamer-example-Quickstart-client-java

Repository files navigation

Lightstreamer - Quickstart Example - Java SE Client

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.

Details

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.

Dig the Code

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 output
  • Portfolio.java is very similar to the Stocklist.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 APIs
  • PortfolioOrderEntry.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.

Screenshot

Build

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):

Follow the instructions on those projects to get them up and running (in the portfolio case, you'll need the full version).

Maven

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"

See Also

Lightstreamer Adapters Needed by This Client

Related Projects

Lightstreamer Compatibility Notes

  • 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.

About

The provided source code can be used as a starting point to familiarize with the Lightstreamer Java SE Client API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages