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 classBuilder forProtocolStackinstances.static interfaceCallback "interface" for changes in the state ofProtocolStack.classTracks where aProtocolLayeris in theProtocolStack. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int size) Borrow a buffer from the pool.voidaddListener(ProtocolStack.Listener listener) Adds a listener.voidclose()booleanvoidExecutes 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.longGets thisProtocolStack's handshaking timeout.Gets theTimeUnitofgetHandshakingTimeout().inthashCode()name()The name of this stack to use in logging.voidUpdates the name of this stack to use in logging.static ProtocolStack.Builderon(NetworkLayer network) Create aProtocolStackon the suppliedNetworkLayer.voidrelease(ByteBuffer buffer) Returns a buffer to the pool.voidremoveListener(ProtocolStack.Listener listener) Removes a listener.toString()static void
-
Method Details
-
on
Create aProtocolStackon the suppliedNetworkLayer.- Parameters:
network- theNetworkLayerto 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:
closein interfaceAutoCloseable- Specified by:
closein 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
Futurethat 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 theTimeUnitofgetHandshakingTimeout().- Returns:
- the
TimeUnitofgetHandshakingTimeout(). - See Also:
-
acquire
Borrow a buffer from the pool.- Specified by:
acquirein interfaceByteBufferPool- Parameters:
size- The minimum size and initial limit of the buffer.- Returns:
- the buffer.
-
release
Returns a buffer to the pool.- Specified by:
releasein interfaceByteBufferPool- Parameters:
buffer- the buffer.
-