Search in sources :

Example 36 with EmptyResultFuture

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;
    }
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreConfigurationBuilder(org.bboxdb.storage.entity.TupleStoreConfigurationBuilder) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 37 with EmptyResultFuture

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;
    }
}
Also used : TupleFileReader(org.bboxdb.tools.TupleFileReader) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 38 with EmptyResultFuture

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;
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 39 with EmptyResultFuture

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);
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 40 with EmptyResultFuture

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