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;
}
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());
}
}
}
Aggregations