use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testEventTypes.
@Test(timeout = 10000)
public void testEventTypes() throws InterruptedException, ZookeeperException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
// Root node is changed on add and remove children
final CountDownLatch changedLatch = new CountDownLatch(2);
final DistributionRegionCallback rootNodeChangedCallback = (e, r) -> {
if (e == DistributionRegionEvent.CHANGED && r.equals(root)) {
changedLatch.countDown();
}
};
distributionRegionSyncer.registerCallback(rootNodeChangedCallback);
// Two new children will be added
final CountDownLatch addedLatch = new CountDownLatch(2);
final DistributionRegionCallback adddedCallback = (e, r) -> {
if (e == DistributionRegionEvent.ADDED && !r.equals(root)) {
addedLatch.countDown();
}
};
distributionRegionSyncer.registerCallback(adddedCallback);
// Two children will be removed
final CountDownLatch removedLatch = new CountDownLatch(2);
final DistributionRegionCallback removedCallback = (e, r) -> {
if (e == DistributionRegionEvent.REMOVED && !r.equals(root)) {
removedLatch.countDown();
}
};
distributionRegionSyncer.registerCallback(removedCallback);
// Mutate tree
createSplittedRoot(distributionRegionSyncer, root);
// Wait
System.out.println("=== Wait for added latch");
addedLatch.await();
distributionRegionAdapter.deleteChild(root.getChildNumber(0));
distributionRegionAdapter.deleteChild(root.getChildNumber(1));
System.out.println("=== Wait for removed latch");
removedLatch.await();
System.out.println("=== Wait for changed latch");
changedLatch.await();
distributionRegionSyncer.unregisterCallback(rootNodeChangedCallback);
distributionRegionSyncer.unregisterCallback(adddedCallback);
distributionRegionSyncer.unregisterCallback(removedCallback);
}
use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.
the class AbstractSpacePartitioner method getRootNode.
@Override
public DistributionRegion getRootNode() throws BBoxDBException {
synchronized (this) {
if (distributionRegionSyncer == null) {
this.distributionRegionSyncer = new DistributionRegionSyncer(spacePartitionerContext);
spacePartitionerContext.getDistributionRegionMapper().clear();
}
}
if (!active) {
throw new BBoxDBException("Get root node on a non active space partitoner called");
}
return distributionRegionSyncer.getRootNode();
}
Aggregations