use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.
the class MembershipConnectionService method shutdown.
/**
* Shutdown the subsystem
*/
@Override
public void shutdown() {
BBoxDBInstanceManager.getInstance().removeListener(distributedEventConsumer);
// Close all connections
synchronized (serverConnections) {
for (final InetSocketAddress instance : serverConnections.keySet()) {
final BBoxDBConnection client = serverConnections.get(instance);
logger.info("Closing connection to server: " + instance);
client.disconnect();
}
serverConnections.clear();
knownInstances.clear();
}
}
use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.
the class MembershipConnectionService method createConnection.
/**
* Create a new connection to the given instance
* @param distributedInstance
*/
private void createConnection(final BBoxDBInstance distributedInstance) {
final String instanceName = distributedInstance.getStringValue();
if (serverConnections.containsKey(distributedInstance.getInetSocketAddress())) {
logger.info("We have already a connection to: {}", instanceName);
return;
}
if (blacklist.contains(distributedInstance.getInetSocketAddress())) {
logger.info("Not creating a connection to the blacklisted system: {}", instanceName);
return;
}
logger.info("Opening connection to instance: {}", instanceName);
final BBoxDBConnection connection = new BBoxDBConnection(distributedInstance.getInetSocketAddress());
final BBoxDBClient client = connection.getBboxDBClient();
client.setPagingEnabled(pagingEnabled);
client.setTuplesPerPage(tuplesPerPage);
client.setTupleStoreManagerRegistry(tupleStoreManagerRegistry);
final boolean result = connection.connect();
if (!result) {
logger.info("Unable to open connection to: {}", instanceName);
} else {
logger.info("Connection successfully established: {}", instanceName);
serverConnections.put(distributedInstance.getInetSocketAddress(), connection);
knownInstances.put(distributedInstance.getInetSocketAddress(), distributedInstance);
}
}
use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.
the class PackageRouter method sendInsertPackage.
/**
* @param insertTupleRequest
* @return
* @throws InterruptedException
* @throws PackageEncodeException
* @throws TimeoutException
* @throws ExecutionException
*/
protected boolean sendInsertPackage(final InsertTupleRequest insertTupleRequest) throws InterruptedException, PackageEncodeException {
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
final RoutingHop routingHop = routingHeader.getRoutingHop();
final BBoxDBInstance receiverInstance = routingHop.getDistributedInstance();
final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(receiverInstance);
if (connection == null) {
logger.error("Unable to get a connection to system: {}", receiverInstance);
return false;
}
final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
final EmptyResultFuture insertFuture = bboxDBClient.insertTuple(insertTupleRequest.getTable().getFullname(), insertTupleRequest.getTuple(), routingHeader);
try {
insertFuture.waitForAll(ROUTING_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
} catch (TimeoutException e) {
logger.warn("Routing timeout, retry routing: {}", connection);
return false;
}
final boolean operationSuccess = (!insertFuture.isFailed());
return operationSuccess;
}
use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.
the class TupleListFuture method performReadRepairForResult.
/**
* Perform read repair for the given result
*
* @param allTuples
* @param resultId
* @throws InterruptedException
* @throws BBoxDBException
* @throws ZookeeperException
*/
private void performReadRepairForResult(final List<Tuple> allTuples, int resultId) throws InterruptedException, BBoxDBException, ZookeeperException {
final List<Tuple> tupleResult = get(resultId);
final BBoxDBConnection bboxDBConnection = getConnection(resultId);
if (bboxDBConnection == null) {
// Unable to perform read repair when the connection is not known
return;
}
for (final Tuple tuple : allTuples) {
final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystem(tablename, tuple.getBoundingBox(), true, bboxDBConnection.getServerAddress(), true);
// System is not responsible for the tuple
if (routingHeader.getHopCount() == 0) {
return;
}
if (!tupleResult.contains(tuple)) {
logger.info("Tuple {} is not contained in result {} from server {}, " + "performing read repair", tuple, tupleResult, bboxDBConnection.getConnectionName());
final BBoxDBClient bboxDBClient = bboxDBConnection.getBboxDBClient();
bboxDBClient.insertTuple(tablename, tuple, routingHeader);
}
}
}
use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.
the class TestNetworkCommunication method connectToServer.
/**
* Build a new connection to the bboxdb server
*
* @return
*/
protected BBoxDBConnection connectToServer() {
final int port = BBoxDBConfigurationManager.getConfiguration().getNetworkListenPort();
final BBoxDBConnection bboxDBClient = new BBoxDBConnection(new InetSocketAddress("127.0.0.1", port));
if (compressPackages()) {
bboxDBClient.getClientCapabilities().setGZipCompression();
Assert.assertTrue(bboxDBClient.getClientCapabilities().hasGZipCompression());
} else {
bboxDBClient.getClientCapabilities().clearGZipCompression();
Assert.assertFalse(bboxDBClient.getClientCapabilities().hasGZipCompression());
}
Assert.assertFalse(bboxDBClient.isConnected());
boolean result = bboxDBClient.connect();
Assert.assertTrue(result);
Assert.assertTrue(bboxDBClient.isConnected());
if (compressPackages()) {
Assert.assertTrue(bboxDBClient.getConnectionCapabilities().hasGZipCompression());
} else {
Assert.assertFalse(bboxDBClient.getConnectionCapabilities().hasGZipCompression());
}
return bboxDBClient;
}
Aggregations