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;
}
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;
}
Aggregations