use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.
the class CLI method actionCreateTable.
/**
* Create a new table
* @param line
*/
protected void actionCreateTable(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Create table should be performed, but no table was specified");
printHelpAndExit();
}
final TupleStoreConfigurationBuilder ssTableConfigurationBuilder = TupleStoreConfigurationBuilder.create();
// Duplicates
if (line.hasOption(CLIParameter.DUPLICATES)) {
final String allowDuplicates = line.getOptionValue(CLIParameter.DUPLICATES);
final boolean duplicatesAllowed = MathUtil.tryParseBooleanOrExit(allowDuplicates, () -> "Unable to parse the bolean value for duplicates: " + allowDuplicates);
ssTableConfigurationBuilder.allowDuplicates(duplicatesAllowed);
}
// TTL
if (line.hasOption(CLIParameter.TTL)) {
final String ttlString = line.getOptionValue(CLIParameter.TTL);
final int ttl = MathUtil.tryParseIntOrExit(ttlString, () -> "Unable to parse the region size: " + ttlString);
ssTableConfigurationBuilder.withTTL(ttl, TimeUnit.MILLISECONDS);
}
// Versions
if (line.hasOption(CLIParameter.VERSIONS)) {
final String versionString = line.getOptionValue(CLIParameter.VERSIONS);
final int versions = MathUtil.tryParseIntOrExit(versionString, () -> "Unable to parse the region size: " + versionString);
ssTableConfigurationBuilder.withVersions(versions);
}
// Spatial index reader
if (line.hasOption(CLIParameter.SPATIAL_INDEX_READER)) {
final String spatialIndexReader = line.getOptionValue(CLIParameter.SPATIAL_INDEX_READER);
ssTableConfigurationBuilder.withSpatialIndexReader(spatialIndexReader);
}
// Spatial index writer
if (line.hasOption(CLIParameter.SPATIAL_INDEX_WRITER)) {
final String spatialIndexWriter = line.getOptionValue(CLIParameter.SPATIAL_INDEX_WRITER);
ssTableConfigurationBuilder.withSpatialIndexWriter(spatialIndexWriter);
}
final TupleStoreConfiguration configuration = ssTableConfigurationBuilder.build();
try {
final String table = line.getOptionValue(CLIParameter.TABLE);
final EmptyResultFuture resultFuture = bboxDbConnection.createTable(table, configuration);
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to create table: " + resultFuture.getAllMessages());
System.exit(-1);
}
} catch (BBoxDBException e) {
System.err.println("Got an exception while creating table: " + 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 actionImportData.
/**
* Import data
* @param line
*/
protected void actionImportData(final CommandLine line) {
final List<String> requiredArgs = Arrays.asList(CLIParameter.FILE, CLIParameter.FORMAT, CLIParameter.TABLE);
checkRequiredArgs(requiredArgs);
final String filename = line.getOptionValue(CLIParameter.FILE);
final String format = line.getOptionValue(CLIParameter.FORMAT);
final String table = line.getOptionValue(CLIParameter.TABLE);
System.out.println("Importing file: " + filename);
final TupleFileReader tupleFile = new TupleFileReader(filename, format);
tupleFile.addTupleListener(t -> {
if (t == null) {
logger.error("Unable to parse line: " + tupleFile.getLastReadLine());
return;
}
if (tupleFile.getProcessedLines() % 1000 == 0) {
System.out.format("Read %d lines%n", tupleFile.getProcessedLines());
}
try {
final EmptyResultFuture result = bboxDbConnection.insertTuple(table, t);
pendingFutures.put(result);
} catch (BBoxDBException e) {
logger.error("Got exception while inserting tuple", e);
}
});
try {
tupleFile.processFile();
pendingFutures.waitForCompletion();
System.out.format("Successfully imported %d lines%n", tupleFile.getProcessedLines());
} catch (IOException e) {
logger.error("Got IO Exception while reading data", 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 actionDeleteTable.
/**
* Delete an existing table
* @param line
*/
protected void actionDeleteTable(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Delete table should be performed, but no table was specified");
printHelpAndExit();
}
try {
final String table = line.getOptionValue(CLIParameter.TABLE);
final EmptyResultFuture resultFuture = bboxDbConnection.deleteTable(table);
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to delete table: " + resultFuture.getAllMessages());
System.exit(-1);
}
} catch (BBoxDBException e) {
System.err.println("Got an exception while deleting table: " + 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 actionDeleteDgroup.
/**
* Delete a distribution group
* @param line
*/
protected void actionDeleteDgroup(final CommandLine line) {
final List<String> requiredArgs = Arrays.asList(CLIParameter.DISTRIBUTION_GROUP);
checkRequiredArgs(requiredArgs);
final String distributionGroup = line.getOptionValue(CLIParameter.DISTRIBUTION_GROUP);
System.out.println("Deleting distribution group: " + distributionGroup);
try {
final EmptyResultFuture future = bboxDbConnection.deleteDistributionGroup(distributionGroup);
future.waitForAll();
if (future.isFailed()) {
System.err.println("Got an error during distribution group deletion: " + 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 TestFixedFutureStore method testTupleStore1.
/**
* Add more futures in failed state
*/
@Test(timeout = 5000)
public void testTupleStore1() {
final FixedSizeFutureStore futureStore = new FixedSizeFutureStore(10);
for (int i = 0; i < 20; i++) {
final EmptyResultFuture future = new EmptyResultFuture(() -> (new ArrayList<>()));
futureStore.put(future);
}
}
Aggregations