camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-7076: camel-spring should not enlist spring-event:default endpoint which is not used anyway.
Date Tue, 17 Dec 2013 16:04:06 GMT
Updated Branches:
  refs/heads/camel-2.12.x 0ab99f90a -> 2e35f212f
  refs/heads/master 96d5b9e7d -> b227086f2


CAMEL-7076: camel-spring should not enlist spring-event:default endpoint which is not used
anyway.


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

Branch: refs/heads/master
Commit: b227086f2832cce297a4e686202b2f7135dc6b29
Parents: 96d5b9e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Dec 17 17:06:27 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 17 17:06:27 2013 +0100

----------------------------------------------------------------------
 .../camel/component/event/EventComponent.java   | 33 ++++++++++++++++++++
 .../camel/component/event/EventEndpoint.java    |  7 +++++
 .../apache/camel/spring/SpringCamelContext.java | 25 ++++++---------
 .../camel/component/event/EventRouteTest.java   |  3 +-
 ...CamelContextManagedAutoAssignedNameTest.java |  2 +-
 .../management/DualCamelContextManagedTest.java |  2 +-
 .../camel/component/event/camelContext.xml      |  2 +-
 .../camel/component/event/mistypedPackage.xml   |  2 +-
 8 files changed, 55 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/main/java/org/apache/camel/component/event/EventComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/component/event/EventComponent.java
b/components/camel-spring/src/main/java/org/apache/camel/component/event/EventComponent.java
index 73218da..9296f64 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/component/event/EventComponent.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/component/event/EventComponent.java
@@ -16,12 +16,17 @@
  */
 package org.apache.camel.component.event;
 
+import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.camel.impl.DefaultComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ConfigurableApplicationContext;
 
 /**
@@ -31,7 +36,9 @@ import org.springframework.context.ConfigurableApplicationContext;
  * @version 
  */
 public class EventComponent extends DefaultComponent implements ApplicationContextAware {
+    private static final Logger LOG = LoggerFactory.getLogger(EventComponent.class);
     private ApplicationContext applicationContext;
+    private final Set<EventEndpoint> endpoints = new LinkedHashSet<EventEndpoint>();
 
     public EventComponent() {
     }
@@ -59,6 +66,32 @@ public class EventComponent extends DefaultComponent implements ApplicationConte
 
     protected EventEndpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         EventEndpoint answer = new EventEndpoint(uri, this);
+        setProperties(answer, parameters);
         return answer;
     }
+
+    protected void consumerStarted(EventEndpoint endpoint) {
+        endpoints.add(endpoint);
+    }
+
+    protected void consumerStopped(EventEndpoint endpoint) {
+        endpoints.remove(endpoint);
+    }
+
+    public void onApplicationEvent(ApplicationEvent event) {
+        // broadcast to the endpoints in use
+        for (EventEndpoint endpoint : endpoints) {
+            try {
+                endpoint.onApplicationEvent(event);
+            } catch (Exception e) {
+                LOG.warn("Error on application event " + event + ". This exception will be
ignored.", e);
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        endpoints.clear();
+        super.doStop();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
b/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
index 258135c..fceea03 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
@@ -107,13 +107,20 @@ public class EventEndpoint extends DefaultEndpoint implements ApplicationContext
         this.loadBalancer = loadBalancer;
     }
 
+    @Override
+    public EventComponent getComponent() {
+        return (EventComponent) super.getComponent();
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
     public synchronized void consumerStarted(EventConsumer consumer) {
+        getComponent().consumerStarted(this);
         getLoadBalancer().addProcessor(consumer.getProcessor());
     }
 
     public synchronized void consumerStopped(EventConsumer consumer) {
+        getComponent().consumerStopped(this);
         getLoadBalancer().removeProcessor(consumer.getProcessor());
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
index 26317fd..cf97cc6 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
@@ -59,7 +59,7 @@ public class SpringCamelContext extends DefaultCamelContext implements Initializ
     private static final Logger LOG = LoggerFactory.getLogger(SpringCamelContext.class);
     private static final ThreadLocal<Boolean> NO_START = new ThreadLocal<Boolean>();
     private ApplicationContext applicationContext;
-    private EventEndpoint eventEndpoint;
+    private EventComponent eventComponent;
 
     public SpringCamelContext() {
     }
@@ -127,10 +127,8 @@ public class SpringCamelContext extends DefaultCamelContext implements
Initializ
             }
         }
 
-        if (eventEndpoint != null) {
-            eventEndpoint.onApplicationEvent(event);
-        } else {
-            LOG.info("No spring-event endpoint enabled to handle event: {}", event);
+        if (eventComponent != null) {
+            eventComponent.onApplicationEvent(event);
         }
     }
 
@@ -158,31 +156,26 @@ public class SpringCamelContext extends DefaultCamelContext implements
Initializ
         if (applicationContext instanceof ConfigurableApplicationContext) {
             // only add if not already added
             if (hasComponent("spring-event") == null) {
-                addComponent("spring-event", new EventComponent(applicationContext));
+                eventComponent = new EventComponent(applicationContext);
+                addComponent("spring-event", eventComponent);
             }
         }
     }
 
+    @Deprecated
     public EventEndpoint getEventEndpoint() {
-        return eventEndpoint;
+        return null;
     }
 
+    @Deprecated
     public void setEventEndpoint(EventEndpoint eventEndpoint) {
-        this.eventEndpoint = eventEndpoint;
+        // noop
     }
 
     // Implementation methods
     // -----------------------------------------------------------------------
 
     @Override
-    protected void doStart() throws Exception {
-        super.doStart();
-        if (eventEndpoint == null) {
-            eventEndpoint = createEventEndpoint();
-        }
-    }
-
-    @Override
     protected Injector createInjector() {
         if (applicationContext instanceof ConfigurableApplicationContext) {
             return new SpringInjector((ConfigurableApplicationContext)applicationContext);

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
b/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
index 9ff5158..421f307 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/event/EventRouteTest.java
@@ -27,8 +27,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
  * @version 
  */
 public class EventRouteTest extends SpringTestSupport {
+
     protected Object expectedBody = "Hello there!";
-    protected String uri = "spring-event:default";
+    protected String uri = "spring-event:foo";
 
     public void testSendingCamelExchangeToEndpointResultsInValidApplicationEventAfterTheRefreshEvent()
throws Exception {
         MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedAutoAssignedNameTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedAutoAssignedNameTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedAutoAssignedNameTest.java
index 9e11f9c..4f10445 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedAutoAssignedNameTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedAutoAssignedNameTest.java
@@ -48,7 +48,7 @@ public class DualCamelContextManagedAutoAssignedNameTest extends DualCamelContex
         assertTrue("Route 2 is missing", on1.getCanonicalName().contains("route2") || on2.getCanonicalName().contains("route2"));
 
         set = mbeanServer.queryNames(new ObjectName("*:type=endpoints,*"), null);
-        assertTrue("Size should be 7 or higher, was: " + set.size(), set.size() >= 7);
+        assertTrue("Size should be 4 or higher, was: " + set.size(), set.size() >= 4);
 
         for (ObjectName on : set) {
             String name = on.getCanonicalName();

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedTest.java
index c4ffe0c..5912cb4 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/management/DualCamelContextManagedTest.java
@@ -60,7 +60,7 @@ public class DualCamelContextManagedTest extends SpringTestSupport {
         assertTrue("Route 2 is missing", on2.getCanonicalName().contains("route2"));
 
         set = mbeanServer.queryNames(new ObjectName("*:type=endpoints,*"), null);
-        assertTrue("Should be at least 7 endpoints, was: " + set.size(), set.size() >=
7);
+        assertTrue("Should be at least 4 endpoints, was: " + set.size(), set.size() >=
4);
 
         for (ObjectName on : set) {
             String name = on.getCanonicalName();

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
b/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
index d5fb8c0..27ddf75 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/event/camelContext.xml
@@ -26,7 +26,7 @@
     <package>org.apache.camel.component.event</package>
 
     <route>
-      <from uri="spring-event:default"/>
+      <from uri="spring-event:foo"/>
       <to uri="mock:result"/>
     </route>
   </camelContext>

http://git-wip-us.apache.org/repos/asf/camel/blob/b227086f/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
b/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
index f1d32ef..79d4bdc 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/event/mistypedPackage.xml
@@ -29,7 +29,7 @@
         </package>
 
         <route>
-            <from uri="spring-event:default"/>
+            <from uri="spring-event:foo"/>
             <to uri="mock:result"/>
         </route>
     </camelContext>


Mime
View raw message