use of org.bboxdb.network.packages.request.QueryBoundingBoxRequest in project bboxdb by jnidzwetzki.
the class HandleBoundingBoxQuery 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 QueryBoundingBoxRequest queryRequest = QueryBoundingBoxRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() != 1) {
throw new IllegalArgumentException("This operator tree needs 1 storage manager");
}
final BoundingBox boundingBox = queryRequest.getBoundingBox();
final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
return operator;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(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));
}
}
use of org.bboxdb.network.packages.request.QueryBoundingBoxRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testDecodeBoundingBoxQuery.
/**
* Test decode bounding box query
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testDecodeBoundingBoxQuery() throws IOException, PackageEncodeException {
final String table = "table1";
final BoundingBox boundingBox = new BoundingBox(10d, 20d);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final QueryBoundingBoxRequest queryRequest = new QueryBoundingBoxRequest(sequenceNumber, ROUTING_HEADER_ROUTED, table, boundingBox, false, (short) 10);
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 QueryBoundingBoxRequest decodedPackage = QueryBoundingBoxRequest.decodeTuple(bb);
Assert.assertEquals(queryRequest.getBoundingBox(), decodedPackage.getBoundingBox());
Assert.assertEquals(queryRequest.getTable(), decodedPackage.getTable());
Assert.assertEquals(queryRequest.isPagingEnabled(), decodedPackage.isPagingEnabled());
Assert.assertEquals(queryRequest.getTuplesPerPage(), decodedPackage.getTuplesPerPage());
Assert.assertEquals(NetworkConst.REQUEST_QUERY_BBOX, NetworkPackageDecoder.getQueryTypeFromRequest(bb));
Assert.assertEquals(queryRequest.toString(), decodedPackage.toString());
}
Aggregations