Class SurefireForkChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    final class SurefireForkChannel
    extends ForkChannel
    The TCP/IP server accepting only one client connection. The forked JVM connects to the server using the connection string. The main purpose of this class is to conect with tthe client, bind the command reader to the internal socket's InputStream, and bind the event handler writing the event objects to the event handler.
    The objects WritableByteChannel and ReadableByteChannel are forked process streams (standard input and output). Both are ignored in this implementation but they are used in LegacyForkChannel.
    The channel is closed after the forked JVM has finished normally or the shutdown hook is executed in the plugin.
    • Field Detail

      • THREAD_POOL

        private static final java.util.concurrent.ExecutorService THREAD_POOL
      • server

        private final java.nio.channels.AsynchronousServerSocketChannel server
      • localHost

        private final java.lang.String localHost
      • localPort

        private final int localPort
      • sessionId

        private final java.lang.String sessionId
      • session

        private volatile java.util.concurrent.Future<java.nio.channels.AsynchronousSocketChannel> session
    • Constructor Detail

      • SurefireForkChannel

        SurefireForkChannel​(@Nonnull
                            ForkNodeArguments arguments)
                     throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getForkNodeConnectionString

        public java.lang.String getForkNodeConnectionString()
        Description copied from class: ForkChannel
        This is server related class, which if binds to a TCP port, determines the connection string for the client.
        Specified by:
        getForkNodeConnectionString in class ForkChannel
        Returns:
        a connection string utilized by the client in the fork JVM
      • bindCommandReader

        public void bindCommandReader​(@Nonnull
                                      CommandReader commands,
                                      java.nio.channels.WritableByteChannel stdIn)
                               throws java.io.IOException,
                                      java.lang.InterruptedException
        Description copied from class: ForkChannel
        Binds command handler to the channel. Starts a Thread streaming out the commands.
        Specified by:
        bindCommandReader in class ForkChannel
        Parameters:
        commands - command reader, see CommandReader.readNextCommand()
        stdIn - optional standard input stream of the JVM to write the encoded commands into it
        Throws:
        java.io.IOException - if an error in the fork channel
        java.lang.InterruptedException - channel interrupted
      • bindEventHandler

        public void bindEventHandler​(@Nonnull
                                     EventHandler<Event> eventHandler,
                                     @Nonnull
                                     CountdownCloseable countdown,
                                     java.nio.channels.ReadableByteChannel stdOut)
                              throws java.io.IOException,
                                     java.lang.InterruptedException
        Description copied from class: ForkChannel
        Starts a Thread reading the events.
        Specified by:
        bindEventHandler in class ForkChannel
        Parameters:
        eventHandler - event eventHandler
        countdown - count down of the final call of Closeable.close()
        stdOut - optional standard output stream of the JVM
        Throws:
        java.io.IOException - if an error in the fork channel
        java.lang.InterruptedException - channel interrupted
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class ForkChannel
        Throws:
        java.io.IOException
      • verifySessionId

        private void verifySessionId()
                              throws java.lang.InterruptedException,
                                     java.io.IOException
        Throws:
        java.lang.InterruptedException
        java.io.IOException
      • setTrueOptions

        @SafeVarargs
        private final void setTrueOptions​(java.net.SocketOption<java.lang.Boolean>... options)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getChannel

        private java.nio.channels.AsynchronousSocketChannel getChannel()
                                                                throws java.lang.InterruptedException,
                                                                       java.io.IOException
        Throws:
        java.lang.InterruptedException
        java.io.IOException