Class TyrusServerContainer

  • All Implemented Interfaces:
    jakarta.websocket.server.ServerContainer, jakarta.websocket.WebSocketContainer, org.glassfish.tyrus.spi.ServerContainer

    public abstract class TyrusServerContainer
    extends org.glassfish.tyrus.core.BaseContainer
    implements org.glassfish.tyrus.spi.ServerContainer
    Server Container Implementation.
    Author:
    Martin Matula, Pavel Bucek, Stepan Kopriva
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.glassfish.tyrus.core.BaseContainer

        org.glassfish.tyrus.core.BaseContainer.ShutDownCondition
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addEndpoint​(jakarta.websocket.server.ServerEndpointConfig serverEndpointConfig)  
      void addEndpoint​(java.lang.Class<?> endpointClass)  
      java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(jakarta.websocket.Endpoint endpointInstance, jakarta.websocket.ClientEndpointConfig cec, java.net.URI path)
      Non-blocking version of WebSocketContainer.connectToServer(jakarta.websocket.Endpoint, jakarta.websocket.ClientEndpointConfig, java.net.URI).
      java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<?> annotatedEndpointClass, java.net.URI path)
      Non-blocking version of WebSocketContainer.connectToServer(Class, java.net.URI).
      java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass, jakarta.websocket.ClientEndpointConfig cec, java.net.URI path)
      Non-blocking version of WebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI).
      java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Object obj, java.net.URI path)
      Non-blocking version of WebSocketContainer.connectToServer(Object, java.net.URI).
      jakarta.websocket.Session connectToServer​(jakarta.websocket.Endpoint endpointInstance, jakarta.websocket.ClientEndpointConfig cec, java.net.URI path)  
      jakarta.websocket.Session connectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass, jakarta.websocket.ClientEndpointConfig cec, java.net.URI path)  
      jakarta.websocket.Session connectToServer​(java.lang.Class annotatedEndpointClass, java.net.URI path)  
      jakarta.websocket.Session connectToServer​(java.lang.Object annotatedEndpointInstance, java.net.URI path)  
      void doneDeployment()
      Container is no longer required to accept addEndpoint(jakarta.websocket.server.ServerEndpointConfig) and addEndpoint(Class) calls.
      protected org.glassfish.tyrus.client.ClientManager getClientManager()
      Can be overridden to provide own ClientManager implementation or instance.
      long getDefaultAsyncSendTimeout()  
      int getDefaultMaxBinaryMessageBufferSize()  
      long getDefaultMaxSessionIdleTimeout()  
      int getDefaultMaxTextMessageBufferSize()  
      java.util.Set<jakarta.websocket.Extension> getInstalledExtensions()  
      int getPort()
      Get port of the started container.
      abstract void register​(jakarta.websocket.server.ServerEndpointConfig serverEndpointConfig)  
      abstract void register​(java.lang.Class<?> endpointClass)  
      void setAsyncSendTimeout​(long timeoutmillis)  
      void setDefaultMaxBinaryMessageBufferSize​(int max)  
      void setDefaultMaxSessionIdleTimeout​(long defaultMaxSessionIdleTimeout)  
      void setDefaultMaxTextMessageBufferSize​(int max)  
      void start​(java.lang.String rootPath, int port)
      Start the container.
      void stop()
      Undeploy all endpoints and stop underlying ServerContainer.
      void upgradeHttpToWebSocket​(java.lang.Object httpServletRequest, java.lang.Object httpServletResponse, jakarta.websocket.server.ServerEndpointConfig sec, java.util.Map<java.lang.String,​java.lang.String> pathParameters)  
      • 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)
        Parameters:
        classes - classes to be included in this application instance. Can contain any combination of annotated endpoints (see ServerEndpoint) or Endpoint descendants.
      • TyrusServerContainer

        public TyrusServerContainer​(jakarta.websocket.server.ServerApplicationConfig serverApplicationConfig)
        Create new TyrusServerContainer using already created ServerApplicationConfig instance.
        Parameters:
        serverApplicationConfig - provided application config.
    • Method Detail

      • start

        public void start​(java.lang.String rootPath,
                          int port)
                   throws java.io.IOException,
                          jakarta.websocket.DeploymentException
        Start the container.
        Specified by:
        start in interface org.glassfish.tyrus.spi.ServerContainer
        Parameters:
        rootPath - context path of the deployed websocket application.
        Throws:
        java.io.IOException - when any IO related issues emerge during ServerContainer.start(String, int).
        jakarta.websocket.DeploymentException - when any deployment related error is found; should contain list of all found issues.
      • stop

        public void stop()
        Undeploy all endpoints and stop underlying ServerContainer.

        Release all created threadpools / executor services.

        Specified by:
        stop in interface org.glassfish.tyrus.spi.ServerContainer
      • register

        public abstract void register​(java.lang.Class<?> endpointClass)
                               throws jakarta.websocket.DeploymentException
        Throws:
        jakarta.websocket.DeploymentException
      • register

        public abstract void register​(jakarta.websocket.server.ServerEndpointConfig serverEndpointConfig)
                               throws jakarta.websocket.DeploymentException
        Throws:
        jakarta.websocket.DeploymentException
      • addEndpoint

        public void addEndpoint​(java.lang.Class<?> endpointClass)
                         throws jakarta.websocket.DeploymentException
        Specified by:
        addEndpoint in interface jakarta.websocket.server.ServerContainer
        Throws:
        jakarta.websocket.DeploymentException
      • addEndpoint

        public void addEndpoint​(jakarta.websocket.server.ServerEndpointConfig serverEndpointConfig)
                         throws jakarta.websocket.DeploymentException
        Specified by:
        addEndpoint in interface jakarta.websocket.server.ServerContainer
        Throws:
        jakarta.websocket.DeploymentException
      • 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 org.glassfish.tyrus.client.ClientManager getClientManager()
        Can be overridden to provide own ClientManager implementation or instance.
        Returns:
        ClientManager associated with this server container.
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Class annotatedEndpointClass,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass,
                                                         jakarta.websocket.ClientEndpointConfig cec,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Object annotatedEndpointInstance,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(jakarta.websocket.Endpoint endpointInstance,
                                                         jakarta.websocket.ClientEndpointConfig cec,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<?> annotatedEndpointClass,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of WebSocketContainer.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:
        jakarta.websocket.DeploymentException - if the class is not a valid annotated endpoint class.
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass,
                                                                                           jakarta.websocket.ClientEndpointConfig cec,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of WebSocketContainer.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 class Endpoint.
        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:
        jakarta.websocket.DeploymentException - if the configuration is not valid
        See Also:
        WebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI)
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(jakarta.websocket.Endpoint endpointInstance,
                                                                                           jakarta.websocket.ClientEndpointConfig cec,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of WebSocketContainer.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 instance Endpoint.
        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:
        jakarta.websocket.DeploymentException - if the configuration is not valid
        See Also:
        WebSocketContainer.connectToServer(jakarta.websocket.Endpoint, jakarta.websocket.ClientEndpointConfig, java.net.URI)
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Object obj,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of WebSocketContainer.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:
        jakarta.websocket.DeploymentException - if the annotated endpoint instance is not valid.
        See Also:
        WebSocketContainer.connectToServer(Object, java.net.URI)
      • getDefaultMaxBinaryMessageBufferSize

        public int getDefaultMaxBinaryMessageBufferSize()
        Specified by:
        getDefaultMaxBinaryMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxBinaryMessageBufferSize

        public void setDefaultMaxBinaryMessageBufferSize​(int max)
        Specified by:
        setDefaultMaxBinaryMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • getDefaultMaxTextMessageBufferSize

        public int getDefaultMaxTextMessageBufferSize()
        Specified by:
        getDefaultMaxTextMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxTextMessageBufferSize

        public void setDefaultMaxTextMessageBufferSize​(int max)
        Specified by:
        setDefaultMaxTextMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • getInstalledExtensions

        public java.util.Set<jakarta.websocket.Extension> getInstalledExtensions()
        Specified by:
        getInstalledExtensions in interface jakarta.websocket.WebSocketContainer
      • getDefaultAsyncSendTimeout

        public long getDefaultAsyncSendTimeout()
        Specified by:
        getDefaultAsyncSendTimeout in interface jakarta.websocket.WebSocketContainer
      • setAsyncSendTimeout

        public void setAsyncSendTimeout​(long timeoutmillis)
        Specified by:
        setAsyncSendTimeout in interface jakarta.websocket.WebSocketContainer
      • getDefaultMaxSessionIdleTimeout

        public long getDefaultMaxSessionIdleTimeout()
        Specified by:
        getDefaultMaxSessionIdleTimeout in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxSessionIdleTimeout

        public void setDefaultMaxSessionIdleTimeout​(long defaultMaxSessionIdleTimeout)
        Specified by:
        setDefaultMaxSessionIdleTimeout in interface jakarta.websocket.WebSocketContainer
      • upgradeHttpToWebSocket

        public void upgradeHttpToWebSocket​(java.lang.Object httpServletRequest,
                                           java.lang.Object httpServletResponse,
                                           jakarta.websocket.server.ServerEndpointConfig sec,
                                           java.util.Map<java.lang.String,​java.lang.String> pathParameters)
                                    throws java.io.IOException,
                                           jakarta.websocket.DeploymentException
        Specified by:
        upgradeHttpToWebSocket in interface jakarta.websocket.server.ServerContainer
        Throws:
        java.io.IOException
        jakarta.websocket.DeploymentException