Search in sources :

Example 1 with PageEndResponse

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();
    }
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 2 with PageEndResponse

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();
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 3 with PageEndResponse

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;
}
Also used : PagedTransferableEntity(org.bboxdb.storage.entity.PagedTransferableEntity) PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse)

Example 4 with PageEndResponse

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();
}
Also used : PageEndResponse(org.bboxdb.network.packages.response.PageEndResponse) MultipleTupleEndResponse(org.bboxdb.network.packages.response.MultipleTupleEndResponse) MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Aggregations

PageEndResponse (org.bboxdb.network.packages.response.PageEndResponse)4 MultipleTupleEndResponse (org.bboxdb.network.packages.response.MultipleTupleEndResponse)3 MultipleTupleStartResponse (org.bboxdb.network.packages.response.MultipleTupleStartResponse)3 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)3 Tuple (org.bboxdb.storage.entity.Tuple)2 PagedTransferableEntity (org.bboxdb.storage.entity.PagedTransferableEntity)1