camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/5] camel git commit: CAMEL-10719 add JMX management to ThrottlingExceptionRoutePolicy
Date Fri, 20 Jan 2017 09:36:13 GMT
CAMEL-10719 add JMX management to ThrottlingExceptionRoutePolicy

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/69b716bb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69b716bb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69b716bb

Branch: refs/heads/master
Commit: 69b716bbb38ff3754b72038526f44e74429ddb6d
Parents: a4f82a2
Author: CodeSmell <mbarlotta@gmail.com>
Authored: Tue Jan 17 16:22:27 2017 -0500
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jan 20 09:44:37 2017 +0100

----------------------------------------------------------------------
 ...agedThrottlingExceptionRoutePolicyMBean.java | 55 +++++++++++
 .../impl/ThrottlingExceptionRoutePolicy.java    | 42 ++++++++-
 .../ManagedThrottlingExceptionRoutePolicy.java  | 99 ++++++++++++++++++++
 3 files changed, 193 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/69b716bb/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
new file mode 100644
index 0000000..86e394c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedThrottlingExceptionRoutePolicyMBean.java
@@ -0,0 +1,55 @@
+/**
+ * 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 org.apache.camel.api.management.ManagedAttribute;
+
+public interface ManagedThrottlingExceptionRoutePolicyMBean extends ManagedServiceMBean {
+
+    @ManagedAttribute(description = "how long to wait before moving open circuit to half
open")
+    long getHalfOpenAfter();
+
+    @ManagedAttribute(description = "how long to wait before moving open circuit to half
open")
+    void setHalfOpenAfter(long milliseconds);
+    
+    @ManagedAttribute(description = "the range of time that failures should occur within")
+    long getFailureWindow();
+
+    @ManagedAttribute(description = "the range of time that failures should occur within")
+    void setFailureWindow(long milliseconds);
+    
+    @ManagedAttribute(description = "number of failures before opening circuit")
+    int getFailureThreshold();
+
+    @ManagedAttribute(description = "number of failures before opening circuit")
+    void setFailureThreshold(int numberOfFailures);
+
+    @ManagedAttribute(description = "State")
+    String currentState();
+    
+    @ManagedAttribute(description = "The half open handler registered (if any)")
+    String hasHalfOpenHandler();
+    
+    @ManagedAttribute(description = "the number of failures caught")
+    int currentFailures();
+    
+    @ManagedAttribute(description = "number of ms since the last failure was recorded")
+    long getLastFailure();
+    
+    @ManagedAttribute(description = "number ms since the circuit was opened")
+    long getOpenAt();
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69b716bb/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
b/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
index aaa4eca..34b755a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ThrottlingExceptionRoutePolicy.java
@@ -255,11 +255,11 @@ public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport
implement
     
     public String dumpState() {
         int num = state.get();
-        String state = stateAsString(num);
+        String routeState = stateAsString(num);
         if (failures.get() > 0) {
-            return String.format("State %s, failures %d, last failure %d ms ago", state,
failures.get(), System.currentTimeMillis() - lastFailure);
+            return String.format("*** State %s, failures %d, last failure %d ms ago", routeState,
failures.get(), System.currentTimeMillis() - lastFailure);
         } else {
-            return String.format("State %s, failures %d", state, failures.get());
+            return String.format("*** State %s, failures %d", routeState, failures.get());
         }
     }
     
@@ -295,4 +295,40 @@ public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport
implement
         this.halfOpenHandler = halfOpenHandler;
     }
 
+    public int getFailureThreshold() {
+        return failureThreshold;
+    }
+
+    public void setFailureThreshold(int failureThreshold) {
+        this.failureThreshold = failureThreshold;
+    }
+
+    public long getFailureWindow() {
+        return failureWindow;
+    }
+
+    public void setFailureWindow(long failureWindow) {
+        this.failureWindow = failureWindow;
+    }
+
+    public long getHalfOpenAfter() {
+        return halfOpenAfter;
+    }
+
+    public void setHalfOpenAfter(long halfOpenAfter) {
+        this.halfOpenAfter = halfOpenAfter;
+    }
+
+    public int getFailures() {
+        return failures.get();
+    }
+
+    public long getLastFailure() {
+        return lastFailure;
+    }
+
+    public long getOpenedAt() {
+        return openedAt;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/69b716bb/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
new file mode 100644
index 0000000..bd2af1f
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThrottlingExceptionRoutePolicy.java
@@ -0,0 +1,99 @@
+/**
+ * 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 org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedThrottlingExceptionRoutePolicyMBean;
+import org.apache.camel.impl.ThrottlingExceptionHalfOpenHandler;
+import org.apache.camel.impl.ThrottlingExceptionRoutePolicy;
+
+@ManagedResource(description = "Managed ThrottlingExceptionRoutePolicy")
+public class ManagedThrottlingExceptionRoutePolicy extends ManagedService implements ManagedThrottlingExceptionRoutePolicyMBean
{
+    
+    private final ThrottlingExceptionRoutePolicy policy;
+
+    public ManagedThrottlingExceptionRoutePolicy(CamelContext context, ThrottlingExceptionRoutePolicy
policy) {
+        super(context, policy);
+        this.policy = policy;
+    }
+
+    public ThrottlingExceptionRoutePolicy getPolicy() {
+        return policy;
+    }
+    
+    @Override
+    public long getHalfOpenAfter() {
+        return getPolicy().getHalfOpenAfter();
+    }
+
+    @Override
+    public void setHalfOpenAfter(long milliseconds) {
+        getPolicy().setHalfOpenAfter(milliseconds);
+    }
+
+    @Override
+    public long getFailureWindow() {
+        return getPolicy().getFailureWindow();
+    }
+
+    @Override
+    public void setFailureWindow(long milliseconds) {
+        getPolicy().setFailureWindow(milliseconds);
+    }
+
+    @Override
+    public int getFailureThreshold() {
+        return getPolicy().getFailureThreshold();
+    }
+
+    @Override
+    public void setFailureThreshold(int numberOfFailures) {
+        getPolicy().setFailureThreshold(numberOfFailures);
+    }
+    
+    @Override
+    public String currentState() {
+        return getPolicy().dumpState();
+    }
+
+    @Override
+    public String hasHalfOpenHandler() {
+        ThrottlingExceptionHalfOpenHandler obj = getPolicy().getHalfOpenHandler();
+        if (obj != null) {
+            return obj.getClass().getSimpleName();
+        } else {
+            return "";
+        }
+    }
+
+    @Override
+    public int currentFailures() {
+        return getPolicy().getFailures();
+    }
+
+    @Override
+    public long getLastFailure() {
+        return System.currentTimeMillis() - getPolicy().getLastFailure();
+    }
+
+    @Override
+    public long getOpenAt() {
+        return System.currentTimeMillis() - getPolicy().getOpenedAt();
+    }
+
+}


Mime
View raw message