camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/5] camel git commit: CAMEL-9577: Only support suspension if a component has custom logic
Date Mon, 08 Feb 2016 16:45:31 GMT
CAMEL-9577: Only support suspension if a component has custom logic


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

Branch: refs/heads/master
Commit: 5973f1416b2233e5f34e357ec15e4d502cafd5b2
Parents: 8e479df
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Feb 8 15:10:58 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Feb 8 17:45:20 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/camel/Suspendable.java | 31 ++++++++++++++++++++
 .../org/apache/camel/SuspendableService.java    |  5 +++-
 .../camel/component/direct/DirectConsumer.java  |  3 +-
 .../component/directvm/DirectVmConsumer.java    |  3 +-
 .../camel/component/seda/SedaConsumer.java      |  4 +--
 .../apache/camel/impl/DefaultCamelContext.java  | 11 +++++--
 .../camel/impl/DefaultShutdownStrategy.java     |  3 +-
 .../camel/impl/EventDrivenConsumerRoute.java    |  3 +-
 .../camel/impl/ScheduledPollConsumer.java       |  3 +-
 .../camel/management/mbean/ManagedService.java  |  5 ++--
 .../org/apache/camel/util/ServiceHelper.java    |  7 +++--
 11 files changed, 62 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/Suspendable.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Suspendable.java b/camel-core/src/main/java/org/apache/camel/Suspendable.java
new file mode 100644
index 0000000..c1030cd
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/Suspendable.java
@@ -0,0 +1,31 @@
+/**
+ * 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;
+
+/**
+ * Marker interface to indicate a custom component has custom implementation for suspending
the {@link SuspendableService} service.
+ * <br/>
+ * This is needed to let Camel know if there is special code happening during a suspension.
+ * <p/>
+ * The {@link org.apache.camel.support.ServiceSupport} implementation that most Camel components
/ endpoints etc use
+ * as base class is a {@link SuspendableService} but the actual implementation may not have
special logic for suspend.
+ * Therefore this marker interface is introduced to indicate when the implementation has
special code for suspension.
+ *
+ * @see SuspendableService
+ */
+public interface Suspendable {
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/SuspendableService.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/SuspendableService.java b/camel-core/src/main/java/org/apache/camel/SuspendableService.java
index 990910c..79e2cbd 100644
--- a/camel-core/src/main/java/org/apache/camel/SuspendableService.java
+++ b/camel-core/src/main/java/org/apache/camel/SuspendableService.java
@@ -24,8 +24,11 @@ package org.apache.camel;
  * <p/>
  * For example this is use by the JmsConsumer which suspends the Spring JMS listener instead
of stopping
  * the consumer totally.
+ * <p/>
+ * <b>Important:</b> The service should also implement the {@link Suspendable}
marker interface to indicate
+ * the service supports suspension using custom code logic.
  *
- * @version 
+ * @see Suspendable
  */
 public interface SuspendableService extends Service {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
b/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
index a5be34f..9b5c8d1 100644
--- a/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.direct;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
 import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.spi.ShutdownAware;
@@ -28,7 +29,7 @@ import org.apache.camel.spi.ShutdownAware;
  *
  * @version 
  */
-public class DirectConsumer extends DefaultConsumer implements ShutdownAware, SuspendableService
{
+public class DirectConsumer extends DefaultConsumer implements ShutdownAware, Suspendable
{
 
     private DirectEndpoint endpoint;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmConsumer.java
b/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmConsumer.java
index 037b7e2..4b18fe3 100644
--- a/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmConsumer.java
@@ -17,13 +17,14 @@
 package org.apache.camel.component.directvm;
 
 import org.apache.camel.Processor;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.impl.DefaultConsumer;
 
 /**
  * The direct-vm consumer
  */
-public class DirectVmConsumer extends DefaultConsumer implements SuspendableService {
+public class DirectVmConsumer extends DefaultConsumer implements Suspendable {
 
     public DirectVmConsumer(DirectVmEndpoint endpoint, Processor processor) {
         super(endpoint, processor);

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
index c0970fb..ca0ddcb 100644
--- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
@@ -30,7 +30,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.ShutdownRunningTask;
-import org.apache.camel.SuspendableService;
+import org.apache.camel.Suspendable;
 import org.apache.camel.processor.MulticastProcessor;
 import org.apache.camel.spi.ExceptionHandler;
 import org.apache.camel.spi.ShutdownAware;
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
  *
  * @version 
  */
-public class SedaConsumer extends ServiceSupport implements Consumer, Runnable, ShutdownAware,
SuspendableService {
+public class SedaConsumer extends ServiceSupport implements Consumer, Runnable, ShutdownAware,
Suspendable {
     private static final Logger LOG = LoggerFactory.getLogger(SedaConsumer.class);
 
     private final AtomicInteger taskCount = new AtomicInteger();

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index bba3ed1..d0c2c37 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -72,6 +72,7 @@ import org.apache.camel.ShutdownRoute;
 import org.apache.camel.ShutdownRunningTask;
 import org.apache.camel.StartupListener;
 import org.apache.camel.StatefulService;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.VetoCamelContextStartException;
@@ -171,7 +172,7 @@ import org.slf4j.LoggerFactory;
  * @version
  */
 @SuppressWarnings("deprecation")
-public class DefaultCamelContext extends ServiceSupport implements ModelCamelContext, SuspendableService
{
+public class DefaultCamelContext extends ServiceSupport implements ModelCamelContext, Suspendable
{
     private final Logger log = LoggerFactory.getLogger(getClass());
     private JAXBContext jaxbContext;
     private CamelContextNameStrategy nameStrategy = new DefaultCamelContextNameStrategy();
@@ -1169,7 +1170,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             // must suspend route service as well
             suspendRouteService(routeService);
             // must suspend the route as well
-            ServiceHelper.suspendService(route);
+            if (route instanceof SuspendableService) {
+                ((SuspendableService) route).suspend();
+            }
         }
     }
 
@@ -1190,7 +1193,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             // must suspend route service as well
             suspendRouteService(routeService);
             // must suspend the route as well
-            ServiceHelper.suspendService(route);
+            if (route instanceof SuspendableService) {
+                ((SuspendableService) route).suspend();
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
index 2eac21e..074837b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
@@ -40,6 +40,7 @@ import org.apache.camel.Route;
 import org.apache.camel.Service;
 import org.apache.camel.ShutdownRoute;
 import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.RouteStartupOrder;
@@ -557,7 +558,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements
ShutdownS
                         if (consumer instanceof ShutdownAware) {
                             shutdown = !((ShutdownAware) consumer).deferShutdown(shutdownRunningTask);
                         }
-                        if (shutdown && consumer instanceof SuspendableService) {
+                        if (shutdown && consumer instanceof Suspendable) {
                             // we prefer to suspend over shutdown
                             suspend = true;
                         }

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
b/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
index 8a6da5d..0e77b17 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
@@ -25,6 +25,7 @@ import org.apache.camel.Navigate;
 import org.apache.camel.Processor;
 import org.apache.camel.RouteAware;
 import org.apache.camel.Service;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.spi.IdAware;
 import org.apache.camel.spi.RouteContext;
@@ -129,6 +130,6 @@ public class EventDrivenConsumerRoute extends DefaultRoute {
     }
 
     public boolean supportsSuspension() {
-        return consumer instanceof SuspendableService;
+        return consumer instanceof Suspendable && consumer instanceof SuspendableService;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java b/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
index 5f25a4f..c0fadaa 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
@@ -27,6 +27,7 @@ import org.apache.camel.FailedToCreateConsumerException;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.PollingConsumerPollingStrategy;
 import org.apache.camel.Processor;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.apache.camel.spi.ScheduledPollConsumerScheduler;
@@ -39,7 +40,7 @@ import org.slf4j.LoggerFactory;
 /**
  * A useful base class for any consumer which is polling based
  */
-public abstract class ScheduledPollConsumer extends DefaultConsumer implements Runnable,
SuspendableService, PollingConsumerPollingStrategy {
+public abstract class ScheduledPollConsumer extends DefaultConsumer implements Runnable,
Suspendable, PollingConsumerPollingStrategy {
     private static final Logger LOG = LoggerFactory.getLogger(ScheduledPollConsumer.class);
 
     private ScheduledPollConsumerScheduler scheduler;

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedService.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedService.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedService.java
index b5dffe0..9fe5df0 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedService.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedService.java
@@ -22,6 +22,7 @@ import org.apache.camel.Service;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.StatefulService;
 import org.apache.camel.StaticService;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.api.management.ManagedInstance;
 import org.apache.camel.api.management.ManagedResource;
@@ -111,7 +112,7 @@ public class ManagedService implements ManagedInstance, ManagedServiceMBean
{
     }
 
     public boolean isSupportSuspension() {
-        return service instanceof SuspendableService;
+        return service instanceof Suspendable && service instanceof SuspendableService;
     }
 
     public boolean isSuspended() {
@@ -127,7 +128,7 @@ public class ManagedService implements ManagedInstance, ManagedServiceMBean
{
         if (!context.getStatus().isStarted()) {
             throw new IllegalArgumentException("CamelContext is not started");
         }
-        if (service instanceof SuspendableService) {
+        if (service instanceof Suspendable && service instanceof SuspendableService)
{
             SuspendableService ss = (SuspendableService) service;
             ss.suspend();
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/5973f141/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java b/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
index 90b5ce9..e0b4d77 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
@@ -28,6 +28,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Service;
 import org.apache.camel.ShutdownableService;
 import org.apache.camel.StatefulService;
+import org.apache.camel.Suspendable;
 import org.apache.camel.SuspendableService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -361,13 +362,13 @@ public final class ServiceHelper {
     /**
      * Suspends the given {@code service}.
      * <p/>
-     * If {@code service} is a {@link org.apache.camel.SuspendableService} then
+     * If {@code service} is both {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService}
then
      * it's {@link org.apache.camel.SuspendableService#suspend()} is called but
      * <b>only</b> if {@code service} is <b>not</b> already
      * {@link #isSuspended(Object) suspended}.
      * <p/>
      * If {@code service} is <b>not</b> a
-     * {@link org.apache.camel.SuspendableService} then it's
+     * {@link org.apache.camel.Suspendable} and {@link org.apache.camel.SuspendableService}
then it's
      * {@link org.apache.camel.Service#stop()} is called.
      * <p/>
      * Calling this method has no effect if {@code service} is {@code null}.
@@ -380,7 +381,7 @@ public final class ServiceHelper {
      * @see #stopService(Object)
      */
     public static boolean suspendService(Object service) throws Exception {
-        if (service instanceof SuspendableService) {
+        if (service instanceof Suspendable && service instanceof SuspendableService)
{
             SuspendableService ss = (SuspendableService) service;
             if (!ss.isSuspended()) {
                 LOG.trace("Suspending service {}", service);


Mime
View raw message