use of org.bboxdb.network.packages.response.PageEndResponse in project bboxdb by jnidzwetzki.
the class ContinuousBoundingBoxClientQuery method fetchAndSendNextTuples.
@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
try {
long sendTuplesInThisPage = 0;
clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
while (queryActive) {
if (sendTuplesInThisPage >= tuplesPerPage) {
clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
return;
}
// Send next tuple or wait
final Tuple tuple = tupleQueue.take();
final JoinedTuple joinedTuple = new JoinedTuple(tuple, requestTable.getFullname());
clientConnectionHandler.writeResultTuple(packageSequence, joinedTuple);
totalSendTuples++;
sendTuplesInThisPage++;
}
// All tuples are send
clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
} catch (InterruptedException e) {
logger.debug("Got interrupted excetion");
close();
Thread.currentThread().interrupt();
}
}
use of org.bboxdb.network.packages.response.PageEndResponse in project bboxdb by jnidzwetzki.
the class StreamClientQuery method fetchAndSendNextTuples.
/* (non-Javadoc)
* @see org.bboxdb.network.server.ClientQuery#fetchAndSendNextTuples(short)
*/
@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
long sendTuplesInThisPage = 0;
clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
while (!isDataExhausted()) {
if (activeOperatorIterator == null) {
setupNewIterator();
}
// Unable to set up a new iterator
if (activeOperatorIterator == null) {
break;
}
while (activeOperatorIterator.hasNext()) {
// Handle page end
if (pageResult == true && sendTuplesInThisPage >= tuplesPerPage) {
clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
return;
}
// Send next tuple
final JoinedTuple tuple = activeOperatorIterator.next();
clientConnectionHandler.writeResultTuple(packageSequence, tuple);
totalSendTuples++;
sendTuplesInThisPage++;
}
closeIteratorNE();
}
// All tuples are send
clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
}
use of org.bboxdb.network.packages.response.PageEndResponse in project bboxdb by jnidzwetzki.
the class PageEndHandler method handleServerResult.
/**
* Handle the end of a page
* @return
*/
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle page end package");
}
final PageEndResponse result = PageEndResponse.decodePackage(encodedPackage);
final short sequenceNumber = result.getSequenceNumber();
final List<PagedTransferableEntity> resultList = bBoxDBConnection.getResultBuffer().remove(sequenceNumber);
// Collect tuples of the next page in new list
bBoxDBConnection.getResultBuffer().put(sequenceNumber, new ArrayList<>());
if (future == null) {
logger.warn("Got handleMultiTupleEnd and pendingCall is empty");
return true;
}
if (resultList == null) {
logger.warn("Got handleMultiTupleEnd and resultList is empty (package {})", sequenceNumber);
future.setFailedState();
future.fireCompleteEvent();
return true;
}
ResponseHandlerHelper.castAndSetFutureResult(future, resultList, false);
return true;
}
use of org.bboxdb.network.packages.response.PageEndResponse in project bboxdb by jnidzwetzki.
the class KeyClientQuery method fetchAndSendNextTuples.
@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
long sendTuplesInThisPage = 0;
clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
final Iterator<Tuple> tupleListIterator = tuplesForKey.iterator();
while (tupleListIterator.hasNext()) {
if (pageResult == true && sendTuplesInThisPage >= tuplesPerPage) {
clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
return;
}
// Send next tuple
final Tuple tuple = tupleListIterator.next();
tupleListIterator.remove();
final JoinedTuple joinedTuple = new JoinedTuple(tuple, requestTable.getFullname());
clientConnectionHandler.writeResultTuple(packageSequence, joinedTuple);
totalSendTuples++;
sendTuplesInThisPage++;
}
// All tuples are send
clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
}
Aggregations