Package org.simpleframework.transport
Class Phase
java.lang.Object
org.simpleframework.transport.Phase
- Direct Known Subclasses:
Handshake.Committer
,Handshake.Consumer
,Handshake.Producer
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Reactor
This is the reactor that is used to schedule execution.protected final int
This is the required operation for the task to complete.protected final Negotiation
This is the negotiation that this task will operate on.protected final Trace
This is the trace used to monitor the handshake socket. -
Constructor Summary
ConstructorsConstructorDescriptionPhase
(Negotiation state, Reactor reactor, Trace trace, int require) Constructor for thePhase
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
This is used to cancel the operation if it has timed out.protected void
execute()
This is used to execute the task.This is theSelectableChannel
which is used to determine if the operation should be executed.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.
-
Field Details
-
state
This is the negotiation that this task will operate on. -
reactor
This is the reactor that is used to schedule execution. -
trace
This is the trace used to monitor the handshake socket. -
require
protected final int requireThis is the required operation for the task to complete.
-
-
Constructor Details
-
Phase
Constructor for thePhase
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 onreactor
- this is the reactor used to schedule the tasktrace
- the trace that is used to monitor the handshakerequire
- this is the required operation for the task
-
-
Method Details
-
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. -
getChannel
This is theSelectableChannel
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 interfaceOperation
- 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. -
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. -
execute
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:
IOException
-
ready
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:
IOException
-