com.prosysopc.ua.server
Class AttributeServiceHandler

java.lang.Object
  extended by com.prosysopc.ua.server.ServiceHandler
      extended by com.prosysopc.ua.server.AttributeServiceHandler
All Implemented Interfaces:
org.opcfoundation.ua.core.AttributeServiceSetHandler

public class AttributeServiceHandler
extends ServiceHandler
implements org.opcfoundation.ua.core.AttributeServiceSetHandler

A basic implementation of a node attribute value provider. The class handles all service calls in the OPC UA Attribute Service Set by making sure that valid responses are sent for each service, even when they are not implemented. To implement the services you should override the methods that actually handle the calls, i.e. readAttribute, writeAttribute, historyReadAttribute, historyUpdateAttribute. These handle individual requests per single attribute. Alternatively, you can override the "higher-level" functions that handle complete requests. By default these loop through the individual requests.


Field Summary
protected static org.slf4j.Logger logger
           
 
Fields inherited from class com.prosysopc.ua.server.ServiceHandler
stringTable
 
Constructor Summary
AttributeServiceHandler(SessionManager sessionManager, NodeManagerTable nodeManagerTable)
           
 
Method Summary
protected  org.slf4j.Logger getLogger()
           
 int getMaxNodesPerHistoryReadData()
           
 int getMaxNodesPerHistoryReadEvents()
           
 int getMaxNodesPerHistoryUpdateData()
           
 int getMaxNodesPerHistoryUpdateEvents()
           
 int getMaxNodesPerRead()
           
 int getMaxNodesPerWrite()
           
protected  void historyRead(ServiceContext serviceContext, org.opcfoundation.ua.core.HistoryReadRequest request, org.opcfoundation.ua.core.HistoryReadResponse response)
          Handle the onHistoryRead service call.
protected  void historyUpdate(ServiceContext serviceContext, org.opcfoundation.ua.core.HistoryUpdateRequest request, org.opcfoundation.ua.core.HistoryUpdateResponse response)
          Handle the onHistoryUpdate service call.
 void onHistoryRead(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.HistoryReadRequest,org.opcfoundation.ua.core.HistoryReadResponse> req)
           
 void onHistoryUpdate(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.HistoryUpdateRequest,org.opcfoundation.ua.core.HistoryUpdateResponse> req)
           
 void onRead(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.ReadRequest,org.opcfoundation.ua.core.ReadResponse> req)
           
 void onWrite(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.WriteRequest,org.opcfoundation.ua.core.WriteResponse> req)
           
protected  void read(ServiceContext serviceContext, org.opcfoundation.ua.core.ReadRequest request, org.opcfoundation.ua.core.ReadResponse response)
          Handle the onRead service call.
protected  void readAttribute(ServiceContext serviceContext, Object dataset, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId, org.opcfoundation.ua.utils.NumericRange indexRange, org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn, org.opcfoundation.ua.builtintypes.DateTime minTimestamp, org.opcfoundation.ua.builtintypes.DataValue dataValue)
          Read the value of a single node attribute.
protected  HistoryResult readNodeHistory(ServiceContext serviceContext, Object dataset, org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.utils.NumericRange indexRange, HistoryContinuationPoint continuationPoint, org.opcfoundation.ua.core.HistoryReadDetails details, int aggregateIndex)
          Read history of a single node.
protected  void releaseHistoryContinuationPoint(ServiceContext serviceContext, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.ByteString continuationPoint)
           
 void setMaxNodesPerHistoryReadData(int maxNodesPerHistoryReadData)
          Safety limit for the maximum request size for history reads (data).
 void setMaxNodesPerHistoryReadEvents(int maxNodesPerHistoryReadEvents)
          Safety limit for the maximum request size for history reads (events).
 void setMaxNodesPerHistoryUpdateData(int maxNodesPerHistoryUpdateData)
          Safety limit for the maximum request size for history updates containing data updates.
 void setMaxNodesPerHistoryUpdateEvents(int maxNodesPerHistoryUpdateEvents)
          Safety limit for the maximum request size for history updates containing event updates.
 void setMaxNodesPerRead(int maxNodesPerRead)
          Safety limit for the maximum request size for reads.
 void setMaxNodesPerWrite(int maxNodesPerWrite)
          Safety limit for the maximum request size for writes.
protected  void updateNodeHistory(ServiceContext serviceContext, Object dataset, org.opcfoundation.ua.core.HistoryUpdateDetails details, org.opcfoundation.ua.core.HistoryUpdateResult historyUpdateResult)
           
protected  void write(ServiceContext serviceContext, org.opcfoundation.ua.core.WriteRequest request, org.opcfoundation.ua.core.WriteResponse response)
          Handle the onWrite service call.
protected  boolean writeAttribute(ServiceContext serviceContext, Object operationContext, org.opcfoundation.ua.builtintypes.NodeId nodeId, org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId, org.opcfoundation.ua.utils.NumericRange indexRange, org.opcfoundation.ua.builtintypes.DataValue value)
          Write the value of a single node attribute.
 
Methods inherited from class com.prosysopc.ua.server.ServiceHandler
checkRequestLength, createServiceContext, fireRequestResponse, getEncoderContext, getMaxOperationsPerRequest, getNode, getNodeManagerTable, getOperationLimits, getServer, getSessionManager, handleServiceResultException, hasNode, setMaxOperationsPerRequest, setRequestResponseListener, toExtensionObject, validateEncoding, validateOperationalDiagnostics, validateRequest, validateResponse, validateResponse, validateServiceDiagnostics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.slf4j.Logger logger
Constructor Detail

AttributeServiceHandler

public AttributeServiceHandler(SessionManager sessionManager,
                               NodeManagerTable nodeManagerTable)
Method Detail

getMaxNodesPerHistoryReadData

public int getMaxNodesPerHistoryReadData()
Returns:
the maxNodesPerHistoryReadData
See Also:
setMaxNodesPerHistoryReadData(int)

getMaxNodesPerHistoryReadEvents

public int getMaxNodesPerHistoryReadEvents()
Returns:
the maxNodesPerHistoryReadEvents
See Also:
setMaxNodesPerHistoryReadEvents(int)

getMaxNodesPerHistoryUpdateData

public int getMaxNodesPerHistoryUpdateData()
Returns:
the maxNodesPerHistoryUpdate
See Also:
setMaxNodesPerHistoryUpdateData(int)

getMaxNodesPerHistoryUpdateEvents

public int getMaxNodesPerHistoryUpdateEvents()
Returns:
the maxNodesPerHistoryUpdate
See Also:
setMaxNodesPerHistoryUpdateEvents(int)

getMaxNodesPerRead

public int getMaxNodesPerRead()
Returns:
the maxNodesPerRead
See Also:
setMaxNodesPerRead(int)

getMaxNodesPerWrite

public int getMaxNodesPerWrite()
Returns:
the maxNodesPerWrite
See Also:
setMaxNodesPerWrite(int)

onHistoryRead

public final void onHistoryRead(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.HistoryReadRequest,org.opcfoundation.ua.core.HistoryReadResponse> req)
                         throws org.opcfoundation.ua.common.ServiceFaultException
Specified by:
onHistoryRead in interface org.opcfoundation.ua.core.AttributeServiceSetHandler
Throws:
org.opcfoundation.ua.common.ServiceFaultException

onHistoryUpdate

public final void onHistoryUpdate(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.HistoryUpdateRequest,org.opcfoundation.ua.core.HistoryUpdateResponse> req)
                           throws org.opcfoundation.ua.common.ServiceFaultException
Specified by:
onHistoryUpdate in interface org.opcfoundation.ua.core.AttributeServiceSetHandler
Throws:
org.opcfoundation.ua.common.ServiceFaultException

onRead

public final void onRead(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.ReadRequest,org.opcfoundation.ua.core.ReadResponse> req)
                  throws org.opcfoundation.ua.common.ServiceFaultException
Specified by:
onRead in interface org.opcfoundation.ua.core.AttributeServiceSetHandler
Throws:
org.opcfoundation.ua.common.ServiceFaultException

onWrite

public final void onWrite(org.opcfoundation.ua.transport.endpoint.EndpointServiceRequest<org.opcfoundation.ua.core.WriteRequest,org.opcfoundation.ua.core.WriteResponse> req)
                   throws org.opcfoundation.ua.common.ServiceFaultException
Specified by:
onWrite in interface org.opcfoundation.ua.core.AttributeServiceSetHandler
Throws:
org.opcfoundation.ua.common.ServiceFaultException

setMaxNodesPerHistoryReadData

public void setMaxNodesPerHistoryReadData(int maxNodesPerHistoryReadData)
Safety limit for the maximum request size for history reads (data). Limits the number of nodes that can be requested in one call.

If the value is 0 or negative, the limit is not used. In this case, the ServiceHandler#setMaxOperationsPerRequest() is used to limit the request size.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerHistoryReadData - the maxNodesPerHistoryReadData to set

setMaxNodesPerHistoryReadEvents

public void setMaxNodesPerHistoryReadEvents(int maxNodesPerHistoryReadEvents)
Safety limit for the maximum request size for history reads (events). Limits the number of nodes that can be requested in one call.

If the value is 0 or negative, the limit is not used. In this case, the ServiceHandler#setMaxOperationsPerRequest() is used to limit the request size.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerHistoryReadEvents - the maxNodesPerHistoryReadEvents to set

setMaxNodesPerHistoryUpdateData

public void setMaxNodesPerHistoryUpdateData(int maxNodesPerHistoryUpdateData)
Safety limit for the maximum request size for history updates containing data updates. Limits the number of nodes that can be requested in one call.

If the value is 0 or negative, the limit is not used. In this case, the ServiceHandler#setMaxOperationsPerRequest() is used to limit the request size.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerHistoryUpdateData - the maxNodesPerHistoryUpdateData to set

setMaxNodesPerHistoryUpdateEvents

public void setMaxNodesPerHistoryUpdateEvents(int maxNodesPerHistoryUpdateEvents)
Safety limit for the maximum request size for history updates containing event updates. Limits the number of nodes that can be requested in one call.

If the value is 0 or negative, the limit is not used. In this case, the ServiceHandler#setMaxOperationsPerRequest() is used to limit the request size.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerHistoryUpdateEvents - the maxNodesPerHistoryUpdateData to set

setMaxNodesPerRead

public void setMaxNodesPerRead(int maxNodesPerRead)
Safety limit for the maximum request size for reads. Limits the number of nodes that can be requested in one call.

If the value is 0 or negative, the limit is not used. In this case, the ServiceHandler#setMaxOperationsPerRequest() is used to limit the request size.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerRead - the maxNodesPerRead to set

setMaxNodesPerWrite

public void setMaxNodesPerWrite(int maxNodesPerWrite)
Safety limit for the maximum request size for writes. Limits the number of nodes that can be requested in one call.

The value is reflected to ServerCapabilities/OperationLimits.

Parameters:
maxNodesPerWrite - the maxNodesPerWrite to set

getLogger

protected org.slf4j.Logger getLogger()
Overrides:
getLogger in class ServiceHandler
Returns:
the logger

historyRead

protected void historyRead(ServiceContext serviceContext,
                           org.opcfoundation.ua.core.HistoryReadRequest request,
                           org.opcfoundation.ua.core.HistoryReadResponse response)
                    throws ServiceException
Handle the onHistoryRead service call.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
request - The request message.
response - The response message. Fill in here the results. Make sure that for each node a new DataValue object is created and initialized with current timestamps. The actual data is read in readAttribute, which may return DiagnosticInfo, when necessary.
Throws:
ServiceException - When the request is invalid or the call fails for some other reason. The following error StatusCodes are expected: Bad_NothingToDo, Bad_TooManyOperations, Bad_MaxAgeInvalid, Bad_TimestampsToReturnInvalid

historyUpdate

protected void historyUpdate(ServiceContext serviceContext,
                             org.opcfoundation.ua.core.HistoryUpdateRequest request,
                             org.opcfoundation.ua.core.HistoryUpdateResponse response)
                      throws ServiceException
Handle the onHistoryUpdate service call.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
request - The request message.
response - The response message. Fill in here the results. Make sure that for each node a new DataValue object is created and initialized with current timestamps. The actual data is read in readAttribute, which may return DiagnosticInfo, when necessary.
Throws:
ServiceException - When the request is invalid or the call fails for some other reason. The following error StatusCodes are expected: Bad_NothingToDo, Bad_TooManyOperations, Bad_MaxAgeInvalid, Bad_TimestampsToReturnInvalid

read

protected void read(ServiceContext serviceContext,
                    org.opcfoundation.ua.core.ReadRequest request,
                    org.opcfoundation.ua.core.ReadResponse response)
             throws ServiceException
Handle the onRead service call.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
request - The request message.
response - The response message. Fill in here the results. Make sure that for each node a new DataValue object is created and initialized with current timestamps. The actual data is read in readAttribute, which may return DiagnosticInfo, when necessary.
Throws:
ServiceException - When the request is invalid or the call fails for some other reason. The following error StatusCodes are expected: Bad_NothingToDo, Bad_TooManyOperations, Bad_MaxAgeInvalid, Bad_TimestampsToReturnInvalid

readAttribute

protected void readAttribute(ServiceContext serviceContext,
                             Object dataset,
                             org.opcfoundation.ua.builtintypes.NodeId nodeId,
                             org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId,
                             org.opcfoundation.ua.utils.NumericRange indexRange,
                             org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn,
                             org.opcfoundation.ua.builtintypes.DateTime minTimestamp,
                             org.opcfoundation.ua.builtintypes.DataValue dataValue)
                      throws StatusException
Read the value of a single node attribute.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
dataset - the possible dataset prepared in beginRead(com.prosysopc.ua.server.ServiceContext, java.util.Map, org.opcfoundation.ua.core.ReadValueId[], org.opcfoundation.ua.core.TimestampsToReturn, org.opcfoundation.ua.builtintypes.DateTime, org.opcfoundation.ua.builtintypes.DataValue[], org.opcfoundation.ua.builtintypes.DiagnosticInfo[])
nodeId - The node to read.
attributeId - The attribute to read.
indexRange - The requested index range for an array value. May be null.
timestampsToReturn - Which timestamps were requested by the client.
minTimestamp - Minimum value of the ServerTimestamp of the value to be read. If there is no value available that is new enough already available (in the server cache), the server should attempt to read a new value from the actual data source, instead of using the cached value. If a new value cannot be read, the best value available is returned. If minTimestamp == DateTime.MAX_VALUE a new value should be read from the source.
dataValue - The data value to return. Set Value, and for Value attribute also StatusCode and the Timestamps.
Throws:
StatusException - If the read fails. Expected result codes: Bad_NodeIdInvalid, Bad_NodeIdUnknown, Bad_AttributeIdInvalid, Bad_IndexRangeInvalid, Bad_IndexRangeNoData, Bad_DataEncodingInvalid, Bad_DataEncodingUnsupported, Bad_NotReadable, Bad_UserAccessDenied

readNodeHistory

protected HistoryResult readNodeHistory(ServiceContext serviceContext,
                                        Object dataset,
                                        org.opcfoundation.ua.core.TimestampsToReturn timestampsToReturn,
                                        org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                        org.opcfoundation.ua.utils.NumericRange indexRange,
                                        HistoryContinuationPoint continuationPoint,
                                        org.opcfoundation.ua.core.HistoryReadDetails details,
                                        int aggregateIndex)
                                 throws StatusException
Read history of a single node.

Parameters:
serviceContext -
dataset - the possible dataset prepared in beginHistoryRead(com.prosysopc.ua.server.ServiceContext, java.util.Map, org.opcfoundation.ua.core.HistoryReadDetails, org.opcfoundation.ua.core.HistoryReadValueId[], com.prosysopc.ua.server.HistoryContinuationPoint[], org.opcfoundation.ua.core.TimestampsToReturn, com.prosysopc.ua.server.HistoryResult[])
timestampsToReturn -
nodeId -
indexRange -
continuationPoint -
details -
aggregateIndex - the aggregate that should be used from the AggregateType array in ReadProcessedDetails (if such is provided)
Returns:
HistoryResult
Throws:
StatusException - If the read fails. Expected result codes: Bad_NodeIdInvalid, Bad_NodeIdUnknown, Bad_AttributeIdInvalid, Bad_DataEncodingInvalid, Bad_DataEncodingUnsupported, Bad_ContinuationPointInvalid, Bad_UserAccessDenied

releaseHistoryContinuationPoint

protected void releaseHistoryContinuationPoint(ServiceContext serviceContext,
                                               org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                               org.opcfoundation.ua.builtintypes.ByteString continuationPoint)
                                        throws StatusException
Parameters:
serviceContext -
nodeId -
continuationPoint -
Throws:
StatusException

updateNodeHistory

protected void updateNodeHistory(ServiceContext serviceContext,
                                 Object dataset,
                                 org.opcfoundation.ua.core.HistoryUpdateDetails details,
                                 org.opcfoundation.ua.core.HistoryUpdateResult historyUpdateResult)
                          throws StatusException
Parameters:
serviceContext -
dataset -
details -
historyUpdateResult -
Throws:
ServiceException
StatusException

write

protected void write(ServiceContext serviceContext,
                     org.opcfoundation.ua.core.WriteRequest request,
                     org.opcfoundation.ua.core.WriteResponse response)
              throws ServiceException
Handle the onWrite service call.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
request - The request message.
response - The response message. Fill in here the result codes. Make sure that for each node a new StatusCode object is created and initialized to StatusCode.Good. The actual data is written in writeAttribute, which may return DiagnosticInfo, when necessary.
Throws:
ServiceException - When the request is invalid or the call fails for some other reason. The following error StatusCodes are expected: Bad_NothingToDo, Bad_TooManyOperations, Bad_MaxAgeInvalid, Bad_TimestampsToReturnInvalid

writeAttribute

protected boolean writeAttribute(ServiceContext serviceContext,
                                 Object operationContext,
                                 org.opcfoundation.ua.builtintypes.NodeId nodeId,
                                 org.opcfoundation.ua.builtintypes.UnsignedInteger attributeId,
                                 org.opcfoundation.ua.utils.NumericRange indexRange,
                                 org.opcfoundation.ua.builtintypes.DataValue value)
                          throws StatusException
Write the value of a single node attribute.

Parameters:
serviceContext - The serviceContext of the client connection used to call this service.
operationContext -
nodeId - The node to write.
attributeId - The attribute to write.
indexRange - The index range to set for an array value. May be null.
dataValue - The data value to write.
Throws:
StatusException - If the write fails. Expected result codes: Bad_NodeIdInvalid, Bad_NodeIdUnknown, Bad_AttributeIdInvalid, Bad_IndexRangeInvalid, Bad_IndexRangeNoData, Bad_DataEncodingInvalid, Bad_DataEncodingUnsupported, Bad_NotWriteable, Bad_UserAccessDenied, Bad_OutOfRange, Bad_TypeMismatch, Bad_WriteNotSupported


Copyright © 2018. All rights reserved.