Search in sources :

Example 11 with SuccessResponse

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

the class DisconnectHandler method handleRequest.

@Override
public /**
 * Handle the disconnect request
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    logger.info("Got disconnect package, preparing for connection close: " + clientConnectionHandler.clientSocket.getInetAddress());
    clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
    return false;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse)

Example 12 with SuccessResponse

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

SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)12 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)7 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)6 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)2 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)2 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 CancelQueryRequest (org.bboxdb.network.packages.request.CancelQueryRequest)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 CreateTableRequest (org.bboxdb.network.packages.request.CreateTableRequest)1 DeleteDistributionGroupRequest (org.bboxdb.network.packages.request.DeleteDistributionGroupRequest)1 DeleteTableRequest (org.bboxdb.network.packages.request.DeleteTableRequest)1 KeepAliveRequest (org.bboxdb.network.packages.request.KeepAliveRequest)1 ClientQuery (org.bboxdb.network.server.ClientQuery)1