Search in sources :

Example 26 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture 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)

Example 27 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class BBoxDBConnection method disconnect.

/* (non-Javadoc)
	 * @see org.bboxdb.network.client.BBoxDB#disconnect()
	 */
public void disconnect() {
    if (!connectionState.isInRunningState()) {
        logger.error("Unable to disconnect, connection is in state {}", connectionState);
        return;
    }
    synchronized (this) {
        logger.info("Disconnecting from server: {}", getConnectionName());
        connectionState.dispatchToStopping();
        final NetworkOperationFuture future = new NetworkOperationFuture(this, () -> {
            return new DisconnectRequest(getNextSequenceNumber());
        });
        future.execute();
    }
    settlePendingCalls(DEFAULT_TIMEOUT_MILLIS);
    terminateConnection();
}
Also used : DisconnectRequest(org.bboxdb.network.packages.request.DisconnectRequest) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture)

Example 28 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testAllRetry2.

@Test(timeout = 60000)
public void testAllRetry2() throws InterruptedException {
    final NetworkOperationFuture networkFuture1 = getFailingNetworkFuture();
    final NetworkOperationFuture networkFuture2 = getReadyNetworkFuture();
    final Supplier<List<NetworkOperationFuture>> supplier = () -> (Arrays.asList(networkFuture1, networkFuture2));
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(supplier, FutureRetryPolicy.RETRY_POLICY_ALL_FUTURES);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    final int totalRetries = OperationFuture.TOTAL_RETRIES + 1;
    final int executions1 = networkFuture1.getExecutions();
    final int executions2 = networkFuture2.getExecutions();
    Assert.assertTrue(executions1 == totalRetries || executions2 == totalRetries);
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) List(java.util.List) Test(org.junit.Test)

Example 29 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testNoRetry1.

@Test(timeout = 60000)
public void testNoRetry1() throws InterruptedException {
    final NetworkOperationFuture networkFuture = getFailingNetworkFuture();
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(networkFuture, FutureRetryPolicy.RETRY_POLICY_NONE);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    Assert.assertEquals(1, networkFuture.getExecutions());
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) Test(org.junit.Test)

Example 30 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testOneRetry2.

@Test(timeout = 60000)
public void testOneRetry2() throws InterruptedException {
    final NetworkOperationFuture networkFuture1 = getFailingNetworkFuture();
    final NetworkOperationFuture networkFuture2 = getReadyNetworkFuture();
    final Supplier<List<NetworkOperationFuture>> supplier = () -> (Arrays.asList(networkFuture1, networkFuture2));
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(supplier, FutureRetryPolicy.RETRY_POLICY_ONE_FUTURE);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    Assert.assertEquals(OperationFuture.TOTAL_RETRIES + 1, networkFuture1.getExecutions());
    Assert.assertEquals(1, networkFuture2.getExecutions());
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) List(java.util.List) Test(org.junit.Test)

Aggregations

NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)31 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)16 List (java.util.List)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)11 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)9 ArrayList (java.util.ArrayList)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)8 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)8 RoutingHop (org.bboxdb.network.routing.RoutingHop)8 Test (org.junit.Test)8 OperationFutureImpl (org.bboxdb.network.client.future.OperationFutureImpl)6 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)5 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)3 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)2 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)2 Tuple (org.bboxdb.storage.entity.Tuple)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1