You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2009/02/26 10:57:50 UTC

svn commit: r748071 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: CamelContext.java ServiceStatus.java impl/DefaultCamelContext.java impl/ServiceSupport.java

Author: jstrachan
Date: Thu Feb 26 09:57:50 2009
New Revision: 748071

URL: http://svn.apache.org/viewvc?rev=748071&view=rev
Log:
CAMEL-1004 - added a ServiceStatus property to most Service implementations - and exposed the status of a route

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=748071&r1=748070&r2=748071&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Feb 26 09:57:50 2009
@@ -333,4 +333,9 @@
      * @return the factory finder
      */
     FactoryFinder createFactoryFinder(String path);
+
+    /**
+     * Returns the current status of the given route
+     */
+    ServiceStatus getRouteStatus(RouteType route);
 }

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java?rev=748071&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java Thu Feb 26 09:57:50 2009
@@ -0,0 +1,27 @@
+/**
+ *
+ * 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;
+
+/**
+ * Reresents the status of a {@link Service} instance
+ *
+ * @version $Revision: 1.1 $
+ */
+public enum ServiceStatus {
+    Created, Starting, Started, Stopping, Stopped;
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/ServiceStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=748071&r1=748070&r2=748071&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu Feb 26 09:57:50 2009
@@ -39,6 +39,7 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.Service;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.management.InstrumentationLifecycleStrategy;
@@ -435,6 +436,21 @@
 
     }
 
+    public ServiceStatus getRouteStatus(RouteType route) {
+        return getRouteStatus(route.idOrCreate());
+    }
+
+    /**
+     * Returns the status of the service of the given ID or null if there is no service created yet
+     */
+    public ServiceStatus getRouteStatus(String key) {
+        RouteService routeService = routeServices.remove(key);
+        if (routeService != null) {
+            return routeService.getStatus();
+        }
+        return null;
+    }
+
     public void startRoute(RouteType route) throws Exception {
         Collection<Route> routes = new ArrayList<Route>();
         List<RouteContext> routeContexts = route.addRoutes(this, routes);
@@ -444,10 +460,22 @@
 
 
     public void stopRoute(RouteType route) throws Exception {
-        stopRouteService(route.idOrCreate());
+        stopRoute(route.idOrCreate());
     }
 
     /**
+     * Stops the route denoted by the given RouteType id
+     */
+    public synchronized void stopRoute(String key) throws Exception {
+        RouteService routeService = routeServices.remove(key);
+        if (routeService != null) {
+            routeService.stop();
+        }
+    }
+
+
+
+    /**
      * Adds a service, starting it so that it will be stopped with this context
      */
     public void addService(Object object) throws Exception {
@@ -726,22 +754,13 @@
      */
     protected synchronized void startRouteService(RouteService routeService) throws Exception {
         String key = routeService.getId();
-        stopRouteService(key);
+        stopRoute(key);
         routeServices.put(key, routeService);
         if (shouldStartRoutes()) {
             routeService.start();
         }
     }
 
-    /**
-     * Stops the route denoted by the given RouteType id
-     */
-    protected synchronized void stopRouteService(String key) throws Exception {
-        RouteService routeService = routeServices.remove(key);
-        if (routeService != null) {
-            routeService.stop();
-        }
-    }
 
 
     protected synchronized  void doStop() throws Exception {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java?rev=748071&r1=748070&r2=748071&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java Thu Feb 26 09:57:50 2009
@@ -21,6 +21,7 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.camel.Service;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 
@@ -69,6 +70,26 @@
     }
 
     /**
+     * Returns the current status
+     */
+    public ServiceStatus getStatus() {
+        // lets check these in oldest first as these flags can be changing in a concurrent world
+        if (isStarting()) {
+            return ServiceStatus.Starting;
+        }
+        if (isStarted()) {
+            return ServiceStatus.Started;
+        }
+        if (isStopping()) {
+            return ServiceStatus.Stopping;
+        }
+        if (isStopped()) {
+            return ServiceStatus.Stopped;
+        }
+        return ServiceStatus.Created;
+    }
+    
+    /**
      * @return true if this service has been started
      */
     public boolean isStarted() {