Package org.jenkinsci.remoting.protocol
Class FilterLayer
java.lang.Object
org.jenkinsci.remoting.protocol.FilterLayer
- All Implemented Interfaces:
ProtocolLayer,ProtocolLayer.Recv,ProtocolLayer.Send
- Direct Known Subclasses:
AckFilterLayer,AgentProtocolClientFilterLayer,ConnectionHeadersFilterLayer,SSLEngineFilterLayer
public abstract class FilterLayer
extends Object
implements ProtocolLayer, ProtocolLayer.Send, ProtocolLayer.Recv
An intermediate
ProtocolLayer in a ProtocolStack. This layer can be responsible for
- Filtering the data stream
- Initial handshaking
- Transforming the data stream, e.g. encryption
- Monitoring the data stream
- etc.
- 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 TypeMethodDescriptionprotected final voidabort(IOException cause) TheFilterLayerimplementation calls this to signify that a critical error in the stack has occurred and that the stack should be torn down and closed.protected final voidTheFilterLayerimplementation calls this to signify that it is now a no-op layer in both directions and can be removed from theProtocolStackvoidNotify the lower layer that it should close.abstract voiddoSend(ByteBuffer data) SPI: Sends data to the lower layer.protected final voidflushRecv(ByteBufferQueue queue) protected final voidflushSend(ByteBufferQueue queue) Flushes the suppliedByteBufferQueuetonext()'sProtocolStack.Ptr.doSend(ByteBuffer)This method is especially helpful forFilterLayerimplementations that are involved in initial handshaking as they will need to queue up data until the handshake is completed and then flush the data to the remainder of the stack.final voidinit(ProtocolStack<?>.Ptr ptr) Initializes the layer with itsProtocolStack.Ptr.booleanTracks if this layer is accepting received data viaProtocolLayer.Recv.onRecv(ByteBuffer).booleanTracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer).protected ProtocolStack<?>.Ptrnext()Accessor for the next layers in theProtocolStack.abstract voidonRecv(ByteBuffer data) SPI: Callback on data being received from the lower layer.voidonRecvClosed(IOException cause) Callback on the lower layer's source of data being closed.protected ProtocolStack<?>stack()Accessor for theProtocolStackthat we are bound to.voidstart()Starts this layer.
-
Constructor Details
-
FilterLayer
public FilterLayer()
-
-
Method Details
-
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.
-
start
Starts this layer. All layers in the stack will be initialized before a call to this method. All lower layers in the stack will have been started before this layer is started.- Specified by:
startin interfaceProtocolLayer- Throws:
IOException- if something goes wrong.
-
completed
protected final void completed()TheFilterLayerimplementation calls this to signify that it is now a no-op layer in both directions and can be removed from theProtocolStack -
abort
TheFilterLayerimplementation calls this to signify that a critical error in the stack has occurred and that the stack should be torn down and closed.- Parameters:
cause- the root cause to report.
-
stack
Accessor for theProtocolStackthat we are bound to.- Returns:
- the
ProtocolStackthat we are bound to ornullif we are not currently bound to a stack.
-
next
Accessor for the next layers in theProtocolStack.- Returns:
- our
ProtocolStack.Ptrornullif we are not currently bound to a stack.
-
flushRecv
Flushes the suppliedByteBufferQueuetonext()'sProtocolStack.Ptr.onRecv(ByteBuffer). This method is especially helpful forFilterLayerimplementations that are involved in initial handshaking as they will need to queue up data until the handshake is completed and then flush the data to the remainder of the stack.- Parameters:
queue- the data to receive.- Throws:
IOException- if there is an I/O error during the receive.
-
flushSend
Flushes the suppliedByteBufferQueuetonext()'sProtocolStack.Ptr.doSend(ByteBuffer)This method is especially helpful forFilterLayerimplementations that are involved in initial handshaking as they will need to queue up data until the handshake is completed and then flush the data to the remainder of the stack.- Parameters:
queue- the data to send.- Throws:
IOException- if there is an I/O error during the receive.
-
onRecv
SPI: 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
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
public 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).
-
doSend
SPI: Sends data to the lower layer.- Specified by:
doSendin interfaceProtocolLayer.Send- Parameters:
data- the data to send. 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.
-
doCloseSend
Notify the lower layer that it should close. Callers to this method are assumed to have already calledProtocolLayer.Recv.onRecvClosed(IOException)for any upper layers.- Specified by:
doCloseSendin interfaceProtocolLayer.Send- Throws:
IOException- if there was an error closing the lower layer.
-
isSendOpen
public boolean isSendOpen()Tracks if this layer is submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer). Once this method returnsfalseit must always returnfalseand can be assumed to behave in this way.- Specified by:
isSendOpenin interfaceProtocolLayer.Send- Returns:
trueif submitting data to be sent viaProtocolLayer.Send.doSend(ByteBuffer).
-