Package org.glassfish.tyrus.server
Class TyrusServerContainer
- java.lang.Object
-
- org.glassfish.tyrus.core.ExecutorServiceProvider
-
- org.glassfish.tyrus.core.BaseContainer
-
- org.glassfish.tyrus.server.TyrusServerContainer
-
- All Implemented Interfaces:
ServerContainer
,WebSocketContainer
,ServerContainer
public abstract class TyrusServerContainer extends BaseContainer implements ServerContainer
Server Container Implementation.- Author:
- Martin Matula (martin.matula at oracle.com), Pavel Bucek (pavel.bucek at oracle.com), Stepan Kopriva (stepan.kopriva at oracle.com)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.glassfish.tyrus.core.BaseContainer
BaseContainer.ShutDownCondition
-
-
Constructor Summary
Constructors Constructor Description TyrusServerContainer(java.util.Set<java.lang.Class<?>> classes)
Create newTyrusServerContainer
.TyrusServerContainer(ServerApplicationConfig serverApplicationConfig)
Create newTyrusServerContainer
using already createdServerApplicationConfig
instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addEndpoint(java.lang.Class<?> endpointClass)
Deploys the given annotated endpoint into this ServerContainer during the initialization phase of deploying the application.void
addEndpoint(ServerEndpointConfig serverEndpointConfig)
java.util.concurrent.Future<Session>
asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path)
Non-blocking version ofWebSocketContainer.connectToServer(Class, java.net.URI)
.java.util.concurrent.Future<Session>
asyncConnectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path)
Non-blocking version ofWebSocketContainer.connectToServer(Class, javax.websocket.ClientEndpointConfig, java.net.URI)
.java.util.concurrent.Future<Session>
asyncConnectToServer(java.lang.Object obj, java.net.URI path)
Non-blocking version ofWebSocketContainer.connectToServer(Object, java.net.URI)
.java.util.concurrent.Future<Session>
asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path)
Session
connectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path)
Connect the supplied programmatic endpoint to its server with the given configuration.Session
connectToServer(java.lang.Class annotatedEndpointClass, java.net.URI path)
Connect the supplied annotated endpoint to its server.Session
connectToServer(java.lang.Object annotatedEndpointInstance, java.net.URI path)
Connect the supplied annotated endpoint instance to its server.Session
connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path)
Connect the supplied programmatic client endpoint instance to its server with the given configuration.void
doneDeployment()
Container is no longer required to acceptaddEndpoint(javax.websocket.server.ServerEndpointConfig)
andaddEndpoint(Class)
calls.protected ClientManager
getClientManager()
Can be overridden to provide ownClientManager
implementation or instance.long
getDefaultAsyncSendTimeout()
Return the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container.int
getDefaultMaxBinaryMessageBufferSize()
Returns the default maximum size of incoming binary message that this container will buffer.long
getDefaultMaxSessionIdleTimeout()
Return the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive.int
getDefaultMaxTextMessageBufferSize()
Returns the default maximum size of incoming text message that this container will buffer.java.util.Set<Extension>
getInstalledExtensions()
Return the set of Extensions installed in the container.int
getPort()
Get port of the started container.abstract void
register(java.lang.Class<?> endpointClass)
abstract void
register(ServerEndpointConfig serverEndpointConfig)
void
setAsyncSendTimeout(long timeoutmillis)
Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container.void
setDefaultMaxBinaryMessageBufferSize(int max)
Sets the default maximum size of incoming binary message that this container will buffer.void
setDefaultMaxSessionIdleTimeout(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.void
setDefaultMaxTextMessageBufferSize(int max)
Sets the maximum size of incoming text message that this container will buffer.void
start(java.lang.String rootPath, int port)
Start the container.void
stop()
Undeploy all endpoints and stop underlyingServerContainer
.-
Methods inherited from class org.glassfish.tyrus.core.BaseContainer
getExecutorService, getScheduledExecutorService, shutdown, shutdown
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.glassfish.tyrus.spi.ServerContainer
getWebSocketEngine
-
-
-
-
Constructor Detail
-
TyrusServerContainer
public TyrusServerContainer(java.util.Set<java.lang.Class<?>> classes)
Create newTyrusServerContainer
.- Parameters:
classes
- classes to be included in this application instance. Can contain any combination of annotated endpoints (seeServerEndpoint
) orEndpoint
descendants.
-
TyrusServerContainer
public TyrusServerContainer(ServerApplicationConfig serverApplicationConfig)
Create newTyrusServerContainer
using already createdServerApplicationConfig
instance.- Parameters:
serverApplicationConfig
- provided application config.
-
-
Method Detail
-
start
public void start(java.lang.String rootPath, int port) throws java.io.IOException, DeploymentException
Start the container.- Specified by:
start
in interfaceServerContainer
- Parameters:
rootPath
- context path of the deployed websocket application.port
- TCP port- Throws:
java.io.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:
stop
in interfaceServerContainer
-
register
public abstract void register(java.lang.Class<?> endpointClass) throws DeploymentException
- Throws:
DeploymentException
-
register
public abstract void register(ServerEndpointConfig serverEndpointConfig) throws DeploymentException
- Throws:
DeploymentException
-
addEndpoint
public void addEndpoint(java.lang.Class<?> endpointClass) throws DeploymentException
Description copied from interface:ServerContainer
Deploys the given annotated endpoint into this ServerContainer during the initialization phase of deploying the application.- Specified by:
addEndpoint
in interfaceServerContainer
- Parameters:
endpointClass
- the class of the annotated endpoint- Throws:
DeploymentException
- if the annotated endpoint was badly formed.
-
addEndpoint
public void addEndpoint(ServerEndpointConfig serverEndpointConfig) throws DeploymentException
- Specified by:
addEndpoint
in 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
protected ClientManager getClientManager()
Can be overridden to provide ownClientManager
implementation or instance.- Returns:
ClientManager
associated with this server container.
-
connectToServer
public Session connectToServer(java.lang.Class annotatedEndpointClass, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied annotated endpoint to its server. The supplied object must be a class decorated with the class leveljavax.websocket.server.ServerEndpoint
annotation. 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:
connectToServer
in 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.java.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being connected to its server.
-
connectToServer
public Session connectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect 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:
connectToServer
in 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 validjava.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being connected to its server
-
connectToServer
public Session connectToServer(java.lang.Object annotatedEndpointInstance, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied annotated endpoint instance to its server. The supplied object must be a class decorated with the class leveljavax.websocket.server.ServerEndpoint
annotation. 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:
connectToServer
in 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.java.io.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, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect 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, javax.websocket.ClientEndpointConfig, java.net.URI)
instead.- Specified by:
connectToServer
in 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 validjava.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being connected to its server
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.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 java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.connectToServer(Class, javax.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
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException
- if the configuration is not valid- See Also:
WebSocketContainer.connectToServer(Class, javax.websocket.ClientEndpointConfig, java.net.URI)
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.connectToServer(javax.websocket.Endpoint, javax.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
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException
- if the configuration is not valid- See Also:
WebSocketContainer.connectToServer(javax.websocket.Endpoint, javax.websocket.ClientEndpointConfig, java.net.URI)
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Object obj, java.net.URI path) throws DeploymentException
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:
WebSocketContainer.connectToServer(Object, java.net.URI)
-
getDefaultMaxBinaryMessageBufferSize
public int getDefaultMaxBinaryMessageBufferSize()
Description copied from interface:WebSocketContainer
Returns 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:
getDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- the maximum size of incoming binary message in number of bytes.
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int max)
Description copied from interface:WebSocketContainer
Sets the default maximum size of incoming binary message that this container will buffer.- Specified by:
setDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
max
- the maximum size of binary message in number of bytes.
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()
Description copied from interface:WebSocketContainer
Returns 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:
getDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- the maximum size of incoming text message in number of bytes.
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int max)
Description copied from interface:WebSocketContainer
Sets the maximum size of incoming text message that this container will buffer.- Specified by:
setDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
max
- the maximum size of text message in number of bytes.
-
getInstalledExtensions
public java.util.Set<Extension> getInstalledExtensions()
Description copied from interface:WebSocketContainer
Return the set of Extensions installed in the container.- Specified by:
getInstalledExtensions
in interfaceWebSocketContainer
- Returns:
- the set of extensions.
-
getDefaultAsyncSendTimeout
public long getDefaultAsyncSendTimeout()
Description copied from interface:WebSocketContainer
Return the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A non-positive number indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
getDefaultAsyncSendTimeout
in interfaceWebSocketContainer
- Returns:
- the timeout time in milliseconds.
-
setAsyncSendTimeout
public void setAsyncSendTimeout(long timeoutmillis)
Description copied from interface:WebSocketContainer
Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A non-positive number indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
setAsyncSendTimeout
in interfaceWebSocketContainer
- Parameters:
timeoutmillis
- the timeout in milliseconds or a non-positive number for no timeout
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()
Description copied from interface:WebSocketContainer
Return 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 0 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:
getDefaultMaxSessionIdleTimeout
in 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:WebSocketContainer
Sets 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 0 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:
setDefaultMaxSessionIdleTimeout
in interfaceWebSocketContainer
- Parameters:
defaultMaxSessionIdleTimeout
- the maximum time in milliseconds.
-
doneDeployment
public void doneDeployment()
Container is no longer required to acceptaddEndpoint(javax.websocket.server.ServerEndpointConfig)
andaddEndpoint(Class)
calls.
-
-