org.apache.camel.support
Class ServiceSupport

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
All Implemented Interfaces:
Service, ShutdownableService, StatefulService, SuspendableService
Direct Known Subclasses:
AggregateProcessor, BaseTypeConverterRegistry, BatchProcessor, BeanProcessor, CamelLogger, ChildServiceSupport, ChoiceProcessor, ConsumerCache, ConvertBodyProcessor, DefaultCamelContext, DefaultChannel, DefaultComponent, DefaultConsumer, DefaultConsumerTemplate, DefaultEndpoint, DefaultExecutorServiceManager, DefaultExecutorServiceStrategy, DefaultInflightRepository, DefaultManagementAgent, DefaultManagementLifecycleStrategy, DefaultPackageScanClassResolver, DefaultProducer, DefaultProducerTemplate, DefaultRoute, DefaultServicePool, DefaultShutdownStrategy, DefaultTimeoutMap, DelegateAsyncProcessor, DelegateProcessor, Enricher, EventNotifierSupport, ExchangePatternProcessor, FileIdempotentRepository, IdempotentConsumer, InterceptorToAsyncProcessorBridge, LoadBalancerSupport, LogProcessor, MainSupport, MarshalProcessor, MemoryAggregationRepository, MemoryIdempotentRepository, MulticastProcessor, OnCompletionProcessor, PollEnricher, PollingConsumerSupport, PredicateValidatingProcessor, ProducerCache, RecipientList, RollbackProcessor, RoutePolicySupport, RoutingSlip, SedaConsumer, SendProcessor, ServiceSupport, SetBodyProcessor, SortProcessor, StopProcessor, StreamResequencer, ThreadsProcessor, ThroughputLogger, ThrowExceptionProcessor, TimerListenerManager, TransformProcessor, TryProcessor, UnmarshalProcessor, WireTapProcessor, XPathBuilder

public abstract class ServiceSupport
extends Object
implements StatefulService

A useful base class which ensures that a service is only initialized once and provides some helper methods for enquiring of its status.

Implementations can extend this base class and implement SuspendableService in case they support suspend/resume.

Version:

Field Summary
protected  AtomicBoolean shutdown
           
protected  AtomicBoolean shuttingdown
           
protected  AtomicBoolean started
           
protected  AtomicBoolean starting
           
protected  AtomicBoolean stopped
           
protected  AtomicBoolean stopping
           
protected  AtomicBoolean suspended
           
protected  AtomicBoolean suspending
           
 
Constructor Summary
ServiceSupport()
           
 
Method Summary
protected  void doResume()
          Implementations override this method to support customized suspend/resume.
protected  void doShutdown()
          Implementations override this method to perform customized shutdown.
protected abstract  void doStart()
          Implementations override this method to support customized start/stop.
protected abstract  void doStop()
          Implementations override this method to support customized start/stop.
protected  void doSuspend()
          Implementations override this method to support customized suspend/resume.
 ServiceStatus getStatus()
          Returns the current status
 String getVersion()
          Returns the version of this service
 boolean isRunAllowed()
          Helper methods so the service knows if it should keep running.
 boolean isStarted()
          Whether the service is started
 boolean isStarting()
          Whether the service is starting
 boolean isStopped()
          Whether the service is stopped
 boolean isStopping()
          Whether the service is stopping
 boolean isSuspended()
          Tests whether the service is suspended or not.
 boolean isSuspending()
          Whether the service is suspending
 void resume()
          Resumes the service.
 void shutdown()
          Shutdown the service, which means it cannot be started again.
 void start()
          Starts the service
 void stop()
          Stops the service
 void suspend()
          Suspends the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

started

protected final AtomicBoolean started

starting

protected final AtomicBoolean starting

stopping

protected final AtomicBoolean stopping

stopped

protected final AtomicBoolean stopped

suspending

protected final AtomicBoolean suspending

suspended

protected final AtomicBoolean suspended

shuttingdown

protected final AtomicBoolean shuttingdown

shutdown

protected final AtomicBoolean shutdown
Constructor Detail

ServiceSupport

public ServiceSupport()
Method Detail

start

public void start()
           throws Exception
Description copied from interface: Service
Starts the service

Specified by:
start in interface Service
Throws:
Exception - is thrown if starting failed

stop

public void stop()
          throws Exception
Description copied from interface: Service
Stops the service

Specified by:
stop in interface Service
Throws:
Exception - is thrown if stopping failed

suspend

public void suspend()
             throws Exception
Description copied from interface: SuspendableService
Suspends the service.

Specified by:
suspend in interface SuspendableService
Throws:
Exception - is thrown if suspending failed

resume

public void resume()
            throws Exception
Description copied from interface: SuspendableService
Resumes the service.

Specified by:
resume in interface SuspendableService
Throws:
Exception - is thrown if resuming failed

shutdown

public void shutdown()
              throws Exception
Description copied from interface: ShutdownableService
Shutdown the service, which means it cannot be started again.

Specified by:
shutdown in interface ShutdownableService
Throws:
Exception - thrown if shutting down failed

getStatus

public ServiceStatus getStatus()
Description copied from interface: StatefulService
Returns the current status

Specified by:
getStatus in interface StatefulService
Returns:
the current status

isStarted

public boolean isStarted()
Description copied from interface: StatefulService
Whether the service is started

Specified by:
isStarted in interface StatefulService
Returns:
true if this service has been started

isStarting

public boolean isStarting()
Description copied from interface: StatefulService
Whether the service is starting

Specified by:
isStarting in interface StatefulService
Returns:
true if this service is being started

isStopping

public boolean isStopping()
Description copied from interface: StatefulService
Whether the service is stopping

Specified by:
isStopping in interface StatefulService
Returns:
true if this service is in the process of stopping

isStopped

public boolean isStopped()
Description copied from interface: StatefulService
Whether the service is stopped

Specified by:
isStopped in interface StatefulService
Returns:
true if this service is stopped

isSuspending

public boolean isSuspending()
Description copied from interface: StatefulService
Whether the service is suspending

Specified by:
isSuspending in interface StatefulService
Returns:
true if this service is in the process of suspending

isSuspended

public boolean isSuspended()
Description copied from interface: SuspendableService
Tests whether the service is suspended or not.

Specified by:
isSuspended in interface SuspendableService
Returns:
true if suspended

isRunAllowed

public boolean isRunAllowed()
Description copied from interface: StatefulService
Helper methods so the service knows if it should keep running. Returns false if the service is being stopped or is stopped.

Specified by:
isRunAllowed in interface StatefulService
Returns:
true if the service should continue to run.

doStart

protected abstract void doStart()
                         throws Exception
Implementations override this method to support customized start/stop.

Important: See doStop() for more details.

Throws:
Exception
See Also:
doStop()

doStop

protected abstract void doStop()
                        throws Exception
Implementations override this method to support customized start/stop.

Important: Camel will invoke this doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Throws:
Exception
See Also:
doStart()

doSuspend

protected void doSuspend()
                  throws Exception
Implementations override this method to support customized suspend/resume.

Throws:
Exception

doResume

protected void doResume()
                 throws Exception
Implementations override this method to support customized suspend/resume.

Throws:
Exception

doShutdown

protected void doShutdown()
                   throws Exception
Implementations override this method to perform customized shutdown.

Throws:
Exception

getVersion

public String getVersion()
Description copied from interface: StatefulService
Returns the version of this service

Specified by:
getVersion in interface StatefulService
Returns:
the version


Apache CAMEL