use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method handleRequest.
@Override
public /**
* Handle the insert tuple request
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Got insert tuple request");
}
try {
final InsertTupleRequest insertTupleRequest = InsertTupleRequest.decodeTuple(encodedPackage);
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
if (!routingHeader.isRoutedPackage()) {
final String errorMessage = "Error while inserting tuple - package is not routed";
logger.error(errorMessage);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, errorMessage);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
// Needs to be rerouted?
if (routingHeader.getHop() == -1) {
routingHeader.dispatchToNextHop();
final RoutingHop localHop = routingHeader.getRoutingHop();
if (PackageRouter.checkLocalSystemNameMatches(localHop)) {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
} else {
logger.debug("Rerouting package {}", packageSequence);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} else {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} catch (RejectedException e) {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_LOCAL_OPERATION_REJECTED_RETRY + " " + e.getMessage());
clientConnectionHandler.writeResultPackage(responsePackage);
} catch (Throwable e) {
logger.error("Error while inserting tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method processPackageLocally.
/**
* @param packageSequence
* @param clientConnectionHandler
* @param insertTupleRequest
* @param routingHeader
* @throws BBoxDBException
* @throws RejectedException
* @throws PackageEncodeException
*/
private void processPackageLocally(final short packageSequence, final ClientConnectionHandler clientConnectionHandler, final InsertTupleRequest insertTupleRequest) throws BBoxDBException, RejectedException, PackageEncodeException {
final Tuple tuple = insertTupleRequest.getTuple();
final TupleStoreName requestTable = insertTupleRequest.getTable();
final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
final RoutingHop localHop = routingHeader.getRoutingHop();
PackageRouter.checkLocalSystemNameMatchesAndThrowException(localHop);
final List<Long> distributionRegions = localHop.getDistributionRegions();
processInsertPackage(tuple, requestTable, storageRegistry, distributionRegions);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
Aggregations