com.prosysopc.ua
Class SubscriptionBase

java.lang.Object
  extended by com.prosysopc.ua.SubscriptionBase
All Implemented Interfaces:
Comparable<SubscriptionBase>
Direct Known Subclasses:
Subscription, Subscription

public abstract class SubscriptionBase
extends Object
implements Comparable<SubscriptionBase>

Base class for an OPC UA Subscription.


Field Summary
protected  Map<org.opcfoundation.ua.builtintypes.UnsignedInteger,MonitoredItemBase> items
           
protected  long lifetimeCount
           
protected  long maxKeepAliveCount
           
protected  int maxNotificationsPerPublish
           
protected  int priority
           
protected  boolean publishingEnabled
           
protected  double publishingInterval
           
protected  int updateCount
           
 
Constructor Summary
SubscriptionBase(org.opcfoundation.ua.builtintypes.UnsignedInteger id, boolean publishingEnabled, double publishingInterval, long lifetimeCount, long maxKeepAliveCount, int maxNotificationsPerPublish, int priority)
           
SubscriptionBase(org.opcfoundation.ua.builtintypes.UnsignedInteger id, Boolean publishingEnabled, Double publishingInterval, org.opcfoundation.ua.builtintypes.UnsignedInteger lifetimeCount, org.opcfoundation.ua.builtintypes.UnsignedInteger maxKeepAliveCount, org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish, org.opcfoundation.ua.builtintypes.UnsignedByte priority)
           
 
Method Summary
 void addItem(MonitoredItemBase item, org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
          Add a new monitoring item to the subscription.
protected  void applyUpdates()
          Apply the pending modifications guarded by beginUpdate/endUpdate.
 void beginUpdate()
          Starts a property or item modification sequence.
 int compareTo(SubscriptionBase s)
           
protected  void enabledChanged()
          Handles a change in PublishingEnabled
 void endUpdate()
          Ends a property or item modification, which was started with beginUpdate().
 MonitoredItemBase getItem(org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
          Find the item that is listening to the specified node attribute.
 MonitoredItemBase getItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
          Get an item from the subscription.
 int getItemCount()
           
 MonitoredItemBase[] getItems()
           
 long getLifetimeCount()
          The lifetime count should be a mimimum of three times the keep-alive count.
 long getMaxKeepAliveCount()
          Max keep alive count defines the number of Publishing Intervals that may pass without any notification being sent.
 int getMaxNotificationsPerPublish()
          The maximum number of notifications that the Client wishes to receive in a single Publish response.
 int getPriority()
          Indicates the relative priority of the Subscription.
 double getPublishingInterval()
          This interval defines the cyclic rate that the Subscription is being requested to return Notifications to the Client.
 org.opcfoundation.ua.builtintypes.UnsignedInteger getSubscriptionId()
          The Server-assigned identifier for the Subscription.
 boolean hasItem(org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
          Checks if the subscription contains an item that is listening to the specified node attribute.
 boolean hasItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
          Checks if the subscription contains an item with the ID.
 boolean isPublishingEnabled()
           
protected  void paramChanged()
          Parameter change "event".
abstract  MonitoredItemBase removeItem(MonitoredItemBase item)
          Remove an item from the subscription.
 MonitoredItemBase removeItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
          Remove an item from the subscription.
 void setLifetimeCount(long requestedLifetimeCount)
          The lifetime count should be a mimimum of three times the keep-alive count.
 void setLifetimeCount(org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount)
          The lifetime count shall be a mimimum of three times the keep-alive count.
 void setMaxKeepAliveCount(long requestedMaxKeepAliveCount)
          When the publishing timer in the Server has expired this number of times without requiring any NotificationMessage to be sent, the Subscription sends a keep-alive Message to the Client.
 void setMaxKeepAliveCount(org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount)
          When the publishing timer in the Server has expired this number of times without requiring any NotificationMessage to be sent, the Subscription sends a keep-alive Message to the Client.
 void setMaxNotificationsPerPublish(long maxNotificationsPerPublish)
          The maximum number of notifications that the Client wishes to receive in a single Publish response.
 void setMaxNotificationsPerPublish(org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish)
          The maximum number of notifications that the Client wishes to receive in a single Publish response.
 void setPriority(int priority)
          Indicates the relative priority of the Subscription.
 void setPriority(org.opcfoundation.ua.builtintypes.UnsignedByte priority)
          Indicates the relative priority of the Subscription.
 void setPublishingEnabled(boolean publishingEnabled)
          A Boolean parameter with the following values : TRUE publishing is enabled for the Subscription.
 void setPublishingInterval(double requestedPublishingInterval)
          This interval defines the cyclic rate that the Subscription is being requested to return Notifications to the Client.
 void setPublishingInterval(long requestedPublishingInterval, TimeUnit timeUnit)
           
protected  void setSubscriptionId(org.opcfoundation.ua.builtintypes.UnsignedInteger id)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

items

protected final Map<org.opcfoundation.ua.builtintypes.UnsignedInteger,MonitoredItemBase> items

lifetimeCount

protected long lifetimeCount

maxKeepAliveCount

protected long maxKeepAliveCount

maxNotificationsPerPublish

protected int maxNotificationsPerPublish

priority

protected int priority

publishingEnabled

protected boolean publishingEnabled

publishingInterval

protected double publishingInterval

updateCount

protected int updateCount
Constructor Detail

SubscriptionBase

public SubscriptionBase(org.opcfoundation.ua.builtintypes.UnsignedInteger id,
                        boolean publishingEnabled,
                        double publishingInterval,
                        long lifetimeCount,
                        long maxKeepAliveCount,
                        int maxNotificationsPerPublish,
                        int priority)

SubscriptionBase

public SubscriptionBase(org.opcfoundation.ua.builtintypes.UnsignedInteger id,
                        Boolean publishingEnabled,
                        Double publishingInterval,
                        org.opcfoundation.ua.builtintypes.UnsignedInteger lifetimeCount,
                        org.opcfoundation.ua.builtintypes.UnsignedInteger maxKeepAliveCount,
                        org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish,
                        org.opcfoundation.ua.builtintypes.UnsignedByte priority)
Method Detail

addItem

public void addItem(MonitoredItemBase item,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
Add a new monitoring item to the subscription.

Parameters:
item -
itemId - The ID to use to map the item in the list. On server side this is the monitoredItemId. On client side it is the clientHandle.

beginUpdate

public void beginUpdate()
Starts a property or item modification sequence. Use the method to group changes to the subscription or items and avoid several modifySubscription or modifyMonitoredItems calls to the server during the edits.

The method must be paired with endUpdate(), preferably with a try-finally block. You can nest several beginUpdate/endUpdate blocks. The final endUpdate will trigger the changes being written to the server using a modifySubscription or modifyMonitoredItems service call.


compareTo

public int compareTo(SubscriptionBase s)
Specified by:
compareTo in interface Comparable<SubscriptionBase>

endUpdate

public final void endUpdate()
                     throws ServiceException
Ends a property or item modification, which was started with beginUpdate().

Throws:
ServiceException - if the update fails due to an error in modifySubscription, modifyItems or setMonitoringMode service call to the server. In that case, you can retry by using a new beginUpdate/endUpdate sequence.

getItem

public MonitoredItemBase getItem(org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                 org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
Find the item that is listening to the specified node attribute.

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

getItem

public MonitoredItemBase getItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
                          throws StatusException
Get an item from the subscription.

Parameters:
itemId - the ID of the item. On the client side this is the ClientHandle and on the server side it is the MonitoredItemId.
Returns:
the item
Throws:
StatusException - if the item is not found, with StatusCode=Bad_MonitoredItemIdInvalid

getItemCount

public int getItemCount()
Returns:
the number of items in the subscription.

getItems

public MonitoredItemBase[] getItems()
Returns:

getLifetimeCount

public long getLifetimeCount()
The lifetime count should be a mimimum of three times the keep-alive count.

When the publishing timer has expired this number of times without a Publish request being available to send a NotificationMessage, then the Subscription will be deleted by the Server.

Returns:
the subscription lifetime count
See Also:
setLifetimeCount(long)

getMaxKeepAliveCount

public long getMaxKeepAliveCount()
Max keep alive count defines the number of Publishing Intervals that may pass without any notification being sent.

If the client does not receive any notification message during the interval specified by the MaxKeepAliveCount (plus some tolerance), the subscription can be considered to be at timeout and the client can assume a problem with a connection to the server.

Returns:
the maximum number of PublishingInterval to pass before a new keep alive message is sent.

getMaxNotificationsPerPublish

public int getMaxNotificationsPerPublish()
The maximum number of notifications that the Client wishes to receive in a single Publish response. A value of zero indicates that there is no limit.

Returns:
the maximum number of notifications in a single publish message
See Also:
setMaxNotificationsPerPublish(long)

getPriority

public int getPriority()
Indicates the relative priority of the Subscription. When more than one Subscription needs to send Notifications, the Server should dequeue a Publish request to the Subscription with the highest priority number (the bigger the number, the higher the priority). For Subscriptions with equal priority the Server should dequeue Publish requests in a round-robin fashion. When the keep-alive period expires for a Subscription it shall take precedence regardless of its priority, in order to prevent the Subscription from expiring.

A Client that does not require special priority settings should set this value to zero.

Returns:
the priority of the subscription
See Also:
setPriority(int)

getPublishingInterval

public double getPublishingInterval()
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.

Returns:
the publishing interval
See Also:
setPublishingInterval(double)

getSubscriptionId

public org.opcfoundation.ua.builtintypes.UnsignedInteger getSubscriptionId()
The Server-assigned identifier for the Subscription. This identifier shall be unique for the entire Server, not just for the Session, in order to allow the Subscription to be transferred to another Session using the TransferSubscriptions service.

Returns:
the current ID

hasItem

public boolean hasItem(org.opcfoundation.ua.builtintypes.NodeId nodeId,
                       org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId)
Checks if the subscription contains an item that is listening to the specified node attribute.

Parameters:
nodeId - the node
attributeId - the attribute
Returns:
true if the subscription has an item listening to the node attribute

hasItem

public boolean hasItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
Checks if the subscription contains an item with the ID.

Parameters:
itemId - the ID of the item. On the client side this is the ClientHandle and on the server side it is the MonitoredItemId.
Returns:
true if the subscription has an item with the ID.

isPublishingEnabled

public boolean isPublishingEnabled()
Returns:
true if publishing is currently enabled in the server.
See Also:
setPublishingEnabled(boolean)

removeItem

public abstract MonitoredItemBase removeItem(MonitoredItemBase item)
                                      throws ServiceException,
                                             StatusException
Remove an item from the subscription.

Parameters:
item - The item to remove.
Returns:
The item that was removed or null, if it was not in the subscription
Throws:
ServiceException - if the (possible) service call to delete the item from the server fails.
StatusException - if the subscription does not contain the item

removeItem

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

Parameters:
itemId - The ID of the item to remove. In the client side this should be the ClientHandle, but on server side, the MonitoredItemId is used.
Returns:
The item that was removed or null, if there was no such item.
Throws:
ServiceException - if the service call to delete the item from the server fails.
StatusException - if the delete response from the server is bad

setLifetimeCount

public final void setLifetimeCount(long requestedLifetimeCount)
                            throws ServiceException
The lifetime count should be a mimimum of three times the keep-alive count.

When the publishing timer has expired this number of times without a Publish request being available to send a NotificationMessage, then the Subscription will be deleted by the Server.

Parameters:
requestedLifetimeCount - The value must be in the range of UnsignedInteger
Throws:
ServiceException - If the parameter could not be changed.

setLifetimeCount

public void setLifetimeCount(org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount)
                      throws ServiceException
The lifetime count shall be a mimimum of three times the keep-alive count.

When the publishing timer has expired this number of times without a Publish request being available to send a NotificationMessage, then the Subscription will be deleted by the Server.

Throws:
ServiceException - If the parameter could not be changed.

setMaxKeepAliveCount

public final void setMaxKeepAliveCount(long requestedMaxKeepAliveCount)
                                throws ServiceException
When the publishing timer in the Server has expired this number of times without requiring any NotificationMessage to be sent, the Subscription sends a keep-alive Message to the Client.

The value 0 is invalid.

Parameters:
requestedMaxKeepAliveCount - The value must be in the range of UnsignedInteger
Throws:
ServiceException - If the parameter could not be changed.

setMaxKeepAliveCount

public void setMaxKeepAliveCount(org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount)
                          throws ServiceException
When the publishing timer in the Server has expired this number of times without requiring any NotificationMessage to be sent, the Subscription sends a keep-alive Message to the Client.

The value 0 is invalid.

Parameters:
requestedMaxKeepAliveCount -
Throws:
ServiceException - If the parameter could not be changed.

setMaxNotificationsPerPublish

public final void setMaxNotificationsPerPublish(long maxNotificationsPerPublish)
                                         throws ServiceException
The maximum number of notifications that the Client wishes to receive in a single Publish response. A value of zero indicates that there is no limit.

Parameters:
maxNotificationsPerPublish - The value must be in the range of UnsignedInteger, but if the value is bigger than Integer.MAX_VALUE, Integer.MAX_VALUE will be used instead.
Throws:
ServiceException - If the parameter could not be changed.

setMaxNotificationsPerPublish

public void setMaxNotificationsPerPublish(org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish)
                                   throws ServiceException
The maximum number of notifications that the Client wishes to receive in a single Publish response. A value of zero indicates that there is no limit.

Parameters:
maxNotificationsPerPublish - If the value is bigger than Integer.MAX_VALUE, Integer.MAX_VALUE will be used instead.
Throws:
ServiceException - If the parameter could not be changed.

setPriority

public final void setPriority(int priority)
                       throws ServiceException
Indicates the relative priority of the Subscription. When more than one Subscription needs to send Notifications, the Server should dequeue a Publish request to the Subscription with the highest priority number (the bigger the number, the higher the priority). For Subscriptions with equal priority the Server should dequeue Publish requests in a round-robin fashion. When the keep-alive period expires for a Subscription it shall take precedence regardless of its priority, in order to prevent the Subscription from expiring.

A Client that does not require special priority settings should set this value to zero.

Parameters:
priority - The value must be in the range of UnsignedByte
Throws:
ServiceException - If the parameter could not be changed.

setPriority

public void setPriority(org.opcfoundation.ua.builtintypes.UnsignedByte priority)
                 throws ServiceException
Indicates the relative priority of the Subscription. When more than one Subscription needs to send Notifications, the Server should dequeue a Publish request to the Subscription with the highest priority number. For Subscriptions with equal priority the Server should dequeue Publish requests in a round-robin fashion. When the keep-alive period expires for a Subscription it shall take precedence regardless of its priority, in order to prevent the Subscription from expiring.

A Client that does not require special priority settings should set this value to zero.

Parameters:
priority -
Throws:
ServiceException - If the parameter could not be changed.

setPublishingEnabled

public void setPublishingEnabled(boolean publishingEnabled)
                          throws ServiceException,
                                 StatusException
A Boolean parameter with the following values :
TRUE publishing is enabled for the Subscription.
FALSE publishing is disabled for the Subscription.
The value of this parameter does not affect the value of the monitoring mode Attribute of MonitoredItems.

Parameters:
publishingEnabled - the new value to set
Throws:
StatusException - If the parameter could not be changed due to an operation error from the server.
ServiceException - If the parameter could not be changed due to a service call error.

setPublishingInterval

public void setPublishingInterval(double requestedPublishingInterval)
                           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.

Parameters:
requestedPublishingInterval - requested value for the publishing interval in milliseconds
Throws:
ServiceException - If the parameter could not be changed.

setPublishingInterval

public void setPublishingInterval(long requestedPublishingInterval,
                                  TimeUnit timeUnit)
                           throws ServiceException
Throws:
ServiceException
See Also:
setPublishingInterval(double)

toString

public String toString()
Overrides:
toString in class Object

applyUpdates

protected void applyUpdates()
                     throws ServiceException
Apply the pending modifications guarded by beginUpdate/endUpdate.

Throws:
ServiceException

enabledChanged

protected void enabledChanged()
                       throws ServiceException,
                              StatusException
Handles a change in PublishingEnabled

Throws:
ServiceException
StatusException

paramChanged

protected void paramChanged()
                     throws ServiceException
Parameter change "event".

Throws:
ServiceException

setSubscriptionId

protected void setSubscriptionId(org.opcfoundation.ua.builtintypes.UnsignedInteger id)
Parameters:
id -


Copyright © 2018. All rights reserved.