Search in sources :

Example 11 with DistributionRegionSyncer

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);
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 12 with DistributionRegionSyncer

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();
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer)

Aggregations

DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)12 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 Test (org.junit.Test)10 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)9 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)9 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)9 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)9 BBoxDBException (org.bboxdb.misc.BBoxDBException)9 Set (java.util.Set)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)8 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)8 DistributionRegionEvent (org.bboxdb.distribution.region.DistributionRegionEvent)8 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)8 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)8 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)8 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)8 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)8 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)8