use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class PackageRouter method performInsertPackageRoutingAsync.
/**
* Perform the routing task async
* @param packageSequence
* @param insertTupleRequest
* @param boundingBox
*/
public void performInsertPackageRoutingAsync(final short packageSequence, final InsertTupleRequest insertTupleRequest) {
final Runnable routeRunable = new ExceptionSafeRunnable() {
@Override
protected void runThread() {
boolean operationSuccess = true;
try {
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
assert (routingHeader.isRoutedPackage()) : "Tuple is not a routed package";
if (!routingHeader.reachedFinalInstance()) {
routingHeader.dispatchToNextHop();
operationSuccess = sendInsertPackage(insertTupleRequest);
}
} catch (InterruptedException e) {
logger.error("Exception while routing package", e);
Thread.currentThread().interrupt();
operationSuccess = false;
} catch (PackageEncodeException e) {
logger.error("Exception while routing package", e);
operationSuccess = false;
}
if (operationSuccess) {
final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
clientConnectionHandler.writeResultPackageNE(responsePackage);
} else {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_ROUTING_FAILED);
clientConnectionHandler.writeResultPackageNE(responsePackage);
}
}
};
// Submit the runnable to our pool
if (threadPool.isShutdown()) {
logger.warn("Thread pool is shutting down, don't route package: {}", packageSequence);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_SHUTDOWN);
clientConnectionHandler.writeResultPackageNE(responsePackage);
} else {
threadPool.submit(routeRunable);
}
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class DeleteTableHandler method handleRequest.
@Override
public /**
* Handle the delete table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final DeleteTableRequest deletePackage = DeleteTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = deletePackage.getTable();
logger.info("Got delete call for table: {}", requestTable);
// Delete zookeeper configuration
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
tupleStoreAdapter.deleteTable(requestTable);
// Clear cached data
TupleStoreConfigurationCache.getInstance().clear();
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while delete tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class KeepAliveHandler method handleRequest.
/**
* Handle the keep alive package. Simply send a success response package back
*/
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
this.clientConnectionHandler = clientConnectionHandler;
final KeepAliveRequest keepAliveRequst = KeepAliveRequest.decodeTuple(encodedPackage);
boolean gossipResult = true;
if (!keepAliveRequst.getTuples().isEmpty()) {
gossipResult = handleGossip(keepAliveRequst, clientConnectionHandler);
}
if (gossipResult) {
final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_OUTDATED_TUPLES);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.ErrorResponse 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;
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupHandler method handleRequest.
@Override
public /**
* Create a new distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = createPackage.getDistributionGroup();
logger.info("Create distribution group: {}", distributionGroup);
final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
if (knownGroups.contains(distributionGroup)) {
logger.error("Untable to create distributon group {}, already exists", distributionGroup);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion region = spacePartitioner.getRootNode();
distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while create distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
Aggregations