Class ClusteredExecutorService

    • Constructor Detail

      • ClusteredExecutorService

        public ClusteredExecutorService​(com.tangosol.net.CacheService cacheService)
        Constructs a ClusteredExecutorService based on the specified CacheService.
        Parameters:
        cacheService - the CacheService to use for orchestration metadata
      • ClusteredExecutorService

        public ClusteredExecutorService​(com.tangosol.net.ConfigurableCacheFactory cacheFactory)
        Constructs a ClusteredExecutorService based on the specified ConfigurableCacheFactory.
        Parameters:
        cacheFactory - the ConfigurableCacheFactory
      • ClusteredExecutorService

        public ClusteredExecutorService​(com.tangosol.net.Session session)
        Constructs a ClusteredExecutorService based on the specified Session.
        Parameters:
        session - the Session
    • Method Detail

      • getCacheService

        public com.tangosol.net.CacheService getCacheService()
        Obtains the CacheService being used by the TaskExecutorService.
        Returns:
        the CacheService
      • isShutdown

        public boolean isShutdown()
        Description copied from interface: RemoteExecutor
        Returns true if this executor has been shut down.
        Specified by:
        isShutdown in interface RemoteExecutor
        Returns:
        true if this executor has been shut down
      • isTerminated

        public boolean isTerminated()
        Description copied from interface: RemoteExecutor
        Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.
        Specified by:
        isTerminated in interface RemoteExecutor
        Returns:
        true if all tasks have completed following shut down
      • awaitTermination

        public boolean awaitTermination​(long lcTimeout,
                                        TimeUnit unit)
                                 throws InterruptedException
        Description copied from interface: RemoteExecutor
        Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
        Specified by:
        awaitTermination in interface RemoteExecutor
        Parameters:
        lcTimeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        true if this executor terminated and false if the timeout elapsed before termination
        Throws:
        InterruptedException - if interrupted while waiting
      • shutdown

        public void shutdown()
        Description copied from interface: RemoteExecutor
        Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

        This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

        Specified by:
        shutdown in interface RemoteExecutor
      • shutdownNow

        public List<Runnable> shutdownNow()
        Description copied from interface: RemoteExecutor
        Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

        This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

        There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.

        Specified by:
        shutdownNow in interface RemoteExecutor
        Returns:
        list of tasks that never commenced execution
      • execute

        public void execute​(com.tangosol.util.function.Remote.Runnable command)
        Description copied from interface: RemoteExecutor
        Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
        Specified by:
        execute in interface RemoteExecutor
        Parameters:
        command - the runnable task
      • schedule

        public <T> ScheduledFuture<T> schedule​(com.tangosol.util.function.Remote.Callable<T> callable,
                                               long lcDelay,
                                               TimeUnit unit)
        Description copied from interface: RemoteExecutor
        Submits a value-returning one-shot task that becomes enabled after the given delay.
        Specified by:
        schedule in interface RemoteExecutor
        Type Parameters:
        T - the type of the callable's result
        Parameters:
        callable - the function to execute
        lcDelay - the time from now to delay execution
        unit - the time unit of the delay parameter
        Returns:
        a ScheduledFuture that can be used to extract result or cancel
      • schedule

        public ScheduledFuture<?> schedule​(com.tangosol.util.function.Remote.Runnable command,
                                           long lcDelay,
                                           TimeUnit unit)
        Description copied from interface: RemoteExecutor
        Submits a one-shot task that becomes enabled after the given delay.
        Specified by:
        schedule in interface RemoteExecutor
        Parameters:
        command - the task to execute
        lcDelay - the time from now to delay execution
        unit - the time unit of the delay parameter
        Returns:
        a ScheduledFuture representing the pending completion of the task and whose get() method will return null upon completion
      • scheduleAtFixedRate

        public ScheduledFuture<?> scheduleAtFixedRate​(com.tangosol.util.function.Remote.Runnable command,
                                                      long lcInitialDelay,
                                                      long lcPeriod,
                                                      TimeUnit unit)
        Description copied from interface: RemoteExecutor
        Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.

        The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

        • The task is explicitly cancelled via the returned future.
        • The executor terminates, also resulting in task cancellation.
        • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
        Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.

        If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

        Specified by:
        scheduleAtFixedRate in interface RemoteExecutor
        Parameters:
        command - the task to execute
        lcInitialDelay - the time to delay first execution
        lcPeriod - the period between successive executions
        unit - the time unit of the initialDelay and period parameters
        Returns:
        a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.
      • scheduleWithFixedDelay

        public ScheduledFuture<?> scheduleWithFixedDelay​(com.tangosol.util.function.Remote.Runnable command,
                                                         long cInitialDelay,
                                                         long cDelay,
                                                         TimeUnit unit)
        Description copied from interface: RemoteExecutor
        Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

        The sequence of task executions continues indefinitely until one of the following exceptional completions occur:

        • The task is explicitly cancelled via the returned future.
        • The executor terminates, also resulting in task cancellation.
        • An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.
        Subsequent executions are suppressed. Subsequent calls to isDone() on the returned future will return true.
        Specified by:
        scheduleWithFixedDelay in interface RemoteExecutor
        Parameters:
        command - the task to execute
        cInitialDelay - the time to delay first execution
        cDelay - the delay between the termination of one execution and the commencement of the next
        unit - the time unit of the initialDelay and delay parameters
        Returns:
        a ScheduledFuture representing pending completion of the series of repeated tasks. The future's get() method will never return normally, and will throw an exception upon task cancellation or abnormal termination of a task execution.
      • invokeAny

        public <T> T invokeAny​(Collection<? extends com.tangosol.util.function.Remote.Callable<T>> colTasks)
                        throws InterruptedException,
                               ExecutionException
        Description copied from interface: RemoteExecutor
        Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.
        Specified by:
        invokeAny in interface RemoteExecutor
        Type Parameters:
        T - the type of the values returned from the tasks
        Parameters:
        colTasks - the collection of tasks
        Returns:
        the result returned by one of the tasks
        Throws:
        InterruptedException - if interrupted while waiting
        ExecutionException - if no task successfully completes
      • invokeAll

        public <T> List<Future<T>> invokeAll​(Collection<? extends com.tangosol.util.function.Remote.Callable<T>> tasks)
                                      throws InterruptedException
        Description copied from interface: RemoteExecutor
        Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future.isDone() is true for each element of the returned list. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
        Specified by:
        invokeAll in interface RemoteExecutor
        Type Parameters:
        T - the type of the values returned from the tasks
        Parameters:
        tasks - the collection of tasks
        Returns:
        a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed
        Throws:
        InterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled
      • invokeAll

        public <T> List<Future<T>> invokeAll​(Collection<? extends com.tangosol.util.function.Remote.Callable<T>> tasks,
                                             long lcTimeout,
                                             TimeUnit unit)
                                      throws InterruptedException
        Description copied from interface: RemoteExecutor
        Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. Future.isDone() is true for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
        Specified by:
        invokeAll in interface RemoteExecutor
        Type Parameters:
        T - the type of the values returned from the tasks
        Parameters:
        tasks - the collection of tasks
        lcTimeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed.
        Throws:
        InterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled
      • submit

        public <T> Future<T> submit​(com.tangosol.util.function.Remote.Callable<T> task)
        Description copied from interface: RemoteExecutor
        Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

        If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

        Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, PrivilegedAction to Callable form so they can be submitted.

        Specified by:
        submit in interface RemoteExecutor
        Type Parameters:
        T - the type of the task's result
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
      • submit

        public <T> Future<T> submit​(com.tangosol.util.function.Remote.Runnable task,
                                    T result)
        Description copied from interface: RemoteExecutor
        Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
        Specified by:
        submit in interface RemoteExecutor
        Type Parameters:
        T - the type of the result
        Parameters:
        task - the task to submit
        result - the result to return
        Returns:
        a Future representing pending completion of the task
      • submit

        public Future<?> submit​(com.tangosol.util.function.Remote.Runnable task)
        Description copied from interface: RemoteExecutor
        Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.
        Specified by:
        submit in interface RemoteExecutor
        Parameters:
        task - the task to submit
        Returns:
        a Future representing pending completion of the task
      • cancelAll

        protected static <T> void cancelAll​(List<Future<T>> futures)
        Cancels all provided futures.
        Type Parameters:
        T - the future result type
        Parameters:
        futures - list of futures
      • cancelAll

        protected static <T> void cancelAll​(List<Future<T>> futures,
                                            int nStartIdx)
        Cancels provided futures beginning with the specified index.
        Type Parameters:
        T - the future result type
        Parameters:
        futures - list of futures
        nStartIdx - the start index within the list
      • init

        protected void init​(com.tangosol.net.CacheService cacheService)
        Responsible for adding indexes for the ClusteredAssignment cache.
        Parameters:
        cacheService - the cache service providing the caches used by the executor service
      • scheduleRunnable

        protected ScheduledFuture<?> scheduleRunnable​(Runnable command,
                                                      long cInitialDelay,
                                                      long cPeriod,
                                                      long cDelay,
                                                      TimeUnit unit)
        Schedules the specified Runnable.
        Parameters:
        command - the Runnable to schedule
        cInitialDelay - the initial delay before scheduling occurs
        cPeriod - the period between execution
        cDelay - the delay to start the next execution after the completion of the current execution
        unit - the TimeUnit to apply
        Returns:
        a ScheduledFuture representing the result from processing the command
      • shutdownInternal

        protected boolean shutdownInternal()
        Initiate graceful shutdown.
        Returns:
        true if shutdown has been initiated; false if the ClusteredExecutorService is already shutting down or terminated.
      • shutdownNowInternal

        protected boolean shutdownNowInternal()
        Initiate immediate shutdown.
        Returns:
        true if shutdown has been initiated; false if the ClusteredExecutorService is already shutting down or terminated.