use of com.jbm.framework.opcua.key.KeyLoader in project JBM by numen06.
the class OpcUaTemplate method getOpcUaClient.
/**
* Get Opc Ua Client
*
* @param deviceId Device Id
* @param driverInfo Driver Info
* @return OpcUaClient
* @throws UaException UaException
*/
public OpcUaClient getOpcUaClient(String deviceId, OpcUaSource driverInfo) {
OpcUaClient opcUaClient = null;
if (clientMap.containsKey(deviceId))
return clientMap.get(deviceId).getOpcUaClient();
try {
KeyLoader loader = new KeyLoader().load(Paths.get(FileUtil.getTmpDirPath()));
if (null == opcUaClient) {
try {
List<EndpointDescription> remoteEndpoints = DiscoveryClient.getEndpoints(driverInfo.getUrl()).get();
EndpointDescription configPoint = EndpointUtil.updateUrl(remoteEndpoints.get(0), driverInfo.getHost(), driverInfo.getPort());
opcUaClient = OpcUaClient.create(driverInfo.getUrl(), endpoints -> remoteEndpoints.stream().findFirst(), configBuilder -> configBuilder.setIdentityProvider(new AnonymousProvider()).setCertificate(loader.getClientCertificate()).setKeepAliveInterval(uint(3000)).setRequestTimeout(uint(5000)).setEndpoint(configPoint).build());
// clientMap.put(deviceId, new OpcUaClientBean(deviceId, opcUaClient));
} catch (UaException e) {
log.error("get opc ua client error: {}", e.getMessage());
// clientMap.entrySet().removeIf(next -> next.getKey().equals(deviceId));
}
}
} catch (Exception e) {
log.error("get opc ua client error: {}", e.getMessage());
}
// return clientMap.get(deviceId).getOpcUaClient();
return opcUaClient;
}
Aggregations