in tools/cli/src/main/java/org/apache/batchee/cli/command/StartableCommand.java [176:221]
public void run() {
try {
serverSocket = new ServerSocket(adminSocketPort);
while (Integer.MIN_VALUE == id || !Batches.isDone(operator, id)) {
final Socket client = serverSocket.accept();
final OutputStream outputStream = client.getOutputStream();
synchronized (this) { // no need to support N clients
try {
final String[] command = IOUtils.toString(client.getInputStream()).trim().split(" ");
if (command.length >= 2) {
final long id = Long.parseLong(command[1]);
try {
if ("stop".equals(command[0])) {
operator.stop(id);
} else if ("abandon".equals(command[0])) {
operator.abandon(id);
}
} catch (final Exception e) {
// no-op
}
if (command.length >= 3 && Boolean.parseBoolean(command[2])) {
Batches.waitForEnd(id);
}
// let the client close if waiting
outputStream.write(0);
} else { // error
outputStream.write(-1);
}
outputStream.flush();
} finally {
IOUtils.closeQuietly(client);
}
}
}
} catch (final IOException e) {
if (!serverSocket.isClosed()) {
e.printStackTrace();
}
} finally {
if (!serverSocket.isClosed()) {
IOUtils.closeQuietly(serverSocket);
}
}
}