Class TyrusServerContainer
- All Implemented Interfaces:
ServerContainer,WebSocketContainer,ServerContainer
- Author:
- Martin Matula, Pavel Bucek, Stepan Kopriva
-
Nested Class Summary
Nested classes/interfaces inherited from class org.glassfish.tyrus.core.BaseContainer
BaseContainer.ShutDownCondition -
Constructor Summary
ConstructorsConstructorDescriptionTyrusServerContainer(ServerApplicationConfig serverApplicationConfig) Create newTyrusServerContainerusing already createdServerApplicationConfiginstance.TyrusServerContainer(Set<Class<?>> classes) Create newTyrusServerContainer. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEndpoint(ServerEndpointConfig serverEndpointConfig) Deploys the given endpoint described by the provided configuration into this ServerContainer.voidaddEndpoint(Class<?> endpointClass) Deploys the given annotated endpoint into this ServerContainer.asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, URI path) asyncConnectToServer(Class<?> annotatedEndpointClass, URI path) Non-blocking version ofWebSocketContainer.connectToServer(Class, java.net.URI).asyncConnectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, URI path) Non-blocking version ofWebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI).asyncConnectToServer(Object obj, URI path) Non-blocking version ofWebSocketContainer.connectToServer(Object, java.net.URI).connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, URI path) Connect the supplied programmatic client endpoint instance to its server with the given configuration.connectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, URI path) Connect the supplied programmatic endpoint to its server with the given configuration.connectToServer(Class annotatedEndpointClass, URI path) Connect the supplied annotated endpoint to its server.connectToServer(Object annotatedEndpointInstance, URI path) Connect the supplied annotated endpoint instance to its server.voidContainer is no longer required to acceptaddEndpoint(jakarta.websocket.server.ServerEndpointConfig)andaddEndpoint(Class)calls.protected ClientManagerCan be overridden to provide ownClientManagerimplementation or instance.longReturn the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container.intReturns the default maximum size of incoming binary message that this container will buffer.longReturn the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive.intReturns the default maximum size of incoming text message that this container will buffer.Return the set of Extensions installed in the container.intgetPort()Get port of the started container.abstract voidregister(ServerEndpointConfig serverEndpointConfig) abstract voidvoidsetAsyncSendTimeout(long timeoutmillis) Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container.voidsetDefaultMaxBinaryMessageBufferSize(int max) Sets the default maximum size of incoming binary message that this container will buffer.voidsetDefaultMaxSessionIdleTimeout(long defaultMaxSessionIdleTimeout) Sets the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive.voidsetDefaultMaxTextMessageBufferSize(int max) Sets the maximum size of incoming text message that this container will buffer.voidStart the container.voidstop()Undeploy all endpoints and stop underlyingServerContainer.voidupgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, ServerEndpointConfig sec, Map<String, String> pathParameters) Upgrade the HTTP connection represented by theHttpServletRequestandHttpServletResponseto the WebSocket protocol and establish a WebSocket connection as per the providedServerEndpointConfig.Methods inherited from class org.glassfish.tyrus.core.BaseContainer
getExecutorService, getScheduledExecutorService, shutdown, shutdownMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.glassfish.tyrus.spi.ServerContainer
getWebSocketEngine
-
Constructor Details
-
TyrusServerContainer
Create newTyrusServerContainer.- Parameters:
classes- classes to be included in this application instance. Can contain any combination of annotated endpoints (seeServerEndpoint) orEndpointdescendants.
-
TyrusServerContainer
Create newTyrusServerContainerusing already createdServerApplicationConfiginstance.- Parameters:
serverApplicationConfig- provided application config.
-
-
Method Details
-
start
Start the container.- Specified by:
startin interfaceServerContainer- Parameters:
rootPath- context path of the deployed websocket application.port- TCP port- Throws:
IOException- when any IO related issues emerge duringServerContainer.start(String, int).DeploymentException- when any deployment related error is found; should contain list of all found issues.
-
stop
public void stop()Undeploy all endpoints and stop underlyingServerContainer.Release all created threadpools / executor services.
- Specified by:
stopin interfaceServerContainer
-
register
- Throws:
DeploymentException
-
register
- Throws:
DeploymentException
-
addEndpoint
Description copied from interface:ServerContainerDeploys the given annotated endpoint into this ServerContainer.- Specified by:
addEndpointin interfaceServerContainer- Parameters:
endpointClass- the class of the annotated endpoint- Throws:
DeploymentException- if the annotated endpoint was badly formed.
-
addEndpoint
Description copied from interface:ServerContainerDeploys the given endpoint described by the provided configuration into this ServerContainer.- Specified by:
addEndpointin interfaceServerContainer- Parameters:
serverEndpointConfig- the configuration instance representing the logical endpoint that will be registered.- Throws:
DeploymentException- if the endpoint was badly formed.
-
getPort
public int getPort()Get port of the started container.- Returns:
- the port of the started container or
-1, when the container is not started or the container does not provide the port.
-
getClientManager
Can be overridden to provide ownClientManagerimplementation or instance.- Returns:
ClientManagerassociated with this server container.
-
connectToServer
public Session connectToServer(Class annotatedEndpointClass, URI path) throws DeploymentException, IOException Description copied from interface:WebSocketContainerConnect the supplied annotated endpoint to its server. The supplied object must be a class decorated with the class levelClientEndpointannotation. This method blocks until the connection is established, or throws an error if either the connection could not be made or there was a problem with the supplied endpoint class.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
annotatedEndpointClass- the annotated websocket client endpoint.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the class is not a valid annotated endpoint class.IOException- if there was a network or protocol problem that prevented the client endpoint being connected to its server.
-
connectToServer
public Session connectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, URI path) throws DeploymentException, IOException Description copied from interface:WebSocketContainerConnect the supplied programmatic endpoint to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
endpointClass- the programmatic client endpoint classEndpoint.cec- the configuration used to configure the programmatic endpoint.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the configuration is not validIOException- if there was a network or protocol problem that prevented the client endpoint being connected to its server
-
connectToServer
public Session connectToServer(Object annotatedEndpointInstance, URI path) throws DeploymentException, IOException Description copied from interface:WebSocketContainerConnect the supplied annotated endpoint instance to its server. The supplied object must be a class decorated with the class levelClientEndpointannotation. This method blocks until the connection is established, or throws an error if either the connection could not be made or there was a problem with the supplied endpoint class. If the developer uses this method to deploy the client endpoint, services like dependency injection that are supported, for example, when the implementation is part of the Java EE platform may not be available. If the client endpoint uses dependency injection, useWebSocketContainer.connectToServer(java.lang.Class, java.net.URI)instead.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
annotatedEndpointInstance- the annotated websocket client endpoint instance.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the annotated endpoint instance is not valid.IOException- if there was a network or protocol problem that prevented the client endpoint being connected to its server.
-
connectToServer
public Session connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, URI path) throws DeploymentException, IOException Description copied from interface:WebSocketContainerConnect the supplied programmatic client endpoint instance to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made. If the developer uses this method to deploy the client endpoint, services like dependency injection that are supported, for example, when the implementation is part of the Java EE platform may not be available. If the client endpoint uses dependency injection, useWebSocketContainer.connectToServer(java.lang.Class, jakarta.websocket.ClientEndpointConfig, java.net.URI)instead.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
endpointInstance- the programmatic client endpoint instanceEndpoint.cec- the configuration used to configure the programmatic endpoint.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the configuration is not validIOException- if there was a network or protocol problem that prevented the client endpoint being connected to its server
-
asyncConnectToServer
public Future<Session> asyncConnectToServer(Class<?> annotatedEndpointClass, URI path) throws DeploymentException Non-blocking version ofWebSocketContainer.connectToServer(Class, java.net.URI).Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
- Parameters:
annotatedEndpointClass- the annotated websocket client endpoint.path- the complete path to the server endpoint.- Returns:
- Future for the Session created if the connection is successful.
- Throws:
DeploymentException- if the class is not a valid annotated endpoint class.
-
asyncConnectToServer
public Future<Session> asyncConnectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, URI path) throws DeploymentException Non-blocking version ofWebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI).Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
- Parameters:
endpointClass- the programmatic client endpoint classEndpoint.cec- the configuration used to configure the programmatic endpoint.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the configuration is not valid- See Also:
-
asyncConnectToServer
public Future<Session> asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, URI path) throws DeploymentException Non-blocking version ofWebSocketContainer.connectToServer(jakarta.websocket.Endpoint, jakarta.websocket.ClientEndpointConfig, java.net.URI).Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
- Parameters:
endpointInstance- the programmatic client endpoint instanceEndpoint.cec- the configuration used to configure the programmatic endpoint.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the configuration is not valid- See Also:
-
asyncConnectToServer
Non-blocking version ofWebSocketContainer.connectToServer(Object, java.net.URI).Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
- Parameters:
obj- the annotated websocket client endpoint instance.path- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException- if the annotated endpoint instance is not valid.- See Also:
-
getDefaultMaxBinaryMessageBufferSize
public int getDefaultMaxBinaryMessageBufferSize()Description copied from interface:WebSocketContainerReturns the default maximum size of incoming binary message that this container will buffer. This default may be overridden on a per session basis usingSession.setMaxBinaryMessageBufferSize(int)- Specified by:
getDefaultMaxBinaryMessageBufferSizein interfaceWebSocketContainer- Returns:
- the maximum size of incoming binary message in number of bytes.
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int max) Description copied from interface:WebSocketContainerSets the default maximum size of incoming binary message that this container will buffer.- Specified by:
setDefaultMaxBinaryMessageBufferSizein interfaceWebSocketContainer- Parameters:
max- the maximum size of binary message in number of bytes.
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()Description copied from interface:WebSocketContainerReturns the default maximum size of incoming text message that this container will buffer. This default may be overridden on a per session basis usingSession.setMaxTextMessageBufferSize(int)- Specified by:
getDefaultMaxTextMessageBufferSizein interfaceWebSocketContainer- Returns:
- the maximum size of incoming text message in number of bytes.
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int max) Description copied from interface:WebSocketContainerSets the maximum size of incoming text message that this container will buffer.- Specified by:
setDefaultMaxTextMessageBufferSizein interfaceWebSocketContainer- Parameters:
max- the maximum size of text message in number of bytes.
-
getInstalledExtensions
Description copied from interface:WebSocketContainerReturn the set of Extensions installed in the container.- Specified by:
getInstalledExtensionsin interfaceWebSocketContainer- Returns:
- the set of extensions.
-
getDefaultAsyncSendTimeout
public long getDefaultAsyncSendTimeout()Description copied from interface:WebSocketContainerReturn the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
getDefaultAsyncSendTimeoutin interfaceWebSocketContainer- Returns:
- the timeout time in milliseconds.
-
setAsyncSendTimeout
public void setAsyncSendTimeout(long timeoutmillis) Description copied from interface:WebSocketContainerSets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
setAsyncSendTimeoutin interfaceWebSocketContainer- Parameters:
timeoutmillis- the timeout in milliseconds; use zero or negative value for no timeout
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()Description copied from interface:WebSocketContainerReturn the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is zero or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis usingSession.setMaxIdleTimeout(long)- Specified by:
getDefaultMaxSessionIdleTimeoutin interfaceWebSocketContainer- Returns:
- the default number of milliseconds after which an idle session in this container will be closed
-
setDefaultMaxSessionIdleTimeout
public void setDefaultMaxSessionIdleTimeout(long defaultMaxSessionIdleTimeout) Description copied from interface:WebSocketContainerSets the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is zero or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis usingSession.setMaxIdleTimeout(long)- Specified by:
setDefaultMaxSessionIdleTimeoutin interfaceWebSocketContainer- Parameters:
defaultMaxSessionIdleTimeout- the maximum time in milliseconds; use zero or negative value for no timeout
-
doneDeployment
public void doneDeployment()Container is no longer required to acceptaddEndpoint(jakarta.websocket.server.ServerEndpointConfig)andaddEndpoint(Class)calls. -
upgradeHttpToWebSocket
public void upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, ServerEndpointConfig sec, Map<String, String> pathParameters) throws IOException, DeploymentExceptionDescription copied from interface:ServerContainerUpgrade the HTTP connection represented by theHttpServletRequestandHttpServletResponseto the WebSocket protocol and establish a WebSocket connection as per the providedServerEndpointConfig.This method is primarily intended to be used by frameworks that implement the front-controller pattern. It does not deploy the provided endpoint.
If the WebSocket implementation is not deployed as part of a Jakarta Servlet container, this method will throw an
UnsupportedOperationException.- Specified by:
upgradeHttpToWebSocketin interfaceServerContainer- Parameters:
httpServletRequest- TheHttpServletRequestto be processed as a WebSocket handshake as per section 4.0 of RFC 6455.httpServletResponse- TheHttpServletResponseto be used when processing thehttpServletRequestas a WebSocket handshake as per section 4.0 of RFC 6455.sec- The server endpoint configuration to use to configure the WebSocket endpointpathParameters- Provides a mapping of path parameter names and values, if any, to be used for the WebSocket connection established by the call to this method. If no such mapping is defined, an empty Map must be passed.- Throws:
IOException- if an I/O error occurs during the establishment of a WebSocket connectionDeploymentException- if a configuration error prevents the establishment of a WebSocket connection
-