use of org.eclipse.milo.opcua.stack.core.util.Unit in project milo by eclipse.
the class DataTypeTreeBuilder method addChildren.
private static CompletableFuture<Unit> addChildren(Tree<DataTypeTree.DataType> tree, UaStackClient client, OpcUaSession session, NamespaceTable namespaceTable) {
CompletableFuture<List<ReferenceDescription>> subtypes = browseSafe(client, session, new BrowseDescription(tree.getValue().getNodeId(), BrowseDirection.Forward, Identifiers.HasSubtype, false, uint(NodeClass.DataType.getValue()), uint(BrowseResultMask.All.getValue())));
CompletableFuture<List<DataTypeTree.DataType>> dataTypesFuture = subtypes.thenCompose(references -> {
Stream<CompletableFuture<DataTypeTree.DataType>> dataTypeFutures = references.stream().map(dataTypeReference -> {
NodeId dataTypeId = dataTypeReference.getNodeId().toNodeId(namespaceTable).orElse(NodeId.NULL_VALUE);
CompletableFuture<List<ReferenceDescription>> encodings = browseSafe(client, session, new BrowseDescription(dataTypeId, BrowseDirection.Forward, Identifiers.HasEncoding, false, uint(NodeClass.Object.getValue()), uint(BrowseResultMask.All.getValue())));
return encodings.thenApply(encodingReferences -> {
NodeId binaryEncodingId = null;
NodeId xmlEncodingId = null;
for (ReferenceDescription r : encodingReferences) {
if (r.getBrowseName().equals(OpcUaDefaultBinaryEncoding.ENCODING_NAME)) {
binaryEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
} else if (r.getBrowseName().equals(OpcUaDefaultXmlEncoding.ENCODING_NAME)) {
xmlEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
}
}
return new DataTypeTree.DataType(dataTypeReference.getBrowseName(), dataTypeId, binaryEncodingId, xmlEncodingId);
});
});
return FutureUtils.sequence(dataTypeFutures);
});
return dataTypesFuture.thenCompose(dataTypes -> {
Stream<CompletableFuture<Unit>> futures = dataTypes.stream().map(tree::addChild).map(childNode -> addChildren(childNode, client, session, namespaceTable));
return FutureUtils.sequence(futures);
}).thenApply(v -> Unit.VALUE);
}
use of org.eclipse.milo.opcua.stack.core.util.Unit in project milo by eclipse.
the class ServerChannelManager method bind.
public CompletableFuture<Unit> bind(EndpointConfiguration endpoint) {
CompletableFuture<Unit> future = new CompletableFuture<>();
semaphore.acquire().thenApply(permit -> {
future.whenComplete((u, ex) -> permit.release());
InetSocketAddress bindAddress = new InetSocketAddress(endpoint.getBindAddress(), endpoint.getBindPort());
if (channels.containsKey(bindAddress)) {
return future.complete(Unit.VALUE);
} else {
logger.debug("binding to {}", bindAddress);
CompletableFuture<Channel> bootstrap = bootstrap(stackServer, bindAddress, endpoint.getTransportProfile());
return bootstrap.whenComplete((channel, ex) -> {
if (channel != null) {
addresses.add(bindAddress);
channels.put(bindAddress, channel);
future.complete(Unit.VALUE);
} else {
future.completeExceptionally(ex);
}
});
}
});
return future;
}
use of org.eclipse.milo.opcua.stack.core.util.Unit in project milo by eclipse.
the class ServerChannelManager method unbind.
public CompletableFuture<Unit> unbind(EndpointConfiguration endpoint) {
CompletableFuture<Unit> future = new CompletableFuture<>();
semaphore.acquire().thenAccept(permit -> {
future.whenComplete((u, ex) -> permit.release());
InetSocketAddress bindAddress = new InetSocketAddress(endpoint.getBindAddress(), endpoint.getBindPort());
if (addresses.remove(bindAddress, 1) == 1) {
logger.debug("unbinding from {}", bindAddress);
Channel channel = channels.remove(bindAddress);
if (channel != null) {
channel.close();
}
}
future.complete(Unit.VALUE);
});
return future;
}
use of org.eclipse.milo.opcua.stack.core.util.Unit 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.util.Unit in project milo by eclipse.
the class SessionFsmFactory method initialize.
private static CompletableFuture<Unit> initialize(FsmContext<State, Event> ctx, OpcUaClient client, OpcUaSession session) {
List<SessionFsm.SessionInitializer> initializers = KEY_SESSION_INITIALIZERS.get(ctx).sessionInitializers;
if (initializers.isEmpty()) {
return completedFuture(Unit.VALUE);
} else {
UaStackClient stackClient = client.getStackClient();
CompletableFuture<?>[] futures = initializers.stream().map(i -> i.initialize(stackClient, session)).toArray(CompletableFuture[]::new);
return CompletableFuture.allOf(futures).thenApply(v -> Unit.VALUE);
}
}
Aggregations