Search in sources :

Example 16 with EmptyResultFuture

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

the class CLI method actionInsertTuple.

/**
 * Insert a new tuple
 * @param line
 */
protected void actionInsertTuple(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.TABLE, CLIParameter.KEY, CLIParameter.BOUNDING_BOX, CLIParameter.VALUE);
    checkRequiredArgs(requiredArgs);
    final String table = line.getOptionValue(CLIParameter.TABLE);
    final String key = line.getOptionValue(CLIParameter.KEY);
    final String value = line.getOptionValue(CLIParameter.VALUE);
    final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
    final Tuple tuple = new Tuple(key, boundingBox, value.getBytes());
    System.out.println("Insert new tuple into table: " + table);
    try {
        final EmptyResultFuture future = bboxDbConnection.insertTuple(table, tuple);
        pendingFutures.put(future);
        pendingFutures.waitForCompletion();
    } catch (BBoxDBException e) {
        System.err.println("Got an error during insert: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 17 with EmptyResultFuture

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

the class CLI method actionCreateDgroup.

/**
 * Create a new distribution group
 * @param line
 */
protected void actionCreateDgroup(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.DISTRIBUTION_GROUP, CLIParameter.DIMENSIONS, CLIParameter.REPLICATION_FACTOR);
    checkRequiredArgs(requiredArgs);
    final String maxRegionSizeString = CLIHelper.getParameterOrDefault(line, CLIParameter.MAX_REGION_SIZE, Integer.toString(Const.DEFAULT_MAX_REGION_SIZE));
    final String minRegionSizeString = CLIHelper.getParameterOrDefault(line, CLIParameter.MIN_REGION_SIZE, Integer.toString(Const.DEFAULT_MIN_REGION_SIZE));
    final int maxRegionSize = MathUtil.tryParseIntOrExit(maxRegionSizeString, () -> "Unable to parse the max region size: " + maxRegionSizeString);
    final int minRegionSize = MathUtil.tryParseIntOrExit(minRegionSizeString, () -> "Unable to parse the min region size: " + minRegionSizeString);
    final String resourcePlacement = CLIHelper.getParameterOrDefault(line, CLIParameter.RESOURCE_PLACEMENT, Const.DEFAULT_PLACEMENT_STRATEGY);
    final String resourcePlacementConfig = CLIHelper.getParameterOrDefault(line, CLIParameter.RESOURCE_PLACEMENT_CONFIG, Const.DEFAULT_PLACEMENT_CONFIG);
    final String spacePartitioner = CLIHelper.getParameterOrDefault(line, CLIParameter.SPACE_PARTITIONER, Const.DEFAULT_SPACE_PARTITIONER);
    final String spacePartitionerConfig = CLIHelper.getParameterOrDefault(line, CLIParameter.SPACE_PARTITIONER_CONFIG, Const.DEFAULT_SPACE_PARTITIONER_CONFIG);
    final String distributionGroup = line.getOptionValue(CLIParameter.DISTRIBUTION_GROUP);
    final String replicationFactorString = line.getOptionValue(CLIParameter.REPLICATION_FACTOR);
    final int replicationFactor = MathUtil.tryParseIntOrExit(replicationFactorString, () -> "This is not a valid replication factor: " + replicationFactorString);
    final String dimensionsString = line.getOptionValue(CLIParameter.DIMENSIONS);
    final int dimensions = MathUtil.tryParseIntOrExit(dimensionsString, () -> "This is not a valid dimension: " + dimensionsString);
    System.out.println("Create new distribution group: " + distributionGroup);
    try {
        final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) replicationFactor).withMaximumRegionSize(maxRegionSize).withMinimumRegionSize(minRegionSize).withPlacementStrategy(resourcePlacement, resourcePlacementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).build();
        final EmptyResultFuture future = bboxDbConnection.createDistributionGroup(distributionGroup, configuration);
        future.waitForAll();
        if (future.isFailed()) {
            System.err.println("Got an error during distribution group creation: " + future.getAllMessages());
        }
    } catch (BBoxDBException e) {
        System.err.println("Got an exception during distribution group creation: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        System.err.println("Waiting was interrupted");
        System.exit(-1);
    }
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 18 with EmptyResultFuture

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

the class CLI method actionDeleteTuple.

/**
 * Delete a tuple
 * @param line
 */
protected void actionDeleteTuple(final CommandLine line) {
    if (!line.hasOption(CLIParameter.KEY) || !line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Key or table are missing");
        printHelpAndExit();
    }
    final String key = line.getOptionValue(CLIParameter.KEY);
    final String table = line.getOptionValue(CLIParameter.TABLE);
    System.out.println("Deleting tuple for key: " + key);
    try {
        final EmptyResultFuture resultFuture = bboxDbConnection.deleteTuple(table, key);
        pendingFutures.put(resultFuture);
        pendingFutures.waitForCompletion();
    } catch (BBoxDBException e) {
        System.err.println("Got an error during delete: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 19 with EmptyResultFuture

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

the class TestFixedFutureStore method testTupleStore3.

/**
 * Add more futures in failed state and count failed callbacks
 * @throws InterruptedException
 */
@Test(timeout = 5000)
public void testTupleStore3() throws InterruptedException {
    final FixedSizeFutureStore futureStore = new FixedSizeFutureStore(10);
    final AtomicInteger atomicInteger = new AtomicInteger(0);
    futureStore.addFailedFutureCallback(c -> {
        atomicInteger.incrementAndGet();
    });
    for (int i = 0; i < 20; i++) {
        final NetworkOperationFuture networkOperationFuture = TestFuture.getFailingNetworkFuture();
        final EmptyResultFuture future = new EmptyResultFuture(networkOperationFuture);
        futureStore.put(future);
    }
    futureStore.waitForCompletion();
    Assert.assertTrue(true);
    Assert.assertEquals(20, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) FixedSizeFutureStore(org.bboxdb.network.client.tools.FixedSizeFutureStore) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Example 20 with EmptyResultFuture

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

the class TestFixedFutureStore method testTupleStore2.

/**
 * Add more futures in done state
 */
@Test(timeout = 5000)
public void testTupleStore2() {
    final FixedSizeFutureStore futureStore = new FixedSizeFutureStore(10);
    // Fail test on failed callback
    futureStore.addFailedFutureCallback(c -> {
        Assert.assertTrue(false);
    });
    for (int i = 0; i < 20; i++) {
        final EmptyResultFuture future = new EmptyResultFuture(() -> (new ArrayList<>()));
        futureStore.put(future);
    }
    Assert.assertTrue(true);
}
Also used : ArrayList(java.util.ArrayList) FixedSizeFutureStore(org.bboxdb.network.client.tools.FixedSizeFutureStore) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)43 Tuple (org.bboxdb.storage.entity.Tuple)17 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)15 BoundingBox (org.bboxdb.commons.math.BoundingBox)11 BBoxDBException (org.bboxdb.misc.BBoxDBException)11 Test (org.junit.Test)11 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)9 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)8 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)8 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)8 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)7 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)3 FixedSizeFutureStore (org.bboxdb.network.client.tools.FixedSizeFutureStore)3 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)3 List (java.util.List)2