/*
 * Copyright (c) 2009-2011 Cloudsoft Corporation Ltd. All rights reserved.
 * Supplied under license http://www.cloudsoftcorp.com/license/montereyDeveloperEdition
 * or such subsequent license agreed between Cloudsoft Corporation Ltd and the licensee.
 */
package com.cloudsoftcorp.monterey.brooklyn.entity;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

import brooklyn.location.Location;

import com.cloudsoftcorp.monterey.location.api.MontereyActiveLocation;
import com.cloudsoftcorp.util.Loggers;

/**
 * Registry for tracking all the locations that can be accessed.
 *  
 * @author aled
 */
public class LocationRegistry {
	
	private static final Logger LOG = Loggers.getLogger(LocationRegistry.class);

    private final Map<MontereyActiveLocation, Location> montereyLocationMapping = new ConcurrentHashMap<MontereyActiveLocation, Location>();
    
    public Location getConvertedLocation(MontereyActiveLocation montereyLoc) {
        Location result = montereyLocationMapping.get(montereyLoc);
        if (result == null) {
            result = new FooLocation(montereyLoc);
            montereyLocationMapping.put(montereyLoc, result);
        }
        return result;
    }
}

@@ -322,16 +322,41 @@
 va.util.
+concurrent.ConcurrentHash
 Map;%0Aimp
@@ -382,36 +382,32 @@
 rrent.Concurrent
-Hash
 Map;%0Aimport java
@@ -706,10 +706,8 @@
 y %7B%0A
-%09%0A
 %09pri
@@ -799,16 +799,26 @@
 e final 
+Concurrent
 Map%3CMont
@@ -1027,26 +1027,8 @@
     
- Location result =
  mon
@@ -1048,18 +1048,26 @@
 Mapping.
-ge
+putIfAbsen
 t(monter
@@ -1075,61 +1075,9 @@
 yLoc
-);%0A        if (result == null) %7B%0A            result =
+,
  new
@@ -1101,16 +1101,17 @@
 ereyLoc)
+)
 ;%0A      
@@ -1108,27 +1108,41 @@
 ));%0A        
-   
+Location result =
  montereyLoc
@@ -1154,18 +1154,18 @@
 Mapping.
-pu
+ge
 t(monter
@@ -1173,28 +1173,10 @@
 yLoc
-, result);%0A        %7D
+);
 %0A   

Use ConcurrentMap methods