use of org.eclipse.milo.opcua.sdk.client.api.UaSession in project JBM by numen06.
the class OpcUaClientBean method startUp.
@Override
protected void startUp() throws Exception {
// add
log.info("OPCUA客户端[{}]开始启动执行守护线程", deviceId);
this.opcUaClient.addSessionActivityListener(new SessionActivityListener() {
@Override
public void onSessionActive(UaSession session) {
log.info("PLC[{}][{}]建立链接成功", deviceId, session.getSessionName());
}
@Override
public void onSessionInactive(UaSession session) {
log.info("PLC[{}][{}]断开了链接", deviceId, session.getSessionName());
}
});
}
use of org.eclipse.milo.opcua.sdk.client.api.UaSession in project milo by eclipse.
the class OpcUaSubscriptionManager method sendPublishRequest.
private void sendPublishRequest(UaSession session, AtomicLong pendingCount) {
List<SubscriptionAcknowledgement> subscriptionAcknowledgements = new ArrayList<>();
subscriptions.values().forEach(subscription -> {
synchronized (subscription.availableAcknowledgements) {
subscription.availableAcknowledgements.forEach(sequenceNumber -> subscriptionAcknowledgements.add(new SubscriptionAcknowledgement(subscription.getSubscriptionId(), sequenceNumber)));
subscription.availableAcknowledgements.clear();
}
});
RequestHeader requestHeader = client.getStackClient().newRequestHeader(session.getAuthenticationToken(), getTimeoutHint());
UInteger requestHandle = requestHeader.getRequestHandle();
PublishRequest request = new PublishRequest(requestHeader, subscriptionAcknowledgements.toArray(new SubscriptionAcknowledgement[0]));
if (logger.isDebugEnabled()) {
String[] ackStrings = subscriptionAcknowledgements.stream().map(ack -> String.format("id=%s/seq=%s", ack.getSubscriptionId(), ack.getSequenceNumber())).toArray(String[]::new);
logger.debug("Sending PublishRequest, requestHandle={}, acknowledgements={}", requestHandle, Arrays.toString(ackStrings));
}
client.<PublishResponse>sendRequest(request).whenComplete((response, ex) -> {
if (response != null) {
logger.debug("Received PublishResponse, sequenceNumber={}", response.getNotificationMessage().getSequenceNumber());
processingQueue.submit(() -> onPublishComplete(response, pendingCount));
} else {
StatusCode statusCode = UaException.extract(ex).map(UaException::getStatusCode).orElse(StatusCode.BAD);
logger.debug("Publish service failure (requestHandle={}): {}", requestHandle, statusCode, ex);
pendingCount.getAndUpdate(p -> (p > 0) ? p - 1 : 0);
if (statusCode.getValue() != StatusCodes.Bad_NoSubscription && statusCode.getValue() != StatusCodes.Bad_TooManyPublishRequests) {
maybeSendPublishRequests();
}
UaException uax = UaException.extract(ex).orElse(new UaException(ex));
subscriptionListeners.forEach(l -> l.onPublishFailure(uax));
}
});
}
Aggregations