public abstract class NetworkLayer extends Object implements ProtocolLayer, ProtocolLayer.Send
ProtocolLayer in a ProtocolStack. This layer is responsible for sending the output of
the protocol
to the recipient and injecting the input from the recipient into the protocol stack.ProtocolLayer.Recv, ProtocolLayer.SendEMPTY_BUFFER| Constructor and Description |
|---|
NetworkLayer(IOHub ioHub)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuffer |
acquire()
SPI: Acquired a new
ByteBuffer optimally sized for network read/write operations. |
abstract void |
doCloseRecv()
Request the recv side to be closed.
|
void |
doSend(ByteBuffer data)
Sends data to the lower layer.
|
IOHub |
getIoHub()
Gets the
IOHub that we are using. |
void |
init(ProtocolStack.Ptr ptr)
Initializes the layer with its
ProtocolStack.Ptr. |
protected boolean |
isRecvOpen()
SPI: Check if the recipient is open.
|
protected ByteBufferQueue |
newByteBufferQueue()
SPI: Creates a new
ByteBuffer optimally sized for network read/write operations. |
protected void |
onRead(ByteBuffer data)
SPI: Performed the handling of te actual read from the recipient.
|
protected void |
onRecvClosed()
SPI: Notify that the connection with the recipient is closed.
|
protected void |
release(ByteBuffer buffer)
SPI: Returns a previously acquired
ByteBuffer to the pool. |
protected ProtocolStack<?> |
stack()
Returns the
ProtocolStack instance that we belong to. |
void |
start()
Starts this layer.
|
protected abstract void |
write(ByteBuffer data)
SPI: Perform the actual write to the recipient.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdoCloseSend, isSendOpenpublic final 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.protected abstract void write(@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 something goes wrongprotected final void onRead(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 something goes wrong@OverrideMustInvoke protected final void onRecvClosed()
public abstract void doCloseRecv()
protected final boolean isRecvOpen()
true if the recipient is open.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.@OverrideMustInvoke
public void start()
throws IOException
start in interface ProtocolLayerIOException - if something goes wrong.@NonNull public IOHub getIoHub()
IOHub that we are using.IOHub that we are using.protected ByteBuffer acquire()
ByteBuffer optimally sized for network read/write operations.ByteBuffer.protected void release(ByteBuffer buffer)
ByteBuffer to the pool.buffer - the ByteBuffer.protected ByteBufferQueue newByteBufferQueue()
ByteBuffer optimally sized for network read/write operations.ByteBuffer optimally sized for network read/write operations.protected ProtocolStack<?> stack()
ProtocolStack instance that we belong to.ProtocolStack instance that we belong to.Copyright © 2004–2022. All rights reserved.