Search in sources :

Example 1 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class AbstractTheadedListFutureIterator method setupProducer.

/**
 * Setup the worker that fetches the data from the futures
 */
public void setupProducer(final int resultId) {
    logger.trace("Start producer for {}", resultId);
    final Runnable producer = new Runnable() {

        @Override
        public void run() {
            try {
                final List<T> tupleList = abstractLisFuture.get(resultId);
                addTupleListToQueue(tupleList);
                if (!abstractLisFuture.isCompleteResult(resultId)) {
                    handleAdditionalPages();
                }
            } catch (ExecutionException e) {
                logger.warn("Got exception while writing data to queue", e);
            } catch (InterruptedException e) {
                logger.warn("Got exception while writing data to queue", e);
                Thread.currentThread().interrupt();
            } finally {
                addTerminalNE();
                logger.trace("Producer {} is done", resultId);
            }
        }

        /**
         * Request and add the additional pages to the queue
         * @throws ExecutionException
         * @throws InterruptedException
         */
        @SuppressWarnings("unchecked")
        protected void handleAdditionalPages() throws InterruptedException, ExecutionException {
            final BBoxDBConnection bboxdbConnection = abstractLisFuture.getConnection(resultId);
            if (bboxdbConnection == null) {
                logger.error("Unable to get connection for paging: {}", resultId);
                return;
            }
            final short queryRequestId = abstractLisFuture.getRequestId(resultId);
            final BBoxDBClient bbBoxDBClient = bboxdbConnection.getBboxDBClient();
            AbstractListFuture<T> nextPage = null;
            do {
                nextPage = (AbstractListFuture<T>) bbBoxDBClient.getNextPage(queryRequestId);
                nextPage.waitForAll();
                if (nextPage.isFailed()) {
                    logger.error("Requesting next page failed! Query result is incomplete: {}", nextPage.getAllMessages());
                    return;
                }
                // result objects should be 1
                if (nextPage.getNumberOfResultObjets() != 1) {
                    logger.error("Got a non expected number of result objects {}", nextPage.getNumberOfResultObjets());
                }
                addTupleListToQueue(nextPage.get(0));
            } while (!nextPage.isCompleteResult(0));
        }

        /**
         * Add the tuple list into the queue
         * @param tupleList
         * @throws InterruptedException
         */
        protected void addTupleListToQueue(final List<T> tupleList) throws InterruptedException {
            for (final T element : tupleList) {
                tupleQueue.put(element);
            }
        }

        /**
         * Add the terminal to the queue
         */
        protected void addTerminalNE() {
            try {
                tupleQueue.put(QUEUE_TERMINAL);
            } catch (InterruptedException e) {
            // Got the interrupted exception while addint the
            // terminal, ignoring
            }
        }
    };
    executor.submit(producer);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) List(java.util.List) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class OperationFutureImpl method cancelOldFuture.

/**
 * Cancel the old future
 * @param future
 */
private void cancelOldFuture(final NetworkOperationFuture future) {
    final NetworkRequestPackage transmittedPackage = future.getTransmittedPackage();
    if (transmittedPackage == null) {
        return;
    }
    if (!transmittedPackage.needsToBeCanceled()) {
        return;
    }
    // Only successfull futures needs to be canceled
    if (future.isFailed()) {
        return;
    }
    final BBoxDBConnection connection = future.getConnection();
    final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
    bboxDBClient.cancelQuery(transmittedPackage.getSequenceNumber());
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection)

Example 3 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testInsertAndDelete.

/**
 * The the insert and the deletion of a tuple
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testInsertAndDelete() throws InterruptedException, ExecutionException, BBoxDBException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    NetworkQueryHelper.testInsertAndDeleteTuple(bboxDBClient, DISTRIBUTION_GROUP);
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Test(org.junit.Test)

Example 4 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testVersionTimeQuery.

/**
 * Execute the version time query
 * @throws BBoxDBException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testVersionTimeQuery() throws InterruptedException, BBoxDBException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    NetworkQueryHelper.testVersionTimeQuery(bboxDBClient, DISTRIBUTION_GROUP);
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Test(org.junit.Test)

Example 5 with BBoxDBClient

use of org.bboxdb.network.client.BBoxDBClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testGetByKey.

/**
 * Insert a tuple and request it via key
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testGetByKey() throws InterruptedException, ExecutionException, BBoxDBException {
    System.out.println("=== Running testGetByKey");
    final String table = DISTRIBUTION_GROUP + "_relation12333";
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Inside our bbox query
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0d, 1d, 0d, 1d), "abc".getBytes());
    final EmptyResultFuture result1 = bboxDBClient.insertTuple(table, tuple1);
    result1.waitForAll();
    final TupleListFuture future = bboxDBClient.queryKey(table, "abc");
    future.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    Assert.assertEquals(1, resultList.size());
    System.out.println("=== End testGetByKey");
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)27 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)26 Test (org.junit.Test)20 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)8 Tuple (org.bboxdb.storage.entity.Tuple)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)4 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)1 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)1 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)1 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)1 StorageManagerException (org.bboxdb.storage.StorageManagerException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 Before (org.junit.Before)1