public class Subscription
extends java.lang.Object
LightstreamerClient.subscribe(Subscription)
method, its state becomes "active".
This means that the client activates a subscription to the required items through
Lightstreamer Server and the Subscription object begins to receive real-time events. setItemGroup(String)
method.setItems(String[])
method or by specifying it in the constructor.setFieldSchema(String)
method.setFields(String[])
method or by specifying it in the constructor.Constructor and Description |
---|
Subscription(java.lang.String subscriptionMode)
Creates an object to be used to describe a Subscription that is going to be subscribed to
through Lightstreamer Server.
|
Subscription(java.lang.String subscriptionMode,
java.lang.String[] items,
java.lang.String[] fields)
Creates an object to be used to describe a Subscription that is going to be subscribed to
through Lightstreamer Server.
|
Subscription(java.lang.String subscriptionMode,
java.lang.String item,
java.lang.String[] fields)
Creates an object to be used to describe a Subscription that is going to be subscribed to
through Lightstreamer Server.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(SubscriptionListener listener)
Adds a listener that will receive events from the Subscription instance.
|
int |
getCommandPosition()
Returns the position of the "command" field in a COMMAND Subscription.
|
java.lang.String |
getCommandSecondLevelDataAdapter()
Inquiry method that can be used to read the second-level Data Adapter name configured
through
setCommandSecondLevelDataAdapter(String) . |
java.lang.String[] |
getCommandSecondLevelFields()
Inquiry method that can be used to read the "Field List" specified for second-level
Subscriptions.
|
java.lang.String |
getCommandSecondLevelFieldSchema()
Inquiry method that can be used to read the "Field Schema" specified for second-level
Subscriptions.
|
java.lang.String |
getCommandValue(int itemPos,
java.lang.String keyValue,
int fieldPos)
Returns the latest value received for the specified item/key/field combination.
|
java.lang.String |
getCommandValue(int itemPos,
java.lang.String keyValue,
java.lang.String fieldName)
Returns the latest value received for the specified item/key/field combination.
|
java.lang.String |
getCommandValue(java.lang.String itemName,
java.lang.String keyValue,
int fieldPos)
Returns the latest value received for the specified item/key/field combination.
|
java.lang.String |
getCommandValue(java.lang.String itemName,
java.lang.String keyValue,
java.lang.String fieldName)
Returns the latest value received for the specified item/key/field combination.
|
java.lang.String |
getDataAdapter()
Inquiry method that can be used to read the name of the Data Adapter specified for this
Subscription through
setDataAdapter(String) . |
java.lang.String[] |
getFields()
Inquiry method that can be used to read the "Field List" specified for this Subscription.
|
java.lang.String |
getFieldSchema()
Inquiry method that can be used to read the field schema specified for this Subscription.
|
java.lang.String |
getItemGroup()
Inquiry method that can be used to read the item group specified for this Subscription.
|
java.lang.String[] |
getItems()
Inquiry method that can be used to read the "Item List" specified for this Subscription.
|
int |
getKeyPosition()
Returns the position of the "key" field in a COMMAND Subscription.
|
java.util.List<SubscriptionListener> |
getListeners()
Returns a list containing the
SubscriptionListener instances that were
added to this client. |
java.lang.String |
getMode()
Inquiry method that can be used to read the mode specified for this
Subscription.
|
java.lang.String |
getRequestedBufferSize()
Inquiry method that can be used to read the buffer size, configured though
setRequestedBufferSize(java.lang.String) , to be requested to the Server for
this Subscription. |
java.lang.String |
getRequestedMaxFrequency()
Inquiry method that can be used to read the max frequency, configured
through
setRequestedMaxFrequency(String) , to be requested to the
Server for this Subscription. |
java.lang.String |
getRequestedSnapshot()
Inquiry method that can be used to read the snapshot preferences,
configured through
setRequestedSnapshot(String) , to be requested
to the Server for this Subscription. |
java.lang.String |
getSelector()
Inquiry method that can be used to read the selector name
specified for this Subscription through
setSelector(String) . |
java.lang.String |
getValue(int itemPos,
int fieldPos)
Returns the latest value received for the specified item/field pair.
|
java.lang.String |
getValue(int itemPos,
java.lang.String fieldName)
Returns the latest value received for the specified item/field pair.
|
java.lang.String |
getValue(java.lang.String itemName,
int fieldPos)
Returns the latest value received for the specified item/field pair.
|
java.lang.String |
getValue(java.lang.String itemName,
java.lang.String fieldName)
Returns the latest value received for the specified item/field pair.
|
boolean |
isActive()
Inquiry method that checks if the Subscription is currently "active" or not.
|
boolean |
isSubscribed()
Inquiry method that checks if the Subscription is currently subscribed to
through the server or not.
|
void |
removeListener(SubscriptionListener listener)
Removes a listener from the Subscription instance so that it will not receive
events anymore.
|
void |
setCommandSecondLevelDataAdapter(java.lang.String dataAdapter)
Setter method that sets the name of the second-level Data Adapter (within
the Adapter Set used by the current session) that supplies all the
second-level items.
|
void |
setCommandSecondLevelFields(java.lang.String[] fields)
Setter method that sets the "Field List" to be subscribed to through
Lightstreamer Server for the second-level items.
|
void |
setCommandSecondLevelFieldSchema(java.lang.String schemaName)
Setter method that sets the "Field Schema" to be subscribed to through
Lightstreamer Server for the second-level items.
|
void |
setDataAdapter(java.lang.String dataAdapter)
Setter method that sets the name of the Data Adapter
(within the Adapter Set used by the current session)
that supplies all the items for this Subscription.
|
void |
setFields(java.lang.String[] fields)
Setter method that sets the "Field List" to be subscribed to through
Lightstreamer Server.
|
void |
setFieldSchema(java.lang.String schemaName)
Setter method that sets the "Field Schema" to be subscribed to through
Lightstreamer Server.
|
void |
setItemGroup(java.lang.String groupName)
Setter method that sets the "Item Group" to be subscribed to through
Lightstreamer Server.
|
void |
setItems(java.lang.String[] items)
Setter method that sets the "Item List" to be subscribed to through
Lightstreamer Server.
|
void |
setRequestedBufferSize(java.lang.String size)
Setter method that sets the length to be requested to Lightstreamer
Server for the internal queuing buffers for the items in the Subscription.
|
void |
setRequestedMaxFrequency(java.lang.String freq)
Setter method that sets the maximum update frequency to be requested to
Lightstreamer Server for all the items in the Subscription.
|
void |
setRequestedSnapshot(java.lang.String required)
Setter method that enables/disables snapshot delivery request for the
items in the Subscription.
|
void |
setSelector(java.lang.String selector)
Setter method that sets the selector name for all the items in the
Subscription.
|
public Subscription(@Nonnull java.lang.String subscriptionMode, @Nonnull java.lang.String[] items, @Nonnull java.lang.String[] fields)
LightstreamerClient.subscribe(Subscription)
and
LightstreamerClient.unsubscribe(Subscription)
, in order to bring the Subscription
to "active" or back to "inactive" state. setRequestedMaxFrequency(String)
.subscriptionMode
- the subscription mode for the items, required by Lightstreamer Server.
Permitted values are:
items
- an array of items to be subscribed to through Lightstreamer server. setItems(String[])
and setItemGroup(java.lang.String)
.fields
- an array of fields for the items to be subscribed to through Lightstreamer Server. setFields(String[])
and setFieldSchema(String)
.java.lang.IllegalArgumentException
- If no or invalid subscription mode is passed.java.lang.IllegalArgumentException
- If either the items or the fields array is left null.java.lang.IllegalArgumentException
- If the specified "Item List" or "Field List" is not valid;
see setItems(String[])
and setFields(String[])
for details.public Subscription(@Nonnull java.lang.String subscriptionMode, @Nonnull java.lang.String item, @Nonnull java.lang.String[] fields)
LightstreamerClient.subscribe(Subscription)
and
LightstreamerClient.unsubscribe(Subscription)
, in order to bring the Subscription
to "active" or back to "inactive" state. setRequestedMaxFrequency(String)
.subscriptionMode
- the subscription mode for the items, required by Lightstreamer Server.
Permitted values are:
item
- the item name to be subscribed to through Lightstreamer Server.fields
- an array of fields for the items to be subscribed to through Lightstreamer Server. setFields(String[])
and setFieldSchema(String)
.java.lang.IllegalArgumentException
- If no or invalid subscription mode is passed.java.lang.IllegalArgumentException
- If either the item or the fields array is left null.java.lang.IllegalArgumentException
- If the specified "Field List" is not valid;
see setFields(String[])
for details..public Subscription(@Nonnull java.lang.String subscriptionMode)
LightstreamerClient.subscribe(Subscription)
and
LightstreamerClient.unsubscribe(Subscription)
, in order to bring the Subscription
to "active" or back to "inactive" state. setRequestedMaxFrequency(String)
.subscriptionMode
- the subscription mode for the items, required by Lightstreamer Server.
Permitted values are:
public void addListener(@Nonnull SubscriptionListener listener)
listener
- An object that will receive the events as documented in the
SubscriptionListener interface.removeListener(SubscriptionListener)
public void removeListener(@Nonnull SubscriptionListener listener)
listener
- The listener to be removed.addListener(SubscriptionListener)
@Nonnull public java.util.List<SubscriptionListener> getListeners()
SubscriptionListener
instances that were
added to this client.addListener(SubscriptionListener)
public boolean isActive()
LightstreamerClient.subscribe(Subscription)
method and back to
"inactive" through the LightstreamerClient.unsubscribe(Subscription)
one.LightstreamerClient.subscribe(Subscription)
,
LightstreamerClient.unsubscribe(Subscription)
public boolean isSubscribed()
LightstreamerClient.unsubscribe(Subscription)
calls and server
sent unsubscription events.@Nullable public java.lang.String getDataAdapter()
setDataAdapter(String)
.public void setDataAdapter(@Nullable java.lang.String dataAdapter)
dataAdapter
- the name of the Data Adapter. A null value
is equivalent to the "DEFAULT" name.java.lang.IllegalStateException
- if the Subscription is currently
"active".ConnectionDetails.setAdapterSet(String)
@Nonnull public java.lang.String getMode()
@Nonnull public java.lang.String[] getItems()
java.lang.IllegalStateException
- if the Subscription was initialized with an "Item Group"
or was not initialized at all.public void setItems(@Nullable java.lang.String[] items)
items
- an array of items to be subscribed to through the server.java.lang.IllegalArgumentException
- if any of the item names in the "Item List"
contains a space or is a number or is empty/null.java.lang.IllegalStateException
- if the Subscription is currently
"active".@Nonnull public java.lang.String getItemGroup()
java.lang.IllegalStateException
- if the Subscription was initialized with an "Item List"
or was not initialized at all.public void setItemGroup(@Nullable java.lang.String groupName)
groupName
- A String to be expanded into an item list by the
Metadata Adapter.java.lang.IllegalStateException
- if the Subscription is currently
"active".@Nonnull public java.lang.String[] getFields()
java.lang.IllegalStateException
- if the Subscription was initialized with a "Field Schema"
or was not initialized at all.public void setFields(@Nullable java.lang.String[] fields)
fields
- an array of fields to be subscribed to through the server.java.lang.IllegalArgumentException
- if any of the field names in the list
contains a space or is empty/null.java.lang.IllegalStateException
- if the Subscription is currently
"active".@Nonnull public java.lang.String getFieldSchema()
java.lang.IllegalStateException
- if the Subscription was initialized with a "Field List" or was
not initialized at all.public void setFieldSchema(@Nullable java.lang.String schemaName)
schemaName
- A String to be expanded into a field list by the
Metadata Adapter.java.lang.IllegalStateException
- if the Subscription is currently
"active".@Nullable public java.lang.String getRequestedBufferSize()
setRequestedBufferSize(java.lang.String)
, to be requested to the Server for
this Subscription.public void setRequestedBufferSize(@Nullable java.lang.String size)
size
- An integer number, representing the length of the internal queuing buffers
to be used in the Server. If the string "unlimited" is supplied, then no buffer
size limit is requested (the check is case insensitive). It is also possible
to supply a null value to stick to the Server default (which currently
depends on the subscription mode).java.lang.IllegalStateException
- if the Subscription is currently
"active".java.lang.IllegalArgumentException
- if the specified value is not
null nor "unlimited" nor a valid positive integer number.setRequestedMaxFrequency(String)
@Nullable public java.lang.String getRequestedSnapshot()
setRequestedSnapshot(String)
, to be requested
to the Server for this Subscription.public void setRequestedSnapshot(@Nullable java.lang.String required)
required
- "yes"/"no" to request/not request snapshot
delivery (the check is case insensitive). If the Subscription mode is
DISTINCT, instead of "yes", it is also possible to supply an integer number,
to specify the requested length of the snapshot (though the length of
the received snapshot may be less than requested, because of insufficient
data or server side limits);
passing "yes" means that the snapshot length should be determined
only by the Server. Null is also a valid value; if specified, no snapshot
preference will be sent to the server that will decide itself whether
or not to send any snapshot.java.lang.IllegalStateException
- if the Subscription is currently
"active".java.lang.IllegalArgumentException
- if the specified value is not
"yes" nor "no" nor null nor a valid integer positive number.java.lang.IllegalArgumentException
- if the specified value is not
compatible with the mode of the Subscription:
ItemUpdate.isSnapshot
@Nullable public java.lang.String getRequestedMaxFrequency()
setRequestedMaxFrequency(String)
, to be requested to the
Server for this Subscription.public void setRequestedMaxFrequency(@Nullable java.lang.String freq)
setCommandSecondLevelFields(String[])
and setCommandSecondLevelFieldSchema(String)
)
, the specified frequency limit applies to both first-level and second-level items. freq
- A decimal number, representing the maximum update frequency (expressed in updates
per second) for each item in the Subscription; for instance, with a setting
of 0.5, for each single item, no more than one update every 2 seconds
will be received. If the string "unlimited" is supplied, then no frequency
limit is requested. It is also possible to supply the string
"unfiltered", to ask for unfiltered dispatching, if it is allowed for the
items, or a null value to stick to the Server default (which currently
corresponds to "unlimited").
The check for the string constants is case insensitive.java.lang.IllegalStateException
- if the Subscription is currently
"active" and the current value of this property is "unfiltered".java.lang.IllegalStateException
- if the Subscription is currently
"active" and the given parameter is null or "unfiltered".java.lang.IllegalArgumentException
- if the specified value is not
null nor one of the special "unlimited" and "unfiltered" values nor
a valid positive number.@Nullable public java.lang.String getSelector()
setSelector(String)
.public void setSelector(@Nullable java.lang.String selector)
selector
- name of a selector, to be recognized by the
Metadata Adapter, or null to unset the selector.java.lang.IllegalStateException
- if the Subscription is currently
"active".public int getCommandPosition()
java.lang.IllegalStateException
- if the Subscription mode is not COMMAND or if the
SubscriptionListener.onSubscription()
event for this Subscription was not
yet fired.java.lang.IllegalStateException
- if a "Field List" was specified.SubscriptionListener.onSubscription()
event.public int getKeyPosition()
java.lang.IllegalStateException
- if the Subscription mode is not
COMMAND or if the SubscriptionListener.onSubscription()
event for this Subscription
was not yet fired.@Nullable public java.lang.String getCommandSecondLevelDataAdapter()
setCommandSecondLevelDataAdapter(String)
.java.lang.IllegalStateException
- if the Subscription mode is not COMMANDsetCommandSecondLevelDataAdapter(String)
public void setCommandSecondLevelDataAdapter(@Nullable java.lang.String dataAdapter)
dataAdapter
- the name of the Data Adapter. A null value
is equivalent to the "DEFAULT" name.java.lang.IllegalStateException
- if the Subscription is currently
"active".java.lang.IllegalStateException
- if the Subscription mode is not "COMMAND".setCommandSecondLevelFields(String[])
,
setCommandSecondLevelFieldSchema(String)
@Nonnull public java.lang.String[] getCommandSecondLevelFields()
java.lang.IllegalStateException
- if the Subscription was initialized with a "Field Schema"
or was not initialized at all.java.lang.IllegalStateException
- if the Subscription mode is not COMMANDsetCommandSecondLevelFields(String[])
public void setCommandSecondLevelFields(@Nullable java.lang.String[] fields)
fields
- An array of Strings containing a list of fields to
be subscribed to through the server. java.lang.IllegalArgumentException
- if any of the field names in the "Field List"
contains a space or is empty/null.java.lang.IllegalStateException
- if the Subscription is currently
"active".java.lang.IllegalStateException
- if the Subscription mode is not "COMMAND".setCommandSecondLevelFieldSchema(String)
@Nonnull public java.lang.String getCommandSecondLevelFieldSchema()
java.lang.IllegalStateException
- if the Subscription was initialized with a "Field List" or
was not initialized at all.java.lang.IllegalStateException
- if the Subscription mode is not COMMANDsetCommandSecondLevelFieldSchema(String)
public void setCommandSecondLevelFieldSchema(@Nullable java.lang.String schemaName)
schemaName
- A String to be expanded into a field list by the
Metadata Adapter.java.lang.IllegalStateException
- if the Subscription is currently
"active".java.lang.IllegalStateException
- if the Subscription mode is not "COMMAND".setCommandSecondLevelFields(java.lang.String[])
@Nullable public java.lang.String getValue(@Nonnull java.lang.String itemName, @Nonnull java.lang.String fieldName)
SubscriptionListener
rather than probing this method. getCommandValue(java.lang.String, java.lang.String, java.lang.String)
instead. itemName
- an item in the configured "Item List"fieldName
- a item in the configured "Field List"java.lang.IllegalArgumentException
- if an invalid item name or field name is specified.@Nullable public java.lang.String getValue(int itemPos, int fieldPos)
SubscriptionListener
rather than probing this method. getCommandValue(java.lang.String, java.lang.String, java.lang.String)
instead. itemPos
- the 1-based position of an item within the configured "Item Group"
or "Item List"fieldPos
- the 1-based position of a field within the configured "Field Schema"
or "Field List"java.lang.IllegalArgumentException
- if the specified item position or field position is
out of bounds.@Nullable public java.lang.String getValue(@Nonnull java.lang.String itemName, int fieldPos)
SubscriptionListener
rather than probing this method. getCommandValue(java.lang.String, java.lang.String, java.lang.String)
instead. itemName
- an item in the configured "Item List"fieldPos
- the 1-based position of a field within the configured "Field Schema"
or "Field List"java.lang.IllegalArgumentException
- if an invalid item name is specified.java.lang.IllegalArgumentException
- if the specified field position is out of bounds.@Nullable public java.lang.String getValue(int itemPos, @Nonnull java.lang.String fieldName)
SubscriptionListener
rather than probing this method. getCommandValue(java.lang.String, java.lang.String, java.lang.String)
instead. itemPos
- the 1-based position of an item within the configured "Item Group"
or "Item List"fieldName
- a item in the configured "Field List"java.lang.IllegalArgumentException
- if an invalid field name is specified.java.lang.IllegalArgumentException
- if the specified item position is out of bounds.@Nullable public java.lang.String getCommandValue(@Nonnull java.lang.String itemName, @Nonnull java.lang.String keyValue, @Nonnull java.lang.String fieldName)
setCommandSecondLevelFields(String[])
and setCommandSecondLevelFieldSchema(String)
)
can be either a first-level or a second-level one. SubscriptionListener
rather than probing this method. itemName
- an item in the configured "Item List"keyValue
- the value of a key received on the COMMAND subscription.fieldName
- a item in the configured "Field List"java.lang.IllegalArgumentException
- if an invalid item name or field name is specified.java.lang.IllegalStateException
- if the Subscription mode is not COMMAND.@Nullable public java.lang.String getCommandValue(int itemPos, @Nonnull java.lang.String keyValue, int fieldPos)
setCommandSecondLevelFields(String[])
and setCommandSecondLevelFieldSchema(String)
)
are also supported, hence the specified field
can be either a first-level or a second-level one. SubscriptionListener
rather than probing this method. itemPos
- the 1-based position of an item within the configured "Item Group"
or "Item List"keyValue
- the value of a key received on the COMMAND subscription.fieldPos
- the 1-based position of a field within the configured "Field Schema"
or "Field List"java.lang.IllegalArgumentException
- if the specified item position or field position is
out of bounds.java.lang.IllegalStateException
- if the Subscription mode is not COMMAND.@Nullable public java.lang.String getCommandValue(int itemPos, @Nonnull java.lang.String keyValue, @Nonnull java.lang.String fieldName)
setCommandSecondLevelFields(String[])
and setCommandSecondLevelFieldSchema(String)
)
are also supported, hence the specified field
can be either a first-level or a second-level one. SubscriptionListener
rather than probing this method. itemPos
- the 1-based position of an item within the configured "Item Group"
or "Item List"keyValue
- the value of a key received on the COMMAND subscription.fieldName
- a item in the configured "Field List"java.lang.IllegalArgumentException
- if an invalid field name is specified.java.lang.IllegalArgumentException
- if the specified item position is out of bounds.java.lang.IllegalStateException
- if the Subscription mode is not COMMAND.@Nullable public java.lang.String getCommandValue(@Nonnull java.lang.String itemName, @Nonnull java.lang.String keyValue, int fieldPos)
setCommandSecondLevelFields(String[])
and setCommandSecondLevelFieldSchema(String)
)
are also supported, hence the specified field
can be either a first-level or a second-level one. SubscriptionListener
rather than probing this method. itemName
- an item in the configured "Item List"keyValue
- the value of a key received on the COMMAND subscription.fieldPos
- the 1-based position of a field within the configured "Field Schema"
or "Field List"java.lang.IllegalArgumentException
- if an invalid item name is specified.java.lang.IllegalArgumentException
- if the specified field position is out of bounds.