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
A stack of
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)
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder forProtocolStack
instances.static interface
Callback "interface" for changes in the state ofProtocolStack
.class
Tracks where aProtocolLayer
is in theProtocolStack
. -
Method Summary
Modifier and TypeMethodDescriptionacquire
(int size) Borrow a buffer from the pool.void
addListener
(ProtocolStack.Listener listener) Adds a listener.void
close()
boolean
void
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.get()
Gets the application specific API.long
Gets thisProtocolStack
's handshaking timeout.Gets theTimeUnit
ofgetHandshakingTimeout()
.int
hashCode()
name()
The name of this stack to use in logging.void
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.toString()
static void
-
Method Details
-
on
Create aProtocolStack
on the suppliedNetworkLayer
.- Parameters:
network
- theNetworkLayer
to build the stack on.- Returns:
- the
ProtocolStack.Builder
.
-
waitForStart
- Throws:
InterruptedException
-
get
Gets the application specific API.- Returns:
- the application specific API.
- See Also:
-
name
The name of this stack to use in logging.- Returns:
- the name of this stack to use in logging.
-
name
Updates the name of this stack to use in logging.- Parameters:
name
- the new name of this stack to use in logging.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
addListener
Adds a listener.- Parameters:
listener
- the listener.
-
removeListener
Removes a listener.- Parameters:
listener
- the listener.
-
hashCode
public int hashCode() -
equals
-
toString
-
execute
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
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
Gets theTimeUnit
ofgetHandshakingTimeout()
.- Returns:
- the
TimeUnit
ofgetHandshakingTimeout()
. - See Also:
-
acquire
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
Returns a buffer to the pool.- Specified by:
release
in interfaceByteBufferPool
- Parameters:
buffer
- the buffer.
-