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

public Class TyrusEndpointWrapper

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .Reader, .StringReader, .StringWriter, .Writer, java.lang.reflect.InvocationTargetException, .Method, java.net.URI, java.nio.ByteBuffer, java.security.AccessController, .Principal, java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.Callable, .ConcurrentHashMap, .ExecutionException, .ExecutorService, .Future, java.util.concurrent.atomic.AtomicBoolean, java.util.logging.Level, .Logger, jakarta.websocket.CloseReason, .DecodeException, .Decoder, .DeploymentException, .EncodeException, .Encoder, .Endpoint, .EndpointConfig, .Extension, .MessageHandler, .PongMessage, .RemoteEndpoint, .Session, .WebSocketContainer, jakarta.websocket.server.HandshakeRequest, .ServerEndpointConfig, org.glassfish.tyrus.core.cluster.BroadcastListener, .ClusterContext, .RemoteSession, org.glassfish.tyrus.core.coder.CoderWrapper, .InputStreamDecoder, .NoOpByteArrayCoder, .NoOpByteBufferCoder, .NoOpTextCoder, .PrimitiveDecoders, .ReaderDecoder, .ToStringEncoder, org.glassfish.tyrus.core.frame.BinaryFrame, .Frame, .TextFrame, .TyrusFrame, org.glassfish.tyrus.core.l10n.LocalizationMessages, org.glassfish.tyrus.core.monitoring.EndpointEventListener, org.glassfish.tyrus.spi.UpgradeRequest, .UpgradeResponse

Wraps the registered application class.

There is one TyrusEndpointWrapper for each application class, which handles all the methods.

Authors
Danny Coward, Stepan Kopriva, Martin Matula, Pavel Bucek

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
public abstract static class

Field Summary

Modifier and TypeField and Description
private final ClusterContext
private final Map<String, RemoteSession>
private final ComponentProviderService
private final EndpointConfig
private final ServerEndpointConfig.Configurator
private final WebSocketContainer
container

The container for this session.

private final String
private final List<CoderWrapper<Decoder>>
private static final Session
dummySession

Used only as a placeholder to get encoder instances from ComponentProvider.

private final List<CoderWrapper<Encoder>>
private final Endpoint
private final Class<? extends Endpoint>
private final EndpointEventListener
private final String
private static final boolean
private static final AtomicBoolean
private static final Logger
private static final int
MIN_SESSIONS_PER_THREAD

Used as threshold for parallel broadcast.

private final Method
private final Method
private final Method
private final boolean
private final boolean
private final String
private final TyrusEndpointWrapper.SessionListener
private final Map<TyrusWebSocket, TyrusSession>

Constructor Summary

AccessConstructor and Description
public
TyrusEndpointWrapper(Class<? extends Endpoint>
endpoint class for which the wrapper is created.
endpointClass
,
EndpointConfig
endpoint configuration.
configuration
,
ComponentProviderService
component provider.
componentProvider
,
WebSocketContainer
container where the wrapper is running.
container
,
String
context path of the application.
contextPath
,
ServerEndpointConfig.Configurator
endpoint configurator.
configurator
,
TyrusEndpointWrapper.SessionListener
session listener.
sessionListener
,
ClusterContext
cluster context instance. null indicates standalone mode.
clusterContext
,
EndpointEventListener
endpoint event listener.
endpointEventListener
,
Boolean
true if parallel broadcast should be enabled, true is default.
parallelBroadcastEnabled
)

Create TyrusEndpointWrapper for class that extends Endpoint.

public
TyrusEndpointWrapper(Endpoint
endpoint instance for which the wrapper is created.
endpoint
,
EndpointConfig
endpoint configuration.
configuration
,
ComponentProviderService
component provider.
componentProvider
,
WebSocketContainer
container where the wrapper is running.
container
,
String
context path of the application.
contextPath
,
ServerEndpointConfig.Configurator
endpoint configurator.
configurator
,
TyrusEndpointWrapper.SessionListener
session listener.
sessionListener
,
ClusterContext
cluster context instance. null indicates standalone mode.
clusterContext
,
EndpointEventListener
endpoint event listener.
endpointEventListener
,
Boolean
true if parallel broadcast should be enabled, true is default.
parallelBroadcastEnabled
)

Create TyrusEndpointWrapper for Endpoint instance or AnnotatedEndpoint instance.

private
TyrusEndpointWrapper(Endpoint endpoint, Class<? extends Endpoint> endpointClass, EndpointConfig configuration, ComponentProviderService componentProvider, WebSocketContainer container, String contextPath, final ServerEndpointConfig.Configurator configurator, TyrusEndpointWrapper.SessionListener sessionListener, final ClusterContext clusterContext, EndpointEventListener endpointEventListener, Boolean parallelBroadcastEnabled)

Method Summary

Modifier and TypeMethod and Description
pack-priv Map<Session, Future<?>>

Returns:

map of sessions and futures for user to get the information about status of the message. Messages send from other cluster nodes are not included.
broadcast
(final String
message to be broadcasted.
message
)

Broadcasts text message to all connected clients.

private Map<Session, Future<?>>
broadcast(final String message, boolean local)

pack-priv Map<Session, Future<?>>

Returns:

map of sessions and futures for user to get the information about status of the message. Messages send from other cluster nodes are not included.
broadcast
(final ByteBuffer
message to be broadcasted.
message
)

Broadcasts binary message to all connected clients.

private Map<Session, Future<?>>
broadcast(final ByteBuffer message, boolean local)

private Map<Session, Future<?>>

Returns:

map of send futures.
broadcast
(TyrusEndpointWrapper.SessionCallable
callable which serializes a frame to byte[] and passes it to org.glassfish.tyrus.core.TyrusWebSocket. The org.glassfish.tyrus.core.TyrusEndpointWrapper.SessionCallable also handles extensions, if any.
broadcastCallable
)

Perform broadcast.

private HandshakeRequest
createHandshakeRequest(final UpgradeRequest webSocketRequest)

public Session

Returns:

Session representing the connection.
createSessionForRemoteEndpoint
(TyrusWebSocket
the other end of the connection.
socket
,
String
used.
subprotocol
,
List<Extension>
extensions used.
extensions
,
DebugContext
debug context.
debugContext
)

Creates a Session based on the TyrusWebSocket, subprotocols and extensions.

pack-priv TyrusWebSocket

Returns:

TODO
createSocket
(final ProtocolHandler
the ProtocolHandler to use with the newly created TyrusWebSocket.
handler
)

Factory method to create new TyrusWebSocket instances.

pack-priv Object
decodeCompleteMessage(TyrusSession session, Object message, Class<?> type, CoderWrapper<Decoder> selectedDecoder)

public Object
doEncode(Session session, Object message)

private Map<Session, Future<?>>

Returns:

futures of the operations executed on each session.
executeInParallel
(final TyrusEndpointWrapper.SessionCallable
operation to be executed on open sessions.
broadcastCallable
)

Divides open sessions into subsets on which an operation passed as broadcastCallable will be executed in parallel.

private ArrayList<CoderWrapper<Decoder>>
findApplicableDecoders(TyrusSession session, Object message, boolean isString)

private <T> Object
getCoderInstance(Session session, CoderWrapper<T> wrapper)

private Class<?>
getDecoderClassType(Class<?> decoderClass)

pack-priv List<Decoder>

Returns:

List of registered Decoders.
getDecoders
()

Registered Decoders.

pack-priv static List<Class<? extends Decoder>>
private Class<?>
getEncoderClassType(Class<?> encoderClass)

public EndpointConfig

Returns:

configuration.
getEndpointConfig
()

Get Endpoint configuration.

public String

Returns:

endpoint absolute path.
getEndpointPath
()

Server-side; Get Endpoint absolute path.

pack-priv List<Extension>

Returns:

names of extensions supported by both client and class that implements this one.
getNegotiatedExtensions
(List<Extension>
names of the extensions' supported by client.
clientExtensions
)

Server-side; Get the negotiated extensions' names based on the extensions supported by client.

pack-priv String

Returns:

negotiated sub-protocol, null if none found.
getNegotiatedProtocol
(List<String>
sub-protocols supported by client.
clientProtocols
)

Server-side; Compute the sub-protocol which will be used.

pack-priv Set<TyrusSession>

Returns:

open sessions.
getOpenSessions
()

Get the set of open TyrusSession.

pack-priv Set<RemoteSession>
pack-priv String

Returns:

server endpoint path.
getServerEndpointPath
()

Server-side; Get server endpoint path.

private TyrusSession
private static URI
getURI(String uri, String queryString)

private void
private void
pack-priv void
onClose(TyrusWebSocket
TyrusWebSocket who has just closed the connection.
socket
,
CloseReason closeReason)

Called by the provider when the web socket connection to the given remote endpoint has just closed.

pack-priv Session

Returns:

Created Session instance or null when session was not created properly (max sessions limit on endpoint or application or issues with endpoint validation).
onConnect
(TyrusWebSocket
TyrusWebSocket who has just connected to this web socket endpoint.
socket
,
UpgradeRequest
request associated with accepted connection.
upgradeRequest
,
String subProtocol, List<Extension> extensions, String connectionId, DebugContext
debug context.
debugContext
)

Called by the provider when the web socket connection is established.

pack-priv boolean

Returns:

true if the WebSocket should be closed otherwise false.
onError
(TyrusWebSocket
the websocket being processed at the time the exception occurred.
socket
,
Throwable
the unexpected exception.
t
)

This method will be invoked if an unexpected exception is caught by the WebSocket runtime.

pack-priv void
onHandShakeResponse(UpgradeRequest
original request which caused this handshake.
request
,
UpgradeResponse
response to be send.
response
)

Invoked when server side handshake is ready to send response.

pack-priv void
onMessage(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
ByteBuffer
the message.
messageBytes
)

Called by the provider when the web socket connection has an incoming text message from the given remote endpoint.

pack-priv void
onMessage(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
String
the message.
messageString
)

Called by the provider when the web socket connection has an incoming text message from the given remote endpoint.

pack-priv void
onPartialMessage(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
String
the String message.
partialString
,
boolean
to indicate if this is the last partial string in the sequence
last
)

Called by the provider when the web socket connection has an incoming partial text message from the given remote endpoint.

pack-priv void
onPartialMessage(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
ByteBuffer
the piece of the binary message.
partialBytes
,
boolean
to indicate if this is the last partial byte buffer in the sequence
last
)

Called by the provider when the web socket connection has an incoming partial binary message from the given remote endpoint.

pack-priv void
onPing(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
ByteBuffer
the message.
bytes
)

Called by the provider when the web socket connection has an incoming ping message from the given remote endpoint.

pack-priv void
onPong(TyrusWebSocket
TyrusWebSocket who sent the message.
socket
,
final ByteBuffer
the message.
bytes
)

Called by the provider when the web socket connection has an incoming pong message from the given remote endpoint.

private boolean

Returns:

true when exception is handled within this method (framework produced it), false otherwise.
processThrowable
(Throwable
thrown Throwable.
throwable
,
Session
Session related to Throwable.
session
)

Check Throwable produced during jakarta.websocket.OnMessage annotated method call.

private Future<?>

Returns:

future representing outcome of the send operation.
sendBroadcast
(TyrusWebSocket
org.glassfish.tyrus.core.TyrusWebSocket instance used for sending the frame.
webSocket
,
Frame
frame to be sent.
dataFrame
,
TyrusFrame.FrameType
type of the frame (monitoring).
frameType
)

Serialize dataframe and send it to org.glassfish.tyrus.core.TyrusWebSocket.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv final boolean

Returns:

true if the request should be upgraded to a WebSocket connection.
upgrade
(UpgradeRequest
received UpgradeRequest.
request
)

Server side check for protocol specific information to determine whether the request can be upgraded.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait