use of org.bboxdb.network.packages.response.MultipleTupleEndResponse 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.MultipleTupleEndResponse 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.MultipleTupleEndResponse 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();
}
use of org.bboxdb.network.packages.response.MultipleTupleEndResponse in project bboxdb by jnidzwetzki.
the class MultipleTupleEndHandler method handleServerResult.
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle multiple tuple end package");
}
final MultipleTupleEndResponse result = MultipleTupleEndResponse.decodePackage(encodedPackage);
final short sequenceNumber = result.getSequenceNumber();
final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
final List<PagedTransferableEntity> resultList = resultBuffer.remove(sequenceNumber);
if (future == null) {
logger.error("Got handleMultiTupleEnd and future is null (package {}) ", sequenceNumber);
return true;
}
if (resultList == null) {
logger.error("Got handleMultiTupleEnd and resultList is empty (package {})", sequenceNumber);
future.setFailedState();
future.fireCompleteEvent();
return true;
}
ResponseHandlerHelper.castAndSetFutureResult(future, resultList, true);
return true;
}
Aggregations