gnodet-bot commented on code in PR #29522: URL: https://github.com/apache/camel/pull/29522#discussion_r4518894957
########## dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/ConnectorTasks.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.cli.connector; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The periodic tasks of the connector, which must never end: a task that throws is not run again by its scheduler, and + * these tasks are the only way the Camel CLI reaches the integration (its status, the actions, stop). An Error too: an + * OutOfMemoryError of a moment while the status is collected would otherwise leave the status as it was then for good, + * and the integration out of reach of camel stop. + */ +final class ConnectorTasks { + + private static final Logger LOG = LoggerFactory.getLogger(ConnectorTasks.class); + // an Error is logged as a warning once: the task runs every second, and may fail every time + private static final AtomicBoolean WARNED = new AtomicBoolean(); + + private ConnectorTasks() { + } + + /** Runs the task, and ignores what it throws, so the scheduler runs it again. */ + static void safely(Runnable task) { + try { + task.run(); + } catch (Exception e) { + LOG.debug("Error in Camel CLI connector task due to: {}. This exception is ignored.", e.getMessage(), e); + } catch (Throwable e) { Review Comment: 💬 **Nit:** The `Exception` branch uses `e.getMessage()` as the `{}` format argument, while the `Throwable` branches below use `e` directly (which calls `toString()`, including the exception class name). Not a bug — SLF4J will log the full stack trace via the trailing `e` argument in both cases — but consider aligning for consistency. For `Errors`, having the class name in the message via `toString()` is arguably more useful. -- 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]
