Search in sources :

Example 16 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class HandleBoundingBoxTimeQuery method handleQuery.

@Override
public /**
 * Handle the bounding box time query
 */
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException {
    try {
        if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
            logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
        }
        final QueryBoundingBoxTimeRequest queryRequest = QueryBoundingBoxTimeRequest.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);
                final Operator operator1 = new NewerAsInsertTimeSeclectionOperator(queryRequest.getTimestamp(), operator);
                return operator1;
            }
        };
        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.writeResultPackageNE(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
    }
}
Also used : NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) QueryBoundingBoxTimeRequest(org.bboxdb.network.packages.request.QueryBoundingBoxTimeRequest) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) NewerAsInsertTimeSeclectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 17 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse 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)

Example 18 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class HandleKeyQuery method handleQuery.

@Override
public /**
 * Handle a key query
 */
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    final Runnable queryRunable = new ExceptionSafeRunnable() {

        @Override
        public void runThread() throws Exception {
            try {
                if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
                    logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
                    return;
                }
                final QueryKeyRequest queryKeyRequest = QueryKeyRequest.decodeTuple(encodedPackage);
                final TupleStoreName requestTable = queryKeyRequest.getTable();
                if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
                    return;
                }
                final String key = queryKeyRequest.getKey();
                final ClientQuery clientQuery = new KeyClientQuery(key, queryKeyRequest.isPagingEnabled(), queryKeyRequest.getTuplesPerPage(), 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));
            }
        }

        @Override
        protected void afterExceptionHook() {
            final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
            clientConnectionHandler.writeResultPackageNE(responsePackage);
        }
    };
    // Submit the runnable to our pool
    if (clientConnectionHandler.getThreadPool().isShutdown()) {
        logger.warn("Thread pool is shutting down, don't execute query: {}", packageSequence);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_SHUTDOWN);
        clientConnectionHandler.writeResultPackage(responsePackage);
    } else {
        clientConnectionHandler.getThreadPool().submit(queryRunable);
    }
}
Also used : QueryKeyRequest(org.bboxdb.network.packages.request.QueryKeyRequest) KeyClientQuery(org.bboxdb.network.server.KeyClientQuery) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ClientQuery(org.bboxdb.network.server.ClientQuery) KeyClientQuery(org.bboxdb.network.server.KeyClientQuery) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 19 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class HandleVersionTimeQuery method handleQuery.

@Override
public /**
 * Handle a time 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 allready known, please close old query first", packageSequence);
            return;
        }
        final QueryVersionTimeRequest queryRequest = QueryVersionTimeRequest.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 FullTablescanOperator tablescanOperator = new FullTablescanOperator(storageManager.get(0));
                final long timestamp = queryRequest.getTimestamp();
                final Operator opeator = new NewerAsVersionTimeSelectionOperator(timestamp, tablescanOperator);
                return opeator;
            }
        };
        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));
    }
    return;
}
Also used : FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) Operator(org.bboxdb.storage.queryprocessor.operator.Operator) NewerAsVersionTimeSelectionOperator(org.bboxdb.storage.queryprocessor.operator.NewerAsVersionTimeSelectionOperator) QueryVersionTimeRequest(org.bboxdb.network.packages.request.QueryVersionTimeRequest) FullTablescanOperator(org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 20 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class CancelQueryHandler method handleRequest.

@Override
public /**
 * Cancel the given query
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final CancelQueryRequest nextPagePackage = CancelQueryRequest.decodeTuple(encodedPackage);
        final short queryToCancel = nextPagePackage.getQuerySequence();
        logger.debug("Cancel query {} requested", queryToCancel);
        final Map<Short, ClientQuery> activeQueries = clientConnectionHandler.getActiveQueries();
        if (!activeQueries.containsKey(queryToCancel)) {
            logger.error("Unable to cancel query {} - not found", queryToCancel);
            clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_NOT_FOUND));
        } else {
            final ClientQuery clientQuery = activeQueries.remove(queryToCancel);
            clientQuery.close();
            clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
            logger.info("Sending success for canceling query {} (request package {})", queryToCancel, packageSequence);
        }
    } catch (PackageEncodeException e) {
        logger.warn("Error getting next page for a query", e);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
        clientConnectionHandler.writeResultPackage(responsePackage);
    }
    return true;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) ClientQuery(org.bboxdb.network.server.ClientQuery) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) CancelQueryRequest(org.bboxdb.network.packages.request.CancelQueryRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)20 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)16 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)9 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)7 IOException (java.io.IOException)6 List (java.util.List)5 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)5 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)4 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)3 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)3 ClientQuery (org.bboxdb.network.server.ClientQuery)3 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 FullTablescanOperator (org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator)2 NewerAsInsertTimeSeclectionOperator (org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator)2 RejectedException (org.bboxdb.commons.RejectedException)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1