public class MpnSubscription
extends java.lang.Object
LightstreamerClient.registerForMpn(MpnDeviceInterface)
.LightstreamerClient.subscribe(MpnSubscription, boolean)
method, its state switches to "active". This means that the subscription request
is being sent to the Lightstreamer Server. Once the server accepted the request, it begins to send real-time events via native push notifications and
the MpnSubscription object switches to the "subscribed" state.Subscription
apply to MpnSubscription.LightstreamerClient.getMpnSubscriptions(String)
method.Constructor and Description |
---|
MpnSubscription(MpnSubscription copyFrom)
Creates an MpnSubscription object copying all properties (including the subscription ID) from the specified MPN subscription.
The created MpnSubscription is a copy of the original MpnSubscription object and represents the same MPN subscription, since their subscription ID is the same. |
MpnSubscription(java.lang.String subscriptionMode)
Creates an object to be used to describe an MPN subscription that is going to be subscribed to through the MPN Module of Lightstreamer Server.
The object can be supplied to LightstreamerClient.subscribe(MpnSubscription, boolean) in order to bring the MPN subscription to "active" state.Note that all of the methods used to describe the subscription to the server can only be called while the instance is in the "inactive" state. |
MpnSubscription(java.lang.String subscriptionMode,
java.lang.String[] items,
java.lang.String[] fields)
Creates an object to be used to describe an MPN subscription that is going to be subscribed to through the MPN Module of Lightstreamer Server.
The object can be supplied to LightstreamerClient.subscribe(MpnSubscription, boolean) in order to bring the MPN subscription to "active" state.Note that all of the methods used to describe the subscription to the server can only be called while the instance is in the "inactive" state. |
MpnSubscription(java.lang.String subscriptionMode,
java.lang.String item,
java.lang.String[] fields)
Creates an object to be used to describe an MPN subscription that is going to be subscribed to through the MPN Module of Lightstreamer Server.
The object can be supplied to LightstreamerClient.subscribe(MpnSubscription, boolean) in order to bring the MPN subscription to "active" state.Note that all of the methods used to describe the subscription to the server can only be called while the instance is in the "inactive" state. |
MpnSubscription(Subscription copyFrom)
Creates an MpnSubscription object copying subscription mode, items, fields and data adapter from the specified real-time subscription.
The object can be supplied to LightstreamerClient.subscribe(MpnSubscription, boolean) in order to bring the MPN subscription to "active" state.Note that all of the methods used to describe the subscription to the server can only be called while the instance is in the "inactive" state. |
Modifier and Type | Method and Description |
---|---|
void |
addListener(MpnSubscriptionListener listener)
Adds a listener that will receive events from the MpnSubscription instance.
The same listener can be added to several different MpnSubscription instances. |
boolean |
equals(java.lang.Object obj) |
java.lang.String |
getDataAdapter()
Inquiry method that can be used to read the name of the Data Adapter specified for this
MpnSubscription through
setDataAdapter(String) . |
java.lang.String[] |
getFields()
Inquiry method that can be used to read the "Field List" specified for this MpnSubscription.
Note: if the MpnSubscription has been created by the client, such as when obtained through LightstreamerClient.getMpnSubscriptions(String) ,
fields are always expressed with a "Field Schema"", even if originally the MPN subscription used a "Field List". |
java.lang.String |
getFieldSchema()
Inquiry method that can be used to read the field schema specified for this MpnSubscription.
Note: if the MpnSubscription has been created by the client, such as when obtained through LightstreamerClient.getMpnSubscriptions(String) ,
fields are always expressed with a "Field Schema"", even if originally the MPN subscription used a "Field List". |
java.lang.String |
getItemGroup()
Inquiry method that can be used to read the item group specified for this MpnSubscription.
Note: if the MpnSubscription has been created by the client, such as when obtained through LightstreamerClient.getMpnSubscriptions(String) ,
items are always expressed with an "Item Group"", even if originally the MPN subscription used an "Item List". |
java.lang.String[] |
getItems()
Inquiry method that can be used to read the "Item List" specified for this MpnSubscription.
Note that if the single-item-constructor was used, this method will return an array of length 1 containing such item. Note: if the MpnSubscription has been created by the client, such as when obtained through LightstreamerClient.getMpnSubscriptions(String) ,
items are always expressed with an "Item Group"", even if originally the MPN subscription used an "Item List". |
java.util.List<MpnSubscriptionListener> |
getListeners()
Returns the list containing the
MpnSubscriptionListener instances that were added to this MpnSubscription. |
java.lang.String |
getMode()
Inquiry method that can be used to read the mode specified for this
MpnSubscription.
|
java.lang.String |
getNotificationFormat()
Returns the JSON structure to be used as the format of push notifications.
This JSON structure is sent by the server to the push notification service provider (i.e. |
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 MpnSubscription. |
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 MpnSubscription. |
java.lang.String |
getStatus()
The status of the subscription.
The status can be: UNKNOWN : when the MPN subscription has just been created or deleted (i.e. |
long |
getStatusTimestamp()
The server-side timestamp of the subscription status.
|
java.lang.String |
getSubscriptionId()
The server-side unique persistent ID of the MPN subscription.
The ID is available only after the MPN subscription has been successfully subscribed on the server. |
java.lang.String |
getTriggerExpression()
Returns the boolean expression that is evaluated against each update and acts as a trigger to deliver the push notification.
|
int |
hashCode() |
boolean |
isActive()
Checks if the MpnSubscription is currently "active" or not.
Most of the MpnSubscription properties cannot be modified if an MpnSubscription is "active". The status of an MpnSubscription is changed to "active" through the LightstreamerClient.subscribe(MpnSubscription, boolean) method and back to "inactive"
through the LightstreamerClient.unsubscribe(MpnSubscription) and LightstreamerClient.unsubscribeMpnSubscriptions(String) ones. |
boolean |
isSubscribed()
Checks if the MpnSubscription 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(MpnSubscription) or LightstreamerClient.unsubscribeMpnSubscriptions(String) calls, and server sent
unsubscription events. |
boolean |
isTriggered()
Checks if the MpnSubscription is currently triggered or not.
This flag is switched to true when a trigger expression has been set and it evaluated to true at least once. |
void |
removeListener(MpnSubscriptionListener listener)
Removes a listener from the MpnSubscription instance so that it will not receive events anymore.
|
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 MpnSubscription.
|
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 |
setNotificationFormat(java.lang.String format)
Sets the JSON structure to be used as the format of push notifications.
This JSON structure is sent by the server to the push notification service provider (i.e. |
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 MpnSubscription.
A Queuing buffer is used by the Server to accumulate a burst of updates for an item, so that they can all be sent to the client, despite of bandwidth or frequency limits. Note that the Server may pose an upper limit on the size of its internal buffers. |
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 MpnSubscription.
Note that frequency limits on the items can also be set on the server side and this request can only be issued in order to further reduce the frequency, not to rise it beyond these limits. |
void |
setTriggerExpression(java.lang.String expr)
Sets the boolean expression that will be evaluated against each update and will act as a trigger to deliver the push notification.
If a trigger expression is set, the MPN subscription does not send any push notifications until the expression evaluates to true. |
public MpnSubscription(@Nonnull java.lang.String subscriptionMode, @Nonnull java.lang.String[] items, @Nonnull java.lang.String[] fields)
LightstreamerClient.subscribe(MpnSubscription, boolean)
in order to bring the MPN subscription to "active" state.subscriptionMode
- The subscription mode for the items, required by Lightstreamer Server. Permitted values are:MERGE
DISTINCT
items
- An array of items to be subscribed to through Lightstreamer Server. It is also possible specify the "Item List" or
"Item Group" later through setItems(String[])
and setItemGroup(String)
.fields
- An array of fields for the items to be subscribed to through Lightstreamer Server. It is also possible to specify the "Field List" or
"Field Schema" later through 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 MpnSubscription(@Nonnull java.lang.String subscriptionMode, @Nonnull java.lang.String item, @Nonnull java.lang.String[] fields)
LightstreamerClient.subscribe(MpnSubscription, boolean)
in order to bring the MPN subscription to "active" state.subscriptionMode
- The subscription mode for the items, required by Lightstreamer Server. Permitted values are:MERGE
DISTINCT
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. It is also possible to specify the "Field List" or
"Field Schema" later through 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 MpnSubscription(@Nonnull java.lang.String subscriptionMode)
LightstreamerClient.subscribe(MpnSubscription, boolean)
in order to bring the MPN subscription to "active" state.subscriptionMode
- The subscription mode for the items, required by Lightstreamer Server. Permitted values are:MERGE
DISTINCT
java.lang.IllegalArgumentException
- If no or invalid subscription mode is passed.public MpnSubscription(@Nonnull Subscription copyFrom)
LightstreamerClient.subscribe(MpnSubscription, boolean)
in order to bring the MPN subscription to "active" state.copyFrom
- The Subscription object to copy properties from.public MpnSubscription(@Nonnull MpnSubscription copyFrom)
LightstreamerClient.subscribe(MpnSubscription, boolean)
in order to bring it to "active" state, the MPN subscription
is modified: any property changed in this MpnSubscription replaces the corresponding value of the MPN subscription on the server.copyFrom
- The MpnSubscription object to copy properties from.public void addListener(@Nonnull MpnSubscriptionListener listener)
listener
- An object that will receive the events as documented in the MpnSubscriptionListener
interface.removeListener(MpnSubscriptionListener)
public void removeListener(@Nonnull MpnSubscriptionListener listener)
listener
- The listener to be removed.addListener(MpnSubscriptionListener)
@Nonnull public java.util.List<MpnSubscriptionListener> getListeners()
MpnSubscriptionListener
instances that were added to this MpnSubscription.addListener(MpnSubscriptionListener)
@Nullable public java.lang.String getNotificationFormat()
setNotificationFormat(String)
public void setNotificationFormat(@Nonnull java.lang.String format)
${field}
, or indexed arguments with the format $[1]
. These arguments are
replaced by the server with the value of corresponding subscription fields before the push notification is sent.{ "android" : { "notification" : { "body" : "Stock ${stock_name} is now valued ${last_price}" } } }
${LS_MPN_subscription_ID}
: the ID of the MPN subscription generating the push notification.
MpnBuilder
object provides methods to build an appropriate JSON structure from its defining fields.LightstreamerClient.getMpnSubscriptions(String)
,
named arguments are always mapped to its corresponding indexed argument, even if originally the notification format used a named argument.format
- the JSON structure to be used as the format of push notifications.java.lang.IllegalStateException
- if the MpnSubscription is currently "active".MpnBuilder
MpnSubscriptionListener.onPropertyChanged(String)
with argument notification_format
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nullable public java.lang.String getTriggerExpression()
setTriggerExpression(String)
public void setTriggerExpression(@Nonnull java.lang.String expr)
${field}
, or indexed arguments with the format $[1]
.
The same rules that apply to setNotificationFormat(String)
apply also to the trigger expression. The expression is verified and evaluated on the server.Double.parseDouble(${last_price}) > 500.0
LS_MPN_field
followed by an index. Thus, variable names like LS_MPN_field1
should be considered
reserved and their use avoided in the expression.LightstreamerClient.getMpnSubscriptions(String)
,
named arguments are always mapped to its corresponding indexed argument, even if originally the trigger expression used a named argument.expr
- the boolean expression that acts as a trigger to deliver the push notification.java.lang.IllegalStateException
- if the MpnSubscription is currently "active".isTriggered()
MpnSubscriptionListener.onPropertyChanged(String)
with argument trigger
on any MpnSubscriptionListener
listening to the related MpnSubscription.public boolean isActive()
LightstreamerClient.subscribe(MpnSubscription, boolean)
method and back to "inactive"
through the LightstreamerClient.unsubscribe(MpnSubscription)
and LightstreamerClient.unsubscribeMpnSubscriptions(String)
ones.getStatus()
,
LightstreamerClient.subscribe(MpnSubscription, boolean)
,
LightstreamerClient.unsubscribe(MpnSubscription)
,
LightstreamerClient.unsubscribeMpnSubscriptions(String)
public boolean isSubscribed()
LightstreamerClient.unsubscribe(MpnSubscription)
or LightstreamerClient.unsubscribeMpnSubscriptions(String)
calls, and server sent
unsubscription events.getStatus()
,
LightstreamerClient.unsubscribe(MpnSubscription)
,
LightstreamerClient.unsubscribeMpnSubscriptions(String)
public boolean isTriggered()
LightstreamerClient.subscribe(MpnSubscription, boolean)
call on a copy of it, deleted with LightstreamerClient.unsubscribe(MpnSubscription)
or
LightstreamerClient.unsubscribeMpnSubscriptions(String)
calls, and server sent subscription events.getStatus()
,
LightstreamerClient.subscribe(MpnSubscription, boolean)
,
LightstreamerClient.unsubscribe(MpnSubscription)
,
LightstreamerClient.unsubscribeMpnSubscriptions(String)
@Nonnull public java.lang.String getStatus()
UNKNOWN
: when the MPN subscription has just been created or deleted (i.e. unsubscribed). In this status isActive()
, isSubscribed()
and isTriggered()
are all false.ACTIVE
: when the MPN susbcription has been submitted to the server, but no confirm has been received yet. In this status isActive()
is true,
isSubscribed()
and isTriggered()
are false.SUBSCRIBED
: when the MPN subscription has been successfully subscribed on the server. If a trigger expression is set, it has not been
evaluated to true yet. In this status isActive()
and isSubscribed()
are true, isTriggered()
is false.TRIGGERED
: when the MPN subscription has a trigger expression set, has been successfully subscribed on the server and
the trigger expression has been evaluated to true at least once. In this status isActive()
, isSubscribed()
and isTriggered()
are all true.isActive()
,
isSubscribed()
,
isTriggered()
public long getStatusTimestamp()
getStatus()
MpnSubscriptionListener.onPropertyChanged(String)
with argument status_timestamp
on any MpnSubscriptionListener
listening to the related MpnSubscription.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 MpnSubscription is currently
"active".MpnSubscriptionListener.onPropertyChanged(String)
with argument group
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nonnull public java.lang.String[] getItems()
LightstreamerClient.getMpnSubscriptions(String)
,
items are always expressed with an "Item Group"", even if originally the MPN subscription used an "Item List".java.lang.IllegalStateException
- if the MpnSubscription was not initialized.public void setItemGroup(@Nonnull java.lang.String groupName)
groupName
- A String to be expanded into an item list by the
Metadata Adapter.java.lang.IllegalStateException
- if the MpnSubscription is currently
"active".MpnSubscriptionListener.onPropertyChanged(String)
with argument group
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nonnull public java.lang.String getItemGroup()
LightstreamerClient.getMpnSubscriptions(String)
,
items are always expressed with an "Item Group"", even if originally the MPN subscription used an "Item List".java.lang.IllegalStateException
- if the MpnSubscription was not initialized.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 MpnSubscription is currently
"active".MpnSubscriptionListener.onPropertyChanged(String)
with argument schema
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nonnull public java.lang.String[] getFields()
LightstreamerClient.getMpnSubscriptions(String)
,
fields are always expressed with a "Field Schema"", even if originally the MPN subscription used a "Field List".java.lang.IllegalStateException
- if the MpnSubscription was not initialized.public void setFieldSchema(@Nonnull java.lang.String schemaName)
schemaName
- A String to be expanded into a field list by the
Metadata Adapter.java.lang.IllegalStateException
- if the MpnSubscription is currently
"active".MpnSubscriptionListener.onPropertyChanged(String)
with argument schema
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nonnull public java.lang.String getFieldSchema()
LightstreamerClient.getMpnSubscriptions(String)
,
fields are always expressed with a "Field Schema"", even if originally the MPN subscription used a "Field List".java.lang.IllegalStateException
- if the MpnSubscription was not initialized.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)
MpnSubscriptionListener.onPropertyChanged(String)
with argument adapter
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nullable public java.lang.String getDataAdapter()
setDataAdapter(String)
.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 MpnSubscription is currently
"active".java.lang.IllegalArgumentException
- if the specified value is not
null nor "unlimited" nor a valid positive integer number.setRequestedMaxFrequency(String)
MpnSubscriptionListener.onPropertyChanged(String)
with argument requested_buffer_size
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nullable public java.lang.String getRequestedBufferSize()
setRequestedBufferSize(java.lang.String)
, to be requested to the Server for
this MpnSubscription.public void setRequestedMaxFrequency(@Nullable java.lang.String freq)
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 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 MpnSubscription is currently
"active".java.lang.IllegalArgumentException
- if the specified value is not
null nor the special "unlimited" value nor a valid positive number.MpnSubscriptionListener.onPropertyChanged(String)
with argument requested_max_frequency
on any MpnSubscriptionListener
listening to the related MpnSubscription.@Nullable public java.lang.String getRequestedMaxFrequency()
setRequestedMaxFrequency(String)
, to be requested to the
Server for this MpnSubscription.@Nonnull public java.lang.String getMode()
@Nullable public java.lang.String getSubscriptionId()
SUBSCRIBED
or
TRIGGERED
.coalescing
flag of LightstreamerClient.subscribe(MpnSubscription, boolean)
may cause the assignment of a pre-existing MPN subscription ID
to the new subscription.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object