Class Phase

  • All Implemented Interfaces:
    java.lang.Runnable, Operation
    Direct Known Subclasses:
    Handshake.Committer, Handshake.Consumer, Handshake.Producer

    abstract class Phase
    extends java.lang.Object
    implements Operation
    The Phase object represents an asynchronous phase within the negotiation. This is typically used to either schedule an asynchronous read or write when it can not be performed directly. It ensures that the negotiation does not block the thread so that execution can be optimized of high concurrency.
    See Also:
    Handshake
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Reactor reactor
      This is the reactor that is used to schedule execution.
      protected int require
      This is the required operation for the task to complete.
      protected Negotiation state
      This is the negotiation that this task will operate on.
      protected Trace trace
      This is the trace used to monitor the handshake socket.
    • Constructor Summary

      Constructors 
      Constructor Description
      Phase​(Negotiation state, Reactor reactor, Trace trace, int require)
      Constructor for the Phase object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      This is used to cancel the operation if it has timed out.
      protected void execute()
      This is used to execute the task.
      java.nio.channels.SelectableChannel getChannel()
      This is the SelectableChannel which is used to determine if the operation should be executed.
      Trace getTrace()
      This is used to acquire the trace object that is associated with the operation.
      protected boolean ready()
      This method is used to determine if the task is ready.
      void run()
      This is used to execute the task.
      • Methods inherited from class java.lang.Object

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

      • state

        protected final Negotiation state
        This is the negotiation that this task will operate on.
      • reactor

        protected final Reactor reactor
        This is the reactor that is used to schedule execution.
      • trace

        protected final Trace trace
        This is the trace used to monitor the handshake socket.
      • require

        protected final int require
        This is the required operation for the task to complete.
    • Constructor Detail

      • Phase

        public Phase​(Negotiation state,
                     Reactor reactor,
                     Trace trace,
                     int require)
        Constructor for the Phase object. This is used to create an operation that performs some phase of a negotiation. It allows the negotiation to schedule the read and write operations asynchronously.
        Parameters:
        state - this is the negotiation this task works on
        reactor - this is the reactor used to schedule the task
        trace - the trace that is used to monitor the handshake
        require - this is the required operation for the task
    • Method Detail

      • getTrace

        public Trace getTrace()
        This is used to acquire the trace object that is associated with the operation. A trace object is used to collection details on what operations are being performed. For instance it may contain information relating to I/O events or errors.
        Specified by:
        getTrace in interface Operation
        Returns:
        this returns the trace associated with this operation
      • getChannel

        public java.nio.channels.SelectableChannel getChannel()
        This is the SelectableChannel which is used to determine if the operation should be executed. If the channel is ready for a given I/O event it can be run. For instance if the operation is used to perform some form of read operation it can be executed when ready to read data from the channel.
        Specified by:
        getChannel in interface Operation
        Returns:
        this returns the channel used to govern execution
      • run

        public void run()
        This is used to execute the task. It is up to the specific task implementation to decide what to do when executed. If the task needs to read or write data then it can attempt to perform the read or write, if it incomplete the it can be scheduled for execution with the reactor.
        Specified by:
        run in interface java.lang.Runnable
      • cancel

        public void cancel()
        This is used to cancel the operation if it has timed out. This is typically invoked when it has been waiting in a selector for an extended duration of time without any active operations on it. In such a case the reactor must purge the operation to free the memory and open channels associated with the operation.
        Specified by:
        cancel in interface Operation
      • execute

        protected void execute()
                        throws java.io.IOException
        This is used to execute the task. It is up to the specific task implementation to decide what to do when executed. If the task needs to read or write data then it can attempt to perform the read or write, if it incomplete the it can be scheduled for execution with the reactor.
        Throws:
        java.io.IOException
      • ready

        protected boolean ready()
                         throws java.io.IOException
        This method is used to determine if the task is ready. This is executed when the select operation is signaled. When this is true the the task completes. If not then this will schedule the task again for the specified select operation.
        Returns:
        this returns true when the task has completed
        Throws:
        java.io.IOException