Top Description Inners Fields Constructors Methods
org.eclipse.jetty.websocket.core.internal

public Class PerMessageDeflateExtension

extends AbstractExtension
implements DemandChain
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.util.DemandChain
Imports
java.nio.ByteBuffer, java.util.HashMap, .Map, java.util.concurrent.atomic.AtomicReference, java.util.zip.DataFormatException, .Deflater, .Inflater, org.eclipse.jetty.io.RetainableByteBuffer, org.eclipse.jetty.util.BufferUtil, .Callback, org.eclipse.jetty.util.compression.DeflaterPool, .InflaterPool, org.eclipse.jetty.websocket.core.AbstractExtension, .ExtensionConfig, .Frame, .OpCode, .WebSocketComponents, org.eclipse.jetty.websocket.core.exception.BadPayloadException, .MessageTooLargeException, .ProtocolException, org.eclipse.jetty.websocket.core.util.DemandChain, .DemandingFlusher, .TransformingFlusher, org.slf4j.Logger, .LoggerFactory

Per Message Deflate Compression extension for WebSocket.

Attempts to follow Compression Extensions for WebSocket

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private ExtensionConfig
private ExtensionConfig
private static final int
private int
private CompressionPool<Deflater>.Entry
private boolean
private boolean
private final PerMessageDeflateExtension.IncomingFlusher
private int
private CompressionPool<Inflater>.Entry
private static final Logger
private boolean
private final PerMessageDeflateExtension.OutgoingFlusher
private static final byte[]
private static final ByteBuffer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides default org.eclipse.jetty.websocket.core.Extension.close.

Used to clean up any resources after connection close.

public void
public static boolean
public Deflater
public Inflater
public String
getName()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.getName.

Implements org.eclipse.jetty.websocket.core.Extension.getName.

The Sec-WebSocket-Extensions name for this extension.

public void
public boolean
isRsv1User()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.isRsv1User.

Implements org.eclipse.jetty.websocket.core.Extension.isRsv1User.

Used to indicate that the extension makes use of the RSV1 bit of the base websocket framing.

protected void
protected void
public void
onFrame(Frame
the frame to process.
frame
,
Callback
the read completion.
callback
)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.onFrame.

Implements org.eclipse.jetty.websocket.core.IncomingFrames.onFrame.

Process the incoming frame.

public void
public void
public void
sendFrame(Frame
the frame to eventually write to the network layer.
frame
,
Callback
the callback to notify when the frame is written.
callback
,
boolean
the batch mode requested by the sender.
batch
)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.sendFrame.

Implements org.eclipse.jetty.websocket.core.OutgoingFrames.sendFrame.

A frame, and optional callback, intended for the network layer.

public void
private static String
toDetail(Inflater inflater)

private static String
toDetail(Deflater deflater)

public String
toString()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.websocket.core.AbstractExtension:
getByteBufferPoolgetConfiggetConfigurationgetCoreSessiongetDeflaterPoolgetInflaterPoolgetNextIncominggetNextOutgoingisRsv2UserisRsv3UsersetCoreSessionsetNextIncomingFramessetNextOutgoingFrames

Field Detail

configNegotiatedback to summary
private ExtensionConfig configNegotiated
configRequestedback to summary
private ExtensionConfig configRequested
DEFAULT_BUF_SIZEback to summary
private static final int DEFAULT_BUF_SIZE
deflateBufferSizeback to summary
private int deflateBufferSize
deflaterHolderback to summary
private CompressionPool<Deflater>.Entry deflaterHolder
incomingCompressedback to summary
private boolean incomingCompressed
incomingContextTakeoverback to summary
private boolean incomingContextTakeover
incomingFlusherback to summary
private final PerMessageDeflateExtension.IncomingFlusher incomingFlusher
inflateBufferSizeback to summary
private int inflateBufferSize
inflaterHolderback to summary
private CompressionPool<Inflater>.Entry inflaterHolder
LOGback to summary
private static final Logger LOG
outgoingContextTakeoverback to summary
private boolean outgoingContextTakeover
outgoingFlusherback to summary
private final PerMessageDeflateExtension.OutgoingFlusher outgoingFlusher
TAIL_BYTESback to summary
private static final byte[] TAIL_BYTES
TAIL_BYTES_BUFback to summary
private static final ByteBuffer TAIL_BYTES_BUF

Constructor Detail

PerMessageDeflateExtensionback to summary
public PerMessageDeflateExtension()

Method Detail

closeback to summary
public void close()

Overrides default org.eclipse.jetty.websocket.core.Extension.close.

Doc from org.eclipse.jetty.websocket.core.Extension.close.

Used to clean up any resources after connection close.

Annotations
@Override
demandback to summary
public void demand()

Implements org.eclipse.jetty.websocket.core.util.DemandChain.demand.

Annotations
@Override
endsWithTailback to summary
public static boolean endsWithTail(ByteBuffer buf)
getDeflaterback to summary
public Deflater getDeflater()
getInflaterback to summary
public Inflater getInflater()
getNameback to summary
public String getName()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.getName.

Implements org.eclipse.jetty.websocket.core.Extension.getName.

Doc from org.eclipse.jetty.websocket.core.Extension.getName.

The Sec-WebSocket-Extensions name for this extension.

Also known as the extension-token per Section 9.1. Negotiating Extensions.

Returns:String

the name of the extension

Annotations
@Override
initback to summary
public void init(final ExtensionConfig config, WebSocketComponents components)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.init.

Implements org.eclipse.jetty.websocket.core.Extension.init.

Annotations
@Override
isRsv1Userback to summary
public boolean isRsv1User()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.isRsv1User.

Implements org.eclipse.jetty.websocket.core.Extension.isRsv1User.

Doc from org.eclipse.jetty.websocket.core.AbstractExtension.isRsv1User.

Used to indicate that the extension makes use of the RSV1 bit of the base websocket framing.

This is used to adjust validation during parsing, as well as a checkpoint against 2 or more extensions all simultaneously claiming ownership of RSV1.

Returns:boolean

true if extension uses RSV1 for its own purposes.

Annotations
@Override
nextIncomingFrameback to summary
protected void nextIncomingFrame(Frame frame, Callback callback)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.nextIncomingFrame.

Annotations
@Override
nextOutgoingFrameback to summary
protected void nextOutgoingFrame(Frame frame, Callback callback, boolean batch)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.nextOutgoingFrame.

Annotations
@Override
onFrameback to summary
public void onFrame(Frame frame, Callback callback)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.onFrame.

Implements org.eclipse.jetty.websocket.core.IncomingFrames.onFrame.

Doc from org.eclipse.jetty.websocket.core.IncomingFrames.onFrame.

Process the incoming frame.

Note

if you need to hang onto any information from the frame, be sure to copy it, as the information contained in the Frame will be released and/or reused by the implementation.

Failure of the callback will propagate the failure back to the CoreSession to fail the connection and attempt to send a close Frame if one has not been sent.

Parameters
frame:Frame

the frame to process.

callback:Callback

the read completion.

Annotations
@Override
releaseDeflaterback to summary
public void releaseDeflater()
releaseInflaterback to summary
public void releaseInflater()
sendFrameback to summary
public void sendFrame(Frame frame, Callback callback, boolean batch)

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.sendFrame.

Implements org.eclipse.jetty.websocket.core.OutgoingFrames.sendFrame.

Doc from org.eclipse.jetty.websocket.core.OutgoingFrames.sendFrame.

A frame, and optional callback, intended for the network layer.

Note

the frame can undergo many transformations in the various layers and extensions present in the implementation.

If you are implementing a mutation, you are obliged to handle the incoming Callback appropriately.

Parameters
frame:Frame

the frame to eventually write to the network layer.

callback:Callback

the callback to notify when the frame is written.

batch:boolean

the batch mode requested by the sender.

Annotations
@Override
setNextDemandback to summary
public void setNextDemand(DemandChain nextDemand)

Overrides default org.eclipse.jetty.websocket.core.util.DemandChain.setNextDemand.

Annotations
@Override
toDetailback to summary
private static String toDetail(Inflater inflater)
toDetailback to summary
private static String toDetail(Deflater deflater)
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.websocket.core.AbstractExtension.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.websocket.core.internal back to summary

private Class PerMessageDeflateExtension.IncomingFlusher

extends DemandingFlusher
Class Inheritance

Field Summary

Modifier and TypeField and Description
private AtomicReference<RetainableByteBuffer>
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
handle(Frame
the original frame.
frame
,
Callback
to succeed to release the frame payload.
callback
,
boolean
if this is the first time this method has been called for this frame.
first
)

Implements abstract org.eclipse.jetty.websocket.core.util.DemandingFlusher.handle.

Called when there is demand for a single frame to be produced.

private boolean
inflate(Frame frame, Callback callback, boolean first)

protected void
onCompleteFailure(Throwable
the throwable to indicate cause of failure
cause
)

Overrides org.eclipse.jetty.websocket.core.util.DemandingFlusher.onCompleteFailure.

Invoked when the overall task has completed with a failure.

private void
Inherited from org.eclipse.jetty.websocket.core.util.DemandingFlusher:
closeFlusherdemandemitFramefailFlusheronFrameprocesssetNextDemand

Field Detail

_payloadRefback to summary
private AtomicReference<RetainableByteBuffer> _payloadRef
_tailBytesback to summary
private boolean _tailBytes

Constructor Detail

IncomingFlusherback to summary
public IncomingFlusher()

Method Detail

handleback to summary
protected boolean handle(Frame frame, Callback callback, boolean first)

Implements abstract org.eclipse.jetty.websocket.core.util.DemandingFlusher.handle.

Doc from org.eclipse.jetty.websocket.core.util.DemandingFlusher.handle.

Called when there is demand for a single frame to be produced. During this method a single call can be made to emitFrame(Frame, Callback) which will forward this frame towards the application. Returning true from this method signals that you are done processing the current Frame, and the next invocation of this method will have the next frame.

Note that the callback supplied here is specially wrapped so that you can call it multiple times and it will not be completed more than once. This simplifies the handling of failure cases.

Parameters
frame:Frame

the original frame.

callback:Callback

to succeed to release the frame payload.

first:boolean

if this is the first time this method has been called for this frame.

Returns:boolean

false to continue processing this frame, true to complete processing and get a new frame.

Annotations
@Override
inflateback to summary
private boolean inflate(Frame frame, Callback callback, boolean first) throws DataFormatException
onCompleteFailureback to summary
protected void onCompleteFailure(Throwable cause)

Overrides org.eclipse.jetty.websocket.core.util.DemandingFlusher.onCompleteFailure.

Doc from org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Parameters
cause:Throwable

the throwable to indicate cause of failure

Annotations
@Override
releasePayloadback to summary
private void releasePayload(AtomicReference<RetainableByteBuffer> reference)
org.eclipse.jetty.websocket.core.internal back to summary

private Class PerMessageDeflateExtension.OutgoingFlusher

extends TransformingFlusher
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private Frame

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private boolean
deflate(Callback callback)

protected boolean
onFrame(Frame
the frame to transform.
frame
,
Callback
used to signal to start processing again.
callback
,
boolean
whether this frame can be batched.
batch
)

Implements abstract org.eclipse.jetty.websocket.core.util.TransformingFlusher.onFrame.

Called when a frame is ready to be transformed.

protected boolean
transform(Callback
used to signal to start processing again.
callback
)

Implements abstract org.eclipse.jetty.websocket.core.util.TransformingFlusher.transform.

Called to transform the frame given in TransformingFlusher#onFrame(Frame, Callback, boolean).

Inherited from org.eclipse.jetty.websocket.core.util.TransformingFlusher:
closeFlusherfailFlushersendFrame

Field Detail

_batchback to summary
private boolean _batch
_firstback to summary
private boolean _first
_frameback to summary
private Frame _frame

Constructor Detail

OutgoingFlusherback to summary
private OutgoingFlusher()

Method Detail

deflateback to summary
private boolean deflate(Callback callback)
onFrameback to summary
protected boolean onFrame(Frame frame, Callback callback, boolean batch)

Implements abstract org.eclipse.jetty.websocket.core.util.TransformingFlusher.onFrame.

Doc from org.eclipse.jetty.websocket.core.util.TransformingFlusher.onFrame.

Called when a frame is ready to be transformed.

Parameters
frame:Frame

the frame to transform.

callback:Callback

used to signal to start processing again.

batch:boolean

whether this frame can be batched.

Returns:boolean

true to indicate that you have finished transforming this frame.

Annotations
@Override
transformback to summary
protected boolean transform(Callback callback)

Implements abstract org.eclipse.jetty.websocket.core.util.TransformingFlusher.transform.

Doc from org.eclipse.jetty.websocket.core.util.TransformingFlusher.transform.

Called to transform the frame given in TransformingFlusher#onFrame(Frame, Callback, boolean). This method is called on each callback success until it returns true. If the call to onFrame(Frame, Callback, boolean) returns true then this method will not be called.

Parameters
callback:Callback

used to signal to start processing again.

Returns:boolean

true to indicate that you have finished transforming this frame.

Annotations
@Override