This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch task3
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/task3 by this push:
new 69cbaf8374a CAMEL-22189: Foreground and Background tasks make possible
to manage and observe
69cbaf8374a is described below
commit 69cbaf8374af3fbfaa09f2de857d093d205d79cd
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jun 30 11:39:22 2025 +0200
CAMEL-22189: Foreground and Background tasks make possible to manage and
observe
---
.../management/mbean/ManagedBackoffTimerMBean.java | 36 -------
.../management/JmxManagementLifecycleStrategy.java | 4 -
.../management/mbean/ManagedBackoffTimer.java | 87 ----------------
.../camel/management/ManagedBackOffTimerTest.java | 113 ---------------------
4 files changed, 240 deletions(-)
diff --git
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBackoffTimerMBean.java
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBackoffTimerMBean.java
deleted file mode 100644
index 8474810e395..00000000000
---
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBackoffTimerMBean.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.api.management.mbean;
-
-import javax.management.openmbean.TabularData;
-
-import org.apache.camel.api.management.ManagedAttribute;
-import org.apache.camel.api.management.ManagedOperation;
-
-@Deprecated
-public interface ManagedBackoffTimerMBean {
-
- @ManagedAttribute(description = "Name of the backoff timer")
- String getName();
-
- @ManagedAttribute(description = "Number of total tasks")
- Integer getSize();
-
- @ManagedOperation(description = "Lists all the tasks")
- TabularData listTasks();
-
-}
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/JmxManagementLifecycleStrategy.java
b/core/camel-management/src/main/java/org/apache/camel/management/JmxManagementLifecycleStrategy.java
index b68257fad00..e3fdb23c221 100644
---
a/core/camel-management/src/main/java/org/apache/camel/management/JmxManagementLifecycleStrategy.java
+++
b/core/camel-management/src/main/java/org/apache/camel/management/JmxManagementLifecycleStrategy.java
@@ -54,7 +54,6 @@ import org.apache.camel.impl.debugger.DefaultBacklogDebugger;
import org.apache.camel.management.mbean.ManagedAsyncProcessorAwaitManager;
import org.apache.camel.management.mbean.ManagedBacklogDebugger;
import org.apache.camel.management.mbean.ManagedBacklogTracer;
-import org.apache.camel.management.mbean.ManagedBackoffTimer;
import org.apache.camel.management.mbean.ManagedBeanIntrospection;
import org.apache.camel.management.mbean.ManagedCamelContext;
import org.apache.camel.management.mbean.ManagedConsumerCache;
@@ -121,7 +120,6 @@ import
org.apache.camel.throttling.ThrottlingExceptionRoutePolicy;
import org.apache.camel.throttling.ThrottlingInflightRoutePolicy;
import org.apache.camel.util.KeyValueHolder;
import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.backoff.BackOffTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -581,8 +579,6 @@ public class JmxManagementLifecycleStrategy extends
ServiceSupport implements Li
answer = new ManagedValidatorRegistry(context, validatorRegistry);
} else if (service instanceof BrowsableVariableRepository
variableRepository) {
answer = new ManagedVariableRepository(context,
variableRepository);
- } else if (service instanceof BackOffTimer timer) {
- answer = new ManagedBackoffTimer(camelContext, timer);
} else if (service instanceof TaskManagerRegistry registry) {
answer = new ManagedTaskManagerRegistry(camelContext, registry);
} else if (service instanceof CamelClusterService camelClusterService)
{
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBackoffTimer.java
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBackoffTimer.java
deleted file mode 100644
index 469b6630d26..00000000000
---
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBackoffTimer.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.management.mbean;
-
-import java.util.Set;
-
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.CompositeDataSupport;
-import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.TabularData;
-import javax.management.openmbean.TabularDataSupport;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.Service;
-import org.apache.camel.api.management.ManagedResource;
-import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes;
-import org.apache.camel.api.management.mbean.ManagedBackoffTimerMBean;
-import org.apache.camel.util.backoff.BackOffTimer;
-
-@Deprecated
-@ManagedResource(description = "Managed BackoffTimer")
-public class ManagedBackoffTimer extends ManagedService implements
ManagedBackoffTimerMBean {
-
- private final BackOffTimer timer;
-
- public ManagedBackoffTimer(CamelContext context, BackOffTimer timer) {
- super(context, (Service) timer);
- this.timer = timer;
- }
-
- @Override
- public String getName() {
- return timer.getName();
- }
-
- @Override
- public Integer getSize() {
- return timer.size();
- }
-
- @Override
- public TabularData listTasks() {
- try {
- TabularData answer = new
TabularDataSupport(CamelOpenMBeanTypes.listBackoffTaskTabularType());
- Set<BackOffTimer.Task> tasks = timer.getTasks();
- for (BackOffTimer.Task task : tasks) {
- String name = task.getName();
- String kind = "background";
- String status = task.getStatus().name();
- long attempts = task.getCurrentAttempts();
- long delay = task.getCurrentDelay();
- long elapsed = task.getCurrentElapsedTime();
- long firstTime = task.getFirstAttemptTime();
- long lastTime = task.getLastAttemptTime();
- long nextTime = task.getNextAttemptTime();
- String failure = task.getException() != null ?
task.getException().getMessage() : null;
- CompositeType ct =
CamelOpenMBeanTypes.listBackoffTaskCompositeType();
- CompositeData data = new CompositeDataSupport(
- ct,
- new String[] {
- "name", "kind", "status", "attempts", "delay",
"elapsed", "firstTime", "lastTime", "nextTime",
- "failure" },
- new Object[] { name, kind, status, attempts, delay,
elapsed, firstTime, lastTime, nextTime, failure });
- answer.put(data);
- }
- return answer;
- } catch (Exception e) {
- throw RuntimeCamelException.wrapRuntimeCamelException(e);
- }
- }
-
-}
diff --git
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBackOffTimerTest.java
b/core/camel-management/src/test/java/org/apache/camel/management/ManagedBackOffTimerTest.java
deleted file mode 100644
index 0aae5ca2d9c..00000000000
---
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBackOffTimerTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.management;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.openmbean.TabularData;
-
-import org.apache.camel.support.PluginHelper;
-import org.apache.camel.support.service.ServiceHelper;
-import org.apache.camel.util.backoff.BackOff;
-import org.apache.camel.util.backoff.BackOffTimer;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledOnOs;
-import org.junit.jupiter.api.condition.OS;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-@DisabledOnOs(OS.AIX)
-public class ManagedBackOffTimerTest extends ManagementTestSupport {
-
- @Override
- public boolean isUseRouteBuilder() {
- return false;
- }
-
- @Test
- public void testManageBackOffTimer() throws Exception {
- final CountDownLatch latch = new CountDownLatch(1);
- final AtomicInteger counter = new AtomicInteger();
-
- BackOffTimer timer =
PluginHelper.getBackOffTimerFactory(context.getCamelContextExtension())
- .newBackOffTimer("Cheese");
- ServiceHelper.startService(timer);
-
- context.start();
-
- // get the bean introspection for the route
- MBeanServer mbeanServer = getMBeanServer();
- Set<ObjectName> set = mbeanServer.queryNames(new
ObjectName("*:type=services,*"), null);
- List<ObjectName> list = new ArrayList<>(set);
- ObjectName on = null;
- for (ObjectName name : list) {
- if (name.getCanonicalName().contains("DefaultBackOffTimer")) {
- on = name;
- break;
- }
- }
-
- assertNotNull(on, "Should have found DefaultBackOffTimer");
-
- String name = (String) mbeanServer.getAttribute(on, "Name");
- assertEquals("Cheese", name);
-
- final BackOff backOff =
BackOff.builder().delay(100).removeOnComplete(false).build();
- final AtomicLong first = new AtomicLong();
-
- BackOffTimer.Task task = timer.schedule(
- backOff,
- context -> {
- assertEquals(counter.incrementAndGet(),
context.getCurrentAttempts());
- assertEquals(100, context.getCurrentDelay());
- assertEquals(100L * counter.get(),
context.getCurrentElapsedTime());
- if (first.get() == 0) {
- first.set(context.getFirstAttemptTime());
- } else {
- assertEquals(first.get(),
context.getFirstAttemptTime());
- }
-
- return counter.get() < 5;
- });
-
- task.whenComplete(
- (context, throwable) -> {
- assertEquals(5, counter.get());
- latch.countDown();
- });
-
- latch.await(5, TimeUnit.SECONDS);
-
- Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
- assertEquals(1, size);
-
- TabularData data = (TabularData) mbeanServer.invoke(on, "listTasks",
null, null);
- assertEquals(1, data.size());
-
- ServiceHelper.stopService(timer);
- }
-
-}