View Javadoc
1   package org.apache.maven.plugin.surefire.extensions;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.surefire.api.event.Event;
23  import org.apache.maven.surefire.extensions.CloseableDaemonThread;
24  import org.apache.maven.surefire.extensions.CommandReader;
25  import org.apache.maven.surefire.extensions.EventHandler;
26  import org.apache.maven.surefire.extensions.ForkChannel;
27  import org.apache.maven.surefire.extensions.ForkNodeArguments;
28  import org.apache.maven.surefire.extensions.util.CountdownCloseable;
29  
30  import javax.annotation.Nonnull;
31  import java.nio.channels.ReadableByteChannel;
32  import java.nio.channels.WritableByteChannel;
33  
34  /**
35   * The main purpose of this class is to bind the
36   * {@link #bindCommandReader(CommandReader, WritableByteChannel) command reader} reading the commands from
37   * {@link CommandReader}, serializing them and writing the stream to the
38   * {@link WritableByteChannel sub-process}. It binds the
39   * {@link #bindEventHandler(EventHandler, CountdownCloseable, ReadableByteChannel) event handler} deserializing
40   * a received event and sends the event object to the {@link EventHandler event handler}.
41   */
42  final class LegacyForkChannel extends ForkChannel
43  {
44      LegacyForkChannel( @Nonnull ForkNodeArguments arguments )
45      {
46          super( arguments );
47      }
48  
49      @Override
50      public void connectToClient()
51      {
52      }
53  
54      @Override
55      public String getForkNodeConnectionString()
56      {
57          return "pipe://" + getArguments().getForkChannelId();
58      }
59  
60      @Override
61      public int getCountdownCloseablePermits()
62      {
63          return 2;
64      }
65  
66      @Override
67      public CloseableDaemonThread bindCommandReader( @Nonnull CommandReader commands,
68                                                      WritableByteChannel stdIn )
69      {
70          return new StreamFeeder( "std-in-fork-" + getArguments().getForkChannelId(), stdIn, commands,
71              getArguments().getConsoleLogger() );
72      }
73  
74      @Override
75      public CloseableDaemonThread bindEventHandler( @Nonnull EventHandler<Event> eventHandler,
76                                                     @Nonnull CountdownCloseable countdownCloseable,
77                                                     ReadableByteChannel stdOut )
78      {
79          return new EventConsumerThread( "fork-" + getArguments().getForkChannelId() + "-event-thread", stdOut,
80              eventHandler, countdownCloseable, getArguments() );
81      }
82  
83      @Override
84      public void close()
85      {
86      }
87  }