com.prosysopc.ua.client
Class Subscription

java.lang.Object
  extended by com.prosysopc.ua.SubscriptionBase
      extended by com.prosysopc.ua.client.Subscription
All Implemented Interfaces:
Comparable<SubscriptionBase>

public class Subscription
extends SubscriptionBase

OPC UA Subscription. The subscription is used for continuous monitoring of data values from an OPC server.

Use PublishingInterval to define the sampling frequency in the server. LifeTimeCount and MaxKeepAliveCount define the details of connection monitoring, to help keeping track that the connection is still alive to both directions. You can use PublishingEnabled to take the subscription in or out of monitoring for custom periods.

You can also define a Priority for each subscription, to give the server a hint about the relative importance of different subscriptions. Higher values mean higher priority.


Field Summary
protected  boolean modified
           
 
Fields inherited from class com.prosysopc.ua.SubscriptionBase
items, lifetimeCount, maxKeepAliveCount, maxNotificationsPerPublish, priority, publishingEnabled, publishingInterval, updateCount
 
Constructor Summary
Subscription()
          Create a new subscription using the default values.
Subscription(Boolean publishingEnabled, Double requestedPublishingInterval, long requestedLifetimeCount, long requestedMaxKeepAliveCount, long maxNotificationsPerPublish, int priority)
           
Subscription(org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish, org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount, org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount, Double requestedPublishingInterval, Boolean publishingEnabled, org.opcfoundation.ua.builtintypes.UnsignedByte priority)
           
 
Method Summary
 void addAliveListener(SubscriptionAliveListener subscriptionAliveListener)
          Add a listener for the subscription alive and timeout events.
 org.opcfoundation.ua.core.MonitoredItemCreateResult addItem(MonitoredItem item)
          Adds a monitored item to the subscription.
 org.opcfoundation.ua.core.MonitoredItemCreateResult[] addItems(MonitoredItem... items)
          Adds several monitored items to the subscription at once.
 void addNotificationListener(SubscriptionNotificationListener notificationListener)
          Add a listener for the Notification notification event.
protected  void applyUpdates()
          Apply the pending modifications guarded by beginUpdate/endUpdate.
protected  void checkOperationResult(org.opcfoundation.ua.builtintypes.StatusCode statusCode)
           
protected  void checkServiceResult(org.opcfoundation.ua.builtintypes.ServiceResponse response, org.opcfoundation.ua.builtintypes.DiagnosticInfo[] operationDiagnostics)
           
protected  void checkTimeout()
           
protected  void createItems()
           
protected  org.opcfoundation.ua.core.CreateMonitoredItemsResponse createMonitoredItems(MonitoredItemBase... items)
           
protected  org.opcfoundation.ua.core.DeleteMonitoredItemsResponse deleteMonitoredItems(MonitoredItemBase... items)
           
protected  void enabledChanged()
          Handles a change in PublishingEnabled
protected  void finalize()
           
protected  void fireAfterCreate()
           
protected  void fireAlive()
          Fire the Alive event.
protected  void fireBufferOverflow(org.opcfoundation.ua.builtintypes.UnsignedInteger sequenceNumber, org.opcfoundation.ua.builtintypes.ExtensionObject[] notificationData)
           
protected  void fireDataChange(MonitoredDataItem item, org.opcfoundation.ua.builtintypes.DataValue newValue)
           
protected  void fireError(Object notification, Exception exception)
           
protected  void fireEvent(MonitoredEventItem item, org.opcfoundation.ua.builtintypes.Variant[] values)
           
protected  long fireMissingData(org.opcfoundation.ua.builtintypes.UnsignedInteger lastSequenceNumber2, long sequenceNumber, long newSequenceNumber, org.opcfoundation.ua.builtintypes.StatusCode serviceResult)
           
protected  void fireNotification(org.opcfoundation.ua.core.NotificationData notification)
          Fire the Notification event.
protected  void fireStatusChange(org.opcfoundation.ua.builtintypes.StatusCode oldStatus, org.opcfoundation.ua.builtintypes.StatusCode newStatus, org.opcfoundation.ua.builtintypes.DiagnosticInfo diagnosticInfo)
           
protected  void fireTimeout()
          Fire the Timeout event.
 SubscriptionAliveListener[] getAliveListeners()
           
 org.opcfoundation.ua.builtintypes.UnsignedInteger[] getAvailableSequenceNumbers()
           
protected  List<org.opcfoundation.ua.builtintypes.UnsignedInteger> getAvailableSequenceNumbersList()
           
 UaClient getClient()
           
 org.opcfoundation.ua.builtintypes.DiagnosticInfo getDiagnosticInfo()
           
 MonitoredItem getItem(org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
          Find the item that is listening to the specified node attribute.
 Calendar getLastAlive()
           
 org.opcfoundation.ua.builtintypes.DiagnosticInfo[] getLastOperationDiagnostics()
          The operation level diagnostic information related to the last service call.
 org.opcfoundation.ua.builtintypes.UnsignedInteger getLastSequenceNumber()
           
 org.opcfoundation.ua.builtintypes.DiagnosticInfo getLastServiceDiagnostics()
          The service level diagnostic information related to the last service call.
 org.opcfoundation.ua.builtintypes.StatusCode getLastServiceResult()
          The latest service result received for the service calls used to control the subscription.
 int getMaxMonitoredItemsPerCall()
           
protected  org.opcfoundation.ua.core.MonitoringParameters getMonitoringParameters(MonitoredItemBase item)
           
 int getNotificationBufferSize()
          The maximum size of the internal buffer used for incoming data packets.
 SubscriptionNotificationListener[] getNotificationListeners()
           
 org.opcfoundation.ua.builtintypes.StatusCode getStatus()
          The status received from the latest StatusChange notification.
 double getTimeoutDetectionFactor()
           
 org.opcfoundation.ua.core.TimestampsToReturn getTimestampsToReturn()
           
protected  void handleNotificationDatas()
          Handles all pending notifications from the responseQueue, where they have been recorded by onPublishResponse(PublishResponse)
 boolean hasAliveListener(SubscriptionAliveListener subscriptionAliveListener)
          Check if the subscription already has the specified alive listener.
 boolean hasNotificationListener(SubscriptionNotificationListener notificationListener)
          Check if the subscription already has the specified notification listener.
protected  boolean hasPublishResponses()
           
protected  boolean isAliveNotification(org.opcfoundation.ua.builtintypes.ExtensionObject[] notificationData)
           
 boolean isConnected()
          Is the subscription connected to the server.
 boolean isModified()
           
 boolean isRetransmissionEnabled()
          Whether the Subscription is enabled to call Republish to the server.
 boolean isTimeout()
          Check whether the subscription timeout has occurred.
protected  void itemChanged(MonitoredItem item)
           
 String itemsToString()
          Convert the monitored items to a string for output purposes
protected  org.opcfoundation.ua.core.ModifyMonitoredItemsResponse modifyMonitoredItems(List<MonitoredItem> items)
           
protected  void monitoringModeChanged(MonitoredItem monitoredItem)
           
protected  void onPublishResponse(org.opcfoundation.ua.core.PublishResponse response)
          Records the new notification to the responseQueue to be handled later at #handleNotificationData in another thread. this method is called in the stack thread that provides the asynchronous response to Publish
protected  void paramChanged()
          Parameter change "event".
 org.opcfoundation.ua.builtintypes.DataValue[] readAll(Double maxAge, org.opcfoundation.ua.core.TimestampsToReturn timestamps)
          Read the current value of each MonitoredDataItem in the subscription.
 void removeAliveListener(SubscriptionAliveListener subscriptionAliveListener)
          Remove a listener for the subscription alive event.
 MonitoredItemBase removeItem(MonitoredItemBase item)
          Remove a monitored item from the subscription.
 MonitoredItemBase removeItem(org.opcfoundation.ua.builtintypes.UnsignedInteger clientHandle)
          Remove a monitored item from the subscription.
 org.opcfoundation.ua.builtintypes.StatusCode[] removeItems()
          Removes all monitored items from the subscription at once.
 org.opcfoundation.ua.builtintypes.StatusCode[] removeItems(MonitoredItemBase... items)
          Removes several monitored items from the subscription at once.
 void removeNotificationListener(SubscriptionNotificationListener listener)
          Remove a listener from the Notification event.
 void republishAllAvailable()
           
protected  void reset()
          Reset the subscription to a "removed" state.
protected  boolean serverConnected()
           
protected  void setClient(UaClient server)
           
 void setMaxMonitoredItemsPerCall(int maxMonitoredItemsPerCall)
          Define the maximum number of items in one service call: this may reflect the respective OperationLimit (default) of the server or you can define a sensible limit to avoid too big requests, for example when the client is reconnecting.
 void setMonitoringMode(org.opcfoundation.ua.core.MonitoringMode monitoringMode)
          Set the monitoring mode of all items in the subscription.
protected  org.opcfoundation.ua.core.SetMonitoringModeResponse setMonitoringMode(org.opcfoundation.ua.core.MonitoringMode monitoringMode, List<MonitoredItem> items)
          Set the monitoring mode of the specified items.
 void setNotificationBufferSize(int maxNotificationDataQueueSize)
          Define the maximum number of NotificationData packets to keep in the internal buffer.
 void setPublishingInterval(long requestedPublishingInterval, TimeUnit unit)
          This interval defines the cyclic rate that the Subscription is being requested to return Notifications to the Client.
 void setRetransmissionEnabled(boolean republishEnabled)
          Define whether the Subscription is enabled to call Republish to the server.
protected  void setSubscriptionId(int i)
           
protected  void setSubscriptionId(org.opcfoundation.ua.builtintypes.UnsignedInteger id)
           
protected  void setTimeout(boolean value)
           
 void setTimeoutDetectionFactor(double timeoutDetectionFactor)
          Set factor, which is used to predict when the subscription has timed out.
 void setTimestampsToReturn(org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn)
          Define the timestamps to request from the server for the data change notifications.
 void transferTo(UaClient newClient)
          Move the subscription to another client connection.
 void transferTo(UaClient newClient, org.opcfoundation.ua.builtintypes.UnsignedInteger subscriptionId)
          Move the subscription to another client connection, using the provided SubscriptionId.
 void updateItems()
          Update the locally modified monitored items in the server.
 void updateMonitoringModes()
          Update all pending monitoring mode changes to the server.
protected  void updateSubscription()
           
 
Methods inherited from class com.prosysopc.ua.SubscriptionBase
addItem, beginUpdate, compareTo, endUpdate, getItem, getItemCount, getItems, getLifetimeCount, getMaxKeepAliveCount, getMaxNotificationsPerPublish, getPriority, getPublishingInterval, getSubscriptionId, hasItem, hasItem, isPublishingEnabled, setLifetimeCount, setLifetimeCount, setMaxKeepAliveCount, setMaxKeepAliveCount, setMaxNotificationsPerPublish, setMaxNotificationsPerPublish, setPriority, setPriority, setPublishingEnabled, setPublishingInterval, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

modified

protected boolean modified
Constructor Detail

Subscription

public Subscription()
Create a new subscription using the default values. PublishingEnabled=true, PublishingInterval=1000 (ms), LifeTimeCount=60 (intervals), MaxKeepAliveCount=20 (intervals), MaxNotificationsPerPublish=0, Priority=0


Subscription

public Subscription(Boolean publishingEnabled,
                    Double requestedPublishingInterval,
                    long requestedLifetimeCount,
                    long requestedMaxKeepAliveCount,
                    long maxNotificationsPerPublish,
                    int priority)

Subscription

public Subscription(org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount,
                    Double requestedPublishingInterval,
                    Boolean publishingEnabled,
                    org.opcfoundation.ua.builtintypes.UnsignedByte priority)
Parameters:
maxNotificationsPerPublish -
requestedLifetimeCount -
requestedMaxKeepAliveCount -
requestedPublishingInterval -
publishingEnabled -
priority -
Method Detail

addAliveListener

public void addAliveListener(SubscriptionAliveListener subscriptionAliveListener)
Add a listener for the subscription alive and timeout events. If hasAliveListener(SubscriptionAliveListener), the listener is not added again.

Parameters:
subscriptionAliveListener -
See Also:
SubscriptionAliveListener

addItem

public org.opcfoundation.ua.core.MonitoredItemCreateResult addItem(MonitoredItem item)
                                                            throws ServiceException,
                                                                   StatusException
Adds a monitored item to the subscription. If we are connected to a server, the item is also created in the server. The item is added to the subscription even if the server returns an error for it. MonitoredItem.getErrorCode() will be set accordingly and an exception is raised from here. You can use removeItem(MonitoredItemBase) to remove it.

Parameters:
item -
Returns:
Result from the server to the CreateMonitoredItems call or null, if we are not connected.
Throws:
ServiceException - if the service call fails.
StatusException - if the server returns an error for the item.
See Also:
MonitoredItem.getErrorCode()

addItems

public org.opcfoundation.ua.core.MonitoredItemCreateResult[] addItems(MonitoredItem... items)
                                                               throws ServiceException
Adds several monitored items to the subscription at once. If we are connected to a server, the items are also created in the server. The items are added to the subscription even if the server returns an error for them. MonitoredItem.getErrorCode() will be set accordingly for each item.

Parameters:
items - the new item definitions
Returns:
Results from the server to the CreateMonitoredItems call or null, if we are not connected
Throws:
ServiceException - if the service call fails.
See Also:
MonitoredItem.getErrorCode()

addNotificationListener

public void addNotificationListener(SubscriptionNotificationListener notificationListener)
Add a listener for the Notification notification event. If hasNotificationListener(SubscriptionNotificationListener), the listener is not added again.

Parameters:
notificationListener -
See Also:
SubscriptionNotificationListener

getAliveListeners

public SubscriptionAliveListener[] getAliveListeners()
Returns:
the aliveListeners

getAvailableSequenceNumbers

public org.opcfoundation.ua.builtintypes.UnsignedInteger[] getAvailableSequenceNumbers()
Returns:
The available message sequence numbers in the server for this subscription. May be null, if nothing hasn't been received yet.

getClient

public UaClient getClient()
Returns:
the UaClient that is handling the subscription.

getDiagnosticInfo

public org.opcfoundation.ua.builtintypes.DiagnosticInfo getDiagnosticInfo()
Returns:
the diagnosticInfo for the latest StatusChange notification
See Also:
getStatus()

getItem

public MonitoredItem getItem(org.opcfoundation.ua.builtintypes.NodeId nodeId,
                             org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
Description copied from class: SubscriptionBase
Find the item that is listening to the specified node attribute.

Overrides:
getItem in class SubscriptionBase
Parameters:
nodeId - the listened node
attributeId - the attribute
Returns:
the respective monitored item or null, if there is no item that is listening to the specified node attribute

getLastAlive

public Calendar getLastAlive()
Returns:
the timestamp of the last notification message from the server.

getLastOperationDiagnostics

public org.opcfoundation.ua.builtintypes.DiagnosticInfo[] getLastOperationDiagnostics()
The operation level diagnostic information related to the last service call.

Use setOperationDiagnosticMask to define which operation level diagnostic information you wish to receive with the service calls. If you suspect that the results contain diagnostics, check this array after the service call.

Note that if you perform parallel service calls, they must be synchronized so that you get the lastOperationDiagnostics for the previous call. Or use alternative calls, such as 'read', which return the diagnostics as part of the service result.

Returns:
the array of diagnostic information for the last service call or null, if none was returned
See Also:
getLastServiceDiagnostics()

getLastSequenceNumber

public org.opcfoundation.ua.builtintypes.UnsignedInteger getLastSequenceNumber()
Returns:
the sequence number of the last subscription notification received from the server

getLastServiceDiagnostics

public org.opcfoundation.ua.builtintypes.DiagnosticInfo getLastServiceDiagnostics()
The service level diagnostic information related to the last service call. Use setServiceDiagnosticMask to define which service level diagnostics you wish to receive with the service calls. If you suspect that the results contain diagnostics, check this value after the service call.

Note that if you perform parallel service calls, they must be synchronized so that you get the lastServiceDiagnostics for the previous call. Or use alternative calls, such as 'read', which return the diagnostics as part of the service result.

If a service fails due to a bad ServiceResult, you can read the diagnostics to check if the server provide is additional information about the problem.

Returns:
the service level diagnostic information for the last service call or null, if none was returned
See Also:
getLastOperationDiagnostics(), getLastServiceResult()

getLastServiceResult

public org.opcfoundation.ua.builtintypes.StatusCode getLastServiceResult()
The latest service result received for the service calls used to control the subscription.

Returns:
the ServiceResult of the last service call for the subscription
See Also:
getLastServiceDiagnostics()

getMaxMonitoredItemsPerCall

public int getMaxMonitoredItemsPerCall()
Returns:
the maximum number of items to use for a single service call
See Also:
setMaxMonitoredItemsPerCall(int)

getNotificationBufferSize

public int getNotificationBufferSize()
The maximum size of the internal buffer used for incoming data packets.

Returns:
the maxNotificationDataQueueSize
See Also:
setNotificationBufferSize(int)

getNotificationListeners

public SubscriptionNotificationListener[] getNotificationListeners()
Returns:
the notificationListeners

getStatus

public org.opcfoundation.ua.builtintypes.StatusCode getStatus()
The status received from the latest StatusChange notification.

Returns:
the status of the subscription
See Also:
getDiagnosticInfo()

getTimeoutDetectionFactor

public double getTimeoutDetectionFactor()
Returns:
the timeoutDetectionFactor

getTimestampsToReturn

public org.opcfoundation.ua.core.TimestampsToReturn getTimestampsToReturn()
Returns:
the requested timestamps
See Also:
setTimestampsToReturn(TimestampsToReturn)

hasAliveListener

public boolean hasAliveListener(SubscriptionAliveListener subscriptionAliveListener)
Check if the subscription already has the specified alive listener.

Parameters:
subscriptionAliveListener - the listener to check
Returns:
true if the subscription has the listener

hasNotificationListener

public boolean hasNotificationListener(SubscriptionNotificationListener notificationListener)
Check if the subscription already has the specified notification listener.

Parameters:
notificationListener - the listener to check
Returns:
true if the subscription has the listener

isConnected

public boolean isConnected()
Is the subscription connected to the server.

When the subscription is added to the server, it gets a SubscriptionId. When the subscription is removed from the server the subscriptionId is set to null. This method simply checks that the subscriptionId is assigned and is non-zero.

If the client loses a connection to the server, the subscriptions will stay connected. If a the client connection is reopened, and a new session is created, the client will try to transfer the subscriptions that are already connected, to the new session.

Returns:
true when the subscription is connected to the server, i.e. subscriptionId is valid.

isModified

public boolean isModified()
Returns:
the modified state, which is true when there are modifications in the subscription that need to be applied to the server side subscription.

isRetransmissionEnabled

public boolean isRetransmissionEnabled()
Whether the Subscription is enabled to call Republish to the server.

This enables in effect the retransmission of missing notifications, in case the subscription notices such a case.

The notifications are tracked with sequenceNumbers, which enable the client to re-request the notifications that it find missing.

Returns:
the retransmissionEnabled

isTimeout

public boolean isTimeout()
Check whether the subscription timeout has occurred. The timeout occurs, if the server does not send any notification or keep alive message for the time interval specified by MaxKeepAliveCount.

Returns:
true, if the subscription timeout has occurred.
See Also:
SubscriptionBase.getMaxKeepAliveCount()

itemsToString

public String itemsToString()
Convert the monitored items to a string for output purposes

Returns:
the string consisting of the items.

readAll

public org.opcfoundation.ua.builtintypes.DataValue[] readAll(Double maxAge,
                                                             org.opcfoundation.ua.core.TimestampsToReturn timestamps)
                                                      throws ServiceException
Read the current value of each MonitoredDataItem in the subscription.

Makes a UaClient#read() call to the server with the NodeIds for every MonitoredDataItem as provided by SubscriptionBase.getItems().

This is a convenience method to provide a quick way to refresh the current values of the items in a subscription. This may be necessary if data is missed for the subscription during a communication problem, i.e. SubscriptionNotificationListener.onMissingData(UnsignedInteger, long, long, StatusCode) has been called.

Note that the server should provide the initial value for every item when the items are created in the server, so you should not need to use 'read' to get the values then.

Parameters:
maxAge - The maximum age of the value that is accepted. See UaClient.read(Double, TimestampsToReturn, ReadValueId...) for details
timestamps - Which timestamps to return
Returns:
An array of DataValues corresponding to the monitored items as provided by SubscriptionBase.getItems(). Only MonitoredDataItems are regarded. If there are MonitoredEventItems, the respective DataValue in the array is a null value with expected StatusCode Bad_NodeIdInvalid
Throws:
ServiceException - If the read() service call to the server fails

removeAliveListener

public void removeAliveListener(SubscriptionAliveListener subscriptionAliveListener)
Remove a listener for the subscription alive event.

Parameters:
subscriptionAliveListener -
See Also:
SubscriptionAliveListener

removeItem

public MonitoredItemBase removeItem(MonitoredItemBase item)
                             throws ServiceException,
                                    StatusException
Remove a monitored item from the subscription.

Specified by:
removeItem in class SubscriptionBase
Parameters:
item - The monitored item to remove.
Returns:
The removed item or null, if it was not in the subscription.
Throws:
ServiceException - if the service call to delete the item from the server fails.
StatusException - if the delete response from the server is bad
See Also:
removeItem(UnsignedInteger), removeItems(), removeItems(MonitoredItemBase...)

removeItem

public MonitoredItemBase removeItem(org.opcfoundation.ua.builtintypes.UnsignedInteger clientHandle)
                             throws ServiceException,
                                    StatusException
Remove a monitored item from the subscription.

Overrides:
removeItem in class SubscriptionBase
Parameters:
clientHandle - The clientHandle of the monitored item to remove.
Returns:
The removed item or null, if it was not in the subscription.
Throws:
ServiceException - if the service call to delete the item from the server fails.
StatusException - if the delete response from the server is bad
See Also:
removeItem(MonitoredItemBase), removeItems(), removeItems(MonitoredItemBase...)

removeItems

public org.opcfoundation.ua.builtintypes.StatusCode[] removeItems()
                                                           throws ServiceException
Removes all monitored items from the subscription at once. If we are connected to a server, the items are also deleted in the server. The items are removed from the subscription even if the server returns an error for them.

Calls removeItems(MonitoredItemBase...) with null.

Parameters:
items - Monitored items. If null, all items in the subscription are removed.
Returns:
Results from the server to the deleteMonitoredItems call or null, if we are not connected
Throws:
ServiceException - if the service call fails.
See Also:
removeItem(MonitoredItemBase), removeItem(UnsignedInteger), removeItems(MonitoredItemBase...)

removeItems

public org.opcfoundation.ua.builtintypes.StatusCode[] removeItems(MonitoredItemBase... items)
                                                           throws ServiceException
Removes several monitored items from the subscription at once. If we are connected to a server, the items are also deleted in the server. The items are removed from the subscription even if the server returns an error for them.

Parameters:
items - Monitored items. If null, all items in the subscription are removed.
Returns:
Results from the server to the deleteMonitoredItems call or null, if we are not connected
Throws:
ServiceException - if the service call fails.
See Also:
removeItem(MonitoredItemBase), removeItem(UnsignedInteger), removeItems()

removeNotificationListener

public void removeNotificationListener(SubscriptionNotificationListener listener)
Remove a listener from the Notification event.

Parameters:
listener - the listener to remove
See Also:
SubscriptionNotificationListener

republishAllAvailable

public void republishAllAvailable()
                           throws ServiceException
Throws:
ServiceException

setMaxMonitoredItemsPerCall

public void setMaxMonitoredItemsPerCall(int maxMonitoredItemsPerCall)
Define the maximum number of items in one service call: this may reflect the respective OperationLimit (default) of the server or you can define a sensible limit to avoid too big requests, for example when the client is reconnecting.

Parameters:
maxMonitoredItemsPerCall - the maxMonitoredItemsPerCall to set. Use 0 to use no limit. Use -1 to use what UaClient.getActualOperationLimits() defines (this is the default).

setMonitoringMode

public void setMonitoringMode(org.opcfoundation.ua.core.MonitoringMode monitoringMode)
                       throws ServiceException
Set the monitoring mode of all items in the subscription.

Calls #setMonitoringMode(MonitoringMode, MonitoredItemBase...) with 'null' items.

Parameters:
monitoringMode - the mode to set to the items
Throws:
ServiceException - if the service call to the server fails

setNotificationBufferSize

public void setNotificationBufferSize(int maxNotificationDataQueueSize)
Define the maximum number of NotificationData packets to keep in the internal buffer. The buffer is used to handle the incoming notification packets in the client. The PublishTask of the UaClient will remove entries from the buffer and calls the notification methods. But data may come in faster than the client can handle. In this case old entries are simply removed from the buffer to keep the buffer size at the defined limit.

Default: 100

Parameters:
maxNotificationDataQueueSize - the maxNotificationDataQueueSize to set

setPublishingInterval

public void setPublishingInterval(long requestedPublishingInterval,
                                  TimeUnit unit)
                           throws ServiceException
This interval defines the cyclic rate that the Subscription is being requested to return Notifications to the Client. This interval is expressed in milliseconds.

The negotiated value for this parameter returned in the response is used as the default sample interval for MonitoredItems assigned to this Subscription.

The value 0 is invalid.

Converts the requestedPublishingInterval to milliseconds and calls SubscriptionBase.setPublishingInterval(double).

Overrides:
setPublishingInterval in class SubscriptionBase
Parameters:
requestedPublishingInterval - requested value for the publishing interval
unit - the time unit of the requestedPublishingInterval argument
Throws:
ServiceException - If the parameter could not be changed.
See Also:
SubscriptionBase.setPublishingInterval(double)

setRetransmissionEnabled

public void setRetransmissionEnabled(boolean republishEnabled)
Define whether the Subscription is enabled to call Republish to the server.

This enables in effect the retransmission of missing notifications, in case the subscription notices such a case.

The notifications are tracked with sequenceNumbers, which enable the client to re-request the notifications that it find missing. * Default: true

Parameters:
retransmissionEnabled - the retransmissionEnabled to set

setTimeoutDetectionFactor

public void setTimeoutDetectionFactor(double timeoutDetectionFactor)
Set factor, which is used to predict when the subscription has timed out. This factor is multiplied by SubscriptionBase.getMaxKeepAliveCount() and SubscriptionBase.getPublishingInterval()

Parameters:
timeoutDetectionFactor - the timeoutDetectionFactor to set (default 1.3), must be greater than 1
Throws:
IllegalArgumentException - if timeoutDetectionFactor is <= 1

setTimestampsToReturn

public void setTimestampsToReturn(org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn)
Define the timestamps to request from the server for the data change notifications.

Parameters:
timestampsToReturn -

transferTo

public void transferTo(UaClient newClient)
                throws ServiceException,
                       StatusException
Move the subscription to another client connection. If connected to a server, the new client will also call transferSubscription on the server. This will move the subscription in the server to the new client session.

Parameters:
newClient - The new client. If the subscription was defined on another client, it will be moved to the new client session.
Throws:
StatusException - If the transfer to a new client did not succeed.
ServiceException - If the service calls failed.

transferTo

public void transferTo(UaClient newClient,
                       org.opcfoundation.ua.builtintypes.UnsignedInteger subscriptionId)
                throws ServiceException,
                       StatusException
Move the subscription to another client connection, using the provided SubscriptionId. If connected to a server, the new client will also call transferSubscription on the server. This will move the subscription in the server to the new client session.

Parameters:
newClient - The new client. If the subscription was defined on another client, it will be moved to the new client session.
subscriptionId - The SubscriptionId of the subscription to move. This enables moving the subscription from another application by communicating the SubscriptionId between them. If the subscription is created in this application, you can use transferTo(UaClient) to move it to a new UaClient instance.
Throws:
StatusException - If the transfer to a new client did not succeed.
ServiceException - If the service calls failed.

updateItems

public void updateItems()
                 throws ServiceException
Update the locally modified monitored items in the server.

Goes through all Items and checks every one that is marked with MonitoredItem.isModified(). Those are included in a service call to the server for modifymonitoredItems.

The method is automatically called whenever you modify an item or several, inside a SubscriptionBase.beginUpdate()/SubscriptionBase.endUpdate() loop.

In case endUpdate fails, you can retry to update the pending changes by calling the modifyItems later.

Throws:
ServiceException - if the service call to the server fails. You may need to retry again, depending on the actual error.

updateMonitoringModes

public void updateMonitoringModes()
                           throws ServiceException
Update all pending monitoring mode changes to the server.

Throws:
ServiceException

applyUpdates

protected void applyUpdates()
                     throws ServiceException
Description copied from class: SubscriptionBase
Apply the pending modifications guarded by beginUpdate/endUpdate.

Overrides:
applyUpdates in class SubscriptionBase
Throws:
ServiceException

checkOperationResult

protected void checkOperationResult(org.opcfoundation.ua.builtintypes.StatusCode statusCode)
                             throws StatusException
Parameters:
dataValue -
Throws:
StatusException

checkServiceResult

protected void checkServiceResult(org.opcfoundation.ua.builtintypes.ServiceResponse response,
                                  org.opcfoundation.ua.builtintypes.DiagnosticInfo[] operationDiagnostics)
                           throws ServiceException
Parameters:
response - The service response to check.
operationDiagnostics -
Throws:
ServiceException - If the server returns a bad ServiceResult code for the service call.

checkTimeout

protected void checkTimeout()

createItems

protected void createItems()
                    throws ServiceException
Throws:
ServiceException

createMonitoredItems

protected org.opcfoundation.ua.core.CreateMonitoredItemsResponse createMonitoredItems(MonitoredItemBase... items)
                                                                               throws ServiceException
Throws:
ServiceException

deleteMonitoredItems

protected org.opcfoundation.ua.core.DeleteMonitoredItemsResponse deleteMonitoredItems(MonitoredItemBase... items)
                                                                               throws ServiceException
Parameters:
item -
Returns:
Throws:
ServiceException

enabledChanged

protected void enabledChanged()
                       throws ServiceException,
                              StatusException
Description copied from class: SubscriptionBase
Handles a change in PublishingEnabled

Overrides:
enabledChanged in class SubscriptionBase
Throws:
ServiceException
StatusException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

fireAfterCreate

protected void fireAfterCreate()

fireAlive

protected void fireAlive()
Fire the Alive event.


fireBufferOverflow

protected void fireBufferOverflow(org.opcfoundation.ua.builtintypes.UnsignedInteger sequenceNumber,
                                  org.opcfoundation.ua.builtintypes.ExtensionObject[] notificationData)
Parameters:
sequenceNumber -
notificationData -

fireDataChange

protected void fireDataChange(MonitoredDataItem item,
                              org.opcfoundation.ua.builtintypes.DataValue newValue)
Parameters:
item -
newValue -

fireError

protected void fireError(Object notification,
                         Exception exception)
Parameters:
dataChangeNotification -
e -

fireEvent

protected void fireEvent(MonitoredEventItem item,
                         org.opcfoundation.ua.builtintypes.Variant[] values)
Parameters:
item -
values -

fireMissingData

protected long fireMissingData(org.opcfoundation.ua.builtintypes.UnsignedInteger lastSequenceNumber2,
                               long sequenceNumber,
                               long newSequenceNumber,
                               org.opcfoundation.ua.builtintypes.StatusCode serviceResult)
Parameters:
lastSequenceNumber2 -
sequenceNumber -
newSequenceNumber -
serviceResult -
Returns:
newSequenceNumber

fireNotification

protected void fireNotification(org.opcfoundation.ua.core.NotificationData notification)
Fire the Notification event.

Parameters:
notification -

fireStatusChange

protected void fireStatusChange(org.opcfoundation.ua.builtintypes.StatusCode oldStatus,
                                org.opcfoundation.ua.builtintypes.StatusCode newStatus,
                                org.opcfoundation.ua.builtintypes.DiagnosticInfo diagnosticInfo)
Parameters:
oldStatus -
newStatus -
diagnosticInfo -

fireTimeout

protected void fireTimeout()
Fire the Timeout event.


getAvailableSequenceNumbersList

protected List<org.opcfoundation.ua.builtintypes.UnsignedInteger> getAvailableSequenceNumbersList()
Returns:

getMonitoringParameters

protected org.opcfoundation.ua.core.MonitoringParameters getMonitoringParameters(MonitoredItemBase item)
Parameters:
item -
Returns:
Throws:
ServiceException

handleNotificationDatas

protected void handleNotificationDatas()
                                throws ServerConnectionException,
                                       ServiceException
Handles all pending notifications from the responseQueue, where they have been recorded by onPublishResponse(PublishResponse)

Throws:
ServerConnectionException
ServiceException

hasPublishResponses

protected boolean hasPublishResponses()
Returns:

isAliveNotification

protected boolean isAliveNotification(org.opcfoundation.ua.builtintypes.ExtensionObject[] notificationData)
Parameters:
notificationData -
Returns:

itemChanged

protected void itemChanged(MonitoredItem item)
                    throws ServiceException
Throws:
ServiceException

modifyMonitoredItems

protected org.opcfoundation.ua.core.ModifyMonitoredItemsResponse modifyMonitoredItems(List<MonitoredItem> items)
                                                                               throws ServiceException
Parameters:
subscription -
item -
Returns:
Throws:
ServiceException

monitoringModeChanged

protected void monitoringModeChanged(MonitoredItem monitoredItem)
                              throws ServiceException
Parameters:
monitoredItem -
Throws:
ServiceException

onPublishResponse

protected void onPublishResponse(org.opcfoundation.ua.core.PublishResponse response)
Records the new notification to the responseQueue to be handled later at #handleNotificationData in another thread. this method is called in the stack thread that provides the asynchronous response to Publish

Parameters:
response -

paramChanged

protected void paramChanged()
                     throws ServiceException
Description copied from class: SubscriptionBase
Parameter change "event".

Overrides:
paramChanged in class SubscriptionBase
Throws:
ServiceException

reset

protected void reset()
Reset the subscription to a "removed" state.


serverConnected

protected boolean serverConnected()
Returns:
true if the subscription is attached to a server and the server is connected.

setClient

protected void setClient(UaClient server)

setMonitoringMode

protected org.opcfoundation.ua.core.SetMonitoringModeResponse setMonitoringMode(org.opcfoundation.ua.core.MonitoringMode monitoringMode,
                                                                                List<MonitoredItem> items)
                                                                         throws ServiceException
Set the monitoring mode of the specified items.

Parameters:
monitoringMode - the mode to set to the items
items - the items to change. If null, all items in the subscription are changed (equals to using setMonitoringMode(MonitoringMode))
Throws:
ServiceException - if the service call to the server fails

setSubscriptionId

protected void setSubscriptionId(int i)
Parameters:
i -

setSubscriptionId

protected void setSubscriptionId(org.opcfoundation.ua.builtintypes.UnsignedInteger id)
Overrides:
setSubscriptionId in class SubscriptionBase

setTimeout

protected void setTimeout(boolean value)
Parameters:
value -

updateSubscription

protected void updateSubscription()
                           throws ServiceException
Throws:
ServiceException


Copyright © 2018. All rights reserved.