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.Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
subMode |
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.
The same listener can be added to several different Subscription instances. |
protected void |
addSubTable(int item,
java.lang.String key) |
protected void |
debugDescriptor(java.lang.String debugString,
com.lightstreamer.util.Descriptor desc) |
int |
getCommandPosition()
Returns the position of the "command" field in a COMMAND Subscription.
This method can only be used if the Subscription mode is COMMAND and the Subscription was initialized using a "Field Schema". |
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.
This method can only be used if the Subscription mode is COMMAND and the Subscription was initialized using a "Field Schema". |
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.
It is suggested to consume real-time data by implementing and adding a proper SubscriptionListener rather than probing this method.In case of COMMAND Subscriptions, the value returned by this method may be misleading, as in COMMAND mode all the keys received, being part of the same item, will overwrite each other; for COMMAND Subscriptions, use getCommandValue(java.lang.String, java.lang.String, java.lang.String) instead.Note that internal data is cleared when the Subscription is unsubscribed from. |
java.lang.String |
getValue(int itemPos,
java.lang.String fieldName)
Returns the latest value received for the specified item/field pair.
It is suggested to consume real-time data by implementing and adding a proper SubscriptionListener rather than probing this method.In case of COMMAND Subscriptions, the value returned by this method may be misleading, as in COMMAND mode all the keys received, being part of the same item, will overwrite each other; for COMMAND Subscriptions, use getCommandValue(java.lang.String, java.lang.String, java.lang.String) instead.Note that internal data is cleared when the Subscription is unsubscribed from. |
java.lang.String |
getValue(java.lang.String itemName,
int fieldPos)
Returns the latest value received for the specified item/field pair.
It is suggested to consume real-time data by implementing and adding a proper SubscriptionListener rather than probing this method.In case of COMMAND Subscriptions, the value returned by this method may be misleading, as in COMMAND mode all the keys received, being part of the same item, will overwrite each other; for COMMAND Subscriptions, use getCommandValue(java.lang.String, java.lang.String, java.lang.String) instead.Note that internal data is cleared when the Subscription is unsubscribed from. |
java.lang.String |
getValue(java.lang.String itemName,
java.lang.String fieldName)
Returns the latest value received for the specified item/field pair.
It is suggested to consume real-time data by implementing and adding a proper SubscriptionListener rather than probing this method.In case of COMMAND Subscriptions, the value returned by this method may be misleading, as in COMMAND mode all the keys received, being part of the same item, will overwrite each other; for COMMAND Subscriptions, use getCommandValue(java.lang.String, java.lang.String, java.lang.String) instead.Note that internal data is cleared when the Subscription is unsubscribed from. |
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.
This flag is switched to true by server sent Subscription events, and back to false in case of client disconnection, LightstreamerClient.unsubscribe(Subscription) calls and server
sent unsubscription events. |
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.
All the possible second-level items should be supplied in "MERGE" mode with snapshot available. The Data Adapter name is configured on the server side through the "name" attribute of the <data_provider> element, in the "adapters.xml" file that defines the Adapter Set (a missing attribute configures the "DEFAULT" name). |
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.
The Data Adapter name is configured on the server side through the "name" attribute of the "data_provider" element, in the "adapters.xml" file that defines the Adapter Set (a missing attribute configures the "DEFAULT" name). Note that if more than one Data Adapter is needed to supply all the items in a set of items, then it is not possible to group all the items of the set in a single Subscription. |
void |
setFields(java.lang.String[] fields)
Setter method that sets the "Field List" to be subscribed to through
Lightstreamer Server.
Any call to this method will override any "Field List" or "Field Schema" previously specified. |
void |
setFieldSchema(java.lang.String schemaName)
Setter method that sets the "Field Schema" to be subscribed to through
Lightstreamer Server.
Any call to this method will override any "Field List" or "Field Schema" previously specified. |
void |
setItemGroup(java.lang.String groupName)
Setter method that sets the "Item Group" to be subscribed to through
Lightstreamer Server.
Any call to this method will override any "Item List" or "Item Group" previously specified. |
void |
setItems(java.lang.String[] items)
Setter method that sets the "Item List" to be subscribed to through
Lightstreamer Server.
Any call to this method will override any "Item List" or "Item Group" previously specified. |
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(java.lang.String subscriptionMode, java.lang.String[] items, 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(java.lang.String subscriptionMode, java.lang.String item, 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(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(SubscriptionListener listener)
listener
- An object that will receive the events as documented in the
SubscriptionListener interface.removeListener(SubscriptionListener)
public void removeListener(SubscriptionListener listener)
listener
- The listener to be removed.addListener(SubscriptionListener)
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.public java.lang.String getDataAdapter()
setDataAdapter(String)
.public void setDataAdapter(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)
public java.lang.String getMode()
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(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".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(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".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(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 a number or is empty/null.java.lang.IllegalStateException
- if the Subscription is currently
"active".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(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".SubscriptionListener.onSubscriptionError(int, String)
with code 23public java.lang.String getRequestedBufferSize()
setRequestedBufferSize(java.lang.String)
, to be requested to the Server for
this Subscription.public void setRequestedBufferSize(java.lang.String size)
size
- The length of the internal queuing buffers to be
used in the Server. If the string "unlimited" is supplied,
then the buffer length is decided by the Server (the check is case
insensitive).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)
public java.lang.String getRequestedSnapshot()
setRequestedSnapshot(String)
, to be requested
to the Server for this Subscription.public void setRequestedSnapshot(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 a 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
public java.lang.String getRequestedMaxFrequency()
setRequestedMaxFrequency(String)
, to be requested to the
Server for this Subscription.public void setRequestedMaxFrequency(java.lang.String freq)
freq
- 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 the maximum
frequency is decided by the Server. 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 avoid sending any frequency request to the server.
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 null or "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.public java.lang.String getSelector()
setSelector(String)
.public void setSelector(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.public java.lang.String getCommandSecondLevelDataAdapter()
setCommandSecondLevelDataAdapter(String)
.java.lang.IllegalStateException
- if the Subscription mode is not COMMANDsetCommandSecondLevelDataAdapter(String)
public void setCommandSecondLevelDataAdapter(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)
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 COMMANDpublic void setCommandSecondLevelFields(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 a number 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)
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 COMMANDpublic void setCommandSecondLevelFieldSchema(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[])
public java.lang.String getValue(java.lang.String itemName, 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.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.public java.lang.String getValue(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.public java.lang.String getValue(int itemPos, 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.public java.lang.String getCommandValue(java.lang.String itemName, java.lang.String keyValue, java.lang.String fieldName)
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.public java.lang.String getCommandValue(int itemPos, java.lang.String keyValue, int fieldPos)
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.public java.lang.String getCommandValue(int itemPos, java.lang.String keyValue, java.lang.String fieldName)
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.public java.lang.String getCommandValue(java.lang.String itemName, java.lang.String keyValue, int fieldPos)
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.protected void addSubTable(int item, java.lang.String key)
protected void debugDescriptor(java.lang.String debugString, com.lightstreamer.util.Descriptor desc)