Search in sources :

Example 1 with QueryBoundingBoxContinuousRequest

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);
    });
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) QueryBoundingBoxContinuousRequest(org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest)

Example 2 with QueryBoundingBoxContinuousRequest

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);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) QueryBoundingBoxContinuousRequest(org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with QueryBoundingBoxContinuousRequest

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));
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ContinuousBoundingBoxClientQuery(org.bboxdb.network.server.ContinuousBoundingBoxClientQuery) ClientQuery(org.bboxdb.network.server.ClientQuery) ContinuousBoundingBoxClientQuery(org.bboxdb.network.server.ContinuousBoundingBoxClientQuery) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) QueryBoundingBoxContinuousRequest(org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

QueryBoundingBoxContinuousRequest (org.bboxdb.network.packages.request.QueryBoundingBoxContinuousRequest)3 BoundingBox (org.bboxdb.commons.math.BoundingBox)2 ByteBuffer (java.nio.ByteBuffer)1 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)1 ClientQuery (org.bboxdb.network.server.ClientQuery)1 ContinuousBoundingBoxClientQuery (org.bboxdb.network.server.ContinuousBoundingBoxClientQuery)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 Test (org.junit.Test)1