Package com.lightstreamer.client
Class ItemUpdate
- java.lang.Object
-
- com.lightstreamer.client.ItemUpdate
-
public class ItemUpdate extends java.lang.Object
Contains all the information related to an update of the field values for an item. It reports all the new values of the fields.
COMMAND Subscription
If the involved Subscription is a COMMAND Subscription, then the values for the current update are meant as relative to the same key.
Moreover, if the involved Subscription has a two-level behavior enabled, then each update may be associated with either a first-level or a second-level item. In this case, the reported fields are always the union of the first-level and second-level fields and each single update can only change either the first-level or the second-level fields (but for the "command" field, which is first-level and is always set to "UPDATE" upon a second-level update); note that the second-level field values are always null until the first second-level update occurs). When the two-level behavior is enabled, in all methods where a field name has to be supplied, the following convention should be followed:
- The field name can always be used, both for the first-level and the second-level fields. In case of name conflict, the first-level field is meant.
- The field position can always be used; however, the field positions for the second-level fields start at the highest position of the first-level field list + 1. If a field schema had been specified for either first-level or second-level Subscriptions, then client-side knowledge of the first-level schema length would be required.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.String>
getChangedFields()
Returns an immutable Map containing the values for each field changed with the last server update.java.util.Map<java.lang.Integer,java.lang.String>
getChangedFieldsByPosition()
Returns an immutable Map containing the values for each field changed with the last server update.java.util.Map<java.lang.String,java.lang.String>
getFields()
Returns an immutable Map containing the values for each field in the Subscription.java.util.Map<java.lang.Integer,java.lang.String>
getFieldsByPosition()
Returns an immutable Map containing the values for each field in the Subscription.java.lang.String
getItemName()
Inquiry method that retrieves the name of the item to which this update pertains.int
getItemPos()
Inquiry method that retrieves the position in the "Item List" or "Item Group" of the item to which this update pertains.java.lang.String
getValue(int fieldPos)
Returns the current value for the specified fieldjava.lang.String
getValue(java.lang.String fieldName)
Returns the current value for the specified fieldboolean
isSnapshot()
Inquiry method that asks whether the current update belongs to the item snapshot (which carries the current item state at the time of Subscription).boolean
isValueChanged(int fieldPos)
Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item.boolean
isValueChanged(java.lang.String fieldName)
Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item.
-
-
-
Method Detail
-
getItemName
@Nullable public java.lang.String getItemName()
Inquiry method that retrieves the name of the item to which this update pertains.
The name will be null if the related Subscription was initialized using an "Item Group".- Returns:
- The name of the item to which this update pertains.
- See Also:
Subscription.setItemGroup(String)
,Subscription.setItems(String[])
-
getItemPos
public int getItemPos()
Inquiry method that retrieves the position in the "Item List" or "Item Group" of the item to which this update pertains.- Returns:
- The 1-based position of the item to which this update pertains.
- See Also:
Subscription.setItemGroup(String)
,Subscription.setItems(String[])
-
getValue
@Nullable public java.lang.String getValue(@Nonnull java.lang.String fieldName)
Returns the current value for the specified field- Parameters:
fieldName
- The field name as specified within the "Field List".- Returns:
- The value of the specified field; it can be null in the following cases:
- a null value has been received from the Server, as null is a possible value for a field;
- no value has been received for the field yet;
- the item is subscribed to with the COMMAND mode and a DELETE command is received (only the fields used to carry key and command information are valued).
- Throws:
java.lang.IllegalArgumentException
- if the specified field is not part of the Subscription.- See Also:
Subscription.setFields(String[])
-
getValue
@Nullable public java.lang.String getValue(int fieldPos)
Returns the current value for the specified field- Parameters:
fieldPos
- The 1-based position of the field within the "Field List" or "Field Schema".- Returns:
- The value of the specified field; it can be null in the following cases:
- a null value has been received from the Server, as null is a possible value for a field;
- no value has been received for the field yet;
- the item is subscribed to with the COMMAND mode and a DELETE command is received (only the fields used to carry key and command information are valued).
- Throws:
java.lang.IllegalArgumentException
- if the specified field is not part of the Subscription.- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
isSnapshot
public boolean isSnapshot()
Inquiry method that asks whether the current update belongs to the item snapshot (which carries the current item state at the time of Subscription). Snapshot events are sent only if snapshot information was requested for the items throughSubscription.setRequestedSnapshot(String)
and precede the real time events. Snapshot information take different forms in different subscription modes and can be spanned across zero, one or several update events. In particular:- if the item is subscribed to with the RAW subscription mode, then no snapshot is sent by the Server;
- if the item is subscribed to with the MERGE subscription mode, then the snapshot consists of exactly one event, carrying the current value for all fields;
- if the item is subscribed to with the DISTINCT subscription mode, then the snapshot
consists of some of the most recent updates; these updates are as many as specified
through
Subscription.setRequestedSnapshot(String)
, unless fewer are available; - if the item is subscribed to with the COMMAND subscription mode, then the snapshot consists of an "ADD" event for each key that is currently present.
- Returns:
- true if the current update event belongs to the item snapshot; false otherwise.
-
isValueChanged
public boolean isValueChanged(@Nonnull java.lang.String fieldName)
Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item. If the Subscription mode is COMMAND then the change is meant as relative to the same key.- Parameters:
fieldName
- The field name as specified within the "Field List".- Returns:
- Unless the Subscription mode is COMMAND, the return value is true in the following cases:
- It is the first update for the item;
- the new field value is different than the previous field value received for the item.
- it is the first update for the involved key value (i.e. the event carries an "ADD" command);
- the new field value is different than the previous field value received for the item, relative to the same key value (the event must carry an "UPDATE" command);
- the event carries a "DELETE" command (this applies to all fields other than the field used to carry key information).
- Throws:
java.lang.IllegalArgumentException
- if the specified field is not part of the Subscription.- See Also:
Subscription.setFields(String[])
-
isValueChanged
public boolean isValueChanged(int fieldPos)
Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item. If the Subscription mode is COMMAND then the change is meant as relative to the same key.- Parameters:
fieldPos
- The 1-based position of the field within the "Field List" or "Field Schema".- Returns:
- Unless the Subscription mode is COMMAND, the return value is true in the following cases:
- It is the first update for the item;
- the new field value is different than the previous field value received for the item.
- it is the first update for the involved key value (i.e. the event carries an "ADD" command);
- the new field value is different than the previous field value received for the item, relative to the same key value (the event must carry an "UPDATE" command);
- the event carries a "DELETE" command (this applies to all fields other than the field used to carry key information).
- Throws:
java.lang.IllegalArgumentException
- if the specified field is not part of the Subscription.- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
getChangedFields
@Nonnull public java.util.Map<java.lang.String,java.lang.String> getChangedFields()
Returns an immutable Map containing the values for each field changed with the last server update. The related field name is used as key for the values in the map. Note that if the Subscription mode of the involved Subscription is COMMAND, then changed fields are meant as relative to the previous update for the same key. On such tables if a DELETE command is received, all the fields, excluding the key field, will be present as changed, with null value. All of this is also true on tables that have the two-level behavior enabled, but in case of DELETE commands second-level fields will not be iterated.- Returns:
- An immutable Map containing the values for each field changed with the last server update.
- Throws:
java.lang.IllegalStateException
- if the Subscription was initialized using a field schema.- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
getChangedFieldsByPosition
@Nonnull public java.util.Map<java.lang.Integer,java.lang.String> getChangedFieldsByPosition()
Returns an immutable Map containing the values for each field changed with the last server update. The 1-based field position within the field schema or field list is used as key for the values in the map. Note that if the Subscription mode of the involved Subscription is COMMAND, then changed fields are meant as relative to the previous update for the same key. On such tables if a DELETE command is received, all the fields, excluding the key field, will be present as changed, with null value. All of this is also true on tables that have the two-level behavior enabled, but in case of DELETE commands second-level fields will not be iterated.- Returns:
- An immutable Map containing the values for each field changed with the last server update.
- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
getFields
@Nonnull public java.util.Map<java.lang.String,java.lang.String> getFields()
Returns an immutable Map containing the values for each field in the Subscription. The related field name is used as key for the values in the map.- Returns:
- An immutable Map containing the values for each field in the Subscription.
- Throws:
java.lang.IllegalStateException
- if the Subscription was initialized using a field schema.- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
getFieldsByPosition
@Nonnull public java.util.Map<java.lang.Integer,java.lang.String> getFieldsByPosition()
Returns an immutable Map containing the values for each field in the Subscription. The 1-based field position within the field schema or field list is used as key for the values in the map.- Returns:
- An immutable Map containing the values for each field in the Subscription.
- See Also:
Subscription.setFieldSchema(String)
,Subscription.setFields(String[])
-
-