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());
}
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;
}
Aggregations