com.prosysopc.ua.server
Class EventManager

java.lang.Object
  extended by com.prosysopc.ua.server.ServiceManagerBase
      extended by com.prosysopc.ua.server.EventManager
All Implemented Interfaces:
CallableListener
Direct Known Subclasses:
EventManagerUaNode

public abstract class EventManager
extends ServiceManagerBase
implements CallableListener

OPC UA Event Manager interface. The Event Manager is the OPC UA server component that is responsible of handling event generation and client requests related to event handling.

The base implementation simply dispatches the calls to the registered listener.


Field Summary
protected  AtomicReference<EventManagerListener> listener
           
protected static org.slf4j.Logger logger
           
protected static org.opcfoundation.ua.core.EventFilterResult RESULT_OK
           
 
Constructor Summary
EventManager(NodeManager nodeManager)
          The constructor used to create a new EventManager.
 
Method Summary
protected  void afterCreateMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem item)
           
protected  void afterDeleteMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem item)
           
protected  void afterModifyMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem item)
           
static org.opcfoundation.ua.builtintypes.ByteString createEventId(long l)
          Create an event ID from a long value
static org.opcfoundation.ua.builtintypes.ByteString createFullEventId(org.opcfoundation.ua.builtintypes.ByteString userEventId)
          Creates a new eventId using a user specific ID.
protected  void createMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.core.EventFilter filter, org.opcfoundation.ua.core.EventFilterResult eventFilterResult)
           
protected  void deleteMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem monitoredItem)
           
static org.opcfoundation.ua.builtintypes.ByteString extractUserEventId(org.opcfoundation.ua.builtintypes.ByteString fullEventId)
          Extract the custom part from the event ID.
 EventManagerListener getListener()
          The listener implementation that gets notified about event manager related actions.
 NodeManager getNodeManager()
          The NodeManager that the event manager is serving.
protected  boolean methodEqualsIdOrName(UaMethod method, org.opcfoundation.ua.builtintypes.NodeId methodId, String methodName)
           
protected  void modifyMonitoredEventItem(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem item, org.opcfoundation.ua.core.EventFilter eventFilter, org.opcfoundation.ua.core.EventFilterResult eventFilterResult)
           
 boolean onCall(ServiceContext serviceContext, org.opcfoundation.ua.builtintypes.NodeId objectId, UaNode object, org.opcfoundation.ua.builtintypes.NodeId methodId, UaMethod method, org.opcfoundation.ua.builtintypes.Variant[] inputArguments, org.opcfoundation.ua.builtintypes.StatusCode[] inputArgumentResults, org.opcfoundation.ua.builtintypes.DiagnosticInfo[] inputArgumentDiagnosticInfos, org.opcfoundation.ua.builtintypes.Variant[] output)
          A method call notification.
protected  boolean refresh(ServiceContext serviceContext, Subscription subscription)
          Handle a ConditionRefresh call from a client.
protected  boolean refresh(ServiceContext serviceContext, Subscription subscription, MonitoredEventItem monitoredItem)
           
protected  void refreshEndEvent(MonitoredEventItem monitoredItem)
           
protected  void refreshEndEvent(Subscription subscription)
          Trigger a RefreshEndEventType.
protected abstract  void refreshItem(MonitoredEventItem item)
           
protected  void refreshItems(ServiceContext serviceContext, Subscription subscription)
          Handles condition refresh for a subscription.
protected  void refreshStartEvent(MonitoredEventItem monitoredItem)
           
protected  void refreshStartEvent(Subscription subscription)
          Trigger a RefreshStartEventType.
protected  void refreshSubscription(ServiceContext serviceContext, org.opcfoundation.ua.builtintypes.UnsignedInteger subscriptionId)
          called internally
 void setListener(EventManagerListener l)
          Define a listener to the Event Manager to get notifications about client actions.
 
Methods inherited from class com.prosysopc.ua.server.ServiceManagerBase
arrayDimensionsMatch, checkIsMethod, checkIsValueNode, checkIsVariable, checkIsVariableOrVariableType, dataTypeEquals, getNode, getNode, getNode, getNode, getNodeManagerTable, getServer, getSubscriptionManager, isValueNode, isVariable, listenerError, requireUaNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger

RESULT_OK

protected static final org.opcfoundation.ua.core.EventFilterResult RESULT_OK

listener

protected final AtomicReference<EventManagerListener> listener
Constructor Detail

EventManager

public EventManager(NodeManager nodeManager)
The constructor used to create a new EventManager.

The event manager is automatically connected to the node manager.

Parameters:
nodeManager - the node manager that the event manager is serving. Must not be null.
Method Detail

createEventId

public static org.opcfoundation.ua.builtintypes.ByteString createEventId(long l)
                                                                  throws RuntimeException
Create an event ID from a long value

Throws:
RuntimeException

createFullEventId

public static org.opcfoundation.ua.builtintypes.ByteString createFullEventId(org.opcfoundation.ua.builtintypes.ByteString userEventId)
Creates a new eventId using a user specific ID. The base of the ID is an automatically incremented long value, converted to a byte array. userEventId is appended to this byte array.

The method is used from triggerEvent methods of the Event types and and you do not normally need to use it.

You can use createEventId(long) to create the user specific part which you can provide to this method or to triggerEvent.

Use #extractUserEventId(byte[]) to get the userEventId out of a full event ID.

Parameters:
userEventId - your own ID for the event.
Returns:
the full event ID.

extractUserEventId

public static org.opcfoundation.ua.builtintypes.ByteString extractUserEventId(org.opcfoundation.ua.builtintypes.ByteString fullEventId)
Extract the custom part from the event ID.

Parameters:
fullEventId - the full eventId created by the SDK
Returns:
the userEventId part, supplied to triggerEvent, or null, if none was given.

getListener

public EventManagerListener getListener()
The listener implementation that gets notified about event manager related actions.

Returns:
the current listener

getNodeManager

public NodeManager getNodeManager()
The NodeManager that the event manager is serving.

Returns:
the nodeManager

onCall

public boolean onCall(ServiceContext serviceContext,
                      org.opcfoundation.ua.builtintypes.NodeId objectId,
                      UaNode object,
                      org.opcfoundation.ua.builtintypes.NodeId methodId,
                      UaMethod method,
                      org.opcfoundation.ua.builtintypes.Variant[] inputArguments,
                      org.opcfoundation.ua.builtintypes.StatusCode[] inputArgumentResults,
                      org.opcfoundation.ua.builtintypes.DiagnosticInfo[] inputArgumentDiagnosticInfos,
                      org.opcfoundation.ua.builtintypes.Variant[] output)
               throws StatusException
Description copied from interface: CallableListener
A method call notification.

Use onCall to check whether the called method is the one that you handle. If so, return true, and set the outputs. Do not create a new array for the outputs, just assign your values in there - it is already created for the length defined by the OutputArguments of the UaMethod.

If you find errors in the inputArguments, fill in the inputArgumentResults and inputArgumentDiagnosticInfos respectively. They are also preallocated.

Specified by:
onCall in interface CallableListener
objectId - the ID of the node whose method is being called
object - the object node whose method is being called, if available
methodId - the ID of the method being called
method - the method node being called, if available
inputArguments - input argument values
inputArgumentResults - room for argument errors. Fill in the array if you encounter errors in the values.
inputArgumentDiagnosticInfos - room for diagnostic info, in case of errors.
output - room for output values. The array is pre-created, so just fill in the values.
Returns:
true if you handle the call, which prevents any other handler being called.
Throws:
StatusException - if there are errors in the method handling. For example, if you set inputArgumentResults, you should throw a StatusException with StatusCodes.Bad_InvalidArgument

setListener

public void setListener(EventManagerListener l)
Define a listener to the Event Manager to get notifications about client actions.

The listener gives you a simple mechanism to react to actions in any node manager. The alternative is to implement your own event manager, but the listener is typically a simpler way to do the same.

Parameters:
l - your EventManagerListener implementation. Use null to clear the setting (it will change the listener to an internal NULL_LISTENER).
See Also:
EventManagerListener

afterCreateMonitoredEventItem

protected void afterCreateMonitoredEventItem(ServiceContext serviceContext,
                                             Subscription subscription,
                                             MonitoredEventItem item)
Parameters:
serviceContext -
subscription -
item -

afterDeleteMonitoredEventItem

protected void afterDeleteMonitoredEventItem(ServiceContext serviceContext,
                                             Subscription subscription,
                                             MonitoredEventItem item)
Parameters:
serviceContext -
subscription -
item -

afterModifyMonitoredEventItem

protected void afterModifyMonitoredEventItem(ServiceContext serviceContext,
                                             Subscription subscription,
                                             MonitoredEventItem item)
Parameters:
serviceContext -
subscription -
item -

createMonitoredEventItem

protected void createMonitoredEventItem(ServiceContext serviceContext,
                                        Subscription subscription,
                                        org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                        org.opcfoundation.ua.core.EventFilter filter,
                                        org.opcfoundation.ua.core.EventFilterResult eventFilterResult)
                                 throws StatusException
Throws:
StatusException

deleteMonitoredEventItem

protected void deleteMonitoredEventItem(ServiceContext serviceContext,
                                        Subscription subscription,
                                        MonitoredEventItem monitoredItem)

methodEqualsIdOrName

protected boolean methodEqualsIdOrName(UaMethod method,
                                       org.opcfoundation.ua.builtintypes.NodeId methodId,
                                       String methodName)
Parameters:
method -
methodId -
methodName -
Returns:

modifyMonitoredEventItem

protected void modifyMonitoredEventItem(ServiceContext serviceContext,
                                        Subscription subscription,
                                        MonitoredEventItem item,
                                        org.opcfoundation.ua.core.EventFilter eventFilter,
                                        org.opcfoundation.ua.core.EventFilterResult eventFilterResult)
                                 throws StatusException
Throws:
StatusException

refresh

protected boolean refresh(ServiceContext serviceContext,
                          Subscription subscription)
                   throws StatusException
Handle a ConditionRefresh call from a client.

The method gets called for every Subscription in the server.

The method goes through all MonitoredEventItems of the Subscription and calls refreshStartEvent(MonitoredEventItem), #refreshItems(MonitoredEventItem) and refreshEndEvent(MonitoredEventItem) for every item.

Parameters:
serviceContext - the client calling context.
subscription - the subscription to refresh
Returns:
true if the method is handled by this method
Throws:
StatusException - if refresh is not allowed, for example

refresh

protected boolean refresh(ServiceContext serviceContext,
                          Subscription subscription,
                          MonitoredEventItem monitoredItem)
                   throws StatusException
Throws:
StatusException

refreshEndEvent

protected void refreshEndEvent(MonitoredEventItem monitoredItem)

refreshEndEvent

protected void refreshEndEvent(Subscription subscription)
Trigger a RefreshEndEventType. This method is called after #refreshItems() is called. The default implementation triggers the standard event of type RefreshEndEventType for every monitored event item.

Parameters:
subscription - must not be null

refreshItem

protected abstract void refreshItem(MonitoredEventItem item)
Parameters:
item -

refreshItems

protected void refreshItems(ServiceContext serviceContext,
                            Subscription subscription)
                     throws StatusException
Handles condition refresh for a subscription.

Parameters:
serviceContext - the client calling context.
subscription - must not be null
Throws:
StatusException

refreshStartEvent

protected void refreshStartEvent(MonitoredEventItem monitoredItem)

refreshStartEvent

protected void refreshStartEvent(Subscription subscription)
Trigger a RefreshStartEventType. This method is called before #refreshItems() is called. The default implementation triggers the standard event of type RefreshStartEventType for every monitored event item.

Parameters:
subscription - must not be null

refreshSubscription

protected void refreshSubscription(ServiceContext serviceContext,
                                   org.opcfoundation.ua.builtintypes.UnsignedInteger subscriptionId)
                            throws StatusException,
                                   ServiceException
called internally

Parameters:
serviceContext -
subscriptionId -
Throws:
StatusException
ServiceException


Copyright © 2018. All rights reserved.