Class ForkChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    LegacyForkChannel, SurefireForkChannel

    public abstract class ForkChannel
    extends java.lang.Object
    implements java.io.Closeable
    It's a session object used only by a particular Thread in ForkStarter and communicates with a dedicated forked JVM. It represents a server.

    It connects to a remote client by tryConnectToClient(), provides a connection string getForkNodeConnectionString() needed by the client in forked JVM, binds event handler and command reader. This object is called in one Thread.
    Since:
    3.0.0-M5
    • Constructor Detail

      • ForkChannel

        protected ForkChannel​(@Nonnull
                              ForkNodeArguments arguments)
        Parameters:
        arguments - data necessary for command reader and event handler.
    • Method Detail

      • tryConnectToClient

        public abstract void tryConnectToClient()
                                         throws java.io.IOException,
                                                java.lang.InterruptedException
        Asynchronously connects to the client.
        Throws:
        java.io.IOException - if stream fails
        java.lang.InterruptedException - if interrupted thread
      • getForkNodeConnectionString

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

        public abstract int getCountdownCloseablePermits()
        the permits in CountdownCloseable.
      • bindCommandReader

        public abstract void bindCommandReader​(@Nonnull
                                               CommandReader commands,
                                               java.nio.channels.WritableByteChannel stdIn)
                                        throws java.io.IOException,
                                               java.lang.InterruptedException
        Binds command handler to the channel. Starts a Thread streaming out the commands.
        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 abstract void bindEventHandler​(@Nonnull
                                              EventHandler<Event> eventHandler,
                                              @Nonnull
                                              CountdownCloseable countdownCloseable,
                                              java.nio.channels.ReadableByteChannel stdOut)
                                       throws java.io.IOException,
                                              java.lang.InterruptedException
        Starts a Thread reading the events.
        Parameters:
        eventHandler - event eventHandler
        countdownCloseable - 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
      • disable

        public abstract void disable()
      • close

        public abstract void close()
                            throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException