camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-7780: ManagedCamelContext - Add operation to check if you can send to an endpoint
Date Thu, 04 Sep 2014 16:01:22 GMT
Repository: camel
Updated Branches:
  refs/heads/master 354945e38 -> ce8aac572


CAMEL-7780: ManagedCamelContext - Add operation to check if you can send to an endpoint


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

Branch: refs/heads/master
Commit: ce8aac572936e5f159aa5063c5d65c4c874520d7
Parents: 354945e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Sep 4 17:57:26 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Sep 4 17:57:26 2014 +0200

----------------------------------------------------------------------
 .../management/mbean/ManagedCamelContextMBean.java   |  3 +++
 .../camel/management/mbean/ManagedCamelContext.java  | 15 +++++++++++++++
 .../camel/management/ManagedCamelContextTest.java    |  6 ++++++
 3 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ce8aac57/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 91ade70..441e301 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -146,6 +146,9 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     @ManagedOperation(description = "Starts all the routes which currently is not started")
     void startAllRoutes() throws Exception;
 
+    @ManagedOperation(description = "Whether its possible to send to the endpoint (eg the
endpoint has a producer)")
+    boolean canSendToEndpoint(String endpointUri);
+
     @ManagedOperation(description = "Send body (in only)")
     void sendBody(String endpointUri, Object body) throws Exception;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ce8aac57/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 45833b7..2ccad19 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -36,6 +36,7 @@ import org.apache.camel.Component;
 import org.apache.camel.ComponentConfiguration;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ManagementStatisticsLevel;
+import org.apache.camel.Producer;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
 import org.apache.camel.TimerListener;
@@ -252,6 +253,20 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         context.startAllRoutes();
     }
 
+    public boolean canSendToEndpoint(String endpointUri) {
+        try {
+            Endpoint endpoint = context.getEndpoint(endpointUri);
+            if (endpoint != null) {
+                Producer producer = endpoint.createProducer();
+                return producer != null;
+            }
+        } catch (Exception e) {
+            // ignore
+        }
+
+        return false;
+    }
+
     public void sendBody(String endpointUri, Object body) throws Exception {
         ProducerTemplate template = context.createProducerTemplate();
         try {

http://git-wip-us.apache.org/repos/asf/camel/blob/ce8aac57/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 735ee6c..6fc3dd1 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -106,6 +106,12 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
         assertEquals("Hello World", reply);
         assertMockEndpointsSatisfied();
 
+        // test can send
+        Boolean can = (Boolean) mbeanServer.invoke(on, "canSendToEndpoint", new Object[]{"direct:start"},
new String[]{"java.lang.String"});
+        assertEquals(true, can.booleanValue());
+        can = (Boolean) mbeanServer.invoke(on, "canSendToEndpoint", new Object[]{"timer:foo"},
new String[]{"java.lang.String"});
+        assertEquals(false, can.booleanValue());
+
         // stop Camel
         mbeanServer.invoke(on, "stop", null, null);
     }


Mime
View raw message