Package org.jenkinsci.remoting.protocol
Class ApplicationLayer<T>
java.lang.Object
org.jenkinsci.remoting.protocol.ApplicationLayer<T>
- Type Parameters:
T
- the application specific API.
- All Implemented Interfaces:
ProtocolLayer
,ProtocolLayer.Recv
- Direct Known Subclasses:
ChannelApplicationLayer
public abstract class ApplicationLayer<T>
extends Object
implements ProtocolLayer, ProtocolLayer.Recv
The highest
ProtocolLayer
in a ProtocolStack
. This layer is responsible for translating the protocol stack
into the application specific API.- Since:
- 3.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer
ProtocolLayer.Recv, ProtocolLayer.Send
-
Field Summary
Fields inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer
EMPTY_BUFFER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
SPI: Implementations ofApplicationLayer
should use this method to request that the read path of theProtocolStack
be closed.final void
SPI: Implementations ofApplicationLayer
should use this method to request that the write path of theProtocolStack
be closed.abstract T
get()
SPI: Returns the application specific API instance.final void
init
(ProtocolStack<?>.Ptr ptr) Initializes the layer with itsProtocolStack.Ptr
.abstract boolean
SPI: Implementations ofApplicationLayer
must ensure this method either returnstrue
while the application specific API instance (get()
) is accepting data viaonRead(ByteBuffer)
or returnsfalse
once it is permanently closed to incoming data.final boolean
Tracks if this layer is accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer)
.final boolean
SPI: Implementations ofApplicationLayer
should use method to detect if theProtocolStack
is open for writing viawrite(ByteBuffer)
or has been closed.abstract void
onRead
(ByteBuffer data) SPI: Callback on data being received from the protocol stack.abstract void
onReadClosed
(IOException cause) Callback on the lower layer's source of data being closed.final void
onRecv
(ByteBuffer data) Callback on data being received from the lower layer.final void
onRecvClosed
(IOException cause) Callback on the lower layer's source of data being closed.protected ProtocolStack<?>
stack()
Accessor for theProtocolStack
that we are bound to.final void
write
(ByteBuffer data) SPI: Implementations ofApplicationLayer
should use this method to write data through theProtocolStack
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jenkinsci.remoting.protocol.ProtocolLayer
start
-
Constructor Details
-
ApplicationLayer
public ApplicationLayer()
-
-
Method Details
-
get
SPI: Returns the application specific API instance.- Returns:
- the application specific API instance.
-
isReadOpen
public abstract boolean isReadOpen()SPI: Implementations ofApplicationLayer
must ensure this method either returnstrue
while the application specific API instance (get()
) is accepting data viaonRead(ByteBuffer)
or returnsfalse
once it is permanently closed to incoming data. If the application specific API instance is temporarily not accepting data then this method should returntrue
and the implementation is responsible for caching the data submitted in calls toonRead(ByteBuffer)
Once this method returnsfalse
it must always returnfalse
and can be assumed to behave in this way.- Returns:
true
if the application specific API instance (get()
is accepting data viaonRead(ByteBuffer)
-
onRead
SPI: Callback on data being received from the protocol stack.- Parameters:
data
- the data received. Any data consumed from theByteBuffer
can be assumed as processed. Any data not consumed from theByteBuffer
will be the responsibility of the caller to resubmit in subsequent calls.- Throws:
IOException
- if there was an error during processing of the received data.
-
onReadClosed
Callback on the lower layer's source of data being closed.- Parameters:
cause
- the cause of the lower layer being closed ornull
.- Throws:
IOException
- if there was an error during the processing of the close notification.
-
init
Initializes the layer with itsProtocolStack.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 toProtocolLayer.start()
.- Specified by:
init
in interfaceProtocolLayer
- Parameters:
ptr
- the position of this layer in the stack.- Throws:
IOException
- if something goes wrong.
-
isWriteOpen
public final boolean isWriteOpen()SPI: Implementations ofApplicationLayer
should use method to detect if theProtocolStack
is open for writing viawrite(ByteBuffer)
or has been closed. Once this method returnsfalse
it will always returnfalse
and can be assumed to behave in this way.- Returns:
true
if theProtocolStack
is open for writing viawrite(ByteBuffer)
.
-
write
SPI: Implementations ofApplicationLayer
should use this method to write data through theProtocolStack
.- Parameters:
data
- the data to write. Any data consumed from theByteBuffer
can be assumed as processed. Any data not consumed from theByteBuffer
will be the responsibility of the caller to resubmit in subsequent calls.- Throws:
IOException
- if there was an error during processing of the data.
-
doCloseWrite
SPI: Implementations ofApplicationLayer
should use this method to request that the write path of theProtocolStack
be closed. Depending on the nature of theNetworkLayer
this may force closed the read path (e.g. if the backing transport is using aSocketChannel
).- Throws:
IOException
- if there was an error during the closing of the write path.
-
doCloseRead
SPI: Implementations ofApplicationLayer
should use this method to request that the read path of theProtocolStack
be closed. Depending on the nature of theNetworkLayer
this may force closed the write path (e.g. if the backing transport is using aSocketChannel
).- Throws:
IOException
- if there was an error during the closing of the read path.
-
stack
Accessor for theProtocolStack
that we are bound to.- Returns:
- the
ProtocolStack
that we are bound to ornull
if we are not currently bound to a stack.
-
onRecv
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void onRecv(@NonNull ByteBuffer data) throws IOException Callback on data being received from the lower layer.- Specified by:
onRecv
in interfaceProtocolLayer.Recv
- Parameters:
data
- the data received. Any data consumed from theByteBuffer
can be assumed as processed. Any data not consumed from theByteBuffer
will be the responsibility of the caller to resubmit in subsequent calls.- Throws:
IOException
- if there was an error during processing of the received data.
-
onRecvClosed
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void onRecvClosed(IOException cause) throws IOException Callback on the lower layer's source of data being closed.- Specified by:
onRecvClosed
in interfaceProtocolLayer.Recv
- Parameters:
cause
- the cause of the lower layer being closed ornull
.- Throws:
IOException
- if there was an error during the processing of the close notification.
-
isRecvOpen
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final boolean isRecvOpen()Tracks if this layer is accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer)
. Once this method returnsfalse
it must always returnfalse
and can be assumed to behave in this way.- Specified by:
isRecvOpen
in interfaceProtocolLayer.Recv
- Returns:
true
if accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer)
.
-