Search in sources :

Example 1 with ServerState

use of org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState 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 ServerState

use of org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState in project milo by eclipse.

the class SystemStatusChangeEventTypeNode method getSystemState.

@Override
public ServerState getSystemState() throws UaException {
    PropertyTypeNode node = getSystemStateNode();
    Object value = node.getValue().getValue().getValue();
    if (value instanceof Integer) {
        return ServerState.from((Integer) value);
    } else if (value instanceof ServerState) {
        return (ServerState) value;
    } else {
        return null;
    }
}
Also used : UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode)

Example 3 with ServerState

use of org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState in project milo by eclipse.

the class SessionFsmFactory method configureActiveState.

private static void configureActiveState(FsmBuilder<State, Event> fb, OpcUaClient client) {
    /* Transitions */
    fb.when(State.Active).on(Event.CloseSession.class).transitionTo(State.Closing);
    fb.when(State.Active).on(e -> e.getClass() == Event.KeepAliveFailure.class || e.getClass() == Event.ServiceFault.class).transitionTo(State.CreatingWait);
    /* External Transition Actions */
    fb.onTransitionTo(State.Active).from(State.Initializing).via(Event.InitializeSuccess.class).execute(ctx -> {
        Event.InitializeSuccess event = (Event.InitializeSuccess) ctx.event();
        // reset the wait time
        KEY_WAIT_TIME.remove(ctx);
        long keepAliveInterval = client.getConfig().getKeepAliveInterval().longValue();
        KEY_KEEP_ALIVE_FAILURE_COUNT.set(ctx, 0L);
        ScheduledFuture<?> scheduledFuture = client.getConfig().getScheduledExecutor().scheduleWithFixedDelay(() -> ctx.fireEvent(new Event.KeepAlive(event.session)), keepAliveInterval, keepAliveInterval, TimeUnit.MILLISECONDS);
        KEY_KEEP_ALIVE_SCHEDULED_FUTURE.set(ctx, scheduledFuture);
        KEY_SESSION.set(ctx, event.session);
        SessionFuture sessionFuture = KEY_SESSION_FUTURE.get(ctx);
        client.getConfig().getExecutor().execute(() -> sessionFuture.future.complete(event.session));
    });
    fb.onTransitionTo(State.Active).from(State.Initializing).via(Event.InitializeSuccess.class).execute(FsmContext::processShelvedEvents);
    fb.onTransitionFrom(State.Active).to(s -> s == State.Closing || s == State.CreatingWait).viaAny().execute(ctx -> {
        ScheduledFuture<?> scheduledFuture = KEY_KEEP_ALIVE_SCHEDULED_FUTURE.remove(ctx);
        if (scheduledFuture != null) {
            scheduledFuture.cancel(false);
        }
    });
    // onSessionActive() callbacks
    fb.onTransitionTo(State.Active).from(s -> s != State.Active).viaAny().execute(ctx -> {
        OpcUaSession session = KEY_SESSION.get(ctx);
        SessionFsm.SessionActivityListeners sessionActivityListeners = KEY_SESSION_ACTIVITY_LISTENERS.get(ctx);
        sessionActivityListeners.sessionActivityListeners.forEach(listener -> listener.onSessionActive(session));
    });
    // onSessionInactive() callbacks
    fb.onTransitionFrom(State.Active).to(s -> s != State.Active).viaAny().execute(ctx -> {
        OpcUaSession session = KEY_SESSION.get(ctx);
        SessionFsm.SessionActivityListeners sessionActivityListeners = KEY_SESSION_ACTIVITY_LISTENERS.get(ctx);
        sessionActivityListeners.sessionActivityListeners.forEach(listener -> listener.onSessionInactive(session));
    });
    /* Internal Transition Actions */
    fb.onInternalTransition(State.Active).via(Event.KeepAlive.class).execute(ctx -> {
        Event.KeepAlive event = (Event.KeepAlive) ctx.event();
        sendKeepAlive(client, event.session).whenComplete((response, ex) -> {
            if (response != null) {
                DataValue[] results = response.getResults();
                if (results != null && results.length > 0) {
                    Object value = results[0].getValue().getValue();
                    if (value instanceof Integer) {
                        ServerState state = ServerState.from((Integer) value);
                        LOGGER.debug("[{}] ServerState: {}", ctx.getInstanceId(), state);
                    }
                }
                KEY_KEEP_ALIVE_FAILURE_COUNT.set(ctx, 0L);
            } else {
                Long keepAliveFailureCount = KEY_KEEP_ALIVE_FAILURE_COUNT.get(ctx);
                if (keepAliveFailureCount == null) {
                    keepAliveFailureCount = 1L;
                } else {
                    keepAliveFailureCount += 1L;
                }
                KEY_KEEP_ALIVE_FAILURE_COUNT.set(ctx, keepAliveFailureCount);
                long keepAliveFailuresAllowed = client.getConfig().getKeepAliveFailuresAllowed().longValue();
                if (keepAliveFailureCount > keepAliveFailuresAllowed) {
                    LOGGER.warn("[{}] Keep Alive failureCount={} exceeds failuresAllowed={}", ctx.getInstanceId(), keepAliveFailureCount, keepAliveFailuresAllowed);
                    ctx.fireEvent(new Event.KeepAliveFailure());
                } else {
                    LOGGER.debug("[{}] Keep Alive failureCount={}", ctx.getInstanceId(), keepAliveFailureCount, ex);
                }
            }
        });
    });
    fb.onInternalTransition(State.Active).via(Event.GetSession.class).execute(SessionFsmFactory::handleGetSessionEvent);
    fb.onInternalTransition(State.Active).via(Event.OpenSession.class).execute(SessionFsmFactory::handleOpenSessionEvent);
}
Also used : X509Certificate(java.security.cert.X509Certificate) KEY_CLOSE_FUTURE(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_CLOSE_FUTURE) KeyPair(java.security.KeyPair) SignedSoftwareCertificate(org.eclipse.milo.opcua.stack.core.types.structured.SignedSoftwareCertificate) Arrays(java.util.Arrays) ApplicationType(org.eclipse.milo.opcua.stack.core.types.enumerated.ApplicationType) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) LoggerFactory(org.slf4j.LoggerFactory) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) TransferResult(org.eclipse.milo.opcua.stack.core.types.structured.TransferResult) KEY_WAIT_TIME(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_WAIT_TIME) OpcUaSubscriptionManager(org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager) ByteBuffer(java.nio.ByteBuffer) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UserIdentityToken(org.eclipse.milo.opcua.stack.core.types.structured.UserIdentityToken) SecurityAlgorithm(org.eclipse.milo.opcua.stack.core.security.SecurityAlgorithm) 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) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) KEY_SESSION_INITIALIZERS(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_SESSION_INITIALIZERS) CertificateUtil(org.eclipse.milo.opcua.stack.core.util.CertificateUtil) CreateSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateSessionRequest) ActivateSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.ActivateSessionRequest) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) Predicate(java.util.function.Predicate) KEY_SESSION_ACTIVITY_LISTENERS(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_SESSION_ACTIVITY_LISTENERS) TransferSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsResponse) Streams(com.google.common.collect.Streams) Bytes(com.google.common.primitives.Bytes) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) ServiceFault(org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault) KEY_WAIT_FUTURE(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_WAIT_FUTURE) ActivateSessionResponse(org.eclipse.milo.opcua.stack.core.types.structured.ActivateSessionResponse) List(java.util.List) Stream(java.util.stream.Stream) PrivateKey(java.security.PrivateKey) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) KEY_KEEP_ALIVE_FAILURE_COUNT(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_KEEP_ALIVE_FAILURE_COUNT) EndpointUtil(org.eclipse.milo.opcua.stack.core.util.EndpointUtil) OpcUaSession(org.eclipse.milo.opcua.sdk.client.OpcUaSession) CertificateEncodingException(java.security.cert.CertificateEncodingException) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) CloseSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest) KEY_SESSION_FUTURE(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_SESSION_FUTURE) ActionContext(com.digitalpetri.strictmachine.dsl.ActionContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) SignedIdentityToken(org.eclipse.milo.opcua.sdk.client.api.identity.SignedIdentityToken) CompletableFuture(java.util.concurrent.CompletableFuture) CreateSessionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateSessionResponse) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) ImmutableList(com.google.common.collect.ImmutableList) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) SignatureData(org.eclipse.milo.opcua.stack.core.types.structured.SignatureData) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) FutureUtils.complete(org.eclipse.milo.opcua.stack.core.util.FutureUtils.complete) ServiceFaultListener(org.eclipse.milo.opcua.sdk.client.api.ServiceFaultListener) SessionFuture(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.SessionFuture) SecurityPolicy(org.eclipse.milo.opcua.stack.core.security.SecurityPolicy) TransferSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TransferSubscriptionsRequest) KEY_SESSION(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_SESSION) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) SignatureUtil(org.eclipse.milo.opcua.stack.core.util.SignatureUtil) Fsm(com.digitalpetri.strictmachine.Fsm) Logger(org.slf4j.Logger) OpcUaClientConfig(org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) KEY_KEEP_ALIVE_SCHEDULED_FUTURE(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.KEY_KEEP_ALIVE_SCHEDULED_FUTURE) TimeUnit(java.util.concurrent.TimeUnit) NonceUtil(org.eclipse.milo.opcua.stack.core.util.NonceUtil) FsmContext(com.digitalpetri.strictmachine.FsmContext) ApplicationDescription(org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) FsmBuilder(com.digitalpetri.strictmachine.dsl.FsmBuilder) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) FsmContext(com.digitalpetri.strictmachine.FsmContext) OpcUaSession(org.eclipse.milo.opcua.sdk.client.OpcUaSession) ServiceFault(org.eclipse.milo.opcua.stack.core.types.structured.ServiceFault) SessionFuture(org.eclipse.milo.opcua.sdk.client.session.SessionFsm.SessionFuture) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)

Example 4 with ServerState

use of org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState in project milo by eclipse.

the class ServerStatusTypeNode method getState.

@Override
public ServerState getState() throws UaException {
    BaseDataVariableTypeNode node = getStateNode();
    Object value = node.getValue().getValue().getValue();
    if (value instanceof Integer) {
        return ServerState.from((Integer) value);
    } else if (value instanceof ServerState) {
        return (ServerState) value;
    } else {
        return null;
    }
}
Also used : UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)

Example 5 with ServerState

use of org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState in project milo by eclipse.

the class RequestServerStateChangeMethod method invoke.

@Override
protected Variant[] invoke(AbstractMethodInvocationHandler.InvocationContext context, Variant[] inputValues) throws UaException {
    ServerState state = (ServerState) inputValues[0].getValue();
    DateTime estimatedReturnTime = (DateTime) inputValues[1].getValue();
    UInteger secondsTillShutdown = (UInteger) inputValues[2].getValue();
    LocalizedText reason = (LocalizedText) inputValues[3].getValue();
    Boolean restart = (Boolean) inputValues[4].getValue();
    invoke(context, state, estimatedReturnTime, secondsTillShutdown, reason, restart);
    return new Variant[] {};
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)

Aggregations

ServerState (org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState)5 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)4 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)2 Fsm (com.digitalpetri.strictmachine.Fsm)1 FsmContext (com.digitalpetri.strictmachine.FsmContext)1 ActionContext (com.digitalpetri.strictmachine.dsl.ActionContext)1 FsmBuilder (com.digitalpetri.strictmachine.dsl.FsmBuilder)1 ImmutableList (com.google.common.collect.ImmutableList)1 Streams (com.google.common.collect.Streams)1 Bytes (com.google.common.primitives.Bytes)1 ByteBuffer (java.nio.ByteBuffer)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 X509Certificate (java.security.cert.X509Certificate)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1