Search in sources :

Example 1 with DateTime

use of org.eclipse.milo.opcua.stack.core.types.builtin.DateTime in project milo by eclipse.

the class ReadNodeExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // synchronous connect
    client.connect().get();
    // Get a typed reference to the Server object: ServerNode
    ServerTypeNode serverNode = (ServerTypeNode) client.getAddressSpace().getObjectNode(Identifiers.Server, Identifiers.ServerType);
    // Read properties of the Server object...
    String[] serverArray = serverNode.getServerArray();
    String[] namespaceArray = serverNode.getNamespaceArray();
    logger.info("ServerArray={}", Arrays.toString(serverArray));
    logger.info("NamespaceArray={}", Arrays.toString(namespaceArray));
    // Read the value of attribute the ServerStatus variable component
    ServerStatusDataType serverStatus = serverNode.getServerStatus();
    logger.info("ServerStatus={}", serverStatus);
    // Get a typed reference to the ServerStatus variable
    // component and read value attributes individually
    ServerStatusTypeNode serverStatusNode = serverNode.getServerStatusNode();
    BuildInfo buildInfo = serverStatusNode.getBuildInfo();
    DateTime startTime = serverStatusNode.getStartTime();
    DateTime currentTime = serverStatusNode.getCurrentTime();
    ServerState state = serverStatusNode.getState();
    logger.info("ServerStatus.BuildInfo={}", buildInfo);
    logger.info("ServerStatus.StartTime={}", startTime);
    logger.info("ServerStatus.CurrentTime={}", currentTime);
    logger.info("ServerStatus.State={}", state);
    future.complete(client);
}
Also used : ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.ServerStatusTypeNode) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)

Example 2 with DateTime

use of org.eclipse.milo.opcua.stack.core.types.builtin.DateTime in project milo by eclipse.

the class JsonStructureCodec method opcUaToMemberTypeScalar.

@Override
protected JsonElement opcUaToMemberTypeScalar(String name, Object value, String typeName) {
    if (value == null) {
        return JsonNull.INSTANCE;
    } else if (value instanceof Number) {
        if (value instanceof UByte) {
            return new JsonPrimitive(((UByte) value).shortValue());
        } else if (value instanceof UShort) {
            return new JsonPrimitive(((UShort) value).intValue());
        } else if (value instanceof UInteger) {
            return new JsonPrimitive(((UInteger) value).longValue());
        } else if (value instanceof ULong) {
            return new JsonPrimitive(((ULong) value).toBigInteger());
        } else {
            return new JsonPrimitive((Number) value);
        }
    } else if (value instanceof Boolean) {
        return new JsonPrimitive((Boolean) value);
    } else if (value instanceof String) {
        return new JsonPrimitive((String) value);
    } else if (value instanceof Character) {
        return new JsonPrimitive((Character) value);
    } else if (value instanceof JsonElement) {
        return (JsonElement) value;
    } else if (value instanceof DateTime) {
        return new JsonPrimitive(((DateTime) value).getUtcTime());
    } else if (value instanceof UUID) {
        return new JsonPrimitive(value.toString());
    } else if (value instanceof LocalizedText) {
        return gson.toJsonTree(value);
    } else if (value instanceof QualifiedName) {
        return gson.toJsonTree(value);
    } else if (value instanceof ByteString) {
        ByteString byteString = (ByteString) value;
        byte[] bs = byteString.bytesOrEmpty();
        JsonArray array = new JsonArray();
        for (Byte b : bs) {
            array.add(new JsonPrimitive(b));
        }
        return array;
    } else if (value instanceof XmlElement) {
        String fragment = ((XmlElement) value).getFragment();
        return fragment != null ? new JsonPrimitive(fragment) : JsonNull.INSTANCE;
    } else if (value instanceof NodeId) {
        String nodeId = ((NodeId) value).toParseableString();
        return new JsonPrimitive(nodeId);
    } else if (value instanceof ExpandedNodeId) {
        String xNodeId = ((ExpandedNodeId) value).toParseableString();
        return new JsonPrimitive(xNodeId);
    } else if (value instanceof StatusCode) {
        long code = ((StatusCode) value).getValue();
        return new JsonPrimitive(code);
    } else {
        throw new RuntimeException("could not create JsonElement for value: " + value);
    }
}
Also used : ULong(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.ULong) JsonPrimitive(com.google.gson.JsonPrimitive) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) Unsigned.ulong(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ulong) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) JsonArray(com.google.gson.JsonArray) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) JsonElement(com.google.gson.JsonElement) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) XmlElement(org.eclipse.milo.opcua.stack.core.types.builtin.XmlElement) UUID(java.util.UUID)

Example 3 with DateTime

use of org.eclipse.milo.opcua.stack.core.types.builtin.DateTime in project milo by eclipse.

the class AttributeWriter method writeAttribute.

public static void writeAttribute(AttributeContext context, UaServerNode node, AttributeId attributeId, DataValue value, @Nullable String indexRange) throws UaException {
    AttributeContext internalContext = new AttributeContext(context.getServer());
    NodeClass nodeClass = node.getNodeClass();
    if (attributeId == AttributeId.Value && nodeClass == NodeClass.Variable) {
        Set<AccessLevel> accessLevels = getAccessLevels(node, internalContext);
        if (!accessLevels.contains(AccessLevel.CurrentWrite)) {
            throw new UaException(StatusCodes.Bad_NotWritable);
        }
        Set<AccessLevel> userAccessLevels = getUserAccessLevels(node, context);
        if (!userAccessLevels.contains(AccessLevel.CurrentWrite)) {
            throw new UaException(StatusCodes.Bad_UserAccessDenied);
        }
    } else {
        WriteMask writeMask = writeMaskForAttribute(attributeId);
        Set<WriteMask> writeMasks = getWriteMasks(node, internalContext);
        if (!writeMasks.contains(writeMask)) {
            throw new UaException(StatusCodes.Bad_NotWritable);
        }
        Set<WriteMask> userWriteMasks = getUserWriteMasks(node, context);
        if (!userWriteMasks.contains(writeMask)) {
            throw new UaException(StatusCodes.Bad_UserAccessDenied);
        }
    }
    Variant updateVariant = value.getValue();
    if (indexRange != null) {
        NumericRange range = NumericRange.parse(indexRange);
        DataValue current = node.getAttribute(internalContext, attributeId);
        Variant currentVariant = current.getValue();
        Object valueAtRange = NumericRange.writeToValueAtRange(currentVariant, updateVariant, range);
        updateVariant = new Variant(valueAtRange);
    }
    DateTime sourceTime = value.getSourceTime();
    DateTime serverTime = value.getServerTime();
    value = new DataValue(updateVariant, value.getStatusCode(), (sourceTime == null || sourceTime.isNull()) ? DateTime.now() : sourceTime, (serverTime == null || serverTime.isNull()) ? DateTime.now() : serverTime);
    if (attributeId == AttributeId.Value) {
        NodeId dataType = extract(node.getAttribute(internalContext, AttributeId.DataType));
        if (dataType != null) {
            value = validateDataType(context.getServer(), dataType, value);
        }
        Integer valueRank = extract(node.getAttribute(internalContext, AttributeId.ValueRank));
        if (valueRank == null)
            valueRank = 0;
        if (valueRank > 0) {
            UInteger[] arrayDimensions = extract(node.getAttribute(context, AttributeId.ArrayDimensions));
            validateArrayType(valueRank, arrayDimensions, value);
        }
    }
    node.setAttribute(context, attributeId, value);
}
Also used : AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) WriteMask(org.eclipse.milo.opcua.sdk.core.WriteMask) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)

Example 4 with DateTime

use of org.eclipse.milo.opcua.stack.core.types.builtin.DateTime in project milo by eclipse.

the class SessionDiagnosticsVariable method onStartup.

@Override
protected void onStartup() {
    ServerDiagnosticsTypeNode diagnosticsNode = (ServerDiagnosticsTypeNode) server.getAddressSpaceManager().getManagedNode(Identifiers.Server_ServerDiagnostics).orElseThrow(() -> new NoSuchElementException("NodeId: " + Identifiers.Server_ServerDiagnostics));
    diagnosticsEnabled.set(diagnosticsNode.getEnabledFlag());
    attributeObserver = (node, attributeId, value) -> {
        if (attributeId == AttributeId.Value) {
            DataValue dataValue = (DataValue) value;
            Object o = dataValue.getValue().getValue();
            if (o instanceof Boolean) {
                diagnosticsEnabled.set((Boolean) o);
            }
        }
    };
    diagnosticsNode.getEnabledFlagNode().addAttributeObserver(attributeObserver);
    node.getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject xo = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSessionDiagnosticsDataType());
        return new DataValue(new Variant(xo));
    }));
    node.getSessionIdNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        NodeId value = session.getSessionDiagnostics().getSessionId();
        return new DataValue(new Variant(value));
    }));
    node.getSessionNameNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getSessionName();
        return new DataValue(new Variant(value));
    }));
    node.getClientDescriptionNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getClientDescription());
        return new DataValue(new Variant(value));
    }));
    node.getServerUriNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getServerUri();
        return new DataValue(new Variant(value));
    }));
    node.getEndpointUrlNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getEndpointUrl();
        return new DataValue(new Variant(value));
    }));
    node.getLocaleIdsNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String[] value = session.getSessionDiagnostics().getLocaleIds();
        return new DataValue(new Variant(value));
    }));
    node.getActualSessionTimeoutNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        Double value = session.getSessionDiagnostics().getActualSessionTimeout();
        return new DataValue(new Variant(value));
    }));
    node.getMaxResponseMessageSizeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getMaxResponseMessageSize();
        return new DataValue(new Variant(value));
    }));
    node.getClientConnectionTimeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        DateTime value = session.getSessionDiagnostics().getClientConnectionTime();
        return new DataValue(new Variant(value));
    }));
    node.getClientLastContactTimeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        DateTime value = session.getSessionDiagnostics().getClientLastContactTime();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentSubscriptionsCount();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentMonitoredItemsCount();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentPublishRequestsInQueueNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentPublishRequestsInQueue();
        return new DataValue(new Variant(value));
    }));
    node.getTotalRequestCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTotalRequestCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getUnauthorizedRequestCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(session.getSessionDiagnostics().getUnauthorizedRequestCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getReadCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getReadCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getHistoryReadCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getHistoryReadCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getWriteCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getWriteCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getHistoryUpdateCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getHistoryUpdateCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCallCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCallCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCreateMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCreateMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getModifyMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getModifyMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetMonitoringModeCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetMonitoringModeCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetTriggeringCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetTriggeringCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCreateSubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCreateSubscriptionCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getModifySubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getModifySubscriptionCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetPublishingModeCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetPublishingModeCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getPublishCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getPublishCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getRepublishCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getRepublishCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getTransferSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTransferSubscriptionsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteSubscriptionsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getAddNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getAddNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getAddReferencesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getAddReferencesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteReferencesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteReferencesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getBrowseCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getBrowseCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getBrowseNextCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getBrowseNextCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getTranslateBrowsePathsToNodeIdsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTranslateBrowsePathsToNodeIdsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getQueryFirstCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getQueryFirstCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getQueryNextCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getQueryNextCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getRegisterNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getRegisterNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getUnregisterNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getUnregisterNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionDiagnosticsVariableTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsVariableTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Util.diagnosticValueFilter(org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) Session(org.eclipse.milo.opcua.sdk.server.Session) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) NoSuchElementException(java.util.NoSuchElementException) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with DateTime

use of org.eclipse.milo.opcua.stack.core.types.builtin.DateTime in project milo by eclipse.

the class OpcUaSubscriptionManager method onPublishComplete.

private void onPublishComplete(PublishResponse response, AtomicLong pendingCount) {
    logger.debug("onPublishComplete() response for subscriptionId={}", response.getSubscriptionId());
    UInteger subscriptionId = response.getSubscriptionId();
    OpcUaSubscription subscription = subscriptions.get(subscriptionId);
    if (subscription == null) {
        WatchdogTimer watchdogTimer = watchdogTimers.remove(subscriptionId);
        if (watchdogTimer != null)
            watchdogTimer.cancel();
        pendingCount.getAndUpdate(p -> (p > 0) ? p - 1 : 0);
        maybeSendPublishRequests();
        return;
    }
    WatchdogTimer watchdogTimer = watchdogTimers.get(subscriptionId);
    if (watchdogTimer != null)
        watchdogTimer.kick();
    NotificationMessage notificationMessage = response.getNotificationMessage();
    long sequenceNumber = notificationMessage.getSequenceNumber().longValue();
    long expectedSequenceNumber = subscription.getLastSequenceNumber() + 1;
    if (sequenceNumber > expectedSequenceNumber) {
        logger.warn("[id={}] expected sequence={}, received sequence={}. Calling Republish service...", subscriptionId, expectedSequenceNumber, sequenceNumber);
        processingQueue.pause();
        processingQueue.submitToHead(() -> onPublishComplete(response, pendingCount));
        republish(subscriptionId, expectedSequenceNumber, sequenceNumber).whenComplete((dataLost, ex) -> {
            if (ex != null) {
                logger.debug("Republish failed: {}", ex.getMessage(), ex);
                subscriptionListeners.forEach(l -> l.onNotificationDataLost(subscription));
                subscription.getNotificationListeners().forEach(l -> l.onNotificationDataLost(subscription));
            } else {
                // Republish succeeded, possibly with some data loss, resume processing.
                if (dataLost) {
                    subscriptionListeners.forEach(l -> l.onNotificationDataLost(subscription));
                    subscription.getNotificationListeners().forEach(l -> l.onNotificationDataLost(subscription));
                }
            }
            subscription.setLastSequenceNumber(sequenceNumber - 1);
            processingQueue.resume();
        });
        return;
    }
    if (notificationMessage.getNotificationData() != null && notificationMessage.getNotificationData().length > 0) {
        // Set last sequence number only if this isn't a keep-alive
        subscription.setLastSequenceNumber(sequenceNumber);
    }
    UInteger[] availableSequenceNumbers = response.getAvailableSequenceNumbers();
    synchronized (subscription.availableAcknowledgements) {
        subscription.availableAcknowledgements.clear();
        if (availableSequenceNumbers != null && availableSequenceNumbers.length > 0) {
            Collections.addAll(subscription.availableAcknowledgements, availableSequenceNumbers);
        }
    }
    if (logger.isDebugEnabled() && availableSequenceNumbers != null) {
        String[] seqStrings = Arrays.stream(availableSequenceNumbers).map(sequence -> String.format("id=%s/seq=%s", subscriptionId, sequence)).toArray(String[]::new);
        logger.debug("[id={}] PublishResponse sequence={}, available sequences={}", subscriptionId, sequenceNumber, Arrays.toString(seqStrings));
    }
    DateTime publishTime = notificationMessage.getPublishTime();
    logger.debug("onPublishComplete(), subscriptionId={}, sequenceNumber={}, publishTime={}", subscriptionId, notificationMessage.getSequenceNumber(), publishTime);
    deliverNotificationMessage(subscription, notificationMessage).thenRunAsync(() -> {
        pendingCount.getAndUpdate(p -> (p > 0) ? p - 1 : 0);
        maybeSendPublishRequests();
    }, client.getConfig().getExecutor());
}
Also used : Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) BiFunction(java.util.function.BiFunction) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) UaSubscriptionManager(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscriptionManager) LoggerFactory(org.slf4j.LoggerFactory) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) PublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.PublishRequest) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) UaSubscription(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) Map(java.util.Map) BigInteger(java.math.BigInteger) CreateSubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) EventNotificationList(org.eclipse.milo.opcua.stack.core.types.structured.EventNotificationList) RepublishResponse(org.eclipse.milo.opcua.stack.core.types.structured.RepublishResponse) SubscriptionAcknowledgement(org.eclipse.milo.opcua.stack.core.types.structured.SubscriptionAcknowledgement) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) EventFieldList(org.eclipse.milo.opcua.stack.core.types.structured.EventFieldList) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) UaSession(org.eclipse.milo.opcua.sdk.client.api.UaSession) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) NotificationMessage(org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage) CompletableFuture(java.util.concurrent.CompletableFuture) DataChangeNotification(org.eclipse.milo.opcua.stack.core.types.structured.DataChangeNotification) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) SessionActivityListener(org.eclipse.milo.opcua.sdk.client.SessionActivityListener) StatusChangeNotification(org.eclipse.milo.opcua.stack.core.types.structured.StatusChangeNotification) ExecutionQueue(org.eclipse.milo.opcua.stack.core.util.ExecutionQueue) Logger(org.slf4j.Logger) MonitoredItemNotification(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemNotification) PublishResponse(org.eclipse.milo.opcua.stack.core.types.structured.PublishResponse) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ModifySubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse) UaException(org.eclipse.milo.opcua.stack.core.UaException) Comparator(java.util.Comparator) Collections(java.util.Collections) NotificationMessage(org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)

Aggregations

DateTime (org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)15 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)7 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)7 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)7 UaException (org.eclipse.milo.opcua.stack.core.UaException)5 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)5 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)5 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)4 UShort (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort)4 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)3 Maps (com.google.common.collect.Maps)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 UaRuntimeException (org.eclipse.milo.opcua.stack.core.UaRuntimeException)2