org.apache.camel.util
Class ServiceHelper

java.lang.Object
  extended by org.apache.camel.util.ServiceHelper

public final class ServiceHelper
extends Object

A collection of helper methods for working with Service objects.

Version:

Method Summary
static Set<Service> getChildServices(Service service)
          Gathers all child services by navigating the service to recursively gather all child services.
static Set<Service> getChildServices(Service service, boolean includeErrorHandler)
          Gathers all child services by navigating the service to recursively gather all child services.
static boolean isStarted(Object value)
          Is the given service starting or already started?
static boolean isStopped(Object value)
          Is the given service stopping or already stopped?
static boolean isSuspended(Object value)
          Is the given service suspending or already suspended?
static boolean resumeService(Service service)
          Resumes the given service.
static void resumeServices(Collection<?> services)
          Resumes each element of the given services if services itself is not null, otherwise this method would return immediately.
static void startService(Object value)
          Starts the given value if it's a Service or a collection of it.
static void startService(Service service)
          Starts the given service.
static void startServices(Collection<?> services)
          Starts each element of the given services if services itself is not null, otherwise this method would return immediately.
static void startServices(Object... services)
          Starts each element of the given services if services itself is not null, otherwise this method would return immediately.
static void stopAndShutdownService(Object value)
          Stops and shutdowns the given service, rethrowing the first exception caught.
static void stopAndShutdownServices(Collection<?> services)
          Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.
static void stopAndShutdownServices(Object... services)
          Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.
static void stopService(Object value)
          Stops the given value, rethrowing the first exception caught.
static void stopServices(Collection<?> services)
          Stops each element of the given services if services itself is not null, otherwise this method would return immediately.
static void stopServices(Object... services)
          Stops each element of the given services if services itself is not null, otherwise this method would return immediately.
static boolean suspendService(Service service)
          Suspends the given service.
static void suspendServices(Collection<?> services)
          Suspends each element of the given services if services itself is not null, otherwise this method would return immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startService

public static void startService(Object value)
                         throws Exception
Starts the given value if it's a Service or a collection of it.

Calling this method has no effect if value is null.

Throws:
Exception
See Also:
startService(Service), startServices(Collection)

startService

public static void startService(Service service)
                         throws Exception
Starts the given service.

Calling this method has no effect if service is null.

Throws:
Exception
See Also:
Service.start()

startServices

public static void startServices(Object... services)
                          throws Exception
Starts each element of the given services if services itself is not null, otherwise this method would return immediately.

Throws:
Exception
See Also:
startServices(Collection)

startServices

public static void startServices(Collection<?> services)
                          throws Exception
Starts each element of the given services if services itself is not null, otherwise this method would return immediately.

Throws:
Exception
See Also:
startService(Object)

stopServices

public static void stopServices(Object... services)
                         throws Exception
Stops each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while stopping the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
stopServices(Collection)

stopService

public static void stopService(Object value)
                        throws Exception
Stops the given value, rethrowing the first exception caught.

Calling this method has no effect if value is null.

Throws:
Exception
See Also:
Service.stop(), stopServices(Collection)

stopServices

public static void stopServices(Collection<?> services)
                         throws Exception
Stops each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while stopping the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
stopService(Object)

stopAndShutdownServices

public static void stopAndShutdownServices(Object... services)
                                    throws Exception
Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while stopping/shutting down the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
stopAndShutdownServices(Collection)

stopAndShutdownService

public static void stopAndShutdownService(Object value)
                                   throws Exception
Stops and shutdowns the given service, rethrowing the first exception caught.

Calling this method has no effect if value is null.

Throws:
Exception
See Also:
stopService(Object), ShutdownableService.shutdown()

stopAndShutdownServices

public static void stopAndShutdownServices(Collection<?> services)
                                    throws Exception
Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while stopping/shutting down the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
stopService(Object), ShutdownableService.shutdown()

resumeServices

public static void resumeServices(Collection<?> services)
                           throws Exception
Resumes each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while resuming the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
resumeService(Service)

resumeService

public static boolean resumeService(Service service)
                             throws Exception
Resumes the given service.

If service is a SuspendableService then it's SuspendableService.resume() is called but only if service is already suspended.

If service is not a SuspendableService then it's Service.start() is called.

Calling this method has no effect if service is null.

Parameters:
service - the service
Returns:
true if either resume method or startService(Service) was called, false otherwise.
Throws:
Exception - is thrown if error occurred
See Also:
startService(Service)

suspendServices

public static void suspendServices(Collection<?> services)
                            throws Exception
Suspends each element of the given services if services itself is not null, otherwise this method would return immediately.

If there's any exception being thrown while suspending the elements one after the other this method would rethrow the first such exception being thrown.

Throws:
Exception
See Also:
suspendService(Service)

suspendService

public static boolean suspendService(Service service)
                              throws Exception
Suspends the given service.

If service is a SuspendableService then it's SuspendableService.suspend() is called but only if service is not already suspended.

If service is not a SuspendableService then it's Service.stop() is called.

Calling this method has no effect if service is null.

Parameters:
service - the service
Returns:
true if either the suspend method or stopService(Object) was called, false otherwise.
Throws:
Exception - is thrown if error occurred
See Also:
stopService(Object)

isStopped

public static boolean isStopped(Object value)
Is the given service stopping or already stopped?

Returns:
true if stopping or already stopped, false otherwise
See Also:
StatefulService.isStopping(), StatefulService.isStopped()

isStarted

public static boolean isStarted(Object value)
Is the given service starting or already started?

Returns:
true if starting or already started, false otherwise
See Also:
StatefulService.isStarting(), StatefulService.isStarted()

isSuspended

public static boolean isSuspended(Object value)
Is the given service suspending or already suspended?

Returns:
true if suspending or already suspended, false otherwise
See Also:
StatefulService.isSuspending(), SuspendableService.isSuspended()

getChildServices

public static Set<Service> getChildServices(Service service)
Gathers all child services by navigating the service to recursively gather all child services.

The returned set does not include the childern being error handler.

Parameters:
service - the service
Returns:
the services, including the parent service, and all its children

getChildServices

public static Set<Service> getChildServices(Service service,
                                            boolean includeErrorHandler)
Gathers all child services by navigating the service to recursively gather all child services.

Parameters:
service - the service
includeErrorHandler - whether to include error handlers
Returns:
the services, including the parent service, and all its children


Apache Camel