Author: davsclaus
Date: Tue Mar 27 08:25:54 2012
New Revision: 1305773

URL: http://svn.apache.org/viewvc?rev=1305773&view=rev
Log:
CAMEL-5121: Added support class for lifecycle strategy.

Added:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
Modified:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextWithLifecycleStrategyRestartTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/VetoCamelContextStartTest.java
    
camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java?rev=1305773&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/support/LifecycleStrategySupport.java
 Tue Mar 27 08:25:54 2012
@@ -0,0 +1,113 @@
+/**
+ * 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.support;
+
+import java.util.Collection;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ErrorHandlerFactory;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.Service;
+import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * A useful base class for {@link LifecycleStrategy} implementations.
+ */
+public abstract class LifecycleStrategySupport implements LifecycleStrategy {
+
+    @Override
+    public void onContextStart(CamelContext context) throws 
VetoCamelContextStartException {
+        // noop
+    }
+
+    @Override
+    public void onContextStop(CamelContext context) {
+        // noop
+    }
+
+    @Override
+    public void onComponentAdd(String name, Component component) {
+        // noop
+    }
+
+    @Override
+    public void onComponentRemove(String name, Component component) {
+        // noop
+    }
+
+    @Override
+    public void onEndpointAdd(Endpoint endpoint) {
+        // noop
+    }
+
+    @Override
+    public void onEndpointRemove(Endpoint endpoint) {
+        // noop
+    }
+
+    @Override
+    public void onServiceAdd(CamelContext context, Service service, Route 
route) {
+        // noop
+    }
+
+    @Override
+    public void onServiceRemove(CamelContext context, Service service, Route 
route) {
+        // noop
+    }
+
+    @Override
+    public void onRoutesAdd(Collection<Route> routes) {
+        // noop
+    }
+
+    @Override
+    public void onRoutesRemove(Collection<Route> routes) {
+        // noop
+    }
+
+    @Override
+    public void onRouteContextCreate(RouteContext routeContext) {
+        // noop
+    }
+
+    @Override
+    public void onErrorHandlerAdd(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
+        // noop
+    }
+
+    @Override
+    public void onErrorHandlerRemove(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
+        // noop
+    }
+
+    @Override
+    public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor 
threadPool, String id,
+                                String sourceId, String routeId, String 
threadPoolProfileId) {
+        // noop
+    }
+
+    @Override
+    public void onThreadPoolRemove(CamelContext camelContext, 
ThreadPoolExecutor threadPool) {
+        // noop
+    }
+}

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextWithLifecycleStrategyRestartTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextWithLifecycleStrategyRestartTest.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextWithLifecycleStrategyRestartTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextWithLifecycleStrategyRestartTest.java
 Tue Mar 27 08:25:54 2012
@@ -17,21 +17,14 @@
 package org.apache.camel.impl;
 
 import java.util.Collection;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
-import org.apache.camel.ErrorHandlerFactory;
-import org.apache.camel.Processor;
 import org.apache.camel.Route;
-import org.apache.camel.Service;
 import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.spi.LifecycleStrategy;
-import org.apache.camel.spi.RouteContext;
+import org.apache.camel.support.LifecycleStrategySupport;
 
 /**
  *
@@ -101,7 +94,7 @@ public class DefaultCamelContextWithLife
         };
     }
 
-    private class MyStrategy implements LifecycleStrategy {
+    private class MyStrategy extends LifecycleStrategySupport {
 
         private AtomicInteger contextStartCounter = new AtomicInteger();
         private AtomicInteger removeCounter = new AtomicInteger();
@@ -112,62 +105,10 @@ public class DefaultCamelContextWithLife
         }
 
         @Override
-        public void onContextStop(CamelContext context) {
-        }
-
-        @Override
-        public void onComponentAdd(String name, Component component) {
-        }
-
-        @Override
-        public void onComponentRemove(String name, Component component) {
-        }
-
-        @Override
-        public void onEndpointAdd(Endpoint endpoint) {
-        }
-
-        @Override
-        public void onEndpointRemove(Endpoint endpoint) {
-        }
-
-        @Override
-        public void onServiceAdd(CamelContext context, Service service, Route 
route) {
-        }
-
-        @Override
-        public void onServiceRemove(CamelContext context, Service service, 
Route route) {
-        }
-
-        @Override
-        public void onRoutesAdd(Collection<Route> routes) {
-        }
-
-        @Override
         public void onRoutesRemove(Collection<Route> routes) {
             removeCounter.incrementAndGet();
         }
 
-        @Override
-        public void onRouteContextCreate(RouteContext routeContext) {
-        }
-
-        @Override
-        public void onErrorHandlerAdd(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-        }
-
-        @Override
-        public void onErrorHandlerRemove(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-        }
-
-        @Override
-        public void onThreadPoolAdd(CamelContext camelContext, 
ThreadPoolExecutor threadPool, String id, String sourceId, String routeId, 
String threadPoolProfileId) {
-        }
-
-        @Override
-        public void onThreadPoolRemove(CamelContext camelContext, 
ThreadPoolExecutor threadPool) {
-        }
-
         public int getContextStartCounter() {
             return contextStartCounter.get();
         }

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
 Tue Mar 27 08:25:54 2012
@@ -28,17 +28,18 @@ import org.apache.camel.ErrorHandlerFact
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
 import org.apache.camel.Service;
-import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.support.LifecycleStrategySupport;
 
 /**
  * @version 
  */
-public class DummyLifecycleStrategy implements LifecycleStrategy {
+public class DummyLifecycleStrategy extends LifecycleStrategySupport {
 
     private List<String> events = new ArrayList<String>();
 
-    public void onContextStart(CamelContext context) {
+    public void onContextStart(CamelContext context) throws 
VetoCamelContextStartException {
         events.add("onContextStart");
     }
 

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java
 Tue Mar 27 08:25:54 2012
@@ -18,6 +18,7 @@ package org.apache.camel.impl;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.TestSupport;
+import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.util.jndi.JndiContext;
 
 /**
@@ -46,7 +47,7 @@ public class LifecycleStrategyFailOnStar
     private static class MyLifecycleStrategy extends DummyLifecycleStrategy {
 
         @Override
-        public void onContextStart(CamelContext context) {
+        public void onContextStart(CamelContext context) throws 
VetoCamelContextStartException {
             throw new IllegalArgumentException("Forced");
         }
     }

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/VetoCamelContextStartTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/VetoCamelContextStartTest.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/VetoCamelContextStartTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/VetoCamelContextStartTest.java
 Tue Mar 27 08:25:54 2012
@@ -16,21 +16,12 @@
  */
 package org.apache.camel.impl;
 
-import java.util.Collection;
-import java.util.concurrent.ThreadPoolExecutor;
-
 import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
-import org.apache.camel.ErrorHandlerFactory;
-import org.apache.camel.Processor;
-import org.apache.camel.Route;
-import org.apache.camel.Service;
 import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.spi.LifecycleStrategy;
-import org.apache.camel.spi.RouteContext;
+import org.apache.camel.support.LifecycleStrategySupport;
 
 /**
  *
@@ -63,7 +54,7 @@ public class VetoCamelContextStartTest e
         return context;
     }
 
-    private class MyVeto implements LifecycleStrategy {
+    private class MyVeto extends LifecycleStrategySupport {
 
         @Override
         public void onContextStart(CamelContext context) throws 
VetoCamelContextStartException {
@@ -71,60 +62,5 @@ public class VetoCamelContextStartTest e
             throw new VetoCamelContextStartException("Forced", context, false);
         }
 
-        @Override
-        public void onContextStop(CamelContext context) {
-        }
-
-        @Override
-        public void onComponentAdd(String name, Component component) {
-        }
-
-        @Override
-        public void onComponentRemove(String name, Component component) {
-        }
-
-        @Override
-        public void onEndpointAdd(Endpoint endpoint) {
-        }
-
-        @Override
-        public void onEndpointRemove(Endpoint endpoint) {
-        }
-
-        @Override
-        public void onServiceAdd(CamelContext context, Service service, Route 
route) {
-        }
-
-        @Override
-        public void onServiceRemove(CamelContext context, Service service, 
Route route) {
-        }
-
-        @Override
-        public void onRoutesAdd(Collection<Route> routes) {
-        }
-
-        @Override
-        public void onRoutesRemove(Collection<Route> routes) {
-        }
-
-        @Override
-        public void onRouteContextCreate(RouteContext routeContext) {
-        }
-
-        @Override
-        public void onErrorHandlerAdd(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-        }
-
-        @Override
-        public void onErrorHandlerRemove(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-        }
-
-        @Override
-        public void onThreadPoolAdd(CamelContext camelContext, 
ThreadPoolExecutor threadPool, String id, String sourceId, String routeId, 
String threadPoolProfileId) {
-        }
-
-        @Override
-        public void onThreadPoolRemove(CamelContext camelContext, 
ThreadPoolExecutor threadPool) {
-        }
     }
 }

Modified: 
camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
 (original)
+++ 
camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
 Tue Mar 27 08:25:54 2012
@@ -16,33 +16,25 @@
  */
 package org.apache.camel.core.osgi;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Queue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
-import org.apache.camel.Endpoint;
-import org.apache.camel.ErrorHandlerFactory;
-import org.apache.camel.Processor;
-import org.apache.camel.Route;
-import org.apache.camel.Service;
-import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.Registry;
-import org.apache.camel.spi.RouteContext;
+import org.apache.camel.support.LifecycleStrategySupport;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 /**
  * The OsgiServiceRegistry support to get the service object from the bundle 
context
  */
-public class OsgiServiceRegistry implements Registry, LifecycleStrategy {
+public class OsgiServiceRegistry extends LifecycleStrategySupport implements 
Registry {
     private final BundleContext bundleContext;
     private final Map<String, Object> serviceCacheMap = new 
ConcurrentHashMap<String, Object>();
-    private final ConcurrentLinkedQueue<ServiceReference> 
serviceReferenceQueue = new ConcurrentLinkedQueue<ServiceReference>();
+    private final Queue<ServiceReference> serviceReferenceQueue = new 
ConcurrentLinkedQueue<ServiceReference>();
     
     public OsgiServiceRegistry(BundleContext bc) {
         bundleContext = bc;
@@ -75,18 +67,7 @@ public class OsgiServiceRegistry impleme
         return Collections.<String, T>emptyMap();
     }
 
-    public void onComponentAdd(String name, Component component) {
-        // noop
-    }
-
-    public void onComponentRemove(String name, Component component) {
-        // noop
-    }
-
-    public void onContextStart(CamelContext context) {
-        // noop
-    }
-
+    @Override
     public void onContextStop(CamelContext context) {
         // Unget the OSGi service
         ServiceReference sr = serviceReferenceQueue.poll();
@@ -95,51 +76,8 @@ public class OsgiServiceRegistry impleme
             sr = serviceReferenceQueue.poll();
         }
         // Clean up the OSGi Service Cache
+        serviceReferenceQueue.clear();
         serviceCacheMap.clear();
     }
 
-    public void onEndpointAdd(Endpoint endpoint) {
-        // noop
-    }
-
-    public void onEndpointRemove(Endpoint endpoint) {
-        // noop
-    }
-
-    public void onRouteContextCreate(RouteContext routeContext) {
-        // noop
-    }
-
-    public void onRoutesAdd(Collection<Route> routes) {
-        // noop
-    }
-
-    public void onRoutesRemove(Collection<Route> routes) {
-        // noop
-    }
-
-    public void onServiceAdd(CamelContext context, Service service, Route 
route) {
-        // noop
-    }
-
-    public void onServiceRemove(CamelContext context, Service service, Route 
route) {
-        // noop
-    }
-
-    public void onErrorHandlerAdd(RouteContext routeContext, Processor 
processor, ErrorHandlerFactory errorHandlerBuilder) {
-        // noop
-    }
-
-    public void onErrorHandlerRemove(RouteContext routeContext, Processor 
processor, ErrorHandlerFactory errorHandlerBuilder) {
-        // noop
-    }
-
-    public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor 
threadPoolExecutor,
-                                String id, String sourceId, String routeId, 
String threadPoolProfileId) {
-        // noop
-    }
-
-    public void onThreadPoolRemove(CamelContext camelContext, 
ThreadPoolExecutor threadPoolExecutor) {
-        // noop
-    }
 }

Modified: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java?rev=1305773&r1=1305772&r2=1305773&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DummyLifecycleStrategy.java
 Tue Mar 27 08:25:54 2012
@@ -16,69 +16,13 @@
  */
 package org.apache.camel.spring;
 
-import java.util.Collection;
-import java.util.concurrent.ThreadPoolExecutor;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
-import org.apache.camel.Endpoint;
-import org.apache.camel.ErrorHandlerFactory;
-import org.apache.camel.Processor;
-import org.apache.camel.Route;
-import org.apache.camel.Service;
-import org.apache.camel.spi.LifecycleStrategy;
-import org.apache.camel.spi.RouteContext;
+import org.apache.camel.support.LifecycleStrategySupport;
 
 /**
  * Dummy LifecycleStrategy for LifecycleStrategy injection test.
  *
  * @version 
  */
-public class DummyLifecycleStrategy implements LifecycleStrategy {
-
-    public void onContextStart(CamelContext camelContext) {
-    }
-
-    public void onContextStop(CamelContext camelContext) {
-    }
-
-    public void onComponentAdd(String s, Component component) {
-    }
-
-    public void onComponentRemove(String s, Component component) {
-    }
-
-    public void onEndpointAdd(Endpoint endpoint) {
-    }
-
-    public void onEndpointRemove(Endpoint endpoint) {
-    }
-
-    public void onServiceAdd(CamelContext camelContext, Service service, Route 
route) {
-    }
-
-    public void onServiceRemove(CamelContext camelContext, Service service, 
Route route) {
-    }
-
-    public void onRouteContextCreate(RouteContext routeContext) {
-    }
-
-    public void onErrorHandlerAdd(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-    }
-
-    public void onErrorHandlerRemove(RouteContext routeContext, Processor 
errorHandler, ErrorHandlerFactory errorHandlerBuilder) {
-    }
-
-    public void onRoutesRemove(Collection<Route> routes) {
-    }
-
-    public void onRoutesAdd(Collection<Route> routes) {
-    }
-
-    public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor 
threadPool, String id,
-                                String sourceId, String routeId, String 
threadPoolProfileId) {
-    }
+public class DummyLifecycleStrategy extends LifecycleStrategySupport {
 
-    public void onThreadPoolRemove(CamelContext camelContext, 
ThreadPoolExecutor threadPool) {
-    }
 }


Reply via email to