Search in sources :

Example 1 with CloseSessionRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest in project milo by eclipse.

the class SessionFsmFactory method closeSession.

private static CompletableFuture<Unit> closeSession(FsmContext<State, Event> ctx, OpcUaClient client, OpcUaSession session) {
    CompletableFuture<Unit> closeFuture = new CompletableFuture<>();
    UaStackClient stackClient = client.getStackClient();
    RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), uint(5000));
    CloseSessionRequest request = new CloseSessionRequest(requestHeader, true);
    LOGGER.debug("[{}] Sending CloseSessionRequest...", ctx.getInstanceId());
    stackClient.sendRequest(request).whenCompleteAsync((csr, ex2) -> closeFuture.complete(Unit.VALUE), client.getConfig().getExecutor());
    return closeFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) CloseSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) TimeUnit(java.util.concurrent.TimeUnit)

Example 2 with CloseSessionRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest in project milo by eclipse.

the class SessionManager method closeSession.

private CloseSessionResponse closeSession(ServiceRequest service) throws UaException {
    CloseSessionRequest request = (CloseSessionRequest) service.getRequest();
    long secureChannelId = service.getSecureChannelId();
    NodeId authToken = service.getRequest().getRequestHeader().getAuthenticationToken();
    Session session = activeSessions.get(authToken);
    if (session != null) {
        if (session.getSecureChannelId() != secureChannelId) {
            throw new UaException(StatusCodes.Bad_SecureChannelIdInvalid);
        } else {
            activeSessions.remove(authToken);
            session.close(request.getDeleteSubscriptions());
            return new CloseSessionResponse(service.createResponseHeader());
        }
    } else {
        session = createdSessions.get(authToken);
        if (session == null) {
            throw new UaException(StatusCodes.Bad_SessionIdInvalid);
        } else if (session.getSecureChannelId() != secureChannelId) {
            throw new UaException(StatusCodes.Bad_SecureChannelIdInvalid);
        } else {
            createdSessions.remove(authToken);
            session.close(request.getDeleteSubscriptions());
            return new CloseSessionResponse(service.createResponseHeader());
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) CloseSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) CloseSessionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse)

Aggregations

CloseSessionRequest (org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionRequest)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 UaStackClient (org.eclipse.milo.opcua.stack.client.UaStackClient)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 CloseSessionResponse (org.eclipse.milo.opcua.stack.core.types.structured.CloseSessionResponse)1 RequestHeader (org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader)1 Unit (org.eclipse.milo.opcua.stack.core.util.Unit)1