Search in sources :

Example 1 with HelloFuture

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();
}
Also used : HelloFuture(org.bboxdb.network.client.future.HelloFuture) HelloResponse(org.bboxdb.network.packages.response.HelloResponse) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) HelloRequest(org.bboxdb.network.packages.request.HelloRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 ExecutionException (java.util.concurrent.ExecutionException)1 HelloFuture (org.bboxdb.network.client.future.HelloFuture)1 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 HelloRequest (org.bboxdb.network.packages.request.HelloRequest)1 HelloResponse (org.bboxdb.network.packages.response.HelloResponse)1