Search in sources :

Example 1 with NextPageRequest

use of org.bboxdb.network.packages.request.NextPageRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeNextPage.

/**
 * The encoding and decoding of an next page package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeNextPage() throws IOException, PackageEncodeException {
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final short querySequence = 12;
    final NextPageRequest nextPageRequest = new NextPageRequest(sequenceNumber, querySequence);
    byte[] encodedVersion = networkPackageToByte(nextPageRequest);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final NextPageRequest decodedPackage = NextPageRequest.decodeTuple(bb);
    Assert.assertEquals(decodedPackage.getQuerySequence(), querySequence);
    Assert.assertEquals(nextPageRequest.hashCode(), decodedPackage.hashCode());
    Assert.assertEquals(nextPageRequest.toString(), decodedPackage.toString());
}
Also used : NextPageRequest(org.bboxdb.network.packages.request.NextPageRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with NextPageRequest

use of org.bboxdb.network.packages.request.NextPageRequest in project bboxdb by jnidzwetzki.

the class NextPageHandler method handleRequest.

@Override
public /**
 * Handle the next page package
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final NextPageRequest nextPagePackage = NextPageRequest.decodeTuple(encodedPackage);
        logger.debug("Next page for query {} called", nextPagePackage.getQuerySequence());
        // Send tuples as result for original query
        clientConnectionHandler.sendNextResultsForQuery(packageSequence, nextPagePackage.getQuerySequence());
    } catch (PackageEncodeException e) {
        logger.warn("Error getting next page for a query", e);
        final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
        clientConnectionHandler.writeResultPackage(errorResponse);
    }
    return true;
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) NextPageRequest(org.bboxdb.network.packages.request.NextPageRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

NextPageRequest (org.bboxdb.network.packages.request.NextPageRequest)2 ByteBuffer (java.nio.ByteBuffer)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 Test (org.junit.Test)1