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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidSPI: Implementations ofApplicationLayershould use this method to request that the read path of theProtocolStackbe closed.final voidSPI: Implementations ofApplicationLayershould use this method to request that the write path of theProtocolStackbe closed.abstract Tget()SPI: Returns the application specific API instance.final voidinit(ProtocolStack<?>.Ptr ptr) Initializes the layer with itsProtocolStack.Ptr.abstract booleanSPI: Implementations ofApplicationLayermust ensure this method either returnstruewhile the application specific API instance (get()) is accepting data viaonRead(ByteBuffer)or returnsfalseonce it is permanently closed to incoming data.final booleanTracks if this layer is accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer).final booleanSPI: Implementations ofApplicationLayershould use method to detect if theProtocolStackis open for writing viawrite(ByteBuffer)or has been closed.abstract voidonRead(ByteBuffer data) SPI: Callback on data being received from the protocol stack.abstract voidonReadClosed(IOException cause) Callback on the lower layer's source of data being closed.final voidonRecv(ByteBuffer data) Callback on data being received from the lower layer.final voidonRecvClosed(IOException cause) Callback on the lower layer's source of data being closed.protected ProtocolStack<?>stack()Accessor for theProtocolStackthat we are bound to.final voidwrite(ByteBuffer data) SPI: Implementations ofApplicationLayershould 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, waitMethods 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 ofApplicationLayermust ensure this method either returnstruewhile the application specific API instance (get()) is accepting data viaonRead(ByteBuffer)or returnsfalseonce it is permanently closed to incoming data. If the application specific API instance is temporarily not accepting data then this method should returntrueand the implementation is responsible for caching the data submitted in calls toonRead(ByteBuffer)Once this method returnsfalseit must always returnfalseand can be assumed to behave in this way.- Returns:
trueif 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 theByteBuffercan be assumed as processed. Any data not consumed from theByteBufferwill 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:
initin interfaceProtocolLayer- Parameters:
ptr- the position of this layer in the stack.- Throws:
IOException- if something goes wrong.
-
isWriteOpen
public final boolean isWriteOpen()SPI: Implementations ofApplicationLayershould use method to detect if theProtocolStackis open for writing viawrite(ByteBuffer)or has been closed. Once this method returnsfalseit will always returnfalseand can be assumed to behave in this way.- Returns:
trueif theProtocolStackis open for writing viawrite(ByteBuffer).
-
write
SPI: Implementations ofApplicationLayershould use this method to write data through theProtocolStack.- Parameters:
data- the data to write. Any data consumed from theByteBuffercan be assumed as processed. Any data not consumed from theByteBufferwill 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 ofApplicationLayershould use this method to request that the write path of theProtocolStackbe closed. Depending on the nature of theNetworkLayerthis 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 ofApplicationLayershould use this method to request that the read path of theProtocolStackbe closed. Depending on the nature of theNetworkLayerthis 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 theProtocolStackthat we are bound to.- Returns:
- the
ProtocolStackthat we are bound to ornullif 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:
onRecvin interfaceProtocolLayer.Recv- Parameters:
data- the data received. Any data consumed from theByteBuffercan be assumed as processed. Any data not consumed from theByteBufferwill 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:
onRecvClosedin 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 returnsfalseit must always returnfalseand can be assumed to behave in this way.- Specified by:
isRecvOpenin interfaceProtocolLayer.Recv- Returns:
trueif accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer).
-