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;
}
}
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);
}
}
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;
}
}
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());
}
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);
}
Aggregations