public abstract class FilterLayer extends Object implements ProtocolLayer, ProtocolLayer.Send, ProtocolLayer.Recv
ProtocolLayer in a ProtocolStack. This layer can be responsible for
ProtocolLayer.Recv, ProtocolLayer.SendEMPTY_BUFFER, UTF_8| Constructor and Description |
|---|
FilterLayer() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
abort(IOException cause)
The
FilterLayer implementation calls this to signify that a critical error in the stack has occurred
and that the stack should be torn down and closed. |
protected void |
completed()
The
FilterLayer implementation calls this to signify that it is now a no-op layer in both directions
and can be removed from the ProtocolStack |
void |
doCloseSend()
Notify the lower layer that it should close.
|
abstract void |
doSend(ByteBuffer data)
SPI: Sends data to the lower layer.
|
protected void |
flushRecv(ByteBufferQueue queue)
|
protected void |
flushSend(ByteBufferQueue queue)
Flushes the supplied
ByteBufferQueue to next()'s ProtocolStack.Ptr.doSend(ByteBuffer)
This method is especially helpful for FilterLayer implementations that are involved in initial
handshaking as they will need to queue up data until the handshake is completed and then flush the data to
the remainder of the stack. |
void |
init(ProtocolStack.Ptr ptr)
Initializes the layer with its
ProtocolStack.Ptr. |
boolean |
isRecvOpen()
Tracks if this layer is accepting received data via
ProtocolLayer.Recv.onRecv(ByteBuffer). |
boolean |
isSendOpen()
Tracks if this layer is submitting data to be sent via
ProtocolLayer.Send.doSend(ByteBuffer). |
protected ProtocolStack.Ptr |
next()
Accessor for the next layers in the
ProtocolStack. |
abstract void |
onRecv(ByteBuffer data)
SPI: 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 |
start()
Starts this layer.
|
@OverridingMethodsMustInvokeSuper 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 void start()
throws IOException
start in interface ProtocolLayerIOException - if something goes wrong.protected final void completed()
FilterLayer implementation calls this to signify that it is now a no-op layer in both directions
and can be removed from the ProtocolStackprotected final void abort(@Nonnull IOException cause)
FilterLayer implementation calls this to signify that a critical error in the stack has occurred
and that the stack should be torn down and closed.cause - the root cause to report.@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.@Nullable protected ProtocolStack.Ptr next()
ProtocolStack.ProtocolStack.Ptr or null if we are not currently bound to a stack.protected final void flushRecv(ByteBufferQueue queue) throws IOException
ByteBufferQueue to next()'s ProtocolStack.Ptr.onRecv(ByteBuffer).
This method is especially helpful for FilterLayer implementations that are involved in initial
handshaking as they will need to queue up data until the handshake is completed and then flush the data to
the remainder of the stack.queue - the data to receive.IOException - if there is an I/O error during the receive.protected final void flushSend(ByteBufferQueue queue) throws IOException
ByteBufferQueue to next()'s ProtocolStack.Ptr.doSend(ByteBuffer)
This method is especially helpful for FilterLayer implementations that are involved in initial
handshaking as they will need to queue up data until the handshake is completed and then flush the data to
the remainder of the stack.queue - the data to send.IOException - if there is an I/O error during the receive.public abstract 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.@OverridingMethodsMustInvokeSuper public 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.public 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).public abstract void doSend(@Nonnull ByteBuffer data) throws IOException
doSend in interface ProtocolLayer.Senddata - the data to send. 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.@OverridingMethodsMustInvokeSuper public void doCloseSend() throws IOException
ProtocolLayer.Recv.onRecvClosed(IOException) for any upper layers.doCloseSend in interface ProtocolLayer.SendIOException - if there was an error closing the lower layer.public boolean isSendOpen()
ProtocolLayer.Send.doSend(ByteBuffer).
Once this method returns false it must always return false and can be assumed to behave in
this way.isSendOpen in interface ProtocolLayer.Sendtrue if submitting data to be sent via ProtocolLayer.Send.doSend(ByteBuffer).Copyright © 2004–2018. All rights reserved.