Class ServiceHelper


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void buildService​(Object value)
      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> 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 void initService​(Object value)
      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 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​(Object 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​(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​(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 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 stopService​(Object value)
      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 suspendService​(Object 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.
    • Method Detail

      • 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:
        buildService(Object)
      • 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:
        initService(Object)
      • 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:
        startService(Object)
      • 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(Collection)
      • 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:
        Service.stop(), stopService(Collection)
      • 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:
        stopService(Object)
      • 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:
        stopAndShutdownServices(Collection)
      • 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:
        stopService(Object), ShutdownableService.shutdown()
      • 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:
        stopService(Object), ShutdownableService.shutdown()
      • 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(Object)
      • 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(Object)
      • 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