Interface Launcher<T>

  • Type Parameters:
    T - remote service interface type
    All Known Implementing Classes:
    StandardLauncher

    public interface Launcher<T>
    This is the entry point for applications that use LSP4J. A Launcher does all the wiring that is necessary to connect your endpoint via an input stream and an output stream.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  Launcher.Builder<T>
      The launcher builder wires up all components for JSON-RPC communication.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      static <T> Launcher<T> createIoLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out, boolean validate, java.util.concurrent.ExecutorService executorService, java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper, java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
      static <T> Launcher<T> createIoLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out, java.util.concurrent.ExecutorService executorService, java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
      static <T> Launcher<T> createIoLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out, java.util.concurrent.ExecutorService executorService, java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper, java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
      static Launcher<java.lang.Object> createIoLauncher​(java.util.Collection<java.lang.Object> localServices, java.util.Collection<java.lang.Class<?>> remoteInterfaces, java.lang.ClassLoader classLoader, java.io.InputStream in, java.io.OutputStream out, java.util.concurrent.ExecutorService executorService, java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper, java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
      Create a new Launcher for a collection of local service objects, a collection of remote interfaces and an input and output stream.
      static <T> Launcher<T> createLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
      static <T> Launcher<T> createLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out, boolean validate, java.io.PrintWriter trace)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream, and set up message validation and tracing.
      static <T> Launcher<T> createLauncher​(java.lang.Object localService, java.lang.Class<T> remoteInterface, java.io.InputStream in, java.io.OutputStream out, java.util.concurrent.ExecutorService executorService, java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper)
      Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
      RemoteEndpoint getRemoteEndpoint()
      Returns the remote endpoint.
      T getRemoteProxy()
      Returns the proxy instance that implements the remote service interfaces.
      java.util.concurrent.Future<java.lang.Void> startListening()
      Start a thread that listens to the input stream.
    • Method Detail

      • createLauncher

        static <T> Launcher<T> createLauncher​(java.lang.Object localService,
                                              java.lang.Class<T> remoteInterface,
                                              java.io.InputStream in,
                                              java.io.OutputStream out)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
      • createLauncher

        static <T> Launcher<T> createLauncher​(java.lang.Object localService,
                                              java.lang.Class<T> remoteInterface,
                                              java.io.InputStream in,
                                              java.io.OutputStream out,
                                              boolean validate,
                                              java.io.PrintWriter trace)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream, and set up message validation and tracing.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        validate - - whether messages should be validated with the ReflectiveMessageValidator
        trace - - a writer to which incoming and outgoing messages are traced, or null to disable tracing
      • createLauncher

        static <T> Launcher<T> createLauncher​(java.lang.Object localService,
                                              java.lang.Class<T> remoteInterface,
                                              java.io.InputStream in,
                                              java.io.OutputStream out,
                                              java.util.concurrent.ExecutorService executorService,
                                              java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream. Threads are started with the given executor service. The wrapper function is applied to the incoming and outgoing message streams so additional message handling such as validation and tracing can be included.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        executorService - - the executor service used to start threads
        wrapper - - a function for plugging in additional message consumers
      • createIoLauncher

        static <T> Launcher<T> createIoLauncher​(java.lang.Object localService,
                                                java.lang.Class<T> remoteInterface,
                                                java.io.InputStream in,
                                                java.io.OutputStream out,
                                                java.util.concurrent.ExecutorService executorService,
                                                java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream. Threads are started with the given executor service. The wrapper function is applied to the incoming and outgoing message streams so additional message handling such as validation and tracing can be included.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        executorService - - the executor service used to start threads
        wrapper - - a function for plugging in additional message consumers
      • createIoLauncher

        static <T> Launcher<T> createIoLauncher​(java.lang.Object localService,
                                                java.lang.Class<T> remoteInterface,
                                                java.io.InputStream in,
                                                java.io.OutputStream out,
                                                java.util.concurrent.ExecutorService executorService,
                                                java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper,
                                                java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream. Threads are started with the given executor service. The wrapper function is applied to the incoming and outgoing message streams so additional message handling such as validation and tracing can be included. The configureGson function can be used to register additional type adapters in the GsonBuilder in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        executorService - - the executor service used to start threads
        wrapper - - a function for plugging in additional message consumers
        configureGson - - a function for Gson configuration
      • createIoLauncher

        static <T> Launcher<T> createIoLauncher​(java.lang.Object localService,
                                                java.lang.Class<T> remoteInterface,
                                                java.io.InputStream in,
                                                java.io.OutputStream out,
                                                boolean validate,
                                                java.util.concurrent.ExecutorService executorService,
                                                java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper,
                                                java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
        Create a new Launcher for a given local service object, a given remote interface and an input and output stream. Threads are started with the given executor service. The wrapper function is applied to the incoming and outgoing message streams so additional message handling such as validation and tracing can be included. The configureGson function can be used to register additional type adapters in the GsonBuilder in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
        Parameters:
        localService - - the object that receives method calls from the remote service
        remoteInterface - - an interface on which RPC methods are looked up
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        validate - - whether messages should be validated with the ReflectiveMessageValidator
        executorService - - the executor service used to start threads
        wrapper - - a function for plugging in additional message consumers
        configureGson - - a function for Gson configuration
      • createIoLauncher

        static Launcher<java.lang.Object> createIoLauncher​(java.util.Collection<java.lang.Object> localServices,
                                                           java.util.Collection<java.lang.Class<?>> remoteInterfaces,
                                                           java.lang.ClassLoader classLoader,
                                                           java.io.InputStream in,
                                                           java.io.OutputStream out,
                                                           java.util.concurrent.ExecutorService executorService,
                                                           java.util.function.Function<MessageConsumer,​MessageConsumer> wrapper,
                                                           java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
        Create a new Launcher for a collection of local service objects, a collection of remote interfaces and an input and output stream. Threads are started with the given executor service. The wrapper function is applied to the incoming and outgoing message streams so additional message handling such as validation and tracing can be included. The configureGson function can be used to register additional type adapters in the GsonBuilder in order to support protocol classes that cannot be handled by Gson's reflective capabilities.
        Parameters:
        localServices - - the objects that receive method calls from the remote services
        remoteInterfaces - - interfaces on which RPC methods are looked up
        classLoader - - a class loader that is able to resolve all given interfaces
        in - - input stream to listen for incoming messages
        out - - output stream to send outgoing messages
        executorService - - the executor service used to start threads
        wrapper - - a function for plugging in additional message consumers
        configureGson - - a function for Gson configuration
      • startListening

        java.util.concurrent.Future<java.lang.Void> startListening()
        Start a thread that listens to the input stream. The thread terminates when the stream is closed.
        Returns:
        a future that returns null when the listener thread is terminated
      • getRemoteProxy

        T getRemoteProxy()
        Returns the proxy instance that implements the remote service interfaces.
      • getRemoteEndpoint

        RemoteEndpoint getRemoteEndpoint()
        Returns the remote endpoint. Use this one to send generic request or notify methods to the remote services.