use of org.bboxdb.network.routing.RoutingHop in project bboxdb by jnidzwetzki.
the class TestRoutingHeader method testRoutingHeaderHopParser1.
/**
* Test the hop parser
*/
@Test(timeout = 60000)
public void testRoutingHeaderHopParser1() {
final RoutingHeader routingHeader = new RoutingHeader((short) 0, new ArrayList<RoutingHop>());
// Get routing list as string and parse list
final String stringRoutingList = routingHeader.getRoutingListAsString();
routingHeader.setRoutingList(stringRoutingList);
final List<RoutingHop> parsedRoutingList = routingHeader.getRoutingList();
Assert.assertEquals(0, parsedRoutingList.size());
}
use of org.bboxdb.network.routing.RoutingHop in project bboxdb by jnidzwetzki.
the class DistributionRegionHelper method getRegionsForPredicateAndBox.
/**
* Add the leaf nodes systems that are covered by the bounding box
* @param rootRegion
* @param boundingBox
* @param systems
* @return
*/
public static List<RoutingHop> getRegionsForPredicateAndBox(final DistributionRegion rootRegion, final BoundingBox boundingBox, final Predicate<DistributionRegionState> statePredicate) {
final Map<InetSocketAddress, RoutingHop> hops = new HashMap<>();
final List<DistributionRegion> regions = rootRegion.getThisAndChildRegions();
for (final DistributionRegion region : regions) {
if (!boundingBox.overlaps(region.getConveringBox())) {
continue;
}
if (!statePredicate.test(region.getState())) {
continue;
}
for (final BBoxDBInstance system : region.getSystems()) {
if (!hops.containsKey(system.getInetSocketAddress())) {
final RoutingHop routingHop = new RoutingHop(system, new ArrayList<Long>());
hops.put(system.getInetSocketAddress(), routingHop);
}
final RoutingHop routingHop = hops.get(system.getInetSocketAddress());
routingHop.addRegion(region.getRegionId());
}
}
return new ArrayList<>(hops.values());
}
use of org.bboxdb.network.routing.RoutingHop in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method queryVersionTime.
@Override
public TupleListFuture queryVersionTime(final String table, final long timestamp) throws BBoxDBException {
if (membershipConnectionService.getNumberOfConnections() == 0) {
throw new BBoxDBException("queryTime called, but connection list is empty");
}
if (logger.isDebugEnabled()) {
logger.debug("Query by for timestamp {} in table {}", timestamp, table);
}
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> futureProvider = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForRead(distributionRegion, BoundingBox.FULL_SPACE);
final List<NetworkOperationFuture> futures = new ArrayList<>();
for (final RoutingHop hop : hops) {
final BBoxDBInstance instance = hop.getDistributedInstance();
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
final NetworkOperationFuture future = connection.getBboxDBClient().getVersionTimeFuture(table, timestamp, routingHeader);
futures.add(future);
}
return futures;
};
return new TupleListFuture(futureProvider, new DoNothingDuplicateResolver(), table);
}
use of org.bboxdb.network.routing.RoutingHop in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method lockTuple.
@Override
public EmptyResultFuture lockTuple(final String table, final Tuple tuple) throws BBoxDBException {
final DistributionRegion distributionRegion = getRootNode(table);
final Supplier<List<NetworkOperationFuture>> supplier = () -> {
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
final List<NetworkOperationFuture> futures = new ArrayList<>();
for (final RoutingHop hop : hops) {
final BBoxDBInstance instance = hop.getDistributedInstance();
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
final NetworkOperationFuture future = connection.getBboxDBClient().createLockTupleFuture(table, tuple, routingHeader);
futures.add(future);
}
return futures;
};
// When version locking fails, try again with another version
return new EmptyResultFuture(supplier, FutureRetryPolicy.RETRY_POLICY_NONE);
}
use of org.bboxdb.network.routing.RoutingHop in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method insertTuple.
@Override
public EmptyResultFuture insertTuple(final String table, final Tuple tuple) throws BBoxDBException {
final DistributionRegion distributionRegion = getRootNode(table);
final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
final RoutingHeader routingHeader = new RoutingHeader((short) -1, hops);
if (hops.isEmpty()) {
final String errorMessage = "Insert tuple called, but hop list for bounding box is empty: " + tuple.getBoundingBox();
throw new BBoxDBException(errorMessage);
}
// Determine the first system, it will route the request to the remaining systems
final BBoxDBInstance system = hops.get(0).getDistributedInstance();
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(system);
if (connection == null) {
final String errorMessage = "Unable to insert tuple, no connection to system: " + system;
throw new BBoxDBException(errorMessage);
}
return connection.getBboxDBClient().insertTuple(table, tuple, routingHeader);
}
Aggregations