Class ServiceHelper

java.lang.Object
org.apache.camel.support.service.ServiceHelper

public final class ServiceHelper extends Object
A collection of helper methods for working with Service objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Builds the given value if it's a Service or a collection of it.
    static void
    buildService(Object... services)
    Builds each element of the given services if services itself is not null, otherwise this method would return immediately.
    static Set<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 void
    Initializes the given value if it's a Service or a collection of it.
    static void
    initService(Object... services)
    Initializes each element of the given services if services itself is not null, otherwise this method would return immediately.
    static boolean
    Is the given service starting or already started?
    static boolean
    Is the given service stopping or already stopped?
    static boolean
    Is the given service suspending or already suspended?
    static boolean
    Resumes the given service.
    static void
    Resumes each element of the given services if services itself is not null, otherwise this method would return immediately.
    static void
    Starts the given value if it's a Service or a collection of it.
    static void
    startService(Object... services)
    Starts each element of the given services if services itself is not null, otherwise this method would return immediately.
    static void
    Stops and shutdowns the given service, rethrowing the first exception caught.
    static void
    Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.
    static void
    Stops and shutdowns each element of the given services if services itself is not null, otherwise this method would return immediately.
    static void
    Stops the given value, rethrowing the first exception caught.
    static void
    stopService(Object... services)
    Stops each element of the given services if services itself is not null, otherwise this method would return immediately.
    static void
    stopService(Collection<?> services)
    Stops each element of the given services if services itself is not null, otherwise this method would return immediately.
    static boolean
    Suspends the given service.
    static void
    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 Details

    • buildService

      public static void buildService(Object value)
      Builds the given value if it's a Service or a collection of it.

      Calling this method has no effect if value is null.

    • buildService

      public static void buildService(Object... services)
      Builds each element of the given services if services itself is not null, otherwise this method would return immediately.
      See Also:
    • initService

      public static void initService(Object value)
      Initializes the given value if it's a Service or a collection of it.

      Calling this method has no effect if value is null.

    • initService

      public static void initService(Object... services)
      Initializes each element of the given services if services itself is not null, otherwise this method would return immediately.
      See Also:
    • startService

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

      Calling this method has no effect if value is null.

    • startService

      public static void startService(Object... services)
      Starts each element of the given services if services itself is not null, otherwise this method would return immediately.
      See Also:
    • stopService

      public static void stopService(Object... services)
      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.

      See Also:
    • stopService

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

      Calling this method has no effect if value is null.

      See Also:
    • stopService

      public static void stopService(Collection<?> services)
      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.

      See Also:
    • stopAndShutdownServices

      public 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.

      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.

      See Also:
    • stopAndShutdownService

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

      Calling this method has no effect if value is null.

      See Also:
    • stopAndShutdownServices

      public 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.

      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.

      See Also:
    • resumeServices

      public static void resumeServices(Collection<?> services)
      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.

      See Also:
    • resumeService

      public static boolean resumeService(Object service)
      Resumes the given service.

      If service is both Suspendable and SuspendableService then its SuspendableService.resume() is called but only if service is already suspended.

      If service is not a Suspendable and SuspendableService then its 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(Object) was called, false otherwise.
      Throws:
      Exception - is thrown if error occurred
      See Also:
    • suspendServices

      public static void suspendServices(Collection<?> services)
      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.

      See Also:
    • suspendService

      public static boolean suspendService(Object service)
      Suspends the given service.

      If service is both Suspendable and SuspendableService then its SuspendableService.suspend() is called but only if service is not already suspended.

      If service is not a Suspendable and SuspendableService then its 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:
    • 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:
    • 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:
    • 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:
    • 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 children 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