Top Description Fields Constructors Methods
org.glassfish.tyrus.core

pack-priv Class InputStreamBuffer

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.nio.ByteBuffer, java.util.ArrayList, .List, java.util.concurrent.ExecutorService, java.util.concurrent.locks.Condition, .ReentrantLock, java.util.logging.Level, .Logger, jakarta.websocket.MessageHandler, org.glassfish.tyrus.core.l10n.LocalizationMessages

Buffer used for the case when partial messages are received by the MessageHandler.Whole.

For the first received message MessageHandler.Whole#onMessage(Object) is called in a new Thread to allow blocking reading of passed java.io.InputStream.

Authors
Danny Coward, Stepan Kopriva, Pavel Bucek

Field Summary

Modifier and TypeField and Description
private final List<ByteBuffer>
private volatile int
private final Condition
private volatile int
private final ExecutorService
private volatile BufferedInputStream
private final ReentrantLock
private static final Logger
private volatile MessageHandler.Whole<InputStream>
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
InputStreamBuffer(ExecutorService executorService)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
appendMessagePart(ByteBuffer
the message.
message
,
boolean
should be true iff this is the last part of the message, false otherwise.
last
)

Append next message part to the buffer.

private void
public void
finishReading()

Finish reading of the buffer.

public int

Returns:

next received bytes.
getNextByte
()

Get next received bytes.

pack-priv void
public void
resetBuffer(int
the size to be set.
bufferSize
)

Reset the buffer size.

public void
setMessageHandler(MessageHandler.Whole<InputStream>
MessageHandler that will consume the constructed java.io.InputStream.
messageHandler
)

Set the MessageHandler that will consume the constructed java.io.InputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferedFragmentsback to summary
private final List<ByteBuffer> bufferedFragments
bufferSizeback to summary
private volatile int bufferSize
conditionback to summary
private final Condition condition
currentlyBufferedback to summary
private volatile int currentlyBuffered
executorServiceback to summary
private final ExecutorService executorService
inputStreamback to summary
private volatile BufferedInputStream inputStream
lockback to summary
private final ReentrantLock lock
LOGGERback to summary
private static final Logger LOGGER
messageHandlerback to summary
private volatile MessageHandler.Whole<InputStream> messageHandler
receivedLastback to summary
private volatile boolean receivedLast
sessionClosedback to summary
private volatile boolean sessionClosed

Constructor Detail

InputStreamBufferback to summary
public InputStreamBuffer(ExecutorService executorService)

Constructor.

Method Detail

appendMessagePartback to summary
public void appendMessagePart(ByteBuffer message, boolean last)

Append next message part to the buffer.

Parameters
message:ByteBuffer

the message.

last:boolean

should be true iff this is the last part of the message, false otherwise.

checkClosedSessionback to summary
private void checkClosedSession() throws IOException
finishReadingback to summary
public void finishReading()

Finish reading of the buffer.

getNextByteback to summary
public int getNextByte() throws IOException

Get next received bytes.

Returns:int

next received bytes.

onSessionClosedback to summary
pack-priv void onSessionClosed()
resetBufferback to summary
public void resetBuffer(int bufferSize)

Reset the buffer size.

Parameters
bufferSize:int

the size to be set.

setMessageHandlerback to summary
public void setMessageHandler(MessageHandler.Whole<InputStream> messageHandler)

Set the MessageHandler that will consume the constructed java.io.InputStream.

Parameters
messageHandler:MessageHandler.Whole<InputStream>

MessageHandler that will consume the constructed java.io.InputStream.