Search in sources :

Example 1 with MultipleTupleStartResponse

use of org.bboxdb.network.packages.response.MultipleTupleStartResponse 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 MultipleTupleStartResponse

use of org.bboxdb.network.packages.response.MultipleTupleStartResponse 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 MultipleTupleStartResponse

use of org.bboxdb.network.packages.response.MultipleTupleStartResponse in project bboxdb by jnidzwetzki.

the class MultipleTupleStartHandler method handleServerResult.

/**
 * Handle the multiple tuple start package
 * @return
 */
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
    if (logger.isDebugEnabled()) {
        logger.debug("Handle multiple tuple start package");
    }
    final MultipleTupleStartResponse result = MultipleTupleStartResponse.decodePackage(encodedPackage);
    final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
    resultBuffer.put(result.getSequenceNumber(), new ArrayList<>());
    return false;
}
Also used : MultipleTupleStartResponse(org.bboxdb.network.packages.response.MultipleTupleStartResponse) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with MultipleTupleStartResponse

use of org.bboxdb.network.packages.response.MultipleTupleStartResponse 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

MultipleTupleStartResponse (org.bboxdb.network.packages.response.MultipleTupleStartResponse)4 MultipleTupleEndResponse (org.bboxdb.network.packages.response.MultipleTupleEndResponse)3 PageEndResponse (org.bboxdb.network.packages.response.PageEndResponse)3 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)3 Tuple (org.bboxdb.storage.entity.Tuple)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1