Package org.jenkinsci.remoting.protocol
Class ProtocolStack<T>
- java.lang.Object
-
- org.jenkinsci.remoting.protocol.ProtocolStack<T>
-
- Type Parameters:
T
- the application specific API.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteBufferPool
public class ProtocolStack<T> extends Object implements Closeable, ByteBufferPool
A stack ofProtocolLayer
that make a network protocol. The stack will start with aNetworkLayer
instance, optionally followed by a series ofFilterLayer
instances and terminated by aApplicationLayer
instance. Instances are created using theon(NetworkLayer)
entry point, for exampleProtocolStack.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)
- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProtocolStack.Builder
Builder forProtocolStack
instances.static interface
ProtocolStack.Listener
Callback "interface" for changes in the state ofProtocolStack
.class
ProtocolStack.Ptr
Tracks where aProtocolLayer
is in theProtocolStack
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 thisProtocolStack
's handshaking timeout.TimeUnit
getHandshakingUnits()
Gets theTimeUnit
ofgetHandshakingTimeout()
.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 aProtocolStack
on the suppliedNetworkLayer
.void
release(ByteBuffer buffer)
Returns a buffer to the pool.void
removeListener(ProtocolStack.Listener listener)
Removes a listener.String
toString()
static void
waitForStart()
-
-
-
Method Detail
-
on
public static ProtocolStack.Builder on(NetworkLayer network)
Create aProtocolStack
on the suppliedNetworkLayer
.- Parameters:
network
- theNetworkLayer
to build the stack on.- Returns:
- the
ProtocolStack.Builder
.
-
waitForStart
public static void waitForStart() throws InterruptedException
- Throws:
InterruptedException
-
get
public T get()
Gets the application specific API.- Returns:
- the application specific API.
- See Also:
ApplicationLayer.get()
-
name
public String name()
The name of this stack to use in logging.- Returns:
- the name of this stack to use in logging.
-
name
public void name(String name)
Updates the name of this stack to use in logging.- Parameters:
name
- the new name of this stack to use in logging.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
addListener
public void addListener(ProtocolStack.Listener listener)
Adds a listener.- Parameters:
listener
- the listener.
-
removeListener
public void removeListener(ProtocolStack.Listener listener)
Removes a listener.- Parameters:
listener
- the listener.
-
execute
@OverrideMustInvoke public void execute(Runnable task)
Executes the given command at some time in the future.- Parameters:
task
- the runnable task- Throws:
RejectedExecutionException
- if this task cannot be accepted for executionNullPointerException
- if task is null
-
executeLater
@OverrideMustInvoke public Future<?> executeLater(Runnable task, long delay, TimeUnit units)
Executes a task at a future point in time. This method should not be used for timing critical scheduling, rather it is intended to be used for things such as protocol timeouts.- Parameters:
task
- the task.delay
- the delay.units
- the time units for the delay.- Returns:
- a
Future
that completes when the task has run and can be used to cancel the execution. - Throws:
RejectedExecutionException
- if this task cannot be accepted for executionNullPointerException
- if task is null
-
getHandshakingTimeout
public long getHandshakingTimeout()
Gets thisProtocolStack
's handshaking timeout.- Returns:
- this
ProtocolStack
's handshaking timeout. - See Also:
getHandshakingUnits()
-
getHandshakingUnits
public TimeUnit getHandshakingUnits()
Gets theTimeUnit
ofgetHandshakingTimeout()
.- Returns:
- the
TimeUnit
ofgetHandshakingTimeout()
. - See Also:
()
-
acquire
public ByteBuffer acquire(int size)
Borrow a buffer from the pool.- Specified by:
acquire
in interfaceByteBufferPool
- Parameters:
size
- The minimum size and initial limit of the buffer.- Returns:
- the buffer.
-
release
public void release(ByteBuffer buffer)
Returns a buffer to the pool.- Specified by:
release
in interfaceByteBufferPool
- Parameters:
buffer
- the buffer.
-
-