Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:16

ADD ./src src
ADD ./run.sh run.sh

ENTRYPOINT ["run.sh"]
2 changes: 2 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env sh

javac ./src/Box.java ./src/Controller.java
jar --create --file ./src/box.jar --main-class Box -C src Box.class
java -cp src Controller "$@"
5 changes: 1 addition & 4 deletions src/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.UUID;

Expand Down Expand Up @@ -59,10 +57,9 @@ public void accept() throws IOException {
}
}

public static void main(String[] arguments) throws IOException {
public static void main(String[] arguments) {
validateArguments(arguments);
var box = createBoxFromArguments(arguments);
Files.writeString(Path.of(box.id.toString() + ".box.txt"), box.id.toString());
try {
box.start();
} catch (IOException failure) {
Expand Down
19 changes: 15 additions & 4 deletions src/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,27 @@ private static void redirect(
}
}

private static final int internalPort = 3_1337 ;

// All logging is done to System.err since output is redirected to System.out
public static void main(String[] arguments) throws InterruptedException {
validateArguments(arguments);
var executor = Executors.newCachedThreadPool();
var controller = new Controller(3_1337, arguments[0], executor);
var binaryPath = arguments[0];
var controller = new Controller(internalPort, binaryPath, executor);
runController(executor, controller);
int boxCount = arguments.length > 1 ? Integer.parseInt(arguments[1]) : 3;
startSomeBoxes(controller, boxCount);
startSomeBoxes(controller, readBoxCount(arguments));
Thread.sleep(10_000);
executor.shutdown();
executor.shutdownNow();
}

private static final int boxCountIndex = 1;
private static final int defaultBoxCount = 3;

private static int readBoxCount(String[] arguments) {
return arguments.length > boxCountIndex
? Integer.parseInt(arguments[boxCountIndex])
: defaultBoxCount;
}

private static void runController(Executor executor, Controller controller) {
Expand Down