Class ControlFlowUtility



  • public final class ControlFlowUtility
    extends java.lang.Object
    Utility class addressing control flow related issues.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.concurrent.ExecutorService createCachedExecutorService​(boolean isDaemon)
      Returns a default ExecutorService retrieved from the Executors.
      static java.util.concurrent.ScheduledExecutorService createScheduledExecutorService​(int aCorePoolSize, boolean isDaemon)
      Returns a default ExecutorService retrieved from the Executors.
      static void joinFutures​(java.util.Collection<? extends java.util.concurrent.Future<?>> aFutures)
      Joins the Future instances contained in the given Collection.
      static void joinFutures​(java.util.concurrent.Future<?>... aFutures)
      Joins the Future instances contained in the given Collection.
      static void joinThreads​(java.lang.Thread... aThreads)
      Joins the Thread instances contained in the given Collection.
      static void joinThreads​(java.util.Collection<? extends java.lang.Thread> aThreads)
      Joins the Thread instances contained in the given Collection.
      static void shutdownGracefully​(java.util.concurrent.ExecutorService aExecutorService)
      Tries to orderly shutdown (ExecutorService.shutdown()) all tasks of an ExecutorService, after a timeout of IoRetryCount.NORM milliseconds, shutdown is forced as of ExecutorService.shutdownNow(). ------------------------------------------------------------------------- CAUTION: Do only invoke this methods on ExecutorService instances you manage exclusively yourself, do not apply this method on ExecutorService instances provided to you by your application server (e.g. an JEE server)
      static void shutdownGracefully​(java.util.concurrent.ExecutorService aExecutorService, long aTimeOutInMs)
      Tries to orderly shutdown (ExecutorService.shutdown()) all tasks of an ExecutorService, after a given timeout in milliseconds, shutdown is forced as of ExecutorService.shutdownNow().
      static void throwIllegalStateException​(boolean isIllegalState)
      Code redundancy preventing code snippet (in terms of aspect) throwing an IllegalStateException in case an illegal state false is being provided.
      static java.util.concurrent.ExecutorService toManagedExecutorService​(java.util.concurrent.ExecutorService aExecutorService)
      Converts an ExecutorService to be a ManagedExecutorService with methods ExecutorService.shutdown() and ExecutorService.shutdownNow() being disabled as them are to be managed by an application server.
      static java.lang.Object waitForFutures​(java.util.Collection<? extends java.util.concurrent.Future<?>> aFutures)
      Joins the Future instances contained in the given Collection.
      static java.lang.Object waitForFutures​(java.util.concurrent.Future<?>... aFutures)
      Joins the Future instances contained in the given Collection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • throwIllegalStateException

        public static void throwIllegalStateException​(boolean isIllegalState)
                                               throws java.lang.IllegalStateException
        Code redundancy preventing code snippet (in terms of aspect) throwing an IllegalStateException in case an illegal state false is being provided. This method can be called in the beginning of methods of instances which can be disposed (Disposable) or destroyed (as of org.refcodes.component.Destroyable or decomposed (as of org.refcodes.component.Decomposeable). In such cases the "disposed", "destroyed", "decomposed" or similar flag is being passed.
        Parameters:
        isIllegalState - When true, then an illegal state is being flagged which causes the according IllegalStateException with a default message being thrown.
        Throws:
        java.lang.IllegalStateException - Thrown in case an instance is in a state not allowing the invocation of the according method; for calling that method the instance is in an illegal state.
      • joinThreads

        public static void joinThreads​(java.util.Collection<? extends java.lang.Thread> aThreads)
        Joins the Thread instances contained in the given Collection.
        Parameters:
        aThreads - The Collection containing the Thread instances to be joined.
      • joinThreads

        public static void joinThreads​(java.lang.Thread... aThreads)
        Joins the Thread instances contained in the given Collection.
        Parameters:
        aThreads - The Collection containing the Thread instances to be joined.
      • joinFutures

        public static void joinFutures​(java.util.Collection<? extends java.util.concurrent.Future<?>> aFutures)
        Joins the Future instances contained in the given Collection.
        Parameters:
        aFutures - The Collection containing the Future instances to be joined.
      • joinFutures

        public static void joinFutures​(java.util.concurrent.Future<?>... aFutures)
        Joins the Future instances contained in the given Collection.
        Parameters:
        aFutures - The Collection containing the Future instances to be joined.
      • waitForFutures

        public static java.lang.Object waitForFutures​(java.util.Collection<? extends java.util.concurrent.Future<?>> aFutures)
                                               throws java.lang.Exception
        Joins the Future instances contained in the given Collection. Returns the first result detected or throws the first Exception which occurred.
        Parameters:
        aFutures - The Collection containing the Future instances to be joined.
        Returns:
        the object
        Throws:
        java.lang.Exception - the exception
      • waitForFutures

        public static java.lang.Object waitForFutures​(java.util.concurrent.Future<?>... aFutures)
                                               throws java.lang.Exception
        Joins the Future instances contained in the given Collection. Returns the first result detected or throws the first Exception which occurred.
        Parameters:
        aFutures - The Collection containing the Future instances to be joined.
        Returns:
        the object
        Throws:
        java.lang.Exception - the exception
      • shutdownGracefully

        public static void shutdownGracefully​(java.util.concurrent.ExecutorService aExecutorService)
        Tries to orderly shutdown (ExecutorService.shutdown()) all tasks of an ExecutorService, after a timeout of IoRetryCount.NORM milliseconds, shutdown is forced as of ExecutorService.shutdownNow(). ------------------------------------------------------------------------- CAUTION: Do only invoke this methods on ExecutorService instances you manage exclusively yourself, do not apply this method on ExecutorService instances provided to you by your application server (e.g. an JEE server). -------------------------------------------------------------------------
        Parameters:
        aExecutorService - The service which's threads are to be shut down soon.
      • shutdownGracefully

        public static void shutdownGracefully​(java.util.concurrent.ExecutorService aExecutorService,
                                              long aTimeOutInMs)
        Tries to orderly shutdown (ExecutorService.shutdown()) all tasks of an ExecutorService, after a given timeout in milliseconds, shutdown is forced as of ExecutorService.shutdownNow(). No shutdown is forced in case a timeout of o is being provided. ------------------------------------------------------------------------- CAUTION: Do only invoke this methods on ExecutorService instances you manage exclusively yourself, do not apply this method on ExecutorService instances provided to you by your application server (e.g. an JEE server). -------------------------------------------------------------------------
        Parameters:
        aExecutorService - The service which's threads are to be shut down after the given timeout.
        aTimeOutInMs - The timeout after which to force shutdown eventually, in case 0 is being provided, then no shutdown is being forced (all threads are executed till them terminate normally).
      • toManagedExecutorService

        public static java.util.concurrent.ExecutorService toManagedExecutorService​(java.util.concurrent.ExecutorService aExecutorService)
        Converts an ExecutorService to be a ManagedExecutorService with methods ExecutorService.shutdown() and ExecutorService.shutdownNow() being disabled as them are to be managed by an application server. Usually this method is being invoked with an ExecutorService originating from an application server. See ManagedExecutorService for more details.
        Parameters:
        aExecutorService - The ExecutorService to be transformed to a ManagedExecutorService.
        Returns:
        The ManagedExecutorService from the provided ExecutorService.
      • createCachedExecutorService

        public static java.util.concurrent.ExecutorService createCachedExecutorService​(boolean isDaemon)
        Returns a default ExecutorService retrieved from the Executors.
        Parameters:
        isDaemon - When true, then daemon threads are created by the ExecutorService returned.
        Returns:
        An ExecutorService to be used.
      • createScheduledExecutorService

        public static java.util.concurrent.ScheduledExecutorService createScheduledExecutorService​(int aCorePoolSize,
                                                                                                   boolean isDaemon)
        Returns a default ExecutorService retrieved from the Executors.
        Parameters:
        aCorePoolSize - The number of threads to keep in the pool, even if they are idle.
        isDaemon - When true, then daemon threads are created by the ExecutorService returned.
        Returns:
        An ScheduledExecutorService to be used.