T - the application specific API.public abstract class ApplicationLayer<T> extends Object implements ProtocolLayer, ProtocolLayer.Recv
ProtocolLayer in a ProtocolStack. This layer is responsible for translating the protocol stack
into the application specific API.ProtocolLayer.Recv, ProtocolLayer.SendEMPTY_BUFFER, UTF_8| Constructor and Description |
|---|
ApplicationLayer() |
| Modifier and Type | Method and Description |
|---|---|
void |
doCloseRead()
SPI: Implementations of
ApplicationLayer should use this method to request that the read path of the
ProtocolStack be closed. |
void |
doCloseWrite()
SPI: Implementations of
ApplicationLayer should use this method to request that the write path of the
ProtocolStack be closed. |
abstract T |
get()
SPI: Returns the application specific API instance.
|
void |
init(ProtocolStack.Ptr ptr)
Initializes the layer with its
ProtocolStack.Ptr. |
abstract boolean |
isReadOpen()
SPI: Implementations of
ApplicationLayer must ensure this method either returns true while the
application specific API instance (get()) is accepting data via onRead(ByteBuffer) or
returns false once it is permanently closed to incoming data. |
boolean |
isRecvOpen()
Tracks if this layer is accepting received data via
ProtocolLayer.Recv.onRecv(ByteBuffer). |
boolean |
isWriteOpen()
SPI: Implementations of
ApplicationLayer should use method to detect if the ProtocolStack is
open for writing via write(ByteBuffer) or has been closed. |
abstract void |
onRead(ByteBuffer data)
SPI: Callback on data being received from the protocol stack.
|
abstract void |
onReadClosed(IOException cause)
Callback on the lower layer's source of data being closed.
|
void |
onRecv(ByteBuffer data)
Callback on data being received from the lower layer.
|
void |
onRecvClosed(IOException cause)
Callback on the lower layer's source of data being closed.
|
protected ProtocolStack<?> |
stack()
Accessor for the
ProtocolStack that we are bound to. |
void |
write(ByteBuffer data)
SPI: Implementations of
ApplicationLayer should use this method to write data through the
ProtocolStack. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitstartpublic abstract T get()
public abstract boolean isReadOpen()
ApplicationLayer must ensure this method either returns true while the
application specific API instance (get()) is accepting data via onRead(ByteBuffer) or
returns false once it is permanently closed to incoming data. If the application specific API instance
is temporarily not accepting data then this method should return true and the implementation is
responsible for caching the data submitted in calls to onRead(ByteBuffer)
Once this method returns false it must always return false and can be assumed to behave in
this way.true if the application specific API instance (get() is accepting data via
onRead(ByteBuffer)public abstract void onRead(@Nonnull ByteBuffer data) throws IOException
data - the data received. Any data consumed from the ByteBuffer can be assumed as processed.
Any data not consumed from the ByteBuffer will be the responsibility of the caller
to resubmit in subsequent calls.IOException - if there was an error during processing of the received data.public abstract void onReadClosed(IOException cause) throws IOException
cause - the cause of the lower layer being closed or null.IOException - if there was an error during the processing of the close notification.public final void init(@Nonnull ProtocolStack.Ptr ptr) throws IOException
ProtocolStack.Ptr. All lower layers in the stack will be initialized
before a call to this method. All layers in a stack will be initialized before a call to ProtocolLayer.start().init in interface ProtocolLayerptr - the position of this layer in the stack.IOException - if something goes wrong.public final boolean isWriteOpen()
ApplicationLayer should use method to detect if the ProtocolStack is
open for writing via write(ByteBuffer) or has been closed.
Once this method returns false it will always return false and can be assumed to behave in
this way.true if the ProtocolStack is open for writing via write(ByteBuffer).public final void write(@Nonnull ByteBuffer data) throws IOException
ApplicationLayer should use this method to write data through the
ProtocolStack.data - the data to write. Any data consumed from the ByteBuffer can be assumed as processed.
Any data not consumed from the ByteBuffer will be the responsibility of the caller
to resubmit in subsequent calls.IOException - if there was an error during processing of the data.public final void doCloseWrite()
throws IOException
ApplicationLayer should use this method to request that the write path of the
ProtocolStack be closed. Depending on the nature of the NetworkLayer this may force closed
the read path (e.g. if the backing transport is using a SocketChannel).IOException - if there was an error during the closing of the write path.public final void doCloseRead()
throws IOException
ApplicationLayer should use this method to request that the read path of the
ProtocolStack be closed. Depending on the nature of the NetworkLayer this may force closed
the write path (e.g. if the backing transport is using a SocketChannel).IOException - if there was an error during the closing of the read path.@Nullable protected ProtocolStack<?> stack()
ProtocolStack that we are bound to.ProtocolStack that we are bound to or null if we are not currently bound to a stack.@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void onRecv(@Nonnull ByteBuffer data) throws IOException
onRecv in interface ProtocolLayer.Recvdata - the data received. Any data consumed from the ByteBuffer can be assumed as processed.
Any data not consumed from the ByteBuffer will be the responsibility of the caller
to resubmit in subsequent calls.IOException - if there was an error during processing of the received data.@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void onRecvClosed(IOException cause) throws IOException
onRecvClosed in interface ProtocolLayer.Recvcause - the cause of the lower layer being closed or null.IOException - if there was an error during the processing of the close notification.@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public final boolean isRecvOpen()
ProtocolLayer.Recv.onRecv(ByteBuffer).
Once this method returns false it must always return false and can be assumed to behave in
this way.isRecvOpen in interface ProtocolLayer.Recvtrue if accepting received data via ProtocolLayer.Recv.onRecv(ByteBuffer).Copyright © 2004–2017. All rights reserved.