etzel-mes commented on code in PR #28556:
URL: https://github.com/apache/camel/pull/28556#discussion_r4386773081
##########
components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XTriggeredConsumer.java:
##########
@@ -147,4 +172,27 @@ private PlcReadResponse read() throws Exception {
public String toString() {
return "Plc4XTriggeredConsumer[" + plc4XEndpoint + "]";
}
+
+ /**
+ * Logs like the default exception handler of a consumer, but a failed
poll only at WARN with the stack trace when
+ * it starts a run of failed polls or stops the polling, and the following
failed polls of the run at DEBUG without
+ * it, so that a PLC that cannot be reached is not logged on every poll.
+ */
+ private final class FailedPollExceptionHandler extends
LoggingExceptionHandler {
+ FailedPollExceptionHandler(CamelContext camelContext) {
+ super(camelContext, Plc4XTriggeredConsumer.class);
+ }
+
+ @Override
+ public void handleException(String message, Throwable exception) {
+ // a failed poll is reported without an exchange and before it is
counted, so the first one of a run finds an
+ // error counter of 0, and the one that stops the polling finds
its task unscheduled
+ if (getErrorCounter() == 0 || !isSchedulerStarted()) {
Review Comment:
Done in f26f939b804: the poll that stops the polling now logs "Failed
polling endpoint: … . Polling stops until the route is restarted"; bridged and
custom handlers still get the stock message.
_Claude Code on behalf of etzel-mes_
##########
components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XTriggeredConsumer.java:
##########
@@ -111,10 +124,22 @@ protected int poll() throws Exception {
}
/**
- * Reads the trigger and the tags in one request; fails unless every tag
was read and the trigger is a boolean.
+ * Reads the trigger and the tags in one request; fails unless every tag
was read and the trigger is a boolean. A
+ * connection that is lost without autoReconnect also stops the polling.
*/
private PlcReadResponse read() throws Exception {
plc4XEndpoint.reconnectIfNeeded();
+ // a connection that is lost after reconnectIfNeeded() fails the read
instead, and the next poll shuts it down
+ if (!plc4XEndpoint.isAutoReconnect() && plc4XEndpoint.connection ==
null) {
Review Comment:
Done in f26f939b804: `Plc4XEndpoint.hasConnection()` next to
`isConnected()`, used by the consumer.
_Claude Code on behalf of etzel-mes_
##########
components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XTriggeredConsumer.java:
##########
@@ -86,6 +95,10 @@ protected int poll() throws Exception {
// the consumer stopped while the read was in progress
return 0;
}
+ if (getErrorCounter() > 0) {
Review Comment:
Yes, intended: it is the one line that says the PLC is back, whichever
handler logged the failures.
_Claude Code on behalf of etzel-mes_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]