/**
* Console entry point.
*/
public static void main(String[] args) {
int exitStatus = 0;
Serializer serializer = null;
try {
// Pick the communication channel.
final BootstrapEvent.EventChannelType channel = establishCommunicationChannel();
new Serializer(System.out)
.serialize(new BootstrapEvent(channel))
.flush();
final int bufferSize = 16 * 1024;
switch (channel) {
case STDERR:
serializer = new Serializer(new BufferedOutputStream(System.err, bufferSize));
warnings = System.out;
break;
case STDOUT:
serializer = new Serializer(new BufferedOutputStream(System.out, bufferSize));
warnings = System.err;
break;
default:
warnings = System.err;
throw new RuntimeException("Communication not implemented: " + channel);
}
// Redirect original streams and start running tests.
redirectStreams(serializer);
final SlaveMain main = new SlaveMain(serializer);
parseArguments(main, args);
main.execute();
} catch (Throwable t) {
warn("Exception at main loop level?", t);
exitStatus = -1;
} finally {
restoreStreams();
}
if (serializer != null) {
try {
serializer.serialize(new QuitEvent());
serializer.getOutputStream().close();
} catch (IOException e) {
// Ignore.
}
}