use of org.bboxdb.network.client.future.HelloFuture in project bboxdb by jnidzwetzki.
the class BBoxDBConnection method runHandshake.
/**
* Run the handshake with the server
* @throws ExecutionException
* @throws InterruptedException
*/
private void runHandshake() throws Exception {
if (!connectionState.isInStartingState()) {
logger.error("Handshaking called in wrong state: {}", connectionState);
}
// Capabilities are reported to server; now freeze client capabilities.
clientCapabilities.freeze();
final NetworkOperationFuture operationFuture = new NetworkOperationFuture(this, () -> {
return new HelloRequest(getNextSequenceNumber(), NetworkConst.PROTOCOL_VERSION, clientCapabilities);
});
final HelloFuture helloFuture = new HelloFuture(operationFuture);
helloFuture.waitForAll();
if (operationFuture.isFailed()) {
throw new Exception("Got an error during handshake");
}
final HelloResponse helloResponse = helloFuture.get(0);
connectionCapabilities = helloResponse.getPeerCapabilities();
connectionState.dispatchToRunning();
logger.debug("Handshaking with {} done", getConnectionName());
flushHandler = new ConnectionFlushRunnable(this);
flushThread = new Thread(flushHandler);
flushThread.setName("Flush thread for: " + getConnectionName());
flushThread.start();
mainteinanceHandler = new ConnectionMainteinanceRunnable(this);
mainteinanceThread = new Thread(mainteinanceHandler);
mainteinanceThread.setName("Connection mainteinace thread for: " + getConnectionName());
mainteinanceThread.start();
}
Aggregations