Search in sources :

Example 1 with QueryHandler

use of org.bboxdb.network.server.handler.query.QueryHandler in project bboxdb by jnidzwetzki.

the class ClientConnectionHandler method handleQuery.

/**
 * Handle query package
 * @param bb
 * @param packageSequence
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
protected boolean handleQuery(final ByteBuffer encodedPackage, final short packageSequence) throws IOException, PackageEncodeException {
    final byte queryType = NetworkPackageDecoder.getQueryTypeFromRequest(encodedPackage);
    if (!queryHandlerList.containsKey(queryType)) {
        logger.warn("Unsupported query type: {}", queryType);
        final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_UNSUPPORTED_PACKAGE_TYPE);
        writeResultPackage(errorResponse);
        return false;
    }
    if (activeQueries.size() > MAX_RUNNING_QUERIES) {
        logger.warn("Client requested more than {} parallel queries", MAX_RUNNING_QUERIES);
        final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_TO_MUCH);
        writeResultPackage(errorResponse);
    } else {
        final QueryHandler queryHandler = queryHandlerList.get(queryType);
        queryHandler.handleQuery(encodedPackage, packageSequence, this);
    }
    return true;
}
Also used : QueryHandler(org.bboxdb.network.server.handler.query.QueryHandler) CancelQueryHandler(org.bboxdb.network.server.handler.request.CancelQueryHandler) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 QueryHandler (org.bboxdb.network.server.handler.query.QueryHandler)1 CancelQueryHandler (org.bboxdb.network.server.handler.request.CancelQueryHandler)1