Search in sources :

Example 11 with DistributionRegionCallback

use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.

the class SpacePartitionerCache method getSpacePartitionerForGroupName.

/**
 * Get the distribution region for the given group name
 * @param groupName
 * @return
 * @throws BBoxDBException
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 */
public synchronized SpacePartitioner getSpacePartitionerForGroupName(final String groupName) throws BBoxDBException {
    try {
        if (!spacePartitioner.containsKey(groupName)) {
            final String path = zookeeperClient.getDistributionGroupAdapter().getDistributionGroupPath(groupName);
            final long version = NodeMutationHelper.getNodeMutationVersion(zookeeperClient, path, this);
            // Create callback list
            if (!callbacks.containsKey(groupName)) {
                final Set<DistributionRegionCallback> callback = new CopyOnWriteArraySet<>();
                callbacks.put(groupName, callback);
            }
            // Create region id mapper
            if (!distributionRegionIdMapper.containsKey(groupName)) {
                final DistributionRegionIdMapper mapper = new DistributionRegionIdMapper(groupName);
                distributionRegionIdMapper.put(groupName, mapper);
            }
            final SpacePartitioner adapter = zookeeperClient.getDistributionGroupAdapter().getSpaceparitioner(groupName, callbacks.get(groupName), distributionRegionIdMapper.get(groupName));
            partitionerVersions.put(groupName, version);
            spacePartitioner.put(groupName, adapter);
        }
        return spacePartitioner.get(groupName);
    } catch (ZookeeperException | ZookeeperNotFoundException e) {
        throw new BBoxDBException(e);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

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