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();
}
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();
}
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);
}
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());
}
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());
}
Aggregations