/*******************************************************************************
 *
 *    Copyright (C) 2015-2018 the BBoxDB project
 *  
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License. 
 *    
 *******************************************************************************/
package org.bboxdb.distribution;

import java.util.HashMap;
import java.util.Map;

import org.bboxdb.distribution.partitioner.SpacePartitionerCache;
import org.bboxdb.distribution.zookeeper.ZookeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RegionIdMapperInstanceManager {
	
	/**
	 * The local mappings for a distribution group
	 */
	protected final static Map<DistributionGroupName, RegionIdMapper> instances;
	
	/**
	 * The logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(RegionIdMapperInstanceManager.class);

	
	static {
		instances = new HashMap<DistributionGroupName, RegionIdMapper>();
	}
	
	/**
	 * Get the instance 
	 * @param distributionGroupName
	 */
	public static synchronized RegionIdMapper getInstance(final DistributionGroupName distributionGroupName) {
		if(! instances.containsKey(distributionGroupName)) {
			instances.put(distributionGroupName, new RegionIdMapper());
			
			// Read distribution group to generate the local mappings
			try {
				SpacePartitionerCache.getSpacePartitionerForGroupName(distributionGroupName.getFullname());
			} catch (ZookeeperException e) {
				logger.error("Got an expcetion by reading the space partitioner", e);
			}
			
		}
		
		return instances.get(distributionGroupName);
	}
}

@@ -888,16 +888,77 @@
 l.Map;%0A%0A
+import org.bboxdb.distribution.partitioner.SpacePartitioner;%0A
 import o
@@ -1899,16 +1899,59 @@
 y %7B%0A%09%09%09%09
+final SpacePartitioner partitioner %0A%09%09%09%09%09= 
 SpacePar
@@ -1996,16 +1996,24 @@
 oupName(
+%0A%09%09%09%09%09%09%09
 distribu
@@ -2042,16 +2042,52 @@
 ame());%0A
+%09%09%09%09%0A%09%09%09%09partitioner.getRootNode();%0A
 %09%09%09%7D cat

Read root node