/*******************************************************************************
 *
 *    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.partitioner;

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

import org.bboxdb.distribution.zookeeper.ZookeeperClient;
import org.bboxdb.distribution.zookeeper.ZookeeperClientFactory;
import org.bboxdb.distribution.zookeeper.ZookeeperException;
import org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException;
import org.bboxdb.network.client.BBoxDBException;
import org.bboxdb.storage.entity.TupleStoreName;

public class SpacePartitionerCache {
	
	/**
	 * Mapping between the string group and the group object
	 */
	protected final static Map<String, SpacePartitioner> groupGroupMap;

	static {
		groupGroupMap = new HashMap<String, SpacePartitioner>();
	}
	
	/**
	 * Get the distribution region for the given group name
	 * @param groupName
	 * @return
	 * @throws ZookeeperException 
	 * @throws ZookeeperNotFoundException 
	 */
	public static synchronized SpacePartitioner getSpacePartitionerForGroupName(final String groupName) 
			throws ZookeeperException {
		
		final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
		
		if(! groupGroupMap.containsKey(groupName)) {
			final DistributionGroupZookeeperAdapter distributionGroupZookeeperAdapter 
				= new DistributionGroupZookeeperAdapter(zookeeperClient);
			
			final SpacePartitioner adapter = distributionGroupZookeeperAdapter.getSpaceparitioner(groupName);
			groupGroupMap.put(groupName, adapter);
		}
		
		return groupGroupMap.get(groupName);
	}
	
	/**
	 * Get the distribution region for the given table name
	 * @param groupName
	 * @return
	 * @throws ZookeeperException 
	 * @throws BBoxDBException 
	 * @throws ZookeeperNotFoundException 
	 */
	public static synchronized SpacePartitioner getSpaceParitionerForTableName(
			final TupleStoreName ssTableName) throws ZookeeperException, BBoxDBException {
		
		if(! ssTableName.isValid()) {
			throw new BBoxDBException("Invalid tablename: " + ssTableName);
		}

		return getSpacePartitionerForGroupName(ssTableName.getDistributionGroup());
	}
}

@@ -851,16 +851,46 @@
 ioner;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -907,16 +907,16 @@
 ashMap;%0A
-
 import j
@@ -1488,16 +1488,44 @@
 upMap = 
+Collections.synchronizedMap(
 new Hash
@@ -1555,16 +1555,17 @@
 ioner%3E()
+)
 ;%0A%09%7D%0A%09%0A%09
@@ -1746,37 +1746,24 @@
 blic static 
-synchronized 
 SpacePartiti
@@ -2526,32 +2526,32 @@
 Exception %0A%09 */%0A
+
 %09public static s
@@ -2553,21 +2553,8 @@
 tic 
-synchronized 
 Spac

Removed deadlock