Repository navigation
CAMEL-26339: camel-plc4x - log a run of failed polls once and stop polling a lost connection without autoReconnect #28556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davsclaus
merged 3 commits into
apache:main
from
etzel-mes:fix/CAMEL-26339-plc4x-failed-poll-logging
Oct 27, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d8dc198
CAMEL-26339: camel-plc4x - log a run of failed polls of the triggered…
etzel-mes b323cda
CAMEL-26339: camel-plc4x - shut down a lost connection once and stop …
etzel-mes f26f939
CAMEL-26339: camel-plc4x - say that polling stops in the log line of …
etzel-mes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/LogCapture.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.plc4x; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
|
|
||
| import org.apache.logging.log4j.Level; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.core.LogEvent; | ||
| import org.apache.logging.log4j.core.Logger; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| import org.apache.logging.log4j.core.config.Property; | ||
|
|
||
| /** | ||
| * Captures the log events of one logger, down to DEBUG, while it is open. Only one capture is open at a time: opening | ||
| * another one resets the level of the loggers. | ||
| */ | ||
| final class LogCapture extends AbstractAppender implements AutoCloseable { | ||
|
|
||
| private final List<LogEvent> events = new CopyOnWriteArrayList<>(); | ||
| private final Logger logger; | ||
| private final Level previousLevel; | ||
|
|
||
| LogCapture(Class<?> loggerClass) { | ||
| super("LogCapture-" + loggerClass.getSimpleName(), null, null, true, Property.EMPTY_ARRAY); | ||
| this.logger = (Logger) LogManager.getLogger(loggerClass); | ||
| this.previousLevel = logger.getLevel(); | ||
| start(); | ||
| logger.addAppender(this); | ||
| logger.setLevel(Level.DEBUG); | ||
| } | ||
|
|
||
| @Override | ||
| public void append(LogEvent event) { | ||
| events.add(event.toImmutable()); | ||
| } | ||
|
|
||
| /** | ||
| * @return the events logged so far, in the order they were logged | ||
| */ | ||
| List<LogEvent> events() { | ||
| return List.copyOf(events); | ||
| } | ||
|
|
||
| /** | ||
| * @return the events logged so far whose message contains the given text | ||
| */ | ||
| List<LogEvent> eventsContaining(String text) { | ||
| return events.stream().filter(e -> e.getMessage().getFormattedMessage().contains(text)).toList(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| logger.removeAppender(this); | ||
| logger.setLevel(previousLevel); | ||
| stop(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.