com.prosysopc.ua.server
Class Subscription

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

public class Subscription
extends SubscriptionBase

An OPC UA subscription. Subscriptions are used to report Notifications to the Client.


Nested Class Summary
 class Subscription.PublishTask
          A task for publishing the data change notifications.
 
Field Summary
 
Fields inherited from class com.prosysopc.ua.SubscriptionBase
items, lifetimeCount, maxKeepAliveCount, maxNotificationsPerPublish, priority, publishingEnabled, publishingInterval, updateCount
 
Constructor Summary
Subscription(SubscriptionManager subscriptionManager, org.opcfoundation.ua.builtintypes.UnsignedInteger id, Boolean publishingEnabled, Double requestedPublishingInterval, org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount, org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount, org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish, org.opcfoundation.ua.builtintypes.UnsignedByte priority)
          Create a new subscription.
 
Method Summary
protected  void acknowledge(org.opcfoundation.ua.builtintypes.UnsignedInteger sequenceNumber)
          Acknowledge that a notification was received by the client.
 MonitoredDataItem addDataItem(ServiceContext serviceContext, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId, org.opcfoundation.ua.utils.NumericRange indexRange, org.opcfoundation.ua.builtintypes.QualifiedName dataEncoding, org.opcfoundation.ua.core.MonitoringMode monitoringMode)
          Add a new monitoring item to the subscription.
 MonitoredDataItem addDataItem(ServiceContext serviceContext, UaNode node, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId, org.opcfoundation.ua.utils.NumericRange indexRange, org.opcfoundation.ua.builtintypes.QualifiedName dataEncoding, org.opcfoundation.ua.core.MonitoringMode monitoringMode)
          Add a new monitoring item to the subscription.
 MonitoredEventItem addEventItem(ServiceContext serviceContext, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.core.EventFilter eventFilter, org.opcfoundation.ua.core.EventFilterResult filterResult)
          Add a new item to event monitoring.
protected  void addToPublishQueue(long time, boolean needsKeepAlive)
           
 void close()
          Close the subscription.
 int compareTo(SubscriptionBase s)
           
protected  void enabledChanged()
          Handles a change in PublishingEnabled
 boolean equals(Object obj)
           
 org.opcfoundation.ua.builtintypes.UnsignedInteger[] getAvailableSequenceNumbers()
           
 SubscriptionDiagnostics getDiagnostics()
           
 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.
 int getMaxNotificationsPerPublish()
          The maximum number of notifications that the Client wishes to receive in a single Publish response.
protected  org.opcfoundation.ua.core.NotificationMessage getNextNotificationMessage(Session session)
           
protected  org.opcfoundation.ua.builtintypes.UnsignedInteger getNextSequenceNumber(boolean isKeepAliveMessage)
           
protected  org.opcfoundation.ua.core.NotificationMessage getNotificationMessage(org.opcfoundation.ua.builtintypes.UnsignedInteger retransmitSequenceNumber)
           
protected  BlockingQueue<SubscriptionBase> getPublishQueue()
           
 Session getSession()
           
 SubscriptionManager getSubscriptionManager()
           
 boolean hasExpired()
           
 int hashCode()
           
 Boolean hasMoreNotifications()
           
protected  void internalClose(boolean removeFromQueue)
          Close the subscription.
protected  void internalRemoveItem(MonitoredItem item)
          The actual method that will remove the item from the Subscription.
 boolean isClosed()
           
protected  boolean isTimeToPublish(long now)
           
protected  void monitoringModeChanged(MonitoredItem monitoredItem)
           
protected  void needTrigger(MonitoredItem triggeringItem, boolean isDataChange, boolean isEventChange)
           
protected  void newEventAvailable(MonitoredEventItem monitoredEventItem)
           
protected  void newSampleAvailable(MonitoredItem monitoredItem)
           
protected  void paramChanged()
          Parameter change "event".
 MonitoredItemBase removeItem(MonitoredItemBase item)
          Remove an item from the subscription.
 MonitoredItemBase removeItem(org.opcfoundation.ua.builtintypes.UnsignedInteger itemId)
          Remove an item from the subscription.
protected  void resetKeepAliveCounter()
           
protected  void resetLastAliveTime()
           
protected  void setPublishQueue(BlockingQueue<SubscriptionBase> queue)
           
protected static void setPublishTimeCheckAllowedThresholdMS(int value)
          Set allowed threshold for publish checks.
protected  void setSession(Session session)
           
 void start()
          Close the subscription.
protected  void startPublishing()
          Starts the publish timer.
protected  void stopPublishing()
          Stops the publish timer.
protected  void updateDiagnostics()
           
 
Methods inherited from class com.prosysopc.ua.SubscriptionBase
addItem, applyUpdates, beginUpdate, endUpdate, getItem, getItemCount, getItems, getLifetimeCount, getMaxKeepAliveCount, getPriority, getPublishingInterval, getSubscriptionId, hasItem, hasItem, isPublishingEnabled, setLifetimeCount, setLifetimeCount, setMaxKeepAliveCount, setMaxKeepAliveCount, setMaxNotificationsPerPublish, setMaxNotificationsPerPublish, setPriority, setPriority, setPublishingEnabled, setPublishingInterval, setPublishingInterval, setSubscriptionId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Subscription

public Subscription(SubscriptionManager subscriptionManager,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger id,
                    Boolean publishingEnabled,
                    Double requestedPublishingInterval,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger requestedLifetimeCount,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger requestedMaxKeepAliveCount,
                    org.opcfoundation.ua.builtintypes.UnsignedInteger maxNotificationsPerPublish,
                    org.opcfoundation.ua.builtintypes.UnsignedByte priority)
Create a new subscription.

Parameters:
publishingEnabled -
requestedPublishingInterval -
requestedLifetimeCount -
requestedMaxKeepAliveCount -
maxNotificationsPerPublish -
priority -
Method Detail

setPublishTimeCheckAllowedThresholdMS

protected static void setPublishTimeCheckAllowedThresholdMS(int value)
Set allowed threshold for publish checks. For internal use only!.

Parameters:
value -

addDataItem

public MonitoredDataItem addDataItem(ServiceContext serviceContext,
                                     org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                     org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId,
                                     org.opcfoundation.ua.utils.NumericRange indexRange,
                                     org.opcfoundation.ua.builtintypes.QualifiedName dataEncoding,
                                     org.opcfoundation.ua.core.MonitoringMode monitoringMode)
Add a new monitoring item to the subscription.

Parameters:
nodeId -
dataEncoding -
indexRange -
attributeId -
monitoringMode -
serviceContext -

addDataItem

public MonitoredDataItem addDataItem(ServiceContext serviceContext,
                                     UaNode node,
                                     org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId,
                                     org.opcfoundation.ua.utils.NumericRange indexRange,
                                     org.opcfoundation.ua.builtintypes.QualifiedName dataEncoding,
                                     org.opcfoundation.ua.core.MonitoringMode monitoringMode)
Add a new monitoring item to the subscription.

Parameters:
node -
dataEncoding -
indexRange -
attributeId -
monitoringMode -

addEventItem

public MonitoredEventItem addEventItem(ServiceContext serviceContext,
                                       org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                       org.opcfoundation.ua.core.EventFilter eventFilter,
                                       org.opcfoundation.ua.core.EventFilterResult filterResult)
                                throws StatusException
Add a new item to event monitoring.

Parameters:
nodeId - the node to monitor
dataEncoding -
eventFilter - the event filter definition.
filterResult -
Returns:
the new monitored item.
Throws:
StatusException

close

public void close()
           throws ServiceException
Close the subscription. Requests the SubscriptionManager to close the subscription.

Throws:
ServiceException - if the SubscriptionManager throws the exception

compareTo

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

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getAvailableSequenceNumbers

public org.opcfoundation.ua.builtintypes.UnsignedInteger[] getAvailableSequenceNumbers()
Returns:
array of the sequence numbers of sent, but not acknowledged notification messages

getDiagnostics

public SubscriptionDiagnostics getDiagnostics()

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

getMaxNotificationsPerPublish

public int getMaxNotificationsPerPublish()
Description copied from class: SubscriptionBase
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.

Overrides:
getMaxNotificationsPerPublish in class SubscriptionBase
Returns:
the maximum number of notifications in a single publish message
See Also:
SubscriptionBase.setMaxNotificationsPerPublish(long)

getSession

public Session getSession()

getSubscriptionManager

public SubscriptionManager getSubscriptionManager()
Returns:
the subscriptionManager

hasExpired

public boolean hasExpired()
Returns:
true if the subscription timed out because of missing publishRequests

hashCode

public int hashCode()
Overrides:
hashCode in class Object

hasMoreNotifications

public Boolean hasMoreNotifications()
Returns:

isClosed

public boolean isClosed()
Returns:

removeItem

public MonitoredItemBase removeItem(MonitoredItemBase item)
                             throws ServiceException,
                                    StatusException
Description copied from class: SubscriptionBase
Remove an item from the subscription.

Specified by:
removeItem in class SubscriptionBase
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
Description copied from class: SubscriptionBase
Remove an item from the subscription.

Overrides:
removeItem in class SubscriptionBase
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

start

public void start()
Close the subscription. No more notifications are sent.


acknowledge

protected void acknowledge(org.opcfoundation.ua.builtintypes.UnsignedInteger sequenceNumber)
                    throws ServiceException
Acknowledge that a notification was received by the client. The notification is then removed from the sentNotifications.

Parameters:
sequenceNumber - the message to acknowledge
Throws:
ServiceException - Bad_SequenceNumberUnknown if the seuqnceNumber is not recognized

addToPublishQueue

protected void addToPublishQueue(long time,
                                 boolean needsKeepAlive)
Parameters:
time -

enabledChanged

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

Overrides:
enabledChanged in class SubscriptionBase
Throws:
ServiceException

getNextNotificationMessage

protected org.opcfoundation.ua.core.NotificationMessage getNextNotificationMessage(Session session)
Returns:
Throws:
ServiceException

getNextSequenceNumber

protected org.opcfoundation.ua.builtintypes.UnsignedInteger getNextSequenceNumber(boolean isKeepAliveMessage)

getNotificationMessage

protected org.opcfoundation.ua.core.NotificationMessage getNotificationMessage(org.opcfoundation.ua.builtintypes.UnsignedInteger retransmitSequenceNumber)
                                                                        throws ServiceException
Parameters:
retransmitSequenceNumber -
Returns:
Throws:
StatusException
ServiceException

getPublishQueue

protected BlockingQueue<SubscriptionBase> getPublishQueue()

internalClose

protected void internalClose(boolean removeFromQueue)
Close the subscription. No more notifications are sent.


internalRemoveItem

protected void internalRemoveItem(MonitoredItem item)
                           throws ServiceException,
                                  StatusException
The actual method that will remove the item from the Subscription. The method is always called by the SubscriptionManager from deleteMonitoredItem. By this way we make sure that the related notifications are always sent from all related Managers.

Parameters:
item -
Throws:
StatusException
ServiceException

isTimeToPublish

protected boolean isTimeToPublish(long now)
Returns:

monitoringModeChanged

protected void monitoringModeChanged(MonitoredItem monitoredItem)

needTrigger

protected void needTrigger(MonitoredItem triggeringItem,
                           boolean isDataChange,
                           boolean isEventChange)

newEventAvailable

protected void newEventAvailable(MonitoredEventItem monitoredEventItem)
Parameters:
monitoredEventItem -

newSampleAvailable

protected void newSampleAvailable(MonitoredItem monitoredItem)
Parameters:
monitoredItem -
value -

paramChanged

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

Overrides:
paramChanged in class SubscriptionBase
Throws:
ServiceException

resetKeepAliveCounter

protected void resetKeepAliveCounter()

resetLastAliveTime

protected void resetLastAliveTime()

setPublishQueue

protected void setPublishQueue(BlockingQueue<SubscriptionBase> queue)
Parameters:
queue - the publishQueue to set

setSession

protected void setSession(Session session)
Parameters:
session -

startPublishing

protected void startPublishing()
Starts the publish timer. Use updateTimer normally to start/stop the timer as necessary.


stopPublishing

protected void stopPublishing()
Stops the publish timer. Use updateTimer normally to start/stop the timer as necessary.


updateDiagnostics

protected void updateDiagnostics()


Copyright © 2018. All rights reserved.