Interface ThreadContext

All Superinterfaces:
AutoCloseable, Executor, Scheduler
All Known Implementing Classes:
AbstractThreadContext, NullThreadContext, SingleThreadContext

public interface ThreadContext extends AutoCloseable, Executor, Scheduler
Thread context.

The thread context is used by Catalyst to determine the correct thread on which to execute asynchronous callbacks. All threads created within Catalyst must be instances of AtomixThread. Once a thread has been created, the context is stored in the thread object via AtomixThread.setContext(ThreadContext). This means there is a one-to-one relationship between a context and a thread. That is, a context is representative of a thread and provides an interface for firing events on that thread.

Components of the framework that provide custom threads should use AtomixThreadFactory to allocate new threads and provide a custom ThreadContext implementation.

Author:
Jordan Halterman
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Marks the thread context as blocked.
    default void
    Checks that the current thread is the correct context thread.
    void
    Closes the context.
    Returns the current thread context.
    boolean
    Returns whether the thread context is currently marked blocked.
    default boolean
    Returns a boolean indicating whether the current thread is in this context.
    void
    Marks the thread context as unblocked.

    Methods inherited from interface java.util.concurrent.Executor

    execute

    Methods inherited from interface io.atomix.utils.concurrent.Scheduler

    schedule, schedule, schedule, schedule
  • Method Details

    • currentContext

      static ThreadContext currentContext()
      Returns the current thread context.
      Returns:
      The current thread context or null if no context exists.
    • isCurrentContext

      default boolean isCurrentContext()
      Returns a boolean indicating whether the current thread is in this context.
      Returns:
      Indicates whether the current thread is in this context.
    • checkThread

      default void checkThread()
      Checks that the current thread is the correct context thread.
    • isBlocked

      boolean isBlocked()
      Returns whether the thread context is currently marked blocked.
      Returns:
      whether the thread context is currently marked blocked
    • block

      void block()
      Marks the thread context as blocked.
    • unblock

      void unblock()
      Marks the thread context as unblocked.
    • close

      void close()
      Closes the context.
      Specified by:
      close in interface AutoCloseable