Top Description Inners Fields Constructors Methods
org.glassfish.tyrus.servlet

pack-priv Class TyrusServletWriter

extends Writer
implements WriteListener
Class Inheritance
All Implemented Interfaces
jakarta.servlet.WriteListener, java.util.EventListener
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.Deque, .LinkedList, java.util.logging.Level, .Logger, jakarta.servlet.ServletOutputStream, .WriteListener, org.glassfish.tyrus.spi.CompletionHandler, .Writer

org.glassfish.tyrus.spi.Writer implementation used in Servlet integration.
Author
Pavel Bucek

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private static final Logger
private final Deque<TyrusServletWriter.QueuedFrame>
private ServletOutputStream
servletOutputStream

ServletOutputStream is not thread safe, must be synchronized.

private final TyrusHttpUpgradeHandler

Constructor Summary

AccessConstructor and Description
public
TyrusServletWriter(TyrusHttpUpgradeHandler
encapsulated TyrusHttpUpgradeHandler instance.
tyrusHttpUpgradeHandler
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
_write(ByteBuffer buffer, CompletionHandler<ByteBuffer> completionHandler)

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public synchronized void
onError(Throwable
the throwable to indicate why the write operation failed
t
)

Implements jakarta.servlet.WriteListener.onError.

Invoked when an error occurs writing data using the non-blocking APIs.

public synchronized void
onWritePossible()

Implements jakarta.servlet.WriteListener.onWritePossible.

When an instance of the WriteListener is registered with a ServletOutputStream, this method will be invoked by the container the first time when it is possible to write data.

public synchronized void
write(final ByteBuffer
bytes to write.
buffer
,
CompletionHandler<ByteBuffer>
completion handler to know the write status.
completionHandler
)

Implements abstract org.glassfish.tyrus.spi.Writer.write.

A backward compatible method called from write(ByteBuffer, CompletionHandler, WriterInfo) to handover the data for a connection to the transport.

Inherited from org.glassfish.tyrus.spi.Writer:
write

Field Detail

isListenerSetback to summary
private boolean isListenerSet
LOGGERback to summary
private static final Logger LOGGER
queueback to summary
private final Deque<TyrusServletWriter.QueuedFrame> queue
servletOutputStreamback to summary
private ServletOutputStream servletOutputStream

ServletOutputStream is not thread safe, must be synchronized.

Access synchronized via "this" - Tyrus creates one instance of TyrusServletWriter per WebSocket connection, so that should be ok.

tyrusHttpUpgradeHandlerback to summary
private final TyrusHttpUpgradeHandler tyrusHttpUpgradeHandler

Constructor Detail

TyrusServletWriterback to summary
public TyrusServletWriter(TyrusHttpUpgradeHandler tyrusHttpUpgradeHandler)

Constructor.

Parameters
tyrusHttpUpgradeHandler:TyrusHttpUpgradeHandler

encapsulated TyrusHttpUpgradeHandler instance.

Method Detail

_writeback to summary
private void _write(ByteBuffer buffer, CompletionHandler<ByteBuffer> completionHandler)
closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
onErrorback to summary
public synchronized void onError(Throwable t)

Implements jakarta.servlet.WriteListener.onError.

Doc from jakarta.servlet.WriteListener.onError.

Invoked when an error occurs writing data using the non-blocking APIs.

Parameters
t:Throwable

the throwable to indicate why the write operation failed

Annotations
@Override
onWritePossibleback to summary
public synchronized void onWritePossible() throws IOException

Implements jakarta.servlet.WriteListener.onWritePossible.

Doc from jakarta.servlet.WriteListener.onWritePossible.

When an instance of the WriteListener is registered with a ServletOutputStream, this method will be invoked by the container the first time when it is possible to write data. Subsequently the container will invoke this method if and only if the jakarta.servlet.ServletOutputStream#isReady() method has been called and has returned a value of false and a write operation has subsequently become possible.

Annotations
@Override
Exceptions
IOException:
if an I/O related error has occurred during processing
writeback to summary
public synchronized void write(final ByteBuffer buffer, CompletionHandler<ByteBuffer> completionHandler)

Implements abstract org.glassfish.tyrus.spi.Writer.write.

Doc from org.glassfish.tyrus.spi.Writer.write.

A backward compatible method called from write(ByteBuffer, CompletionHandler, WriterInfo) to handover the data for a connection to the transport. The transport writes bytes to underlying connection. Tyrus runtime must not use the buffer until the write is completed.

The method will be removed in the next major version.

Parameters
buffer:ByteBuffer

bytes to write.

completionHandler:CompletionHandler<ByteBuffer>

completion handler to know the write status.

Annotations
@Override
org.glassfish.tyrus.servlet back to summary

private Class TyrusServletWriter.QueuedFrame

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final CompletionHandler<ByteBuffer>
public final ByteBuffer

Constructor Summary

AccessConstructor and Description
pack-priv
QueuedFrame(CompletionHandler<ByteBuffer> completionHandler, ByteBuffer dataFrame)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

completionHandlerback to summary
public final CompletionHandler<ByteBuffer> completionHandler
dataFrameback to summary
public final ByteBuffer dataFrame

Constructor Detail

QueuedFrameback to summary
pack-priv QueuedFrame(CompletionHandler<ByteBuffer> completionHandler, ByteBuffer dataFrame)