Class Server

  • Direct Known Subclasses:
    DataProviderServer, MetadataProviderServer

    public abstract class Server
    extends java.lang.Object
    A generic Remote Server object, which can run a Remote Data or Metadata Adapter and connect it to the Proxy Adapter running on Lightstreamer Server.
    The object should be provided with a suitable Adapter instance and with suitable initialization parameters and established connections, then activated through start() and finally disposed through close(). Further reuse of the same instance is not supported.
    The Remote Server will take care of sending keepalive packets on the connections when needed. The interval can be configured through the custom "lightstreamer.keepalive.millis" system property, where a value of 0 or negative means no keepalives. By default, it is set to 10000 ms.
    However, if a stricter interval is requested by the Proxy Adapter on startup, it will be obeyed (with a safety minimum of 1 second). This should ensure that the Proxy Adapter activity checks will always succeed, but for some old versions of the Proxy Adapter.
    • Constructor Summary

      Constructors 
      Constructor Description
      Server()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Stops the management of the Remote Adapter and destroys the threads used by this Server.
      ExceptionHandler getExceptionHandler()
      Gets the handler for error conditions occurring on the Remote Server.
      java.lang.String getName()
      Gets the name, used for logging purposes, associated to the Server instance.
      java.io.OutputStream getNotifyStream()
      Gets the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter.
      java.lang.String getRemotePassword()
      Gets the password credential to be sent to the Proxy Adapter upon connection.
      java.lang.String getRemoteUser()
      Gets the user-name credential to be sent to the Proxy Adapter upon connection.
      java.io.OutputStream getReplyStream()
      Gets the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
      java.io.InputStream getRequestStream()
      Gets the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter.
      void setExceptionHandler​(ExceptionHandler handler)
      Sets the handler for error conditions occurring on the Remote Server.
      static void setLoggerProvider​(com.lightstreamer.log.LoggerProvider loggerProvider)
      Sets the LoggerProvider instance that will be used by the classes of the library to obtain Logger instances used to propagate internal logging.
      void setName​(java.lang.String name)
      Sets a name for the Server instance; used for logging purposes.
      void setNotifyStream​(java.io.OutputStream outputStream)
      Sets the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter.
      void setRemotePassword​(java.lang.String password)
      Sets the password credential to be sent to the Proxy Adapter upon connection.
      void setRemoteUser​(java.lang.String user)
      Sets the user-name credential to be sent to the Proxy Adapter upon connection.
      void setReplyStream​(java.io.OutputStream outputStream)
      Sets the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
      void setRequestStream​(java.io.InputStream inputStream)
      Sets the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter.
      void start()
      Starts the communication between the Remote Adapter and the Proxy Adapter through the supplied streams.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Server

        public Server()
    • Method Detail

      • setName

        public final void setName​(@Nonnull
                                  java.lang.String name)
        Sets a name for the Server instance; used for logging purposes.
        Parameters:
        name - a name to identify the instance.
      • getName

        @Nonnull
        public final java.lang.String getName()
        Gets the name, used for logging purposes, associated to the Server instance.
        Returns:
        the name for the Server instance.
      • setRemoteUser

        public final void setRemoteUser​(@Nullable
                                        java.lang.String user)
        Sets the user-name credential to be sent to the Proxy Adapter upon connection. The credentials are needed only if the Proxy Adapter is configured to require Remote Adapter authentication. The credentials will be sent only if both are non-null.
        The default value is null.
        Parameters:
        user - a user name.
      • setRemotePassword

        public final void setRemotePassword​(@Nullable
                                            java.lang.String password)
        Sets the password credential to be sent to the Proxy Adapter upon connection. The credentials are needed only if the Proxy Adapter is configured to require Remote Adapter authentication. The credentials will be sent only if both are non-null.
        The default value is null.
        Parameters:
        password - a password.
      • getRemoteUser

        @Nullable
        public final java.lang.String getRemoteUser()
        Gets the user-name credential to be sent to the Proxy Adapter upon connection. The credentials will be sent only if both are non-null.
        The default value is null.
        Returns:
        the user-name credential or null.
      • getRemotePassword

        @Nullable
        public final java.lang.String getRemotePassword()
        Gets the password credential to be sent to the Proxy Adapter upon connection. The credentials will be sent only if both are non-null.
        The default value is null.
        Returns:
        the password credential or null.
      • setRequestStream

        public final void setRequestStream​(@Nonnull
                                           java.io.InputStream inputStream)
        Sets the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter.
        Parameters:
        inputStream - the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter
      • getRequestStream

        @Nonnull
        public final java.io.InputStream getRequestStream()
        Gets the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter.
        Returns:
        the stream used by the Proxy Adapter in order to forward the requests to the Remote Adapter
      • setReplyStream

        public final void setReplyStream​(@Nonnull
                                         java.io.OutputStream outputStream)
        Sets the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
        Parameters:
        outputStream - the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
      • getReplyStream

        @Nonnull
        public final java.io.OutputStream getReplyStream()
        Gets the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
        Returns:
        the stream used by the Remote Adapter in order to forward the answers to the Proxy Adapter.
      • setNotifyStream

        public final void setNotifyStream​(@Nonnull
                                          java.io.OutputStream outputStream)
        Sets the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter. Currently not used and not needed by the Remote Metadata Adapter.
        Parameters:
        outputStream - the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter.
      • getNotifyStream

        @Nonnull
        public final java.io.OutputStream getNotifyStream()
        Gets the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter. Currently not used and not needed by the Remote Metadata Adapter.
        Returns:
        the stream used by the Remote Adapter in order to send asyncronous data to the Remote Adapter.
      • setExceptionHandler

        public final void setExceptionHandler​(@Nullable
                                              ExceptionHandler handler)
        Sets the handler for error conditions occurring on the Remote Server. By setting the handler, it's possible to override the default exception handling.
        Parameters:
        handler - the handler for error conditions occurring on the Remote Server.
      • getExceptionHandler

        @Nullable
        public final ExceptionHandler getExceptionHandler()
        Gets the handler for error conditions occurring on the Remote Server.
        Returns:
        the handler for error conditions occurring on the Remote Server.
      • start

        public final void start()
                         throws RemotingException,
                                DataProviderException,
                                MetadataProviderException
        Starts the communication between the Remote Adapter and the Proxy Adapter through the supplied streams. If requested by the initializeOnStart flag in the instance constructor, the Remote Adapter is initialized immediately. Then, requests issued by the Proxy Adapter are received and forwarded to the Remote Adapter. If the Remote Adapter is not initialized immediately, initialization will be triggered by the Proxy Adapter and any initialization error will be just notified to the Proxy Adapter.
        Throws:
        RemotingException - An error occurred in the initialization phase. The adapter was not started.
        DataProviderException - An error occurred in the initialization phase. The adapter was not started. Only possible when the Adapter is initialized immediately.
        MetadataProviderException - An error occurred in the initialization phase. The adapter was not started. Only possible when the Adapter is initialized immediately.
      • close

        public final void close()
        Stops the management of the Remote Adapter and destroys the threads used by this Server. This instance can no longer be used.
        The streams supplied to this instance are also closed.
        Note that this does not stop the supplied Remote Adapter, as no close method is available in the Remote Adapter interface. If the process is not terminating, then the Remote Adapter cleanup should be performed by accessing the supplied Adapter instance directly and calling custom methods.
      • setLoggerProvider

        public static void setLoggerProvider​(@Nullable
                                             com.lightstreamer.log.LoggerProvider loggerProvider)
        Sets the LoggerProvider instance that will be used by the classes of the library to obtain Logger instances used to propagate internal logging. Providing a new provider to the library permits to consume the log produced through custom Logger implementation.
        As soon as a new LoggerProvider is provided all the instances of Logger already in use in the library are discarded and substituted with instanced obtained from this new instance. If a null value is provided, the default consumers, that discard all the log, are enabled.
        Parameters:
        loggerProvider - Will be responsible to provide Logger instances to the various classes of the library.