Search in sources :

Example 16 with BBoxDBConnection

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();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection)

Example 17 with BBoxDBConnection

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);
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection)

Example 18 with BBoxDBConnection

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;
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) TimeoutException(java.util.concurrent.TimeoutException)

Example 19 with BBoxDBConnection

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);
        }
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Tuple(org.bboxdb.storage.entity.Tuple)

Example 20 with BBoxDBConnection

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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection)

Aggregations

BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)37 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)26 Test (org.junit.Test)24 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)8 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)5 Tuple (org.bboxdb.storage.entity.Tuple)5 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 InetSocketAddress (java.net.InetSocketAddress)3 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)3 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)3 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)3 ExecutionException (java.util.concurrent.ExecutionException)2 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)2 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)2 StorageManagerException (org.bboxdb.storage.StorageManagerException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 RejectedException (org.bboxdb.commons.RejectedException)1