public CompletableFuture<Object> invokeMethodAsync(final NodeId objectNode, final NodeId methodNode, final Object... inputs) throws OpcUaException { return _invokeMethod(objectNode, methodNode, inputs); }
private OpcUaClient createClient(String connectionString) throws Exception { File securityTempDir = new File(System.getProperty("java.io.tmpdir"), "security"); if (!securityTempDir.exists() && !securityTempDir.mkdirs()) { throw new Exception("unable to create security dir: " + securityTempDir); } LOGGER.info("security temp dir: {}", securityTempDir.getAbsolutePath()); KeyStoreLoader loader = new KeyStoreLoader().load(securityTempDir); SecurityPolicy securityPolicy = getSecurityPolicy(); EndpointDescription[] endpoints; try { endpoints = UaTcpStackClient.getEndpoints(connectionString).get(); } catch (Throwable ex) { // try the explicit discovery endpoint as well String discoveryUrl = connectionString + "/discovery"; LOGGER.info("Trying explicit discovery URL: {}", discoveryUrl); endpoints = UaTcpStackClient.getEndpoints(discoveryUrl).get(); } EndpointDescription endpoint = Arrays.stream(endpoints) .filter(e -> e.getSecurityPolicyUri().equals(securityPolicy.getSecurityPolicyUri())).findFirst() .orElseThrow(() -> new Exception("no desired endpoints returned")); LOGGER.info("Using endpoint: {} [{}]", endpoint.getEndpointUrl(), securityPolicy); OpcUaClientConfig config = OpcUaClientConfig.builder() .setApplicationName(LocalizedText.english("eclipse milo opc-ua client")) .setApplicationUri("urn:eclipse:milo:examples:client").setCertificate(loader.getClientCertificate()) .setKeyPair(loader.getClientKeyPair()).setEndpoint(endpoint).setIdentityProvider(getIdentityProvider()) .setRequestTimeout(uint(5000)).build(); return new OpcUaClient(config); }
@Override public void connectToExternal() throws ComponentException { try { opcuaClient = createClient(componentConfig.getExternalConnectionString()); //opcuaClient.connect().whenComplete((c, ex) -> this.isConnectedToExternal() = true).get(); opcuaClient.connect().get(); } catch (Exception e) { throw new ComponentException(e); } }
protected void onSubscriptionValue(UaMonitoredItem item, DataValue value) { LOGGER.info( "subscription value received: item={}, value={}", item.getReadValueId().getNodeId(), value.getValue()); System.out.println("subscription value received: item="+ item.getReadValueId().getNodeId() + ", value=" + value.getValue() + " (" + getState() + ")"); }
public <T> T invokeMethod(final NodeId objectNode, final NodeId methodNode, final Object... inputs) throws OpcUaException { try { return (T) _invokeMethod(objectNode, methodNode, inputs).get(); } catch (InterruptedException | ExecutionException e) { throw new OpcUaException(e); } }