use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.
the class DataRedistributionLoader method deleteFile.
/**
* Remove the given file
* @param fileid
* @throws InterruptedException
*/
private void deleteFile(final int fileid) throws InterruptedException {
final String filename = files[fileid];
if (!loadedFiles.contains(filename)) {
System.err.println("File " + filename + " is not loaded");
return;
}
System.out.println("Removing content from: " + filename);
final AtomicInteger lineNumber = new AtomicInteger(0);
final String prefix = Integer.toString(fileid) + "_";
try (final Stream<String> lines = Files.lines(Paths.get(filename))) {
lines.forEach(l -> {
final String key = prefix + lineNumber.getAndIncrement();
try {
final EmptyResultFuture resultFuture = bboxDBCluster.deleteTuple(TABLE, key);
pendingFutures.put(resultFuture);
if (lineNumber.get() % 1000 == 0) {
System.out.format("Deleted %d elements\n", lineNumber.get());
}
} catch (BBoxDBException e) {
logger.error("Got error while deleting tuple", e);
}
});
} catch (IOException e) {
System.err.println("Got an exeption while reading file: " + e);
System.exit(-1);
}
pendingFutures.waitForCompletion();
loadedFiles.remove(filename);
}
use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.
the class DataRedistributionLoader method initBBoxDB.
/**
* Re-Create the distribution group and the table
*/
private void initBBoxDB() {
try {
// Delete old distribution group
System.out.println("Delete old distribution group");
final EmptyResultFuture dgroupDeleteResult = bboxDBCluster.deleteDistributionGroup(DGROUP);
dgroupDeleteResult.waitForAll();
if (dgroupDeleteResult.isFailed()) {
System.err.println(dgroupDeleteResult.getAllMessages());
System.exit(-1);
}
// Create new distribution group
System.out.println("Create new distribution group");
final DistributionGroupConfiguration dgroupConfig = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor((short) 1).withMaximumRegionSize(16).withMinimumRegionSize(4).build();
final EmptyResultFuture dgroupCreateResult = bboxDBCluster.createDistributionGroup(DGROUP, dgroupConfig);
dgroupCreateResult.waitForAll();
if (dgroupCreateResult.isFailed()) {
System.err.println(dgroupCreateResult.getAllMessages());
System.exit(-1);
}
// Create new table
System.out.println("Create new table");
final TupleStoreConfiguration storeConfiguration = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
final EmptyResultFuture tableCreateResult = bboxDBCluster.createTable(TABLE, storeConfiguration);
tableCreateResult.waitForAll();
if (tableCreateResult.isFailed()) {
System.err.println(tableCreateResult.getAllMessages());
System.exit(-1);
}
} catch (Exception e) {
System.err.println("Got an exception while prepating BBoxDB");
e.printStackTrace();
System.exit(-1);
}
}
use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.
the class BenchmarkFileInsertPerformance method handleLine.
/**
* Handle a line from the input file
* @param line
* @throws BBoxDBException
*/
protected void handleLine(String line) {
try {
final Polygon polygon = Polygon.fromGeoJson(line);
final byte[] tupleBytes = polygon.toGeoJson().getBytes();
final Tuple tuple = new Tuple(Long.toString(polygon.getId()), polygon.getBoundingBox(), tupleBytes);
final EmptyResultFuture insertFuture = bboxdbClient.insertTuple(table, tuple);
// register pending future
pendingFutures.put(insertFuture);
insertedTuples.incrementAndGet();
} catch (BBoxDBException e) {
System.err.println("Got an exeption while reading file: " + e);
System.exit(-1);
}
}
Aggregations