1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.extensions;
20
21 import javax.annotation.Nonnull;
22
23 import java.nio.channels.ReadableByteChannel;
24 import java.nio.channels.WritableByteChannel;
25
26 import org.apache.maven.surefire.api.event.Event;
27 import org.apache.maven.surefire.api.fork.ForkNodeArguments;
28 import org.apache.maven.surefire.extensions.CloseableDaemonThread;
29 import org.apache.maven.surefire.extensions.CommandReader;
30 import org.apache.maven.surefire.extensions.EventHandler;
31 import org.apache.maven.surefire.extensions.ForkChannel;
32 import org.apache.maven.surefire.extensions.util.CountdownCloseable;
33
34
35
36
37
38
39
40
41
42 final class LegacyForkChannel extends ForkChannel {
43 private CloseableDaemonThread commandReaderBindings;
44 private CloseableDaemonThread eventHandlerBindings;
45
46 LegacyForkChannel(@Nonnull ForkNodeArguments arguments) {
47 super(arguments);
48 }
49
50 @Override
51 public void tryConnectToClient() {}
52
53 @Override
54 public String getForkNodeConnectionString() {
55 return "pipe://" + getArguments().getForkChannelId();
56 }
57
58 @Override
59 public int getCountdownCloseablePermits() {
60 return 2;
61 }
62
63 @Override
64 public void bindCommandReader(@Nonnull CommandReader commands, WritableByteChannel stdIn) {
65 ForkNodeArguments args = getArguments();
66 String threadName = "commands-fork-" + args.getForkChannelId();
67 commandReaderBindings = new StreamFeeder(threadName, stdIn, commands, args.getConsoleLogger());
68 commandReaderBindings.start();
69 }
70
71 @Override
72 public void bindEventHandler(
73 @Nonnull EventHandler<Event> eventHandler,
74 @Nonnull CountdownCloseable countdownCloseable,
75 ReadableByteChannel stdOut) {
76 ForkNodeArguments args = getArguments();
77 String threadName = "fork-" + args.getForkChannelId() + "-event-thread";
78 eventHandlerBindings = new EventConsumerThread(threadName, stdOut, eventHandler, countdownCloseable, args);
79 eventHandlerBindings.start();
80 }
81
82 @Override
83 public void disable() {
84 if (eventHandlerBindings != null) {
85 eventHandlerBindings.disable();
86 }
87
88 if (commandReaderBindings != null) {
89 commandReaderBindings.disable();
90 }
91 }
92
93 @Override
94 public void close() {}
95 }