Class SurefireForkChannel
- java.lang.Object
-
- org.apache.maven.surefire.extensions.ForkChannel
-
- org.apache.maven.plugin.surefire.extensions.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 theconnection string
. The main purpose of this class is toconect with tthe client
, bind thecommand reader
to the internal socket'sInputStream
, and bind theevent handler
writing the event objects to theevent handler
.
The objectsWritableByteChannel
andReadableByteChannel
are forked process streams (standard input and output). Both are ignored in this implementation but they are used inLegacyForkChannel
.
The channel is closed after the forked JVM has finished normally or the shutdown hook is executed in the plugin.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
SurefireForkChannel.Bindings
private class
SurefireForkChannel.CommandBindings
private class
SurefireForkChannel.EventBindings
-
Field Summary
Fields Modifier and Type Field Description private SurefireForkChannel.Bindings
bindings
private SurefireForkChannel.CommandBindings
commandBindings
private CloseableDaemonThread
commandReaderBindings
private SurefireForkChannel.EventBindings
eventBindings
private CloseableDaemonThread
eventHandlerBindings
private java.lang.String
localHost
private int
localPort
private LineConsumerThread
out
private java.nio.channels.AsynchronousServerSocketChannel
server
private java.util.concurrent.Future<java.nio.channels.AsynchronousSocketChannel>
session
private java.lang.String
sessionId
private static java.util.concurrent.ExecutorService
THREAD_POOL
-
Constructor Summary
Constructors Constructor Description SurefireForkChannel(ForkNodeArguments arguments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindCommandReader(CommandReader commands, java.nio.channels.WritableByteChannel stdIn)
Binds command handler to the channel.void
bindEventHandler(EventHandler<Event> eventHandler, CountdownCloseable countdown, java.nio.channels.ReadableByteChannel stdOut)
Starts a Thread reading the events.void
close()
void
disable()
private java.nio.channels.AsynchronousSocketChannel
getChannel()
int
getCountdownCloseablePermits()
the permits inCountdownCloseable
.java.lang.String
getForkNodeConnectionString()
This is server related class, which if binds to a TCP port, determines the connection string for the client.private void
setTrueOptions(java.net.SocketOption<java.lang.Boolean>... options)
void
tryConnectToClient()
Asynchronously connects to the client.private void
verifySessionId()
-
Methods inherited from class org.apache.maven.surefire.extensions.ForkChannel
getArguments
-
-
-
-
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
-
bindings
private final SurefireForkChannel.Bindings bindings
-
session
private volatile java.util.concurrent.Future<java.nio.channels.AsynchronousSocketChannel> session
-
out
private volatile LineConsumerThread out
-
commandReaderBindings
private volatile CloseableDaemonThread commandReaderBindings
-
eventHandlerBindings
private volatile CloseableDaemonThread eventHandlerBindings
-
eventBindings
private volatile SurefireForkChannel.EventBindings eventBindings
-
commandBindings
private volatile SurefireForkChannel.CommandBindings commandBindings
-
-
Constructor Detail
-
SurefireForkChannel
SurefireForkChannel(@Nonnull ForkNodeArguments arguments) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
tryConnectToClient
public void tryConnectToClient()
Description copied from class:ForkChannel
Asynchronously connects to the client.- Specified by:
tryConnectToClient
in classForkChannel
-
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 classForkChannel
- Returns:
- a connection string utilized by the client in the fork JVM
-
getCountdownCloseablePermits
public int getCountdownCloseablePermits()
Description copied from class:ForkChannel
the permits inCountdownCloseable
.- Specified by:
getCountdownCloseablePermits
in classForkChannel
-
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 classForkChannel
- Parameters:
commands
- command reader, seeCommandReader.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 channeljava.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 classForkChannel
- Parameters:
eventHandler
- event eventHandlercountdown
- count down of the final call ofCloseable.close()
stdOut
- optional standard output stream of the JVM- Throws:
java.io.IOException
- if an error in the fork channeljava.lang.InterruptedException
- channel interrupted
-
disable
public void disable()
- Specified by:
disable
in classForkChannel
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classForkChannel
- 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
-
-