use of org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest in project bboxdb by jnidzwetzki.
the class BBoxDBClient method getQueryBoundingBoxContinousFuture.
/**
* @param table
* @param boundingBox
* @return
*/
public NetworkOperationFuture getQueryBoundingBoxContinousFuture(final String table, final BoundingBox boundingBox) {
return new NetworkOperationFuture(connection, () -> {
final RoutingHeader routingHeaderSupplier = RoutingHeaderHelper.getRoutingHeaderForLocalSystemReadNE(table, boundingBox, false, connection.getServerAddress());
final short nextSequenceNumber = connection.getNextSequenceNumber();
return new QueryBoundingBoxContinuousRequest(nextSequenceNumber, routingHeaderSupplier, table, boundingBox);
});
}
use of org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testDecodeCointinousBoundingBoxQuery.
/**
* Test decode bounding box query
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testDecodeCointinousBoundingBoxQuery() throws IOException, PackageEncodeException {
final String table = "table1";
final BoundingBox boundingBox = new BoundingBox(10d, 20d);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final QueryBoundingBoxContinuousRequest queryRequest = new QueryBoundingBoxContinuousRequest(sequenceNumber, ROUTING_HEADER_ROUTED, table, boundingBox);
byte[] encodedPackage = networkPackageToByte(queryRequest);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
boolean result = NetworkPackageDecoder.validateRequestPackageHeader(bb, NetworkConst.REQUEST_TYPE_QUERY);
Assert.assertTrue(result);
final QueryBoundingBoxContinuousRequest decodedPackage = QueryBoundingBoxContinuousRequest.decodeTuple(bb);
Assert.assertEquals(queryRequest.getBoundingBox(), decodedPackage.getBoundingBox());
Assert.assertEquals(queryRequest.getTable(), decodedPackage.getTable());
Assert.assertEquals(NetworkConst.REQUEST_QUERY_CONTINUOUS_BBOX, NetworkPackageDecoder.getQueryTypeFromRequest(bb));
Assert.assertTrue(queryRequest.toString().length() > 10);
}
use of org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest in project bboxdb by jnidzwetzki.
the class HandleContinuousBoundingBoxQuery method handleQuery.
@Override
public /**
* Handle a bounding box query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is already known, please close old query first", packageSequence);
return;
}
final QueryBoundingBoxContinuousRequest queryRequest = QueryBoundingBoxContinuousRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final BoundingBox boundingBox = queryRequest.getBoundingBox();
final ClientQuery clientQuery = new ContinuousBoundingBoxClientQuery(boundingBox, clientConnectionHandler, packageSequence, requestTable);
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
Aggregations