private void init() {
try {
binary = new OperaLauncherBinary(settings.getLauncher().getCanonicalPath(),
Iterables.toArray(arguments, String.class));
} catch (IOException e) {
throw new OperaRunnerException("Unable to start launcher: " + e.getMessage());
}
logger.fine("Waiting for launcher connection on port " + launcherPort);
ServerSocket listenerServer = null;
try {
// Setup listener server
listenerServer = new ServerSocket(launcherPort);
// TODO(andreastt): Unsafe int cast
listenerServer.setSoTimeout((int) OperaIntervals.LAUNCHER_CONNECT_TIMEOUT.getMs());
// Try to connect
protocol = new OperaLauncherProtocol(listenerServer.accept());
// We did it!
logger.fine("Connected with launcher on port " + launcherPort);
// Do the handshake!
LauncherHandshakeRequest.Builder request = LauncherHandshakeRequest.newBuilder();
ResponseEncapsulation res = protocol.sendRequest(
MessageType.MSG_HELLO, request.build().toByteArray());
// Are we happy?
if (res.isSuccess()) {
logger.finer("Got launcher handshake: " + res.getResponse().toString());
} else {
throw new OperaRunnerException(
"Did not get launcher handshake: " + res.getResponse().toString());
}
} catch (SocketTimeoutException e) {
throw new OperaRunnerException("Timeout waiting for launcher to connect on port " +
launcherPort, e);
} catch (IOException e) {
throw new OperaRunnerException("Unable to listen to launcher port " + launcherPort, e);
} finally {
Closeables.closeQuietly(listenerServer);
}
}