public abstract class AbstractEngine extends Object implements IEngine
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractEngine.CloseType |
Modifier and Type | Field and Description |
---|---|
protected HandshakeStatus |
handshakeStatus |
protected AbstractEngine.CloseType |
inboundDone |
protected AbstractEngine.CloseType |
outboundDone |
Constructor and Description |
---|
AbstractEngine() |
Modifier and Type | Method and Description |
---|---|
void |
beginHandshake()
Initiates handshaking on this
IEngine implementation. |
void |
cleanup()
Signals that an
IEngine implementation can cleanup, if
required, its internal state (e.g. |
void |
closeInbound()
Signals that no more inbound network data will be sent to an
IEngine implementation. |
void |
closeOutbound()
Signals that no more outbound application data will be sent to an
IEngine implementation. |
Runnable |
getDelegatedTask()
Returns a delegated
Runnable task for an IEngine
implementation. |
HandshakeStatus |
getHandshakeStatus()
Returns the current handshake status for an
IEngine
implementation. |
int |
getMaxApplicationBufferSize()
Gets the current maximum size of the buffer holding application data
|
int |
getMaxNetworkBufferSize()
Gets the current maximum size of the buffer holding network data
|
int |
getMinApplicationBufferSize()
Gets the current minimum size of the buffer holding application data.
|
int |
getMinNetworkBufferSize()
Gets the current minimum size of the buffer holding network data.
|
Object |
getSession()
Returns an object representing a session in use in an
IEngine
implementation. |
void |
init()
Signals that an
IEngine implementation can initialize, if
required, its internal state (e.g. |
boolean |
isInboundDone()
Returns whether
IEngine.unwrap(ByteBuffer, ByteBuffer) method
will accept any more inbound network data. |
boolean |
isOutboundDone()
Returns whether
IEngine.wrap(ByteBuffer, ByteBuffer) and
IEngine.wrap(ByteBuffer[], ByteBuffer) methods will produce
any more outbound network data. |
protected IEngineResult |
updateHandshakeStatus(IEngineResult result) |
IEngineResult |
wrap(ByteBuffer src,
ByteBuffer dst)
Attempts to encode outbound application data from a data buffer into outbound
network data.
|
protected AbstractEngine.CloseType outboundDone
protected AbstractEngine.CloseType inboundDone
protected HandshakeStatus handshakeStatus
public void init()
IEngine
IEngine
implementation can initialize, if
required, its internal state (e.g. allocate required resources). It is
called during pre-creation phase of an engine driven session (i.e.
before the event SessionEvent.CREATED
is signaled to the session handler).public void cleanup()
IEngine
IEngine
implementation can cleanup, if
required, its internal state (e.g. release allocated resources). It is
called during post-ending phase of an engine driven session (i.e.
after the event SessionEvent.ENDING
is fully processed by the session handler).public void beginHandshake() throws Exception
IEngine
IEngine
implementation. This method
is not called by the SNF4J framework for a initial handshake, as the
initial handshake should be initiated by the wrap()
and
unwrap()
methods when they are called for the first time.
This method is never called by the SNF4J framework when another handshake
is still in progress on this engine. Any try to begin a new handshake
from an engine stream session will be silently ignored unless previously
started handshake is finished. The finishing is signaled by the
HandshakeStatus.FINISHED
status returned by the wrap
or
unwrap
method.
beginHandshake
in interface IEngine
Exception
- if a problem was encountered while signaling the beginning of
a new handshake.public Object getSession()
IEngine
IEngine
implementation.getSession
in interface IEngine
public boolean isOutboundDone()
IEngine
IEngine.wrap(ByteBuffer, ByteBuffer)
and
IEngine.wrap(ByteBuffer[], ByteBuffer)
methods will produce
any more outbound network data.isOutboundDone
in interface IEngine
true
if an IEngine
implementation
will not produce any more network datapublic boolean isInboundDone()
IEngine
IEngine.unwrap(ByteBuffer, ByteBuffer)
method
will accept any more inbound network data.isInboundDone
in interface IEngine
true
if an IEngine
implementation will not
consume anymore network dataIEngine.closeInbound()
public void closeOutbound()
IEngine
IEngine
implementation.
This method should be idempotent: if the outbound side has already been closed, this method should not do anything.
closeOutbound
in interface IEngine
IEngine.isOutboundDone()
public void closeInbound() throws SessionIncidentException
IEngine
IEngine
implementation.
This method should be idempotent: if the inbound side has already been closed, this method should not do anything.
closeInbound
in interface IEngine
SessionIncidentException
- if this engine implementation detected an incident that
should be reported to the associated session's handler (e.g.
when an engine has not received a proper close message from
the peer).IEngine.isInboundDone()
public int getMinApplicationBufferSize()
IEngine
IEngine
implementation may use application data (i.e. the
application data wrapped in one network packet) of any size up to and
including the value returned by this method.getMinApplicationBufferSize
in interface IEngine
public int getMinNetworkBufferSize()
IEngine
IEngine
implementation may generate network packets of any size up to and including the value
returned by this method.getMinNetworkBufferSize
in interface IEngine
public int getMaxApplicationBufferSize()
IEngine
This method is only used by the EngineStreamSession
class.
getMaxApplicationBufferSize
in interface IEngine
public int getMaxNetworkBufferSize()
IEngine
This method is only used by the EngineStreamSession
class.
getMaxNetworkBufferSize
in interface IEngine
public HandshakeStatus getHandshakeStatus()
IEngine
IEngine
implementation.
It should never return the FINISHED
status.
getHandshakeStatus
in interface IEngine
public Runnable getDelegatedTask()
IEngine
Runnable
task for an IEngine
implementation.
IEngine
operations may require the results of operations
that block, or may take an extended period of time to complete. This
method should be used to obtain a pending Runnable
operation
(task). Each task will be assigned a thread to perform the run operation.
The assigned thread will be created by a thread factory configured in the
selector loop that will handle the session associated with this IEngine
implementation.
A call to this method should return each pending task exactly once.
Multiple tasks can be run in parallel.
getDelegatedTask
in interface IEngine
Runnable,
task, or null if none are
available.public IEngineResult wrap(ByteBuffer src, ByteBuffer dst) throws Exception
IEngine
Depending on the state of an IEngine
implementation, this method
can produce network data without consuming any application data (for
example, it may generate handshake data.)
If an IEngine
implementation has not yet started its initial
handshake, this method should automatically start the handshake.
wrap
in interface IEngine
src
- a ByteBuffer
containing the outbound
application datadst
- a ByteBuffer
to hold outbound network dataEngineResult
describing the result of this operation.Exception
- when a problem occurred. Once it is thrown the associated
session will be quickly closedprotected IEngineResult updateHandshakeStatus(IEngineResult result)
Copyright © 2017–2022 SNF4J.ORG. All rights reserved.