GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Overview
  • Use
  • Tree
  • Deprecated
  • Index
  • Search
  • Help
  • io.netty.util.concurrent
  • SingleThreadEventExecutor

This view

  • Original page
  • New address

GeezerVison is showing netty.io — SingleThreadEventExecutor (Netty API Reference (4.1.141.Final))

Class SingleThreadEventExecutor

java.lang.Object
java.util.concurrent.AbstractExecutorService
io.netty.util.concurrent.AbstractEventExecutor
io.netty.util.concurrent.AbstractScheduledEventExecutor
io.netty.util.concurrent.SingleThreadEventExecutor
All Implemented Interfaces:
EventExecutor, EventExecutorGroup, OrderedEventExecutor, Iterable<EventExecutor>, Executor, ExecutorService, ScheduledExecutorService
Direct Known Subclasses:
DefaultEventExecutor, SingleThreadEventLoop

public abstract class SingleThreadEventExecutor extends AbstractScheduledEventExecutor implements OrderedEventExecutor
Abstract base class for OrderedEventExecutor's that execute all its submitted tasks in a single thread.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static interface 
    SingleThreadEventExecutor.NonWakeupRunnable
    Deprecated.
    override wakesUpForTask(Runnable) to re-create this behaviour

    Nested classes/interfaces inherited from class AbstractEventExecutor

    AbstractEventExecutor.LazyRunnable
    Modifier and Type
    Class
    Description
    static interface 
    AbstractEventExecutor.LazyRunnable
    Deprecated.
    override wakesUpForTask(Runnable) to re-create this behaviour
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp)
    Create a new instance
    protected
    SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
    Create a new instance
    protected
    SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp, Queue<Runnable> taskQueue, RejectedExecutionHandler rejectedHandler)
     
    protected
    SingleThreadEventExecutor(EventExecutorGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp)
    Create a new instance
    protected
    SingleThreadEventExecutor(EventExecutorGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
    Create a new instance
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addShutdownHook(Runnable task)
    Add a Runnable which will be executed on shutdown of this instance
    protected void
    addTask(Runnable task)
    Add a task to the task queue, or throws a RejectedExecutionException if this instance was shutdown before.
    protected void
    afterRunningAllTasks()
    Invoked before returning from runAllTasks() and runAllTasks(long).
    boolean
    awaitTermination(long timeout, TimeUnit unit)
     
    protected void
    cleanup()
    Do nothing, sub-classes may override
    protected boolean
    confirmShutdown()
    Confirm that the shutdown if the instance should be done now!
    protected long
    deadlineNanos()
    Returns the absolute point in time (relative to AbstractScheduledEventExecutor.getCurrentTimeNanos()) at which the next closest scheduled task should run.
    protected long
    delayNanos(long currentTimeNanos)
    Returns the amount of time left until the scheduled task with the closest dead line is executed.
    void
    execute(Runnable task)
     
    protected boolean
    hasTasks()
     
    boolean
    inEventLoop(Thread thread)
    Return true if the given Thread is executed in the event loop, false otherwise.
    protected void
    interruptThread()
    Interrupt the current running Thread.
    <T> List<Future<T>>
    invokeAll(Collection<? extends Callable<T>> tasks)
     
    <T> List<Future<T>>
    invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
     
    <T> T
    invokeAny(Collection<? extends Callable<T>> tasks)
     
    <T> T
    invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
     
    boolean
    isShutdown()
     
    boolean
    isShuttingDown()
    Returns true if and only if all EventExecutors managed by this EventExecutorGroup are being shut down gracefully or was shut down.
    boolean
    isTerminated()
     
    void
    lazyExecute(Runnable task)
    Like Executor.execute(Runnable) but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.
    protected Queue<Runnable>
    newTaskQueue()
    Deprecated.
    Please use and override newTaskQueue(int).
    protected Queue<Runnable>
    newTaskQueue(int maxPendingTasks)
    Create a new Queue which will holds the tasks to execute.
    protected Runnable
    peekTask()
     
    int
    pendingTasks()
    Return the number of tasks that are pending for processing.
    protected Runnable
    pollTask()
     
    protected static Runnable
    pollTaskFrom(Queue<Runnable> taskQueue)
     
    protected static void
    reject()
     
    protected final void
    reject(Runnable task)
    Offers the task to the associated RejectedExecutionHandler.
    void
    removeShutdownHook(Runnable task)
    Remove a previous added Runnable as a shutdown hook
    protected boolean
    removeTask(Runnable task)
     
    protected abstract void
    run()
    Runs the task-processing loop until confirmShutdown() returns true.
    protected boolean
    runAllTasks()
    Poll all tasks from the task queue and run them via Runnable.run() method.
    protected boolean
    runAllTasks(long timeoutNanos)
    Poll all tasks from the task queue and run them via Runnable.run() method.
    protected final boolean
    runAllTasksFrom(Queue<Runnable> taskQueue)
    Runs all tasks from the passed taskQueue.
    protected final boolean
    runScheduledAndExecutorTasks(int maxDrainAttempts)
    Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty, or maxDrainAttempts has been exceeded.
    void
    shutdown()
    Deprecated.
    Future<?>
    shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
    Signals this executor that the caller wants the executor to be shut down.
    protected Runnable
    takeTask()
    Take the next Runnable from the task queue and so will block if no task is currently present.
    Future<?>
    terminationFuture()
    Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
    final ThreadProperties
    threadProperties()
    Returns the ThreadProperties of the Thread that powers the SingleThreadEventExecutor.
    protected void
    updateLastExecutionTime()
    Updates the internal timestamp that tells when a submitted task was executed most recently.
    protected boolean
    wakesUpForTask(Runnable task)
    Can be overridden to control which tasks require waking the EventExecutor thread if it is waiting so that they can be run immediately.
    protected void
    wakeup(boolean inEventLoop)
     

    Methods inherited from class AbstractScheduledEventExecutor

    afterScheduledTaskSubmitted, beforeScheduledTaskSubmitted, cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
    Modifier and Type
    Method
    Description
    protected boolean
    afterScheduledTaskSubmitted(long deadlineNanos)
    See AbstractScheduledEventExecutor.beforeScheduledTaskSubmitted(long).
    protected boolean
    beforeScheduledTaskSubmitted(long deadlineNanos)
    Called from arbitrary non-EventExecutor threads prior to scheduled task submission.
    protected void
    cancelScheduledTasks()
    Cancel all scheduled tasks.
    protected static long
    deadlineToDelayNanos(long deadlineNanos)
    Given an arbitrary deadline deadlineNanos, calculate the number of nano seconds from now deadlineNanos would expire.
    protected long
    getCurrentTimeNanos()
    Get the current time in nanoseconds by this executor's clock.
    protected final boolean
    hasScheduledTasks()
    Returns true if a scheduled task is ready for processing.
    protected static long
    initialNanoTime()
    The initial value used for delay and computations based upon a monatomic time source.
    protected static long
    nanoTime()
    Deprecated.
    Use the non-static AbstractScheduledEventExecutor.getCurrentTimeNanos() instead.
    protected final long
    nextScheduledTaskDeadlineNanos()
    Return the deadline (in nanoseconds) when the next scheduled task is ready to be run or -1 if no task is scheduled.
    protected final long
    nextScheduledTaskNano()
    Return the nanoseconds until the next scheduled task is ready to be run or -1 if no task is scheduled.
    protected final Runnable
    pollScheduledTask()
     
    protected final Runnable
    pollScheduledTask(long nanoTime)
    Return the Runnable which is ready to be executed with the given nanoTime.
    ScheduledFuture<?>
    schedule(Runnable command, long delay, TimeUnit unit)
     
    <V> ScheduledFuture<V>
    schedule(Callable<V> callable, long delay, TimeUnit unit)
     
    ScheduledFuture<?>
    scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
     
    ScheduledFuture<?>
    scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
     
    protected void
    validateScheduled(long amount, TimeUnit unit)
    Deprecated.
    will be removed in the future.

    Methods inherited from class AbstractEventExecutor

    inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, next, parent, runTask, safeExecute, shutdownGracefully, shutdownNow, submit, submit, submit
    Modifier and Type
    Method
    Description
    boolean
    inEventLoop()
    Calls EventExecutor.inEventLoop(Thread) with Thread.currentThread() as argument
    Iterator<EventExecutor>
    iterator()
     
    <V> Future<V>
    newFailedFuture(Throwable cause)
    Create a new Future which is marked as failed already.
    <V> ProgressivePromise<V>
    newProgressivePromise()
    Create a new ProgressivePromise.
    <V> Promise<V>
    newPromise()
    Return a new Promise.
    <V> Future<V>
    newSucceededFuture(V result)
    Create a new Future which is marked as succeeded already.
    protected final <T> RunnableFuture<T>
    newTaskFor(Runnable runnable, T value)
     
    protected final <T> RunnableFuture<T>
    newTaskFor(Callable<T> callable)
     
    EventExecutor
    next()
    Returns a reference to itself.
    EventExecutorGroup
    parent()
    Return the EventExecutorGroup which is the parent of this EventExecutor,
    protected static void
    runTask(Runnable task)
     
    protected static void
    safeExecute(Runnable task)
    Try to execute the given Runnable and just log if it throws a Throwable.
    Future<?>
    shutdownGracefully()
    Shortcut method for EventExecutorGroup.shutdownGracefully(long, long, TimeUnit) with sensible default values.
    List<Runnable>
    shutdownNow()
    Deprecated.
    EventExecutorGroup.shutdownGracefully(long, long, TimeUnit) or AbstractEventExecutor.shutdownGracefully() instead.
    Future<?>
    submit(Runnable task)
     
    <T> Future<T>
    submit(Runnable task, T result)
     
    <T> Future<T>
    submit(Callable<T> task)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Iterable

    forEach, spliterator
  • Constructor Details

    • SingleThreadEventExecutor

      protected SingleThreadEventExecutor(EventExecutorGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp)
      Create a new instance
      Parameters:
      parent - the EventExecutorGroup which is the parent of this instance and belongs to it
      threadFactory - the ThreadFactory which will be used for the used Thread
      addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the executor thread
    • SingleThreadEventExecutor

      protected SingleThreadEventExecutor(EventExecutorGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
      Create a new instance
      Parameters:
      parent - the EventExecutorGroup which is the parent of this instance and belongs to it
      threadFactory - the ThreadFactory which will be used for the used Thread
      addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the executor thread
      maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
      rejectedHandler - the RejectedExecutionHandler to use.
    • SingleThreadEventExecutor

      protected SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp)
      Create a new instance
      Parameters:
      parent - the EventExecutorGroup which is the parent of this instance and belongs to it
      executor - the Executor which will be used for executing
      addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the executor thread
    • SingleThreadEventExecutor

      protected SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp, int maxPendingTasks, RejectedExecutionHandler rejectedHandler)
      Create a new instance
      Parameters:
      parent - the EventExecutorGroup which is the parent of this instance and belongs to it
      executor - the Executor which will be used for executing
      addTaskWakesUp - true if and only if invocation of addTask(Runnable) will wake up the executor thread
      maxPendingTasks - the maximum number of pending tasks before new tasks will be rejected.
      rejectedHandler - the RejectedExecutionHandler to use.
    • SingleThreadEventExecutor

      protected SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, boolean addTaskWakesUp, Queue<Runnable> taskQueue, RejectedExecutionHandler rejectedHandler)
  • Method Details

    • newTaskQueue

      @Deprecated protected Queue<Runnable> newTaskQueue()
      Deprecated.
      Please use and override newTaskQueue(int).
    • newTaskQueue

      protected Queue<Runnable> newTaskQueue(int maxPendingTasks)
      Create a new Queue which will holds the tasks to execute. This default implementation will return a LinkedBlockingQueue but if your sub-class of SingleThreadEventExecutor will not do any blocking calls on the this Queue it may make sense to @Override this and return some more performant implementation that does not support blocking operations at all.
    • interruptThread

      protected void interruptThread()
      Interrupt the current running Thread.
    • pollTask

      protected Runnable pollTask()
      See Also:
      • Queue.poll()
    • pollTaskFrom

      protected static Runnable pollTaskFrom(Queue<Runnable> taskQueue)
    • takeTask

      protected Runnable takeTask()
      Take the next Runnable from the task queue and so will block if no task is currently present.

      Be aware that this method will throw an UnsupportedOperationException if the task queue, which was created via newTaskQueue(), does not implement BlockingQueue.

      Returns:
      null if the executor thread has been interrupted or waken up.
    • peekTask

      protected Runnable peekTask()
      See Also:
      • Queue.peek()
    • hasTasks

      protected boolean hasTasks()
      See Also:
      • Collection.isEmpty()
    • pendingTasks

      public int pendingTasks()
      Return the number of tasks that are pending for processing.
    • addTask

      protected void addTask(Runnable task)
      Add a task to the task queue, or throws a RejectedExecutionException if this instance was shutdown before.
    • removeTask

      protected boolean removeTask(Runnable task)
      See Also:
      • Collection.remove(Object)
    • runAllTasks

      protected boolean runAllTasks()
      Poll all tasks from the task queue and run them via Runnable.run() method.
      Returns:
      true if and only if at least one task was run
    • runScheduledAndExecutorTasks

      protected final boolean runScheduledAndExecutorTasks(int maxDrainAttempts)
      Execute all expired scheduled tasks and all current tasks in the executor queue until both queues are empty, or maxDrainAttempts has been exceeded.
      Parameters:
      maxDrainAttempts - The maximum amount of times this method attempts to drain from queues. This is to prevent continuous task execution and scheduling from preventing the EventExecutor thread to make progress and return to the selector mechanism to process inbound I/O events.
      Returns:
      true if at least one task was run.
    • runAllTasksFrom

      protected final boolean runAllTasksFrom(Queue<Runnable> taskQueue)
      Runs all tasks from the passed taskQueue.
      Parameters:
      taskQueue - To poll and execute all tasks.
      Returns:
      true if at least one task was executed.
    • runAllTasks

      protected boolean runAllTasks(long timeoutNanos)
      Poll all tasks from the task queue and run them via Runnable.run() method. This method stops running the tasks in the task queue and returns if it ran longer than timeoutNanos.
    • afterRunningAllTasks

      protected void afterRunningAllTasks()
      Invoked before returning from runAllTasks() and runAllTasks(long).
    • delayNanos

      protected long delayNanos(long currentTimeNanos)
      Returns the amount of time left until the scheduled task with the closest dead line is executed.
    • deadlineNanos

      protected long deadlineNanos()
      Returns the absolute point in time (relative to AbstractScheduledEventExecutor.getCurrentTimeNanos()) at which the next closest scheduled task should run.
    • updateLastExecutionTime

      protected void updateLastExecutionTime()
      Updates the internal timestamp that tells when a submitted task was executed most recently. runAllTasks() and runAllTasks(long) updates this timestamp automatically, and thus there's usually no need to call this method. However, if you take the tasks manually using takeTask() or pollTask(), you have to call this method at the end of task execution loop for accurate quiet period checks.
    • run

      protected abstract void run()
      Runs the task-processing loop until confirmShutdown() returns true.

      Implementations must not let a Throwable thrown by a task escape this method: any uncaught Throwable terminates the executor (logged at WARN and surfaced via terminationFuture()), at which point every Channel registered with this executor stops processing I/O and new task submissions are rejected. The supplied helpers - runAllTasks(), runAllTasks(long), and AbstractEventExecutor.safeExecute(Runnable) - catch Throwable for you; custom loops built on pollTask() or takeTask() are responsible for wrapping each task invocation accordingly.

    • cleanup

      protected void cleanup()
      Do nothing, sub-classes may override
    • wakeup

      protected void wakeup(boolean inEventLoop)
    • inEventLoop

      public boolean inEventLoop(Thread thread)
      Description copied from interface: EventExecutor
      Return true if the given Thread is executed in the event loop, false otherwise.
      Specified by:
      inEventLoop in interface EventExecutor
    • addShutdownHook

      public void addShutdownHook(Runnable task)
      Add a Runnable which will be executed on shutdown of this instance
    • removeShutdownHook

      public void removeShutdownHook(Runnable task)
      Remove a previous added Runnable as a shutdown hook
    • shutdownGracefully

      public Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
      Description copied from interface: EventExecutorGroup
      Signals this executor that the caller wants the executor to be shut down. Once this method is called, EventExecutorGroup.isShuttingDown() starts to return true, and the executor prepares to shut itself down. Unlike EventExecutorGroup.shutdown(), graceful shutdown ensures that no tasks are submitted for 'the quiet period' (usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period, it is guaranteed to be accepted and the quiet period will start over.
      Specified by:
      shutdownGracefully in interface EventExecutorGroup
      Parameters:
      quietPeriod - the quiet period as described in the documentation
      timeout - the maximum amount of time to wait until the executor is EventExecutorGroup.shutdown() regardless if a task was submitted during the quiet period
      unit - the unit of quietPeriod and timeout
      Returns:
      the EventExecutorGroup.terminationFuture()
    • terminationFuture

      public Future<?> terminationFuture()
      Description copied from interface: EventExecutorGroup
      Returns the Future which is notified when all EventExecutors managed by this EventExecutorGroup have been terminated.
      Specified by:
      terminationFuture in interface EventExecutorGroup
    • shutdown

      @Deprecated public void shutdown()
      Deprecated.
      Specified by:
      shutdown in interface EventExecutorGroup
      Specified by:
      shutdown in interface ExecutorService
      Specified by:
      shutdown in class AbstractEventExecutor
    • isShuttingDown

      public boolean isShuttingDown()
      Description copied from interface: EventExecutorGroup
      Returns true if and only if all EventExecutors managed by this EventExecutorGroup are being shut down gracefully or was shut down.
      Specified by:
      isShuttingDown in interface EventExecutorGroup
    • isShutdown

      public boolean isShutdown()
      Specified by:
      isShutdown in interface ExecutorService
    • isTerminated

      public boolean isTerminated()
      Specified by:
      isTerminated in interface ExecutorService
    • confirmShutdown

      protected boolean confirmShutdown()
      Confirm that the shutdown if the instance should be done now!
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Specified by:
      awaitTermination in interface ExecutorService
      Throws:
      InterruptedException
    • execute

      public void execute(Runnable task)
      Specified by:
      execute in interface Executor
    • lazyExecute

      public void lazyExecute(Runnable task)
      Description copied from class: AbstractEventExecutor
      Like Executor.execute(Runnable) but does not guarantee the task will be run until either a non-lazy task is executed or the executor is shut down.

      The default implementation just delegates to Executor.execute(Runnable).

      Overrides:
      lazyExecute in class AbstractEventExecutor
    • invokeAny

      public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
      Specified by:
      invokeAny in interface ExecutorService
      Overrides:
      invokeAny in class AbstractExecutorService
      Throws:
      InterruptedException
      ExecutionException
    • invokeAny

      public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Specified by:
      invokeAny in interface ExecutorService
      Overrides:
      invokeAny in class AbstractExecutorService
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • invokeAll

      public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
      Specified by:
      invokeAll in interface ExecutorService
      Overrides:
      invokeAll in class AbstractExecutorService
      Throws:
      InterruptedException
    • invokeAll

      public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
      Specified by:
      invokeAll in interface ExecutorService
      Overrides:
      invokeAll in class AbstractExecutorService
      Throws:
      InterruptedException
    • threadProperties

      public final ThreadProperties threadProperties()
      Returns the ThreadProperties of the Thread that powers the SingleThreadEventExecutor. If the SingleThreadEventExecutor is not started yet, this operation will start it and block until it is fully started.
    • wakesUpForTask

      protected boolean wakesUpForTask(Runnable task)
      Can be overridden to control which tasks require waking the EventExecutor thread if it is waiting so that they can be run immediately.
    • reject

      protected static void reject()
    • reject

      protected final void reject(Runnable task)
      Offers the task to the associated RejectedExecutionHandler.
      Parameters:
      task - to reject.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.