Class SEPExecutor

    • Field Summary

      Fields 
      Modifier and Type Field Description
      ThreadPoolMetrics metrics  
      java.lang.String name  
      protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Runnable> tasks  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected <T extends java.lang.Runnable>
      T
      addTask​(T task)  
      boolean awaitTermination​(long timeout, java.util.concurrent.TimeUnit unit)  
      void execute​(java.lang.Runnable run)  
      void execute​(WithResources withResources, java.lang.Runnable run)
      Invoke task.
      int getActiveTaskCount()
      Returns the approximate number of threads that are actively executing tasks.
      long getCompletedTaskCount()
      Returns the approximate total number of tasks that have completed execution.
      int getCorePoolSize()
      Returns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).
      int getMaximumPoolSize()
      Returns maximum pool size of thread pool.
      int getMaxTasksQueued()  
      int getPendingTaskCount()
      Returns the approximate total of tasks waiting to be executed.
      boolean inExecutor()  
      boolean isShutdown()  
      boolean isTerminated()  
      void maybeExecuteImmediately​(java.lang.Runnable task)
      MAY execute task immediately, if the calling thread is permitted to do so.
      long oldestTaskQueueTime()  
      protected void onCompletion()  
      void setCorePoolSize​(int newCorePoolSize)
      Allows user to resize minimum size of the thread pool.
      void setMaximumPoolSize​(int newMaximumPoolSize)
      Allows user to resize maximum size of the thread pool.
      void shutdown()  
      java.util.List<java.lang.Runnable> shutdownNow()  
      Future<?> submit​(java.lang.Runnable run)
      Overrides ExecutorService.submit(Runnable) to return a Cassandra Future
      <T> Future<T> submit​(java.lang.Runnable run, T result)
      Overrides ExecutorService.submit(Runnable, Object) to return a Cassandra Future
      <T> Future<T> submit​(java.util.concurrent.Callable<T> call)
      Overrides ExecutorService.submit(Callable) to return a Cassandra Future
      Future<?> submit​(WithResources withResources, java.lang.Runnable run)
      Invoke task, returning a future yielding null if successful, or the abnormal termination of task otherwise.
      <T> Future<T> submit​(WithResources withResources, java.lang.Runnable run, T result)
      Invoke task, returning a future yielding result if successful, or the abnormal termination of task otherwise.
      <T> Future<T> submit​(WithResources withResources, java.util.concurrent.Callable<T> call)
      Invoke task, returning a future representing this computation.
      • Methods inherited from class java.lang.Object

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

      • name

        public final java.lang.String name
      • tasks

        protected final java.util.concurrent.ConcurrentLinkedQueue<java.lang.Runnable> tasks
    • Method Detail

      • onCompletion

        protected void onCompletion()
      • addTask

        protected <T extends java.lang.Runnable> T addTask​(T task)
      • maybeExecuteImmediately

        public void maybeExecuteImmediately​(java.lang.Runnable task)
        Description copied from interface: ExecutorPlus
        MAY execute task immediately, if the calling thread is permitted to do so.
        Specified by:
        maybeExecuteImmediately in interface ExecutorPlus
      • execute

        public void execute​(java.lang.Runnable run)
        Specified by:
        execute in interface java.util.concurrent.Executor
      • execute

        public void execute​(WithResources withResources,
                            java.lang.Runnable run)
        Description copied from interface: ExecutorPlus
        Invoke task. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { task.run(); }
        Specified by:
        execute in interface ExecutorPlus
        Parameters:
        withResources - the resources to create and hold while executing task
        run - the task to execute
      • submit

        public Future<?> submit​(java.lang.Runnable run)
        Description copied from interface: ExecutorPlus
        Overrides ExecutorService.submit(Runnable) to return a Cassandra Future
        Specified by:
        submit in interface ExecutorPlus
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> Future<T> submit​(java.lang.Runnable run,
                                    T result)
        Description copied from interface: ExecutorPlus
        Overrides ExecutorService.submit(Runnable, Object) to return a Cassandra Future
        Specified by:
        submit in interface ExecutorPlus
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> Future<T> submit​(java.util.concurrent.Callable<T> call)
        Description copied from interface: ExecutorPlus
        Overrides ExecutorService.submit(Callable) to return a Cassandra Future
        Specified by:
        submit in interface ExecutorPlus
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> Future<T> submit​(WithResources withResources,
                                    java.lang.Runnable run,
                                    T result)
        Description copied from interface: ExecutorPlus
        Invoke task, returning a future yielding result if successful, or the abnormal termination of task otherwise. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { task.run(); return result; }
        Specified by:
        submit in interface ExecutorPlus
        Parameters:
        withResources - the resources to create and hold while executing task
        run - the task to execute
        result - the result if successful
      • submit

        public Future<?> submit​(WithResources withResources,
                                java.lang.Runnable run)
        Description copied from interface: ExecutorPlus
        Invoke task, returning a future yielding null if successful, or the abnormal termination of task otherwise. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up try (Closeable close = withResources.get()) { task.run(); return null; }
        Specified by:
        submit in interface ExecutorPlus
        Parameters:
        withResources - the resources to create and hold while executing task
        run - the task to execute
      • submit

        public <T> Future<T> submit​(WithResources withResources,
                                    java.util.concurrent.Callable<T> call)
        Description copied from interface: ExecutorPlus
        Invoke task, returning a future representing this computation. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { return task.call(); }
        Specified by:
        submit in interface ExecutorPlus
        Parameters:
        withResources - the resources to create and hold while executing task
        call - the task to execute
      • inExecutor

        public boolean inExecutor()
        Specified by:
        inExecutor in interface ExecutorPlus
        Returns:
        true iff the caller is a worker thread actively serving this executor
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • awaitTermination

        public boolean awaitTermination​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • getPendingTaskCount

        public int getPendingTaskCount()
        Description copied from interface: ResizableThreadPool
        Returns the approximate total of tasks waiting to be executed. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.
        Specified by:
        getPendingTaskCount in interface ResizableThreadPool
        Returns:
        the number of tasks
      • getCompletedTaskCount

        public long getCompletedTaskCount()
        Description copied from interface: ResizableThreadPool
        Returns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.
        Specified by:
        getCompletedTaskCount in interface ResizableThreadPool
        Returns:
        the number of tasks
      • getActiveTaskCount

        public int getActiveTaskCount()
        Description copied from interface: ResizableThreadPool
        Returns the approximate number of threads that are actively executing tasks.
        Specified by:
        getActiveTaskCount in interface ResizableThreadPool
        Returns:
        the number of threads
      • getCorePoolSize

        public int getCorePoolSize()
        Description copied from interface: ResizableThreadPool
        Returns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).
        Specified by:
        getCorePoolSize in interface ResizableThreadPool