public class LightstreamerClient
extends java.lang.Object
Subscription
handling and to send messages.Modifier and Type | Field and Description |
---|---|
ConnectionDetails |
connectionDetails
Bean object that contains the details needed to open a connection to
a Lightstreamer Server.
|
ConnectionOptions |
connectionOptions
Bean object that contains options and policies for the connection to
the server.
|
static java.lang.String |
LIB_NAME
A constant string representing the name of the library.
|
static java.lang.String |
LIB_VERSION
A constant string representing the version of the library.
|
Constructor and Description |
---|
LightstreamerClient(java.lang.String serverAddress,
java.lang.String adapterSet)
Creates an object to be configured to connect to a Lightstreamer server
and to handle all the communications with it.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(ClientListener listener)
Adds a listener that will receive events from the LightstreamerClient instance.
The same listener can be added to several different LightstreamerClient instances. |
void |
connect()
Operation method that requests to open a Session against the configured Lightstreamer Server.
When connect() is called, unless a single transport was forced through ConnectionOptions.setForcedTransport(String) , the so called "Stream-Sense" mechanism is started:
if the client does not receive any answer for some seconds from the streaming connection, then it
will automatically open a polling connection.A polling connection may also be opened if the environment is not suitable for a streaming connection. Note that as "polling connection" we mean a loop of polling requests, each of which requires opening a synchronous (i.e. |
void |
disconnect()
Operation method that requests to close the Session opened against the configured Lightstreamer Server
(if any).
When disconnect() is called, the "Stream-Sense" mechanism is stopped. Note that active Subscription instances, associated with this LightstreamerClient instance, are preserved to be re-subscribed to on future Sessions. |
java.util.List<ClientListener> |
getListeners()
Returns a list containing the
ClientListener instances that were added to this client. |
java.lang.String |
getStatus()
Inquiry method that gets the current client status and transport (when applicable).
|
java.util.List<Subscription> |
getSubscriptions()
Inquiry method that returns a list containing all the Subscription instances that are
currently "active" on this LightstreamerClient.
Internal second-level Subscription are not included. |
void |
removeListener(ClientListener listener)
Removes a listener from the LightstreamerClient instance so that it will not receive events anymore.
|
void |
sendMessage(java.lang.String message)
A simplified version of the
sendMessage(String,String,int,ClientMessageListener,boolean) . |
void |
sendMessage(java.lang.String message,
java.lang.String sequence,
int delayTimeout,
ClientMessageListener listener,
boolean enqueueWhileDisconnected)
Operation method that sends a message to the Server.
|
static void |
setLoggerProvider(com.lightstreamer.log.LoggerProvider provider)
Static method that permits to configure the logging system used by the library.
|
void |
subscribe(Subscription subscription)
Operation method that adds a Subscription to the list of "active" Subscriptions.
|
void |
unsubscribe(Subscription subscription)
Operation method that removes a Subscription that is currently in the "active" state.
By bringing back a Subscription to the "inactive" state, the unsubscription from all its items is requested to Lightstreamer Server. |
public static final java.lang.String LIB_NAME
public static final java.lang.String LIB_VERSION
public final ConnectionOptions connectionOptions
public final ConnectionDetails connectionDetails
public LightstreamerClient(java.lang.String serverAddress, java.lang.String adapterSet)
serverAddress
- the address of the Lightstreamer Server to
which this LightstreamerClient will connect to. It is possible to specify it later
by using null here. See ConnectionDetails.setServerAddress(String)
for details.adapterSet
- the name of the Adapter Set mounted on Lightstreamer Server
to be used to handle all requests in the Session associated with this
LightstreamerClient. It is possible not to specify it at all or to specify
it later by using null here. See ConnectionDetails.setAdapterSet(String)
for details.java.lang.IllegalArgumentException
- if a not valid address is passed. See
ConnectionDetails.setServerAddress(String)
for details.public static void setLoggerProvider(com.lightstreamer.log.LoggerProvider provider)
provider
- A LoggerProvider
instance that will be used to generate log messages by the library classes.public void addListener(ClientListener listener)
listener
- An object that will receive the events as documented in the
ClientListener interface.removeListener(ClientListener)
public void removeListener(ClientListener listener)
listener
- The listener to be removed.addListener(ClientListener)
public java.util.List<ClientListener> getListeners()
ClientListener
instances that were added to this client.addListener(ClientListener)
public void connect()
ConnectionOptions.setForcedTransport(String)
, the so called "Stream-Sense" mechanism is started:
if the client does not receive any answer for some seconds from the streaming connection, then it
will automatically open a polling connection.java.lang.IllegalStateException
- if no server address was configured.getStatus()
,
disconnect()
,
ClientListener.onStatusChange(String)
,
ConnectionDetails.setServerAddress(String)
getStatus()
right after connect() might not reflect the change yet.public void disconnect()
connect()
getStatus()
right after disconnect() might not reflect the change yet.public java.lang.String getStatus()
ClientListener.onStatusChange(String)
public void subscribe(Subscription subscription)
subscription
- A Subscription object, carrying all the information needed to process its pushed values.unsubscribe(Subscription)
unsubscribe(Subscription)
.SubscriptionListener.onSubscription()
event.public void unsubscribe(Subscription subscription)
subscription
- An "active" Subscription object that was activated by this LightstreamerClient
instance.SubscriptionListener.onUnsubscription()
event.public java.util.List<Subscription> getSubscriptions()
subscribe(Subscription)
public void sendMessage(java.lang.String message)
sendMessage(String,String,int,ClientMessageListener,boolean)
.
The internal implementation will call
sendMessage(message,null,0,null,false);
message
- a text message, whose interpretation is entirely demanded to the Metadata Adapter
associated to the current connection.public void sendMessage(java.lang.String message, java.lang.String sequence, int delayTimeout, ClientMessageListener listener, boolean enqueueWhileDisconnected)
message
- a text message, whose interpretation is entirely demanded to the Metadata Adapter
associated to the current connection.sequence
- an alphanumeric identifier, used to identify a subset of messages to be managed in sequence;
underscore characters are also allowed. If the "UNORDERED_MESSAGES" identifier is supplied, the message will
be processed in the special way described above. The parameter is optional; if set to null, "UNORDERED_MESSAGES"
is used as the sequence name.delayTimeout
- a timeout, expressed in milliseconds. If higher than the Server default timeout, the
latter will be used instead.listener
- an object suitable for receiving notifications about the processing outcome. The parameter is
optional; if not supplied, no notification will be available.enqueueWhileDisconnected
- if this flag is set to true, and the client is in a disconnected status when
the provided message is handled, then the message is not aborted right away but is queued waiting for a new
session. Note that the message can still be aborted later when a new session is established.ClientMessageListener.onAbort(java.lang.String, boolean)
event will be fired.