Search in sources :

Example 36 with BBoxDBConnection

use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.

the class RegionMerger method mergeDataByNetworkRead.

/**
 * Merge the region by a network read
 *
 * @param region
 * @param tupleStoreName
 * @param tupleRedistributor
 * @param childRegion
 * @throws InterruptedException
 * @throws StorageManagerException
 * @throws Exception
 */
private void mergeDataByNetworkRead(final DistributionRegion region, final TupleStoreName tupleStoreName, final TupleRedistributor tupleRedistributor, final DistributionRegion childRegion) throws InterruptedException, StorageManagerException {
    final List<BBoxDBInstance> systems = childRegion.getSystems();
    assert (!systems.isEmpty()) : "Systems can not be empty";
    final BBoxDBInstance firstSystem = systems.get(0);
    final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(firstSystem);
    assert (connection != null) : "Connection can not be null: " + firstSystem.getStringValue();
    final BoundingBox bbox = childRegion.getConveringBox();
    final String fullname = tupleStoreName.getFullname();
    final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
    final TupleListFuture result = bboxDBClient.queryBoundingBox(fullname, bbox);
    result.waitForAll();
    if (result.isFailed()) {
        throw new StorageManagerException("Exception while fetching tuples: " + result.getAllMessages());
    }
    for (final Tuple tuple : result) {
        tupleRedistributor.redistributeTuple(tuple);
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 37 with BBoxDBConnection

use of org.bboxdb.network.client.BBoxDBConnection in project bboxdb by jnidzwetzki.

the class MembershipConnectionService method terminateConnection.

/**
 * Terminate the connection to a missing bboxdb system
 * @param distributedInstance
 */
private synchronized void terminateConnection(final BBoxDBInstance distributedInstance) {
    final String instanceName = distributedInstance.getStringValue();
    if (!serverConnections.containsKey(distributedInstance.getInetSocketAddress())) {
        return;
    }
    logger.info("Closing connection to dead instance: {}", instanceName);
    knownInstances.remove(distributedInstance.getInetSocketAddress());
    final BBoxDBConnection connection = serverConnections.remove(distributedInstance.getInetSocketAddress());
    connection.terminateConnection();
}
Also used : 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