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

pack-priv Class ReaderBuffer

extends Object
Class Inheritance
Imports
java.io.IOException, .Reader, java.util.concurrent.ExecutorService, java.util.concurrent.atomic.AtomicBoolean, 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 within a new executor to allow blocking reading of passed Reader.

Authors
Danny Coward, Stepan Kopriva, Pavel Bucek

Field Summary

Modifier and TypeField and Description
private volatile StringBuffer
private final AtomicBoolean
private volatile int
private final Condition
private volatile int
private final ExecutorService
private final ReentrantLock
private static final Logger
private volatile MessageHandler.Whole<Reader>
private volatile BufferedStringReader
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
ReaderBuffer(ExecutorService executorService)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
appendMessagePart(String
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 char[]

Returns:

next received chars.
getNextChars
(int number)

Get next received chars.

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

Reset the buffer size.

public void
setMessageHandler(MessageHandler.Whole<Reader>
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

bufferback to summary
private volatile StringBuffer buffer
bufferingback to summary
private final AtomicBoolean buffering
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
lockback to summary
private final ReentrantLock lock
LOGGERback to summary
private static final Logger LOGGER
messageHandlerback to summary
private volatile MessageHandler.Whole<Reader> messageHandler
readerback to summary
private volatile BufferedStringReader reader
receivedLastback to summary
private volatile boolean receivedLast
sessionClosedback to summary
private volatile boolean sessionClosed

Constructor Detail

ReaderBufferback to summary
public ReaderBuffer(ExecutorService executorService)

Constructor.

Method Detail

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

Append next message part to the buffer.

Parameters
message:String

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.

getNextCharsback to summary
public char[] getNextChars(int number) throws IOException

Get next received chars.

Returns:char[]

next received chars.

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<Reader> messageHandler)

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

Parameters
messageHandler:MessageHandler.Whole<Reader>

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