TcpIncomingConnector incomingConnector = new TcpIncomingConnector(executorFactory, getClass().getClassLoader());
final CompletionHandler finished = new CompletionHandler();
LOGGER.lifecycle("Awaiting requests.");
URI uri = incomingConnector.accept(new Action<ConnectEvent<Connection<Object>>>() {
public void execute(ConnectEvent<Connection<Object>> connectionConnectEvent) {
try {
finished.onStartActivity();
handler.handle(connectionConnectEvent.getConnection(), finished);
} finally {
finished.onActivityComplete();
connectionConnectEvent.getConnection().stop();
}
}
});
try {
File registryFile = getRegistryFile();
registryFile.getParentFile().mkdirs();
// registryFile.createNewFile();
FileOutputStream outputStream = new FileOutputStream(registryFile);
try {
// Lock file while writing to it
outputStream.getChannel().lock();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeUTF(uri.toString());
dataOutputStream.flush();
} finally {
// Also releases the lock
outputStream.close();
}