Search in sources :

Example 16 with TupleListFuture

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

the class BBoxDBCluster method queryVersionTime.

@Override
public TupleListFuture queryVersionTime(final String table, final long timestamp) throws BBoxDBException {
    if (membershipConnectionService.getNumberOfConnections() == 0) {
        throw new BBoxDBException("queryTime called, but connection list is empty");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for timestamp {} in table {}", timestamp, table);
    }
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, BoundingBox.FULL_SPACE);
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getVersionTimeFuture(table, timestamp, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new TupleListFuture(futureProvider, new DoNothingDuplicateResolver(), table);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) DoNothingDuplicateResolver(org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 17 with TupleListFuture

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

the class BBoxDBCluster method queryBoundingBox.

@Override
public TupleListFuture queryBoundingBox(final String table, final BoundingBox boundingBox) throws BBoxDBException {
    if (logger.isDebugEnabled()) {
        logger.debug("Query by for bounding box {} in table {}", boundingBox, table);
    }
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, boundingBox);
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getQueryBoundingBoxFuture(table, boundingBox, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new TupleListFuture(futureProvider, new DoNothingDuplicateResolver(), table);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) DoNothingDuplicateResolver(org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 18 with TupleListFuture

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

the class BBoxDBClientExample method main.

/**
 * Connect to the BBoxDB Server at localhost and insert some tuples
 *
 * @param args
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void main(String[] args) throws InterruptedException, ExecutionException, BBoxDBException {
    // A 2 dimensional table (member of distribution group 'mygroup3') with the name 'testdata'
    final int dimensions = 2;
    final String distributionGroup = "mygroup3";
    final String mytable = distributionGroup + "_testdata";
    // The name of the cluster
    final String clustername = "mycluster";
    // The zookeeper connect points
    final List<String> connectPoints = Arrays.asList("localhost:2181");
    // Connect to the server
    final BBoxDB bboxdbClient = new BBoxDBCluster(connectPoints, clustername);
    bboxdbClient.connect();
    // Check the connection state
    if (!bboxdbClient.isConnected()) {
        System.out.println("Error while connecting to the BBoxDB cluster");
        System.exit(-1);
    }
    // Clean the old content of the distribution group
    final EmptyResultFuture deleteGroupResult = bboxdbClient.deleteDistributionGroup(distributionGroup);
    deleteGroupResult.waitForAll();
    if (deleteGroupResult.isFailed()) {
        System.err.println("Unable to delete distribution group: " + distributionGroup);
        System.err.println(deleteGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create a new distribution group
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) 3).build();
    final EmptyResultFuture createGroupResult = bboxdbClient.createDistributionGroup(distributionGroup, configuration);
    createGroupResult.waitForAll();
    if (createGroupResult.isFailed()) {
        System.err.println("Unable to create distribution group: " + distributionGroup);
        System.err.println(createGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create the table
    final TupleStoreConfiguration tableConfig = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
    final EmptyResultFuture createTableResult = bboxdbClient.createTable(mytable, tableConfig);
    createTableResult.waitForAll();
    if (createTableResult.isFailed()) {
        System.err.println("Unable to create table group: " + mytable);
        System.err.println(createTableResult.getAllMessages());
        System.exit(-1);
    }
    // Insert two new tuples
    final Tuple tuple1 = new Tuple("key1", new BoundingBox(0d, 5d, 0d, 1d), "mydata1".getBytes());
    final EmptyResultFuture insertResult1 = bboxdbClient.insertTuple(mytable, tuple1);
    final Tuple tuple2 = new Tuple("key2", new BoundingBox(-1d, 2d, -1d, 2d), "mydata2".getBytes());
    final EmptyResultFuture insertResult2 = bboxdbClient.insertTuple(mytable, tuple2);
    // Wait for the insert operations to complete
    insertResult1.waitForAll();
    insertResult2.waitForAll();
    if (insertResult1.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult1.getAllMessages());
        System.exit(-1);
    }
    if (insertResult2.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult2.getAllMessages());
        System.exit(-1);
    }
    // Query by key
    final TupleListFuture resultFuture1 = bboxdbClient.queryKey(mytable, "key");
    // We got a future object, the search is performed asynchronous
    // Wait for the result
    resultFuture1.waitForAll();
    if (resultFuture1.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture1.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture1) {
        System.out.println(tuple);
    }
    // Query by bounding box
    final TupleListFuture resultFuture2 = bboxdbClient.queryBoundingBox(mytable, new BoundingBox(-0.5d, 1d, -0.5d, 1d));
    // Again, we got a future object, the search is performed asynchronous
    resultFuture2.waitForAll();
    if (resultFuture2.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture2.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture2) {
        System.out.println("Tuple: " + tuple);
    }
    bboxdbClient.disconnect();
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 19 with TupleListFuture

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

the class BBoxDBClient method queryKey.

/* (non-Javadoc)
	 * @see org.bboxdb.network.client.BBoxDB#queryKey(java.lang.String, java.lang.String)
	 */
@Override
public TupleListFuture queryKey(final String table, final String key) {
    final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystemReadNE(table, BoundingBox.FULL_SPACE, true, connection.getServerAddress());
    final NetworkOperationFuture future = getQueryKeyFuture(table, key, routingHeader);
    final DuplicateResolver<Tuple> duplicateResolver = TupleStoreConfigurationCache.getInstance().getDuplicateResolverForTupleStore(table);
    return new TupleListFuture(future, duplicateResolver, table);
}
Also used : TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Example 20 with TupleListFuture

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

the class BBoxDBClient method queryInsertedTime.

/* (non-Javadoc)
	 * @see org.bboxdb.network.client.BBoxDB#queryTime(java.lang.String, long)
	 */
@Override
public TupleListFuture queryInsertedTime(final String table, final long timestamp) {
    final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystemReadNE(table, BoundingBox.FULL_SPACE, true, connection.getServerAddress());
    final NetworkOperationFuture future = getInsertedTimeFuture(table, timestamp, routingHeader);
    return new TupleListFuture(future, new DoNothingDuplicateResolver(), table);
}
Also used : TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) DoNothingDuplicateResolver(org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)

Aggregations

TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)32 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)18 Tuple (org.bboxdb.storage.entity.Tuple)18 BoundingBox (org.bboxdb.commons.math.BoundingBox)11 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)10 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)9 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)8 ArrayList (java.util.ArrayList)6 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)6 List (java.util.List)5 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)5 BBoxDBException (org.bboxdb.misc.BBoxDBException)5 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)5 RoutingHop (org.bboxdb.network.routing.RoutingHop)5 Test (org.junit.Test)5 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)4 BBoxDB (org.bboxdb.network.client.BBoxDB)2