This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new b0159a1b3fe CAMEL-19358: Add jmx api for setting keepOpen on
throttling circuit breaker
b0159a1b3fe is described below
commit b0159a1b3fe9dc873f88f8d69e6f502b686441de
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed May 8 14:50:09 2024 +0200
CAMEL-19358: Add jmx api for setting keepOpen on throttling circuit breaker
---
.../beans/ThrottlingExceptionRoutePolicy.json | 2 +-
...ManagedThrottlingExceptionRoutePolicyMBean.java | 6 +++++
.../ManagedThrottlingExceptionRoutePolicy.java | 10 +++++++++
.../ThrottlingExceptionRoutePolicyConfigurer.java | 6 +++++
.../camel/bean/ThrottlingExceptionRoutePolicy.json | 2 +-
.../throttling/ThrottlingExceptionRoutePolicy.java | 26 ++++++++++++++++++++--
6 files changed, 48 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/ThrottlingExceptionRoutePolicy.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/ThrottlingExceptionRoutePolicy.json
index 2738d4e9534..d891485d5e0 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/ThrottlingExceptionRoutePolicy.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/ThrottlingExceptionRoutePolicy.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-support",
"version": "4.6.0-SNAPSHOT",
- "properties": { "failureThreshold": { "index": 0, "kind": "property",
"displayName": "Failure Threshold", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"description": "How many failed messages within the window would trigger the
circuit breaker to open" }, "failureWindow": { "index": 1, "kind": "property",
"displayName": "Failure Window", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, [...]
+ "properties": { "failureThreshold": { "index": 0, "kind": "property",
"displayName": "Failure Threshold", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"description": "How many failed messages within the window would trigger the
circuit breaker to open" }, "failureWindow": { "index": 1, "kind": "property",
"displayName": "Failure Window", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, [...]
}
}
diff --git
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
index b9f7be5dfae..6614918632f 100644
---
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
+++
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
@@ -48,6 +48,12 @@ public interface ManagedThrottlingExceptionRoutePolicyMBean
extends ManagedServi
@ManagedAttribute(description = "Whether to keep the circuit breaker open
(never closes)")
void setKeepOpen(boolean keepOpen);
+ @ManagedAttribute(description = "Logging level to use for logging state
changes")
+ String getStateLoggingLevel();
+
+ @ManagedAttribute(description = "Logging level to use for logging state
changes")
+ void setStateLoggingLevel(String stateLoggingLevel);
+
@ManagedOperation(description = "The current state of the circuit")
String currentState();
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
index c9980772b81..17d72e438d6 100644
---
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
+++
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
@@ -90,6 +90,16 @@ public class ManagedThrottlingExceptionRoutePolicy extends
ManagedService
getPolicy().setKeepOpen(keepOpen);
}
+ @Override
+ public String getStateLoggingLevel() {
+ return getPolicy().getStateLoggingLevel().name();
+ }
+
+ @Override
+ public void setStateLoggingLevel(String stateLoggingLevel) {
+ getPolicy().setStateLoggingLevel(stateLoggingLevel);
+ }
+
@Override
public String currentState() {
return getPolicy().dumpState();
diff --git
a/core/camel-support/src/generated/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicyConfigurer.java
b/core/camel-support/src/generated/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicyConfigurer.java
index cfc2e1c3e69..e135c6d0561 100644
---
a/core/camel-support/src/generated/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicyConfigurer.java
+++
b/core/camel-support/src/generated/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicyConfigurer.java
@@ -34,6 +34,8 @@ public class ThrottlingExceptionRoutePolicyConfigurer extends
org.apache.camel.s
case "halfOpenHandler":
target.setHalfOpenHandler(property(camelContext,
org.apache.camel.throttling.ThrottlingExceptionHalfOpenHandler.class, value));
return true;
case "keepopen":
case "keepOpen": target.setKeepOpen(property(camelContext,
boolean.class, value)); return true;
+ case "statelogginglevel":
+ case "stateLoggingLevel":
target.setStateLoggingLevel(property(camelContext,
org.apache.camel.LoggingLevel.class, value)); return true;
default: return false;
}
}
@@ -52,6 +54,8 @@ public class ThrottlingExceptionRoutePolicyConfigurer extends
org.apache.camel.s
case "halfOpenHandler": return
org.apache.camel.throttling.ThrottlingExceptionHalfOpenHandler.class;
case "keepopen":
case "keepOpen": return boolean.class;
+ case "statelogginglevel":
+ case "stateLoggingLevel": return org.apache.camel.LoggingLevel.class;
default: return null;
}
}
@@ -71,6 +75,8 @@ public class ThrottlingExceptionRoutePolicyConfigurer extends
org.apache.camel.s
case "halfOpenHandler": return target.getHalfOpenHandler();
case "keepopen":
case "keepOpen": return target.getKeepOpen();
+ case "statelogginglevel":
+ case "stateLoggingLevel": return target.getStateLoggingLevel();
default: return null;
}
}
diff --git
a/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/ThrottlingExceptionRoutePolicy.json
b/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/ThrottlingExceptionRoutePolicy.json
index 2738d4e9534..d891485d5e0 100644
---
a/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/ThrottlingExceptionRoutePolicy.json
+++
b/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/ThrottlingExceptionRoutePolicy.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-support",
"version": "4.6.0-SNAPSHOT",
- "properties": { "failureThreshold": { "index": 0, "kind": "property",
"displayName": "Failure Threshold", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"description": "How many failed messages within the window would trigger the
circuit breaker to open" }, "failureWindow": { "index": 1, "kind": "property",
"displayName": "Failure Window", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, [...]
+ "properties": { "failureThreshold": { "index": 0, "kind": "property",
"displayName": "Failure Threshold", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"description": "How many failed messages within the window would trigger the
circuit breaker to open" }, "failureWindow": { "index": 1, "kind": "property",
"displayName": "Failure Window", "required": false, "type": "integer",
"javaType": "long", "deprecated": false, [...]
}
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
b/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
index 4101596e433..bc48b67c69e 100644
---
a/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
+++
b/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
@@ -28,7 +28,9 @@ import java.util.concurrent.locks.ReentrantLock;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
+import org.apache.camel.LoggingLevel;
import org.apache.camel.Route;
+import org.apache.camel.spi.CamelLogger;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RoutePolicy;
@@ -64,6 +66,7 @@ public class ThrottlingExceptionRoutePolicy extends
RoutePolicySupport implement
private CamelContext camelContext;
private final Lock lock = new ReentrantLock();
+ private CamelLogger stateLogger;
// configuration
@Metadata(description = "How many failed messages within the window would
trigger the circuit breaker to open")
@@ -76,6 +79,8 @@ public class ThrottlingExceptionRoutePolicy extends
RoutePolicySupport implement
private boolean keepOpen;
@Metadata(description = "Allows to only throttle based on certain types of
exceptions. Multiple exceptions (use FQN class name) can be separated by
comma.")
private String exceptions;
+ @Metadata(description = "Logging level for state changes", defaultValue =
"DEBUG")
+ private LoggingLevel stateLoggingLevel = LoggingLevel.DEBUG;
private List<Class<?>> throttledExceptions;
// handler for half open circuit can be used instead of resuming route to
check on resources
@Metadata(label = "advanced",
@@ -135,6 +140,8 @@ public class ThrottlingExceptionRoutePolicy extends
RoutePolicySupport implement
protected void doInit() throws Exception {
super.doInit();
+ this.stateLogger = new CamelLogger(LOG, stateLoggingLevel);
+
if (exceptions != null && throttledExceptions == null) {
var list = new ArrayList<Class<?>>();
for (String fqn : exceptions.split(",")) {
@@ -334,8 +341,8 @@ public class ThrottlingExceptionRoutePolicy extends
RoutePolicySupport implement
}
private void logState() {
- if (LOG.isDebugEnabled()) {
- LOG.debug(dumpState());
+ if (stateLogger != null) {
+ stateLogger.log(dumpState());
}
}
@@ -433,4 +440,19 @@ public class ThrottlingExceptionRoutePolicy extends
RoutePolicySupport implement
return openedAt;
}
+ public LoggingLevel getStateLoggingLevel() {
+ return stateLoggingLevel;
+ }
+
+ public void setStateLoggingLevel(LoggingLevel stateLoggingLevel) {
+ this.stateLoggingLevel = stateLoggingLevel;
+ if (stateLogger != null) {
+ stateLogger.setLevel(stateLoggingLevel);
+ }
+ }
+
+ public void setStateLoggingLevel(String stateLoggingLevel) {
+ setStateLoggingLevel(LoggingLevel.valueOf(stateLoggingLevel));
+ }
+
}