File tree Expand file tree Collapse file tree 4 files changed +24
-8
lines changed
Expand file tree Collapse file tree 4 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 1+ FROM openjdk:16
2+
3+ ADD ./src src
4+ ADD ./run.sh run.sh
5+
6+ ENTRYPOINT ["run.sh" ]
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env sh
2+
13javac ./src/Box.java ./src/Controller.java
24jar --create --file ./src/box.jar --main-class Box -C src Box.class
35java -cp src Controller " $@ "
Original file line number Diff line number Diff line change 22import java .net .InetSocketAddress ;
33import java .net .Socket ;
44import java .nio .ByteBuffer ;
5- import java .nio .file .Files ;
6- import java .nio .file .Path ;
75import java .time .Duration ;
86import java .util .UUID ;
97
@@ -59,10 +57,9 @@ public void accept() throws IOException {
5957 }
6058 }
6159
62- public static void main (String [] arguments ) throws IOException {
60+ public static void main (String [] arguments ) {
6361 validateArguments (arguments );
6462 var box = createBoxFromArguments (arguments );
65- Files .writeString (Path .of (box .id .toString () + ".box.txt" ), box .id .toString ());
6663 try {
6764 box .start ();
6865 } catch (IOException failure ) {
Original file line number Diff line number Diff line change @@ -150,16 +150,27 @@ private static void redirect(
150150 }
151151 }
152152
153+ private static final int internalPort = 3_1337 ;
154+
153155 // All logging is done to System.err since output is redirected to System.out
154156 public static void main (String [] arguments ) throws InterruptedException {
155157 validateArguments (arguments );
156158 var executor = Executors .newCachedThreadPool ();
157- var controller = new Controller (3_1337 , arguments [0 ], executor );
159+ var binaryPath = arguments [0 ];
160+ var controller = new Controller (internalPort , binaryPath , executor );
158161 runController (executor , controller );
159- int boxCount = arguments .length > 1 ? Integer .parseInt (arguments [1 ]) : 3 ;
160- startSomeBoxes (controller , boxCount );
162+ startSomeBoxes (controller , readBoxCount (arguments ));
161163 Thread .sleep (10_000 );
162- executor .shutdown ();
164+ executor .shutdownNow ();
165+ }
166+
167+ private static final int boxCountIndex = 1 ;
168+ private static final int defaultBoxCount = 3 ;
169+
170+ private static int readBoxCount (String [] arguments ) {
171+ return arguments .length > boxCountIndex
172+ ? Integer .parseInt (arguments [boxCountIndex ])
173+ : defaultBoxCount ;
163174 }
164175
165176 private static void runController (Executor executor , Controller controller ) {
You can’t perform that action at this time.
0 commit comments