diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java index b9d9cedaab7..65572e94a7f 100644 --- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java +++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java @@ -77,8 +77,7 @@ public OpcuaSubscriptionHandle(ConversationContext context, OpcuaProto try { onSubscribeCreateMonitoredItemsRequest().get(); } catch (Exception e) { - LOGGER.info("Unable to serialize the Create Monitored Item Subscription Message"); - e.printStackTrace(); + LOGGER.info("Unable to serialize the Create Monitored Item Subscription Message", e); plcSubscriber.onDisconnect(context); } startSubscriber(); @@ -141,7 +140,7 @@ private CompletableFuture onSubscribeCreateMonitor CreateMonitoredItemsRequest createMonitoredItemsRequest = new CreateMonitoredItemsRequest( requestHeader, subscriptionId, - TimestampsToReturn.timestampsToReturnNeither, + TimestampsToReturn.timestampsToReturnBoth, requestList.size(), requestList ); @@ -175,37 +174,35 @@ private CompletableFuture onSubscribeCreateMonitor plcSubscriber.onDisconnect(context); } } catch (ParseException e) { - LOGGER.error("Unable to parse the returned Subscription response"); - e.printStackTrace(); + LOGGER.error("Unable to parse the returned Subscription response", e); plcSubscriber.onDisconnect(context); } - for (MonitoredItemCreateResult result : responseMessage.getResults().toArray(new MonitoredItemCreateResult[0])) { + MonitoredItemCreateResult[] array = responseMessage.getResults().toArray(new MonitoredItemCreateResult[0]); + for (int index = 0, arrayLength = array.length; index < arrayLength; index++) { + MonitoredItemCreateResult result = array[index]; if (OpcuaStatusCode.enumForValue(result.getStatusCode().getStatusCode()) != OpcuaStatusCode.Good) { - LOGGER.error("Invalid Field {}, subscription created without this field", fieldNames.get((int) result.getMonitoredItemId())); + LOGGER.error("Invalid Field {}, subscription created without this field", fieldNames.get(index)); } else { - LOGGER.debug("Field {} was added to the subscription", fieldNames.get((int) result.getMonitoredItemId() - 1)); + LOGGER.debug("Field {} was added to the subscription", fieldNames.get(index)); } } future.complete(responseMessage); }; Consumer timeout = e -> { - LOGGER.info("Timeout while sending the Create Monitored Item Subscription Message"); - e.printStackTrace(); + LOGGER.info("Timeout while sending the Create Monitored Item Subscription Message", e); plcSubscriber.onDisconnect(context); }; BiConsumer error = (message, e) -> { - LOGGER.info("Error while sending the Create Monitored Item Subscription Message"); - e.printStackTrace(); + LOGGER.info("Error while sending the Create Monitored Item Subscription Message", e); plcSubscriber.onDisconnect(context); }; channel.submit(context, timeout, error, consumer, buffer); } catch (SerializationException e) { - LOGGER.info("Unable to serialize the Create Monitored Item Subscription Message"); - e.printStackTrace(); + LOGGER.info("Unable to serialize the Create Monitored Item Subscription Message", e); plcSubscriber.onDisconnect(context); } return future; @@ -287,8 +284,7 @@ public void startSubscriber() { //plcSubscriber.onDisconnect(context); } } catch (ParseException e) { - LOGGER.error("Unable to parse the returned Subscription response"); - e.printStackTrace(); + LOGGER.error("Unable to parse the returned Subscription response", e); plcSubscriber.onDisconnect(context); } if (serviceFault == null) { @@ -312,14 +308,12 @@ public void startSubscriber() { }; Consumer timeout = e -> { - LOGGER.error("Timeout while waiting for subscription response"); - e.printStackTrace(); + LOGGER.error("Timeout while waiting for subscription response", e); plcSubscriber.onDisconnect(context); }; BiConsumer error = (message, e) -> { - LOGGER.error("Error while waiting for subscription response"); - e.printStackTrace(); + LOGGER.error("Error while waiting for subscription response", e); plcSubscriber.onDisconnect(context); }; @@ -327,8 +321,7 @@ public void startSubscriber() { channel.submit(context, timeout, error, consumer, buffer); } catch (SerializationException e) { - LOGGER.warn("Unable to serialize subscription request"); - e.printStackTrace(); + LOGGER.warn("Unable to serialize subscription request", e); } } /* Put the subscriber loop to sleep for the rest of the cycle. */ @@ -338,8 +331,7 @@ public void startSubscriber() { //sleep(this.revisedCycleTime * 10); complete = true; } catch (Exception e) { - LOGGER.error("Failed :("); - e.printStackTrace(); + LOGGER.error("Failed to start subscription", e); } return null; }); @@ -400,27 +392,23 @@ public void stopSubscriber() { LOGGER.error("Fault when deleteing Subscription ServiceFault return from server with error code, '{}'", header.getServiceResult().toString()); } } catch (ParseException e) { - LOGGER.error("Unable to parse the returned Delete Subscriptions Response"); - e.printStackTrace(); + LOGGER.error("Unable to parse the returned Delete Subscriptions Response", e); } }; Consumer timeout = e -> { - LOGGER.error("Timeout while waiting for delete subscription response"); - e.printStackTrace(); + LOGGER.error("Timeout while waiting for delete subscription response", e); plcSubscriber.onDisconnect(context); }; BiConsumer error = (message, e) -> { - LOGGER.error("Error while waiting for delete subscription response"); - e.printStackTrace(); + LOGGER.error("Error while waiting for delete subscription response", e); plcSubscriber.onDisconnect(context); }; channel.submit(context, timeout, error, consumer, buffer); } catch (SerializationException e) { - LOGGER.warn("Unable to serialize subscription request"); - e.printStackTrace(); + LOGGER.warn("Unable to serialize subscription request", e); } sleep(500);