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 readerto the internal socket'sInputStream, and bind theevent handlerwriting the event objects to theevent handler.
The objectsWritableByteChannelandReadableByteChannelare 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 classSurefireForkChannel.Bindingsprivate classSurefireForkChannel.CommandBindingsprivate classSurefireForkChannel.EventBindings
-
Field Summary
Fields Modifier and Type Field Description private SurefireForkChannel.Bindingsbindingsprivate SurefireForkChannel.CommandBindingscommandBindingsprivate CloseableDaemonThreadcommandReaderBindingsprivate SurefireForkChannel.EventBindingseventBindingsprivate CloseableDaemonThreadeventHandlerBindingsprivate java.lang.StringlocalHostprivate intlocalPortprivate LineConsumerThreadoutprivate java.nio.channels.AsynchronousServerSocketChannelserverprivate java.util.concurrent.Future<java.nio.channels.AsynchronousSocketChannel>sessionprivate java.lang.StringsessionIdprivate static java.util.concurrent.ExecutorServiceTHREAD_POOL
-
Constructor Summary
Constructors Constructor Description SurefireForkChannel(ForkNodeArguments arguments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindCommandReader(CommandReader commands, java.nio.channels.WritableByteChannel stdIn)Binds command handler to the channel.voidbindEventHandler(EventHandler<Event> eventHandler, CountdownCloseable countdown, java.nio.channels.ReadableByteChannel stdOut)Starts a Thread reading the events.voidclose()voiddisable()private java.nio.channels.AsynchronousSocketChannelgetChannel()intgetCountdownCloseablePermits()the permits inCountdownCloseable.java.lang.StringgetForkNodeConnectionString()This is server related class, which if binds to a TCP port, determines the connection string for the client.private voidsetTrueOptions(java.net.SocketOption<java.lang.Boolean>... options)voidtryConnectToClient()Asynchronously connects to the client.private voidverifySessionId()-
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:ForkChannelAsynchronously connects to the client.- Specified by:
tryConnectToClientin classForkChannel
-
getForkNodeConnectionString
public java.lang.String getForkNodeConnectionString()
Description copied from class:ForkChannelThis is server related class, which if binds to a TCP port, determines the connection string for the client.- Specified by:
getForkNodeConnectionStringin classForkChannel- Returns:
- a connection string utilized by the client in the fork JVM
-
getCountdownCloseablePermits
public int getCountdownCloseablePermits()
Description copied from class:ForkChannelthe permits inCountdownCloseable.- Specified by:
getCountdownCloseablePermitsin classForkChannel
-
bindCommandReader
public void bindCommandReader(@Nonnull CommandReader commands, java.nio.channels.WritableByteChannel stdIn) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from class:ForkChannelBinds command handler to the channel. Starts a Thread streaming out the commands.- Specified by:
bindCommandReaderin 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.InterruptedExceptionDescription copied from class:ForkChannelStarts a Thread reading the events.- Specified by:
bindEventHandlerin 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:
disablein classForkChannel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classForkChannel- Throws:
java.io.IOException
-
verifySessionId
private void verifySessionId() throws java.lang.InterruptedException, java.io.IOException- Throws:
java.lang.InterruptedExceptionjava.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.InterruptedExceptionjava.io.IOException
-
-