T - the application specific API.public class ProtocolStack<T> extends Object implements Closeable, ByteBufferPool
ProtocolLayer that make a network protocol. The stack will start with a NetworkLayer
instance,
optionally followed by a series of FilterLayer instances and terminated by a ApplicationLayer
instance.
Instances are created using the on(NetworkLayer) entry point, for example
ProtocolStack.on(netLayer).filter(filterLayer1).filter(filterLayer2).filter(filterLayer3).build(appLayer)
For this stack, the layers will be initialized and started in the following sequence:
NetworkLayer.init(ProtocolStack.Ptr) (netLayer)FilterLayer.init(ProtocolStack.Ptr) (filterLayer1)FilterLayer.init(ProtocolStack.Ptr) (filterLayer2)FilterLayer.init(ProtocolStack.Ptr) (filterLayer3)ApplicationLayer.init(ProtocolStack.Ptr) (appLayer)NetworkLayer.start() (netLayer)FilterLayer.start() (filterLayer1)FilterLayer.start() (filterLayer2)FilterLayer.start() (filterLayer3)ProtocolLayer.start() (appLayer)NetworkLayer (netLayer) detects closeFilterLayer.onRecvClosed(IOException) (filterLayer1)FilterLayer.onRecvClosed(IOException) (filterLayer2)FilterLayer.onRecvClosed(IOException) (filterLayer3)FilterLayer.onRecvClosed(IOException) (appLayer)FilterLayer.doCloseSend() (filterLayer3)FilterLayer.doCloseSend() (filterLayer2)FilterLayer.doCloseSend() (filterLayer1)ProtocolLayer.Send.doCloseSend() (netLayer)FilterLayer (filterLayer2) initiates closeFilterLayer.onRecvClosed(IOException) (filterLayer3)FilterLayer.onRecvClosed(IOException) (appLayer)FilterLayer.doCloseSend() (filterLayer3)FilterLayer.doCloseSend() (filterLayer2)FilterLayer.doCloseSend() (filterLayer1)ProtocolLayer.Send.doCloseSend() (netLayer)FilterLayer.onRecvClosed(IOException) (filterLayer1)| Modifier and Type | Class and Description |
|---|---|
static class |
ProtocolStack.Builder
Builder for
ProtocolStack instances. |
static interface |
ProtocolStack.Listener
Callback "interface" for changes in the state of
ProtocolStack. |
class |
ProtocolStack.Ptr
Tracks where a
ProtocolLayer is in the ProtocolStack. |
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
acquire(int size)
Borrow a buffer from the pool.
|
void |
addListener(ProtocolStack.Listener listener)
Adds a listener.
|
void |
close() |
boolean |
equals(Object obj) |
void |
execute(Runnable task)
Executes the given command at some time in the future.
|
Future<?> |
executeLater(Runnable task,
long delay,
TimeUnit units)
Executes a task at a future point in time.
|
T |
get()
Gets the application specific API.
|
long |
getHandshakingTimeout()
Gets this
ProtocolStack's handshaking timeout. |
TimeUnit |
getHandshakingUnits()
Gets the
TimeUnit of getHandshakingTimeout(). |
int |
hashCode() |
String |
name()
The name of this stack to use in logging.
|
void |
name(String name)
Updates the name of this stack to use in logging.
|
static ProtocolStack.Builder |
on(NetworkLayer network)
Create a
ProtocolStack on the supplied NetworkLayer. |
void |
release(ByteBuffer buffer)
Returns a buffer to the pool.
|
void |
removeListener(ProtocolStack.Listener listener)
Removes a listener.
|
String |
toString() |
static void |
waitForStart() |
public static ProtocolStack.Builder on(NetworkLayer network)
ProtocolStack on the supplied NetworkLayer.network - the NetworkLayer to build the stack on.ProtocolStack.Builder.public static void waitForStart()
throws InterruptedException
InterruptedExceptionpublic T get()
ApplicationLayer.get()public String name()
public void name(String name)
name - the new name of this stack to use in logging.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void addListener(ProtocolStack.Listener listener)
listener - the listener.public void removeListener(ProtocolStack.Listener listener)
listener - the listener.@OverrideMustInvoke public void execute(Runnable task)
task - the runnable taskRejectedExecutionException - if this task cannot be accepted for executionNullPointerException - if task is null@OverrideMustInvoke public Future<?> executeLater(Runnable task, long delay, TimeUnit units)
task - the task.delay - the delay.units - the time units for the delay.Future that completes when the task has run and can be used to cancel the execution.RejectedExecutionException - if this task cannot be accepted for executionNullPointerException - if task is nullpublic long getHandshakingTimeout()
ProtocolStack's handshaking timeout.ProtocolStack's handshaking timeout.getHandshakingUnits()public TimeUnit getHandshakingUnits()
TimeUnit of getHandshakingTimeout().TimeUnit of getHandshakingTimeout().()public ByteBuffer acquire(int size)
acquire in interface ByteBufferPoolsize - The minimum size and initial limit of the buffer.public void release(ByteBuffer buffer)
release in interface ByteBufferPoolbuffer - the buffer.Copyright © 2004–2022. All rights reserved.