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