3737/// - Wait for `ProxyStream.END` packet or `clientSocket.close()`,
3838/// indicating server has finished execution and all data has been received
3939public abstract class ServerLauncher {
40- public static class RunWithConnectionResult <A > {
41- public final A result ;
42-
43- public final int exitCode ;
44-
45- public RunWithConnectionResult (A result , int exitCode ) {
46- this .result = result ;
47- this .exitCode = exitCode ;
48- }
49- }
5040
5141 /// Run a client logic with a connection established to a Mill server (via [#connectToServer]).
5242 ///
@@ -56,13 +46,13 @@ public RunWithConnectionResult(A result, int exitCode) {
5646 // client logic
5747 /// @param runClientLogic the client logic to run
5848 /// @return the exit code that the server sent back
59- public static <A > RunWithConnectionResult <A > runWithConnection (
60- String debugName ,
49+ public static int runWithConnection (
6150 Socket connection ,
6251 Streams streams ,
6352 boolean closeConnectionAfterClientLogic ,
6453 Consumer <OutputStream > sendInitData ,
65- RunClientLogic <A > runClientLogic )
54+ Runnable runClientLogic ,
55+ String debugName )
6656 throws Exception {
6757 // According to
6858 // https://pzemtsov.github.io/2015/01/19/on-the-benefits-of-stream-buffering-in-Java.html it
@@ -76,10 +66,10 @@ public static <A> RunWithConnectionResult<A> runWithConnection(
7666 socketOutputStream .flush ();
7767 var pumperThread =
7868 startStreamPumpers (socketInputStream , socketOutputStream , streams , debugName );
79- var result = runClientLogic .run ();
69+ runClientLogic .run ();
8070 if (closeConnectionAfterClientLogic ) socketInputStream .close ();
8171 pumperThread .join ();
82- return new RunWithConnectionResult <>( result , pumperThread .exitCode () );
72+ return pumperThread .exitCode ();
8373 }
8474
8575 /// Run a client logic with a connection established to a Mill server (via [#connectToServer]).
@@ -90,7 +80,6 @@ public static <A> RunWithConnectionResult<A> runWithConnection(
9080 /// @param runClientLogic the client logic to run
9181 /// @return the exit code that the server sent back
9282 public static <A > A runWithConnection (
93- String debugName ,
9483 Socket connection ,
9584 boolean closeConnectionAfterClientLogic ,
9685 Consumer <OutputStream > sendInitData ,
@@ -266,11 +255,6 @@ public static ServerLaunchResult ensureServerIsRunning(
266255 public boolean isAlive () {
267256 throw new RuntimeException ("not implemented, this should never happen" );
268257 }
269-
270- @ Override
271- public void kill () {
272- throw new RuntimeException ("not implemented, this should never happen" );
273- }
274258 };
275259 return Optional .of (new ServerLaunchResult .AlreadyRunning (launchedServer ));
276260 } catch (IOException | NumberFormatException e ) {
@@ -353,26 +337,11 @@ public interface InitServer {
353337 LaunchedServer init () throws Exception ;
354338 }
355339
356- public interface RunClientLogic <A > {
357- /// Runs the client logic.
358- A run () throws Exception ;
359- }
360-
361340 public interface RunClientLogicWithStreams <A > {
362341 /// Runs the client logic.
363342 A run (BufferedInputStream inStream , BufferedOutputStream outStream ) throws Exception ;
364343 }
365344
366- public static class Result {
367- public final int exitCode ;
368- public final Path daemonDir ;
369-
370- public Result (int exitCode , Path daemonDir ) {
371- this .exitCode = exitCode ;
372- this .daemonDir = daemonDir ;
373- }
374- }
375-
376345 public static class Streams {
377346 /// The input stream to send to the server as the stdin.
378347 public final InputStream stdin ;
0 commit comments