You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/08/18 12:46:27 UTC
[1/3] incubator-brooklyn git commit: [BROOKLYN-162] Package renames
in ./core/internal
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 5dfe944e5 -> ad4cfe6c6
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalManagementContext.java
index b29c178..ab14c42 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalManagementContext.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.api.management.SubscriptionManager;
import org.apache.brooklyn.api.management.Task;
import org.apache.brooklyn.api.management.TaskAdaptable;
import org.apache.brooklyn.core.internal.BrooklynFeatureEnablement;
+import org.apache.brooklyn.core.internal.storage.DataGridFactory;
import org.apache.brooklyn.core.management.entitlement.Entitlements;
import org.apache.brooklyn.core.management.ha.OsgiManager;
import org.apache.brooklyn.core.util.task.BasicExecutionContext;
@@ -60,7 +61,6 @@ import brooklyn.entity.effector.Effectors;
import brooklyn.entity.proxying.InternalEntityFactory;
import brooklyn.entity.proxying.InternalLocationFactory;
import brooklyn.entity.proxying.InternalPolicyFactory;
-import brooklyn.internal.storage.DataGridFactory;
import brooklyn.util.exceptions.Exceptions;
import brooklyn.util.guava.Maybe;
import brooklyn.util.text.Strings;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalUsageManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalUsageManager.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalUsageManager.java
index 991f930..3aeb57a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalUsageManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalUsageManager.java
@@ -35,6 +35,7 @@ import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.management.entitlement.EntitlementContext;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.management.ManagementContextInjectable;
import org.apache.brooklyn.core.management.entitlement.Entitlements;
import org.apache.brooklyn.core.management.usage.ApplicationUsage;
@@ -46,7 +47,6 @@ import org.slf4j.LoggerFactory;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityInternal;
import brooklyn.entity.basic.Lifecycle;
-import brooklyn.internal.storage.BrooklynStorage;
import org.apache.brooklyn.location.basic.AbstractLocation;
import org.apache.brooklyn.location.basic.LocationConfigKeys;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
index 3fc0677..fd19964 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.management.ManagementContext;
import org.apache.brooklyn.api.management.Task;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.management.ha.OsgiManager;
import org.apache.brooklyn.core.util.task.TaskTags;
@@ -38,7 +39,6 @@ import brooklyn.entity.basic.BrooklynTaskTags;
import brooklyn.entity.proxying.InternalEntityFactory;
import brooklyn.entity.proxying.InternalLocationFactory;
import brooklyn.entity.proxying.InternalPolicyFactory;
-import brooklyn.internal.storage.BrooklynStorage;
import brooklyn.util.guava.Maybe;
import com.google.common.annotations.Beta;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
index 693e254..4d8196d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
@@ -60,6 +60,7 @@ import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecordPersister;
import org.apache.brooklyn.api.mementos.BrooklynMementoPersister;
import org.apache.brooklyn.api.mementos.BrooklynMementoRawData;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.management.entitlement.Entitlements;
import org.apache.brooklyn.core.management.ha.OsgiManager;
@@ -69,7 +70,6 @@ import brooklyn.entity.basic.AbstractEntity;
import brooklyn.entity.proxying.InternalEntityFactory;
import brooklyn.entity.proxying.InternalLocationFactory;
import brooklyn.entity.proxying.InternalPolicyFactory;
-import brooklyn.internal.storage.BrooklynStorage;
import brooklyn.util.guava.Maybe;
import brooklyn.util.time.Duration;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/location/basic/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/basic/AbstractLocation.java b/core/src/main/java/org/apache/brooklyn/location/basic/AbstractLocation.java
index 50f48b9..b90e961 100644
--- a/core/src/main/java/org/apache/brooklyn/location/basic/AbstractLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/location/basic/AbstractLocation.java
@@ -36,6 +36,9 @@ import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.management.Task;
import org.apache.brooklyn.api.mementos.LocationMemento;
import org.apache.brooklyn.core.internal.BrooklynFeatureEnablement;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.Reference;
+import org.apache.brooklyn.core.internal.storage.impl.BasicReference;
import org.apache.brooklyn.core.management.internal.LocalLocationManager;
import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
import org.apache.brooklyn.core.util.config.ConfigBag;
@@ -43,17 +46,14 @@ import org.apache.brooklyn.core.util.flags.FlagUtils;
import org.apache.brooklyn.core.util.flags.TypeCoercions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.apache.brooklyn.basic.AbstractBrooklynObject;
+
import brooklyn.config.ConfigInheritance;
import brooklyn.config.ConfigKey;
import brooklyn.config.ConfigKey.HasConfigKey;
import brooklyn.entity.basic.ConfigKeys;
import brooklyn.entity.rebind.BasicLocationRebindSupport;
import brooklyn.event.basic.BasicConfigKey;
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.Reference;
-import brooklyn.internal.storage.impl.BasicReference;
import org.apache.brooklyn.location.geo.HasHostGeoInfo;
import org.apache.brooklyn.location.geo.HostGeoInfo;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/test/java/brooklyn/internal/storage/impl/BrooklynStorageImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/internal/storage/impl/BrooklynStorageImplTest.java b/core/src/test/java/brooklyn/internal/storage/impl/BrooklynStorageImplTest.java
deleted file mode 100644
index 50b7ba3..0000000
--- a/core/src/test/java/brooklyn/internal/storage/impl/BrooklynStorageImplTest.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.AbstractMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.Reference;
-import brooklyn.internal.storage.impl.inmemory.InmemoryDatagrid;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-
-public class BrooklynStorageImplTest {
-
- private DataGrid datagrid;
- private BrooklynStorage storage;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- // TODO Note that InmemoryDatagrid's ConcurrentMap currently returns snapshot for entrySet() and values()
- // so the tests here aren't particularly good for confirming it'll work against a real datagrid...
- datagrid = new InmemoryDatagrid();
- storage = new BrooklynStorageImpl(datagrid);
- }
-
- @Test
- public void testReferenceGetAndSet() throws Exception {
- Reference<Object> ref = storage.getReference("mykey");
- assertNull(ref.get());
- assertTrue(ref.isNull());
- assertFalse(ref.contains("different"));
- assertTrue(ref.contains(null));
-
- ref.set("myval");
- assertEqualsCommutative(ref.get(), storage.getReference("mykey").get(), "myval");
- assertFalse(ref.isNull());
- assertFalse(ref.contains("different"));
- assertTrue(ref.contains("myval"));
-
- ref.clear();
- assertNull(ref.get());
- }
-
- @Test
- public void testReferenceAcceptsNullValue() throws Exception {
- Reference<Object> ref = storage.getReference("mykey");
- ref.set(null);
- assertNull(ref.get());
- assertTrue(ref.isNull());
- assertTrue(ref.contains(null));
- }
-
- @Test
- public void testCreateMapReturnsSameEachTime() throws Exception {
- storage.getMap("mykey").put("k1", "v1");
- assertEqualsCommutative(storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
- }
-
- @Test
- public void testMapOperations() throws Exception {
- Map<Object, Object> map = storage.getMap("mykey");
-
- map.put("k1", "v1");
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
- assertEqualsCommutative(map.keySet(), storage.getMap("mykey").keySet(), ImmutableSet.of("k1"));
- assertEqualsCommutative(ImmutableList.copyOf(map.values()), ImmutableList.copyOf(storage.getMap("mykey").values()), ImmutableList.of("v1"));
-
- assertEquals(map.size(), 1);
- assertEquals(map.get("k1"), "v1");
- assertTrue(map.containsKey("k1"));
- assertTrue(map.containsValue("v1"));
- assertFalse(map.containsKey("notthere"));
- assertFalse(map.containsValue("notthere"));
- assertFalse(map.isEmpty());
-
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
-
- map.put("k1", "v2");
- assertEquals(map.get("k1"), "v2");
- assertEquals(map.size(), 1);
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v2"));
-
- map.remove("k1");
- assertTrue(map.isEmpty());
- assertEquals(map.size(), 0);
- assertEquals(map.get("k1"), null);
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of());
-
- map.putAll(ImmutableMap.of("k1", "v3", "k2", "v4"));
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v3", "k2", "v4"));
-
- map.clear();
- assertEquals(map.size(), 0);
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of());
- }
-
- // TODO InmemoryDatagrid's map.entrySet() returns an immutable snapshot
- // Want to test against a real datagrid instead.
- @Test(enabled=false)
- public void testMapEntrySetIterator() throws Exception {
- Map<Object,Object> map = storage.getMap("mykey");
- map.put("k1", "v1");
- assertEquals(iteratorToList(map.entrySet().iterator()), ImmutableList.of(newMapEntry("k1", "v1")));
-
- // Remove entry while iterating; will use snapshot so still contain k1
- Iterator<Map.Entry<Object, Object>> iter1 = map.entrySet().iterator();
- assertTrue(iter1.hasNext());
- map.remove("k1");
- assertEquals(iteratorToList(iter1), ImmutableList.of(newMapEntry("k1", "v1")));
-
- // iter.remove removes value
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Map.Entry<Object, Object>> iter2 = map.entrySet().iterator();
- assertEquals(newMapEntry("k1", "v1"), iter2.next());
- iter2.remove();
- assertEquals(newMapEntry("k2", "v2"), iter2.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Map.Entry<Object, Object>> iter3 = map.entrySet().iterator();
- assertEquals(newMapEntry("k1", "v1"), iter3.next());
- map.remove("k1");
- iter3.remove();
- assertEquals(newMapEntry("k2", "v2"), iter3.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed, but was then re-added!
- // TODO is this really the desired behaviour?
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Map.Entry<Object, Object>> iter4 = map.entrySet().iterator();
- assertEquals(newMapEntry("k1", "v1"), iter4.next());
- map.remove("k1");
- map.put("k1", "v1b");
- iter4.remove();
- assertEquals(newMapEntry("k2", "v2"), iter4.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
- }
-
- @Test
- public void testMapKeySetIterator() throws Exception {
- Map<Object,Object> map = storage.getMap("mykey");
- map.put("k1", "v1");
- assertEquals(iteratorToList(map.keySet().iterator()), ImmutableList.of("k1"));
-
- // Remove key while iterating; will use snapshot so still contain k1
- Iterator<Object> iter1 = map.keySet().iterator();
- assertTrue(iter1.hasNext());
- map.remove("k1");
- assertEquals(iteratorToList(iter1), ImmutableList.of("k1"));
-
- // iter.remove removes value
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter2 = map.keySet().iterator();
- assertEquals("k1", iter2.next());
- iter2.remove();
- assertEquals("k2", iter2.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter3 = map.keySet().iterator();
- assertEquals("k1", iter3.next());
- map.remove("k1");
- iter3.remove();
- assertEquals("k2", iter3.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed, but was then re-added!
- // TODO is this really the desired behaviour?
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter4 = map.keySet().iterator();
- assertEquals("k1", iter4.next());
- map.remove("k1");
- map.put("k1", "v1b");
- iter4.remove();
- assertEquals("k2", iter4.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
- }
-
- // TODO InmemoryDatagrid.getMap().values() returning snapshot, so iter.remove not supported.
- // Want to test against a real datagrid instead.
- @Test(enabled=false)
- public void testMapValuesIterator() throws Exception {
- Map<Object,Object> map = storage.getMap("mykey");
- map.put("k1", "v1");
- assertEquals(ImmutableList.copyOf(iteratorToList(map.values().iterator())), ImmutableList.of("v1"));
-
- // Remove key while iterating; will use snapshot so still contain k1
- Iterator<Object> iter1 = map.values().iterator();
- assertTrue(iter1.hasNext());
- map.remove("v1");
- assertEquals(ImmutableList.copyOf(iteratorToList(iter1)), ImmutableList.of("v1"));
-
- // iter.remove removes value
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter2 = map.values().iterator();
- assertEquals("v1", iter2.next());
- iter2.remove();
- assertEquals("v2", iter2.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter3 = map.values().iterator();
- assertEquals("v1", iter3.next());
- map.remove("k1");
- iter3.remove();
- assertEquals("v2", iter3.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
-
- // iter.remove when value has already been removed, but was then re-added!
- // TODO is this really the desired behaviour?
- map.clear();
- map.put("k1", "v1"); map.put("k2", "v2");
- Iterator<Object> iter4 = map.values().iterator();
- assertEquals("v1", iter4.next());
- map.remove("k1");
- map.put("k1", "v1b");
- iter4.remove();
- assertEquals("v2", iter4.next());
- assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
- }
-
- private void assertEqualsCommutative(Object o1, Object o2) {
- assertEquals(o1, o2);
- assertEquals(o2, o1);
- }
-
- private void assertEqualsCommutative(Object o1, Object o2, Object o3) {
- assertEquals(o1, o3);
- assertEquals(o3, o1);
- assertEquals(o2, o3);
- assertEquals(o3, o2);
- }
-
- private <T> List<T> iteratorToList(Iterator<T> iter) {
- List<T> result = Lists.newArrayList();
- while (iter.hasNext()) {
- result.add(iter.next());
- }
- return result;
- }
-
- private <K,V> Map.Entry<K,V> newMapEntry(K k, V v) {
- return new AbstractMap.SimpleEntry<K, V>(k, v);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/test/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java b/core/src/test/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
deleted file mode 100644
index e35d50a..0000000
--- a/core/src/test/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.util.AbstractMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.util.collections.MutableList;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.collections.MutableSet;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class ConcurrentMapAcceptingNullValsTest {
-
- private ConcurrentMap<String, String> delegateMap;
- private ConcurrentMapAcceptingNullVals<String, String> map;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- delegateMap = new ConcurrentHashMap<String,String>();
- map = new ConcurrentMapAcceptingNullVals<String,String>(delegateMap);
- }
-
- @Test
- public void testSimpleOperations() throws Exception {
- map.put("k1", "v1");
- assertEquals(map, ImmutableMap.of("k1", "v1"));
- assertEquals(map.keySet(), ImmutableSet.of("k1"));
- assertEquals(ImmutableList.copyOf(map.values()), ImmutableList.of("v1"));
- assertEquals(map.size(), 1);
- assertEquals(map.get("k1"), "v1");
- assertTrue(map.containsKey("k1"));
- assertTrue(map.containsValue("v1"));
- assertFalse(map.containsKey("notthere"));
- assertFalse(map.containsValue("notthere"));
- assertFalse(map.isEmpty());
-
- map.put("k1", "v2");
- assertEquals(map.get("k1"), "v2");
- assertEquals(map.size(), 1);
- assertEquals(map, ImmutableMap.of("k1", "v2"));
-
- map.remove("k1");
- assertTrue(map.isEmpty());
- assertEquals(map.size(), 0);
- assertEquals(map.get("k1"), null);
- assertEquals(map, ImmutableMap.of());
-
- map.putAll(ImmutableMap.of("k1", "v3", "k2", "v4"));
- assertEquals(map, ImmutableMap.of("k1", "v3", "k2", "v4"));
-
- map.clear();
- assertEquals(map.size(), 0);
- assertEquals(map, ImmutableMap.of());
- }
-
- @Test
- public void testAcceptsNullValue() throws Exception {
- map.put("k1", null);
- assertEquals(map, MutableMap.of("k1", null));
- assertEquals(map.keySet(), MutableSet.of("k1"));
- assertEquals(MutableList.copyOf(map.values()), MutableList.of(null));
- assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k1", null)));
- assertEquals(map.size(), 1);
- assertEquals(map.get("k1"), null);
- assertTrue(map.containsKey("k1"));
- assertTrue(map.containsValue(null));
- assertFalse(map.containsKey("notthere"));
- assertFalse(map.containsValue("notthere"));
- assertFalse(map.isEmpty());
-
- map.put("k2", null);
- assertEquals(map.get("k2"), null);
- assertEquals(map.size(), 2);
- assertEquals(map, MutableMap.of("k1", null, "k2", null));
- assertEquals(MutableList.copyOf(map.values()), MutableList.of(null, null));
- assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k1", null), new AbstractMap.SimpleEntry<String,String>("k2", null)));
-
- map.remove("k1");
- assertEquals(map.get("k1"), null);
- assertEquals(map.get("k2"), null);
- assertEquals(map.size(), 1);
- assertEquals(map, MutableMap.of("k2", null));
- assertEquals(MutableList.copyOf(map.values()), MutableList.of(null));
- assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k2", null)));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/test/java/brooklyn/qa/longevity/EntityCleanupLongevityTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/qa/longevity/EntityCleanupLongevityTestFixture.java b/core/src/test/java/brooklyn/qa/longevity/EntityCleanupLongevityTestFixture.java
index 790bfe1..2db80ef 100644
--- a/core/src/test/java/brooklyn/qa/longevity/EntityCleanupLongevityTestFixture.java
+++ b/core/src/test/java/brooklyn/qa/longevity/EntityCleanupLongevityTestFixture.java
@@ -26,6 +26,9 @@ import org.apache.brooklyn.api.entity.proxying.EntitySpec;
import org.apache.brooklyn.api.event.SensorEvent;
import org.apache.brooklyn.api.event.SensorEventListener;
import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
import org.apache.brooklyn.core.management.internal.AbstractManagementContext;
import org.apache.brooklyn.core.management.internal.LocalManagementContext;
import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
@@ -42,9 +45,6 @@ import org.testng.annotations.BeforeMethod;
import brooklyn.entity.basic.ApplicationBuilder;
import brooklyn.entity.basic.Entities;
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.impl.BrooklynStorageImpl;
import org.apache.brooklyn.location.basic.SimulatedLocation;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
new file mode 100644
index 0000000..9dc02c5
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.AbstractMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.Reference;
+import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
+import org.apache.brooklyn.core.internal.storage.impl.inmemory.InmemoryDatagrid;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+
+public class BrooklynStorageImplTest {
+
+ private DataGrid datagrid;
+ private BrooklynStorage storage;
+
+ @BeforeMethod(alwaysRun=true)
+ public void setUp() throws Exception {
+ // TODO Note that InmemoryDatagrid's ConcurrentMap currently returns snapshot for entrySet() and values()
+ // so the tests here aren't particularly good for confirming it'll work against a real datagrid...
+ datagrid = new InmemoryDatagrid();
+ storage = new BrooklynStorageImpl(datagrid);
+ }
+
+ @Test
+ public void testReferenceGetAndSet() throws Exception {
+ Reference<Object> ref = storage.getReference("mykey");
+ assertNull(ref.get());
+ assertTrue(ref.isNull());
+ assertFalse(ref.contains("different"));
+ assertTrue(ref.contains(null));
+
+ ref.set("myval");
+ assertEqualsCommutative(ref.get(), storage.getReference("mykey").get(), "myval");
+ assertFalse(ref.isNull());
+ assertFalse(ref.contains("different"));
+ assertTrue(ref.contains("myval"));
+
+ ref.clear();
+ assertNull(ref.get());
+ }
+
+ @Test
+ public void testReferenceAcceptsNullValue() throws Exception {
+ Reference<Object> ref = storage.getReference("mykey");
+ ref.set(null);
+ assertNull(ref.get());
+ assertTrue(ref.isNull());
+ assertTrue(ref.contains(null));
+ }
+
+ @Test
+ public void testCreateMapReturnsSameEachTime() throws Exception {
+ storage.getMap("mykey").put("k1", "v1");
+ assertEqualsCommutative(storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
+ }
+
+ @Test
+ public void testMapOperations() throws Exception {
+ Map<Object, Object> map = storage.getMap("mykey");
+
+ map.put("k1", "v1");
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
+ assertEqualsCommutative(map.keySet(), storage.getMap("mykey").keySet(), ImmutableSet.of("k1"));
+ assertEqualsCommutative(ImmutableList.copyOf(map.values()), ImmutableList.copyOf(storage.getMap("mykey").values()), ImmutableList.of("v1"));
+
+ assertEquals(map.size(), 1);
+ assertEquals(map.get("k1"), "v1");
+ assertTrue(map.containsKey("k1"));
+ assertTrue(map.containsValue("v1"));
+ assertFalse(map.containsKey("notthere"));
+ assertFalse(map.containsValue("notthere"));
+ assertFalse(map.isEmpty());
+
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v1"));
+
+ map.put("k1", "v2");
+ assertEquals(map.get("k1"), "v2");
+ assertEquals(map.size(), 1);
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v2"));
+
+ map.remove("k1");
+ assertTrue(map.isEmpty());
+ assertEquals(map.size(), 0);
+ assertEquals(map.get("k1"), null);
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of());
+
+ map.putAll(ImmutableMap.of("k1", "v3", "k2", "v4"));
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k1", "v3", "k2", "v4"));
+
+ map.clear();
+ assertEquals(map.size(), 0);
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of());
+ }
+
+ // TODO InmemoryDatagrid's map.entrySet() returns an immutable snapshot
+ // Want to test against a real datagrid instead.
+ @Test(enabled=false)
+ public void testMapEntrySetIterator() throws Exception {
+ Map<Object,Object> map = storage.getMap("mykey");
+ map.put("k1", "v1");
+ assertEquals(iteratorToList(map.entrySet().iterator()), ImmutableList.of(newMapEntry("k1", "v1")));
+
+ // Remove entry while iterating; will use snapshot so still contain k1
+ Iterator<Map.Entry<Object, Object>> iter1 = map.entrySet().iterator();
+ assertTrue(iter1.hasNext());
+ map.remove("k1");
+ assertEquals(iteratorToList(iter1), ImmutableList.of(newMapEntry("k1", "v1")));
+
+ // iter.remove removes value
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Map.Entry<Object, Object>> iter2 = map.entrySet().iterator();
+ assertEquals(newMapEntry("k1", "v1"), iter2.next());
+ iter2.remove();
+ assertEquals(newMapEntry("k2", "v2"), iter2.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Map.Entry<Object, Object>> iter3 = map.entrySet().iterator();
+ assertEquals(newMapEntry("k1", "v1"), iter3.next());
+ map.remove("k1");
+ iter3.remove();
+ assertEquals(newMapEntry("k2", "v2"), iter3.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed, but was then re-added!
+ // TODO is this really the desired behaviour?
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Map.Entry<Object, Object>> iter4 = map.entrySet().iterator();
+ assertEquals(newMapEntry("k1", "v1"), iter4.next());
+ map.remove("k1");
+ map.put("k1", "v1b");
+ iter4.remove();
+ assertEquals(newMapEntry("k2", "v2"), iter4.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+ }
+
+ @Test
+ public void testMapKeySetIterator() throws Exception {
+ Map<Object,Object> map = storage.getMap("mykey");
+ map.put("k1", "v1");
+ assertEquals(iteratorToList(map.keySet().iterator()), ImmutableList.of("k1"));
+
+ // Remove key while iterating; will use snapshot so still contain k1
+ Iterator<Object> iter1 = map.keySet().iterator();
+ assertTrue(iter1.hasNext());
+ map.remove("k1");
+ assertEquals(iteratorToList(iter1), ImmutableList.of("k1"));
+
+ // iter.remove removes value
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter2 = map.keySet().iterator();
+ assertEquals("k1", iter2.next());
+ iter2.remove();
+ assertEquals("k2", iter2.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter3 = map.keySet().iterator();
+ assertEquals("k1", iter3.next());
+ map.remove("k1");
+ iter3.remove();
+ assertEquals("k2", iter3.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed, but was then re-added!
+ // TODO is this really the desired behaviour?
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter4 = map.keySet().iterator();
+ assertEquals("k1", iter4.next());
+ map.remove("k1");
+ map.put("k1", "v1b");
+ iter4.remove();
+ assertEquals("k2", iter4.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+ }
+
+ // TODO InmemoryDatagrid.getMap().values() returning snapshot, so iter.remove not supported.
+ // Want to test against a real datagrid instead.
+ @Test(enabled=false)
+ public void testMapValuesIterator() throws Exception {
+ Map<Object,Object> map = storage.getMap("mykey");
+ map.put("k1", "v1");
+ assertEquals(ImmutableList.copyOf(iteratorToList(map.values().iterator())), ImmutableList.of("v1"));
+
+ // Remove key while iterating; will use snapshot so still contain k1
+ Iterator<Object> iter1 = map.values().iterator();
+ assertTrue(iter1.hasNext());
+ map.remove("v1");
+ assertEquals(ImmutableList.copyOf(iteratorToList(iter1)), ImmutableList.of("v1"));
+
+ // iter.remove removes value
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter2 = map.values().iterator();
+ assertEquals("v1", iter2.next());
+ iter2.remove();
+ assertEquals("v2", iter2.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter3 = map.values().iterator();
+ assertEquals("v1", iter3.next());
+ map.remove("k1");
+ iter3.remove();
+ assertEquals("v2", iter3.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+
+ // iter.remove when value has already been removed, but was then re-added!
+ // TODO is this really the desired behaviour?
+ map.clear();
+ map.put("k1", "v1"); map.put("k2", "v2");
+ Iterator<Object> iter4 = map.values().iterator();
+ assertEquals("v1", iter4.next());
+ map.remove("k1");
+ map.put("k1", "v1b");
+ iter4.remove();
+ assertEquals("v2", iter4.next());
+ assertEqualsCommutative(map, storage.getMap("mykey"), ImmutableMap.of("k2", "v2"));
+ }
+
+ private void assertEqualsCommutative(Object o1, Object o2) {
+ assertEquals(o1, o2);
+ assertEquals(o2, o1);
+ }
+
+ private void assertEqualsCommutative(Object o1, Object o2, Object o3) {
+ assertEquals(o1, o3);
+ assertEquals(o3, o1);
+ assertEquals(o2, o3);
+ assertEquals(o3, o2);
+ }
+
+ private <T> List<T> iteratorToList(Iterator<T> iter) {
+ List<T> result = Lists.newArrayList();
+ while (iter.hasNext()) {
+ result.add(iter.next());
+ }
+ return result;
+ }
+
+ private <K,V> Map.Entry<K,V> newMapEntry(K k, V v) {
+ return new AbstractMap.SimpleEntry<K, V>(k, v);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
new file mode 100644
index 0000000..7f7adcf
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullValsTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.util.AbstractMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.brooklyn.core.internal.storage.impl.ConcurrentMapAcceptingNullVals;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.util.collections.MutableList;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.collections.MutableSet;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+public class ConcurrentMapAcceptingNullValsTest {
+
+ private ConcurrentMap<String, String> delegateMap;
+ private ConcurrentMapAcceptingNullVals<String, String> map;
+
+ @BeforeMethod(alwaysRun=true)
+ public void setUp() throws Exception {
+ delegateMap = new ConcurrentHashMap<String,String>();
+ map = new ConcurrentMapAcceptingNullVals<String,String>(delegateMap);
+ }
+
+ @Test
+ public void testSimpleOperations() throws Exception {
+ map.put("k1", "v1");
+ assertEquals(map, ImmutableMap.of("k1", "v1"));
+ assertEquals(map.keySet(), ImmutableSet.of("k1"));
+ assertEquals(ImmutableList.copyOf(map.values()), ImmutableList.of("v1"));
+ assertEquals(map.size(), 1);
+ assertEquals(map.get("k1"), "v1");
+ assertTrue(map.containsKey("k1"));
+ assertTrue(map.containsValue("v1"));
+ assertFalse(map.containsKey("notthere"));
+ assertFalse(map.containsValue("notthere"));
+ assertFalse(map.isEmpty());
+
+ map.put("k1", "v2");
+ assertEquals(map.get("k1"), "v2");
+ assertEquals(map.size(), 1);
+ assertEquals(map, ImmutableMap.of("k1", "v2"));
+
+ map.remove("k1");
+ assertTrue(map.isEmpty());
+ assertEquals(map.size(), 0);
+ assertEquals(map.get("k1"), null);
+ assertEquals(map, ImmutableMap.of());
+
+ map.putAll(ImmutableMap.of("k1", "v3", "k2", "v4"));
+ assertEquals(map, ImmutableMap.of("k1", "v3", "k2", "v4"));
+
+ map.clear();
+ assertEquals(map.size(), 0);
+ assertEquals(map, ImmutableMap.of());
+ }
+
+ @Test
+ public void testAcceptsNullValue() throws Exception {
+ map.put("k1", null);
+ assertEquals(map, MutableMap.of("k1", null));
+ assertEquals(map.keySet(), MutableSet.of("k1"));
+ assertEquals(MutableList.copyOf(map.values()), MutableList.of(null));
+ assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k1", null)));
+ assertEquals(map.size(), 1);
+ assertEquals(map.get("k1"), null);
+ assertTrue(map.containsKey("k1"));
+ assertTrue(map.containsValue(null));
+ assertFalse(map.containsKey("notthere"));
+ assertFalse(map.containsValue("notthere"));
+ assertFalse(map.isEmpty());
+
+ map.put("k2", null);
+ assertEquals(map.get("k2"), null);
+ assertEquals(map.size(), 2);
+ assertEquals(map, MutableMap.of("k1", null, "k2", null));
+ assertEquals(MutableList.copyOf(map.values()), MutableList.of(null, null));
+ assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k1", null), new AbstractMap.SimpleEntry<String,String>("k2", null)));
+
+ map.remove("k1");
+ assertEquals(map.get("k1"), null);
+ assertEquals(map.get("k2"), null);
+ assertEquals(map.size(), 1);
+ assertEquals(map, MutableMap.of("k2", null));
+ assertEquals(MutableList.copyOf(map.values()), MutableList.of(null));
+ assertEquals(map.entrySet(), MutableSet.of(new AbstractMap.SimpleEntry<String,String>("k2", null)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
index 0b4dfd8..b1ab02a 100644
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
+++ b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
@@ -24,10 +24,9 @@ import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
-import brooklyn.internal.storage.DataGrid;
-
import com.google.common.collect.ImmutableMap;
import com.hazelcast.config.Config;
import com.hazelcast.config.SerializerConfig;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
index c723f67..67a5b44 100644
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
+++ b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
@@ -18,11 +18,10 @@
*/
package org.apache.brooklyn.internal.storage.impl.hazelcast;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.DataGridFactory;
import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.DataGridFactory;
-
import com.hazelcast.core.HazelcastInstance;
public class HazelcastDataGridFactory implements DataGridFactory {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java b/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
index 464117e..451a6b4 100644
--- a/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
+++ b/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
@@ -29,11 +29,11 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import brooklyn.config.BrooklynProperties;
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.DataGridFactory;
-import brooklyn.internal.storage.Reference;
-import brooklyn.internal.storage.impl.BrooklynStorageImpl;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.DataGridFactory;
+import org.apache.brooklyn.core.internal.storage.Reference;
+import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
import org.apache.brooklyn.core.management.internal.LocalManagementContext;
import org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGrid;
import org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGridFactory;
[3/3] incubator-brooklyn git commit: This closes #835
Posted by al...@apache.org.
This closes #835
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ad4cfe6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ad4cfe6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ad4cfe6c
Branch: refs/heads/master
Commit: ad4cfe6c6622c6a0fbfd5541bc5b66482b0aac2f
Parents: 5dfe944 3230e73
Author: Aled Sage <al...@gmail.com>
Authored: Tue Aug 18 11:46:50 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Aug 18 11:46:50 2015 +0100
----------------------------------------------------------------------
.../brooklyn/entity/basic/AbstractEntity.java | 8 +-
.../brooklyn/event/basic/ListConfigKey.java | 2 +-
.../internal/storage/BrooklynStorage.java | 114 --------
.../brooklyn/internal/storage/DataGrid.java | 52 ----
.../internal/storage/DataGridFactory.java | 38 ---
.../brooklyn/internal/storage/Reference.java | 50 ----
.../internal/storage/impl/BackedReference.java | 73 -----
.../internal/storage/impl/BasicReference.java | 67 -----
.../storage/impl/BrooklynStorageImpl.java | 139 ---------
.../impl/ConcurrentMapAcceptingNullVals.java | 272 ------------------
.../impl/inmemory/InMemoryDataGridFactory.java | 41 ---
.../storage/impl/inmemory/InmemoryDatagrid.java | 93 ------
.../internal/BrooklynFeatureEnablement.java | 2 +-
.../core/internal/storage/BrooklynStorage.java | 114 ++++++++
.../core/internal/storage/DataGrid.java | 52 ++++
.../core/internal/storage/DataGridFactory.java | 38 +++
.../core/internal/storage/Reference.java | 50 ++++
.../internal/storage/impl/BackedReference.java | 73 +++++
.../internal/storage/impl/BasicReference.java | 67 +++++
.../storage/impl/BrooklynStorageImpl.java | 139 +++++++++
.../impl/ConcurrentMapAcceptingNullVals.java | 272 ++++++++++++++++++
.../impl/inmemory/InMemoryDataGridFactory.java | 40 +++
.../storage/impl/inmemory/InmemoryDatagrid.java | 93 ++++++
.../internal/AbstractManagementContext.java | 10 +-
.../internal/BrooklynGarbageCollector.java | 2 +-
.../management/internal/LocalEntityManager.java | 2 +-
.../internal/LocalLocationManager.java | 2 +-
.../internal/LocalManagementContext.java | 2 +-
.../management/internal/LocalUsageManager.java | 2 +-
.../internal/ManagementContextInternal.java | 2 +-
.../NonDeploymentManagementContext.java | 2 +-
.../location/basic/AbstractLocation.java | 8 +-
.../storage/impl/BrooklynStorageImplTest.java | 287 -------------------
.../ConcurrentMapAcceptingNullValsTest.java | 114 --------
.../EntityCleanupLongevityTestFixture.java | 6 +-
.../storage/impl/BrooklynStorageImplTest.java | 287 +++++++++++++++++++
.../ConcurrentMapAcceptingNullValsTest.java | 115 ++++++++
.../impl/hazelcast/HazelcastDataGrid.java | 3 +-
.../hazelcast/HazelcastDataGridFactory.java | 5 +-
.../impl/hazelcast/HazelcastStorageTest.java | 8 +-
40 files changed, 1372 insertions(+), 1374 deletions(-)
----------------------------------------------------------------------
[2/3] incubator-brooklyn git commit: [BROOKLYN-162] Package renames
in ./core/internal
Posted by al...@apache.org.
[BROOKLYN-162] Package renames in ./core/internal
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3230e730
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3230e730
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3230e730
Branch: refs/heads/master
Commit: 3230e730188920d015eb5e79951afe433f6b1e9d
Parents: 5dfe944
Author: Hadrian Zbarcea <ha...@apache.org>
Authored: Tue Aug 18 03:51:39 2015 -0400
Committer: Hadrian Zbarcea <ha...@apache.org>
Committed: Tue Aug 18 03:51:39 2015 -0400
----------------------------------------------------------------------
.../brooklyn/entity/basic/AbstractEntity.java | 8 +-
.../brooklyn/event/basic/ListConfigKey.java | 2 +-
.../internal/storage/BrooklynStorage.java | 114 --------
.../brooklyn/internal/storage/DataGrid.java | 52 ----
.../internal/storage/DataGridFactory.java | 38 ---
.../brooklyn/internal/storage/Reference.java | 50 ----
.../internal/storage/impl/BackedReference.java | 73 -----
.../internal/storage/impl/BasicReference.java | 67 -----
.../storage/impl/BrooklynStorageImpl.java | 139 ---------
.../impl/ConcurrentMapAcceptingNullVals.java | 272 ------------------
.../impl/inmemory/InMemoryDataGridFactory.java | 41 ---
.../storage/impl/inmemory/InmemoryDatagrid.java | 93 ------
.../internal/BrooklynFeatureEnablement.java | 2 +-
.../core/internal/storage/BrooklynStorage.java | 114 ++++++++
.../core/internal/storage/DataGrid.java | 52 ++++
.../core/internal/storage/DataGridFactory.java | 38 +++
.../core/internal/storage/Reference.java | 50 ++++
.../internal/storage/impl/BackedReference.java | 73 +++++
.../internal/storage/impl/BasicReference.java | 67 +++++
.../storage/impl/BrooklynStorageImpl.java | 139 +++++++++
.../impl/ConcurrentMapAcceptingNullVals.java | 272 ++++++++++++++++++
.../impl/inmemory/InMemoryDataGridFactory.java | 40 +++
.../storage/impl/inmemory/InmemoryDatagrid.java | 93 ++++++
.../internal/AbstractManagementContext.java | 10 +-
.../internal/BrooklynGarbageCollector.java | 2 +-
.../management/internal/LocalEntityManager.java | 2 +-
.../internal/LocalLocationManager.java | 2 +-
.../internal/LocalManagementContext.java | 2 +-
.../management/internal/LocalUsageManager.java | 2 +-
.../internal/ManagementContextInternal.java | 2 +-
.../NonDeploymentManagementContext.java | 2 +-
.../location/basic/AbstractLocation.java | 8 +-
.../storage/impl/BrooklynStorageImplTest.java | 287 -------------------
.../ConcurrentMapAcceptingNullValsTest.java | 114 --------
.../EntityCleanupLongevityTestFixture.java | 6 +-
.../storage/impl/BrooklynStorageImplTest.java | 287 +++++++++++++++++++
.../ConcurrentMapAcceptingNullValsTest.java | 115 ++++++++
.../impl/hazelcast/HazelcastDataGrid.java | 3 +-
.../hazelcast/HazelcastDataGridFactory.java | 5 +-
.../impl/hazelcast/HazelcastStorageTest.java | 8 +-
40 files changed, 1372 insertions(+), 1374 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
index 3e619b0..c62010c 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
@@ -56,6 +56,9 @@ import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
import org.apache.brooklyn.core.internal.BrooklynFeatureEnablement;
import org.apache.brooklyn.core.internal.BrooklynInitialization;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.Reference;
+import org.apache.brooklyn.core.internal.storage.impl.BasicReference;
import org.apache.brooklyn.core.management.internal.EffectorUtils;
import org.apache.brooklyn.core.management.internal.EntityManagementSupport;
import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
@@ -70,8 +73,8 @@ import org.apache.brooklyn.core.util.task.DeferredSupplier;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.apache.brooklyn.basic.AbstractBrooklynObject;
+
import brooklyn.config.BrooklynLogging;
import brooklyn.config.ConfigKey;
import brooklyn.config.ConfigKey.HasConfigKey;
@@ -85,9 +88,6 @@ import brooklyn.event.basic.BasicNotificationSensor;
import brooklyn.event.basic.Sensors;
import brooklyn.event.feed.AbstractFeed;
import brooklyn.event.feed.ConfigToAttributes;
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.Reference;
-import brooklyn.internal.storage.impl.BasicReference;
import org.apache.brooklyn.location.basic.Locations;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/event/basic/ListConfigKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/ListConfigKey.java b/core/src/main/java/brooklyn/event/basic/ListConfigKey.java
index 0ad4d54..dadbd9e 100644
--- a/core/src/main/java/brooklyn/event/basic/ListConfigKey.java
+++ b/core/src/main/java/brooklyn/event/basic/ListConfigKey.java
@@ -24,10 +24,10 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import org.apache.brooklyn.core.internal.storage.impl.ConcurrentMapAcceptingNullVals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import brooklyn.internal.storage.impl.ConcurrentMapAcceptingNullVals;
import brooklyn.util.collections.MutableList;
/** A config key representing a list of values.
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/BrooklynStorage.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/BrooklynStorage.java b/core/src/main/java/brooklyn/internal/storage/BrooklynStorage.java
deleted file mode 100644
index 6ecabd3..0000000
--- a/core/src/main/java/brooklyn/internal/storage/BrooklynStorage.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-
-import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
-
-public interface BrooklynStorage {
-
- /**
- * Creates a reference to a value, backed by the storage-medium. If a reference with this
- * name has already been created, then that existing reference will be returned.
- *
- * The returned reference is a live view: changes made to the reference will be persisted,
- * and changes that others make will be reflected in the reference.
- *
- * The reference is thread-safe. No additional synchronization is required when getting/setting
- * the reference.
- *
- * @param id
- */
- <T> Reference<T> getReference(String id);
-
- /**
- * Creates a list backed by the storage-medium. If a list with this name has already been
- * created, then that existing list will be returned.
- *
- * The returned list is not a live view. Changes are made by calling reference.set(), and
- * the view is refreshed by calling reference.get(). Changes are thread-safe, but callers
- * must be careful not to overwrite other's changes. For example, the code below could overwrite
- * another threads changes that are made to the map between the call to get() and the subsequent
- * call to set().
- *
- * <pre>
- * {@code
- * Reference<List<String>> ref = storage.<String>createNonConcurrentList("myid");
- * List<String> newval = ImmutableList.<String>builder().addAll(ref.get()).add("another").builder();
- * ref.set(newval);
- * }
- * </pre>
- *
- * TODO Aled says: Is getNonConcurrentList necessary?
- * The purpose of this method, rather than just using
- * {@code Reference ref = getReference(id); ref.set(ImmutableList.of())}
- * is to allow control of the serialization of the things inside the list
- * (e.g. switching the Location object to serialize a proxy object of some sort).
- * I don't want us to have to do deep inspection of every object being added to any map/ref.
- * Feels like we can use normal serialization unless the top-level object matches an
- * instanceof for special things like Entity, Location, etc.
- *
- * Peter responds:
- * What I'm a bit scared of is that we need to write some kind of meta serialization mechanism
- * on top of the mechanisms provided by e.g. Hazelcast or Infinispan. Hazelcast has a very
- * extensive serialization library where you can plug in all kinds of serialization mechanisms.
- *
- * @param id
- */
- @Beta
- <T> Reference<List<T>> getNonConcurrentList(String id);
-
- /**
- * Creates a map backed by the storage-medium. If a map with this name has already been
- * created, then that existing map will be returned.
- *
- * The returned map is a live view: changes made to the map will be persisted, and changes
- * that others make will be reflected in the map.
- *
- * The map is thread-safe: {@link Map#keySet()} etc will iterate over a snapshot view of the
- * contents.
- *
- * @param id
- */
- <K,V> ConcurrentMap<K,V> getMap(String id);
-
- /**
- * Removes the data stored against this id, whether it is a map, ref or whatever.
- */
- void remove(String id);
-
- /**
- * Terminates the BrooklynStorage.
- */
- void terminate();
-
- /** asserts that some of the storage containers which should be empty are empty;
- * this could do more thorough checks, but as it is it is useful to catch many leaks,
- * and the things which aren't empty it's much harder to check whether they should be empty!
- * <p>
- * not meant for use outwith tests */
- @VisibleForTesting
- public boolean isMostlyEmpty();
-
- Map<String, Object> getStorageMetrics();
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/DataGrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/DataGrid.java b/core/src/main/java/brooklyn/internal/storage/DataGrid.java
deleted file mode 100644
index de6d5fc..0000000
--- a/core/src/main/java/brooklyn/internal/storage/DataGrid.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public interface DataGrid {
-
- /**
- * If a map already exists with this id, returns it; otherwise creates a new map stored
- * in the datagrid.
- */
- <K,V> ConcurrentMap<K,V> getMap(String id);
-
- /**
- * Deletes the map for this id, if it exists; otherwise a no-op.
- */
- void remove(String id);
-
- /**
- * Terminates the DataGrid. If there is a real datagrid with multiple machines running, it doesn't mean that the
- * datagrid is going to be terminated; it only means that all local resources of the datagrid are released.
- */
- void terminate();
-
- Map<String, Object> getDatagridMetrics();
-
- /** Returns snapshot of known keys at this datagrid */
- @VisibleForTesting
- Set<String> getKeys();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/DataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/DataGridFactory.java b/core/src/main/java/brooklyn/internal/storage/DataGridFactory.java
deleted file mode 100644
index d5264c1..0000000
--- a/core/src/main/java/brooklyn/internal/storage/DataGridFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage;
-
-import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
-
-/**
- * A factory for creating a {@link DataGrid}.
- *
- * Implementations of this interface should have a public no arg constructor; this constructor will be
- * called through reflection in the {@link org.apache.brooklyn.core.management.internal.LocalManagementContext}.
- */
-public interface DataGridFactory {
-
- /**
- * Creates a {@link BrooklynStorage} instance.
- *
- * @param managementContext the ManagementContextInternal
- * @return the created BrooklynStorage.
- */
- DataGrid newDataGrid(ManagementContextInternal managementContext);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/Reference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/Reference.java b/core/src/main/java/brooklyn/internal/storage/Reference.java
deleted file mode 100644
index 14b3877..0000000
--- a/core/src/main/java/brooklyn/internal/storage/Reference.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage;
-
-/**
- * A reference to a value, backed by the storage-medium.
- *
- * @see BrooklynStorage#getReference(String)
- *
- * @author aled
- */
-public interface Reference<T> {
-
- // TODO We can add compareAndSet(T,T) as and when required
-
- T get();
-
- T set(T val);
-
- /**
- * @return true if the value is null; false otherwise.
- */
- boolean isNull();
-
- /**
- * Sets the value back to null. Similar to {@code set(null)}.
- */
- void clear();
-
- /**
- * @return true if the value equals the given parameter; false otherwise
- */
- boolean contains(Object other);
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/BackedReference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/BackedReference.java b/core/src/main/java/brooklyn/internal/storage/impl/BackedReference.java
deleted file mode 100644
index d1261ab..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/BackedReference.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Map;
-
-import brooklyn.internal.storage.Reference;
-
-import com.google.common.base.Objects;
-
-class BackedReference<T> implements Reference<T> {
- private final Map<String,? super T> backingMap;
- private final String key;
-
- BackedReference(Map<String,? super T> backingMap, String key) {
- this.backingMap = checkNotNull(backingMap, "backingMap");
- this.key = key;
- }
-
- @Override
- public T get() {
- // For happens-before (for different threads calling get and set), relies on
- // underlying map (e.g. from datagrid) having some synchronization
- return (T) backingMap.get(key);
- }
-
- @Override
- public T set(T val) {
- if (val == null) {
- return (T) backingMap.remove(key);
- } else {
- return (T) backingMap.put(key, val);
- }
- }
-
- @Override
- public String toString() {
- return ""+get();
- }
-
- @Override
- public boolean isNull() {
- return get() == null;
- }
-
- @Override
- public void clear() {
- set(null);
- }
-
- @Override
- public boolean contains(Object other) {
- return Objects.equal(get(), other);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/BasicReference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/BasicReference.java b/core/src/main/java/brooklyn/internal/storage/impl/BasicReference.java
deleted file mode 100644
index ce40cf2..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/BasicReference.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-import brooklyn.internal.storage.Reference;
-
-import com.google.common.base.Objects;
-
-public class BasicReference<T> implements Reference<T >{
-
- private final AtomicReference<T> ref = new AtomicReference<T>();
-
- public BasicReference() {
- }
-
- public BasicReference(T val) {
- set(val);
- }
-
- @Override
- public T get() {
- return ref.get();
- }
-
- @Override
- public T set(T val) {
- return ref.getAndSet(val);
- }
-
- @Override
- public boolean isNull() {
- return get() == null;
- }
-
- @Override
- public void clear() {
- set(null);
- }
-
- @Override
- public boolean contains(Object other) {
- return Objects.equal(get(), other);
- }
-
- @Override
- public String toString() {
- return ""+get();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/BrooklynStorageImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/BrooklynStorageImpl.java b/core/src/main/java/brooklyn/internal/storage/impl/BrooklynStorageImpl.java
deleted file mode 100644
index 2fbe411..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/BrooklynStorageImpl.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import java.lang.ref.WeakReference;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.Reference;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-public class BrooklynStorageImpl implements BrooklynStorage {
-
- private final DataGrid datagrid;
- private final ConcurrentMap<String, Object> refsMap;
- private final ConcurrentMap<String, Object> listsMap;
- private final ConcurrentMap<String, WeakReference<Reference<?>>> refsCache;
- private final ConcurrentMap<String, WeakReference<Reference<?>>> listRefsCache;
-
- public BrooklynStorageImpl(DataGrid datagrid) {
- this.datagrid = datagrid;
- this.refsMap = datagrid.getMap("refs");
- this.listsMap = datagrid.getMap("lists");
- this.refsCache = Maps.newConcurrentMap();
- this.listRefsCache = Maps.newConcurrentMap();
- }
-
- /**
- * Returns the DataGrid used by this BrooklynStorageImpl
- *
- * @return the DataGrid.
- */
- @VisibleForTesting
- public DataGrid getDataGrid() {
- return datagrid;
- }
-
- @Override
- public <T> Reference<T> getReference(final String id) {
- // Can use different ref instances; no need to always return same one. Caching is an
- // optimisation to just avoid extra object creation.
- WeakReference<Reference<?>> weakRef = refsCache.get(id);
- Reference<?> ref = (weakRef != null) ? weakRef.get() : null;
- if (ref == null) {
- ref = new BackedReference<T>(refsMap, id) {
- @Override protected void finalize() {
- // TODO Don't like using finalize due to performance overhead, but not
- // optimising yet. Could use PhantomReference instead; see
- // http://java.dzone.com/articles/finalization-and-phantom
- refsCache.remove(id);
- }
- };
- refsCache.putIfAbsent(id, new WeakReference<Reference<?>>(ref));
- }
- return (Reference<T>) ref;
- }
-
- @Override
- public <T> Reference<List<T>> getNonConcurrentList(final String id) {
- WeakReference<Reference<?>> weakRef = listRefsCache.get(id);
- Reference<?> ref = (weakRef != null) ? weakRef.get() : null;
- if (ref == null) {
- ref = new BackedReference<List<T>>(listsMap, id) {
- @Override public List<T> get() {
- List<T> result = super.get();
- return (result == null ? ImmutableList.<T>of() : Collections.unmodifiableList(result));
- }
- @Override protected void finalize() {
- listRefsCache.remove(id);
- }
- };
- listRefsCache.putIfAbsent(id, new WeakReference<Reference<?>>(ref));
- }
- return (Reference<List<T>>) ref;
- }
-
- @Override
- public <K, V> ConcurrentMap<K, V> getMap(final String id) {
- return datagrid.<K,V>getMap(id);
- }
-
- @Override
- public void remove(String id) {
- datagrid.remove(id);
- refsMap.remove(id);
- listsMap.remove(id);
- refsCache.remove(id);
- listRefsCache.remove(id);
- }
-
- @Override
- public void terminate() {
- datagrid.terminate();
- }
-
- public boolean isMostlyEmpty() {
- if (!refsMap.isEmpty() || !listsMap.isEmpty())
- return false;
- // the datagrid may have some standard bookkeeping entries
- return true;
- }
-
- @Override
- public Map<String, Object> getStorageMetrics() {
- return ImmutableMap.of(
- "datagrid", datagrid.getDatagridMetrics(),
- "refsMapSize", ""+refsMap.size(),
- "listsMapSize", ""+listsMap.size());
- }
-
- @Override
- public String toString() {
- return super.toString() + getStorageMetrics();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullVals.java b/core/src/main/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
deleted file mode 100644
index ee998df..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.annotation.Nullable;
-
-/**
- * A decorator for a ConcurrentMap that allows null values to be used.
- *
- * However, {@link #values()} and {@link #entrySet()} return immutable snapshots
- * of the map's contents. This may be revisited in a future version.
- *
- * @author aled
- */
-public class ConcurrentMapAcceptingNullVals<K, V> implements ConcurrentMap<K, V> {
-
- private static enum Marker {
- NULL;
- }
-
- private final ConcurrentMap<K, V> delegate;
-
- public ConcurrentMapAcceptingNullVals(ConcurrentMap<K,V> delegate) {
- this.delegate = checkNotNull(delegate, "delegate");
- }
-
- @Override
- public void clear() {
- delegate.clear();
- }
-
- @Override
- public boolean containsKey(Object key) {
- return delegate.containsKey(key);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return delegate.containsValue(toNonNullValue(value));
- }
-
- @Override
- public Set<Map.Entry<K, V>> entrySet() {
- // Note that returns an immutable snapshot
- Set<Map.Entry<K, V>> result = new LinkedHashSet<Map.Entry<K, V>>(delegate.size());
- for (Map.Entry<K, V> entry : delegate.entrySet()) {
- result.add(new AbstractMap.SimpleEntry<K,V>(entry.getKey(), (V)fromNonNullValue(entry.getValue())));
- }
- return Collections.unmodifiableSet(result);
- }
-
- @Override
- public Collection<V> values() {
- // Note that returns an immutable snapshot
- List<V> result = new ArrayList<V>(delegate.size());
- for (V v : delegate.values()) {
- result.add((V)fromNonNullValue(v));
- }
- return Collections.unmodifiableCollection(result);
- }
-
- @Override
- public Set<K> keySet() {
- return delegate.keySet();
- }
-
- @Override
- public V get(Object key) {
- return (V) fromNonNullValue(delegate.get(key));
- }
-
- @Override
- public boolean isEmpty() {
- return delegate.isEmpty();
- }
-
- @Override
- public V put(K key, V value) {
- return (V) fromNonNullValue(delegate.put(key, (V) toNonNullValue(value)));
- }
-
- @Override
- public void putAll(Map<? extends K, ? extends V> vals) {
- for (Map.Entry<? extends K, ? extends V> entry : vals.entrySet()) {
- put(entry.getKey(), entry.getValue());
- }
- }
-
- @Override
- public V remove(Object key) {
- return (V) fromNonNullValue(delegate.remove(key));
- }
-
- @Override
- public int size() {
- return delegate.size();
- }
-
- @Override
- public V putIfAbsent(K key, V value) {
- return (V) fromNonNullValue(delegate.putIfAbsent(key, (V) toNonNullValue(value)));
- }
-
- @Override
- public boolean remove(Object key, Object value) {
- return delegate.remove(key, (V) toNonNullValue(value));
- }
-
- @Override
- public V replace(K key, V value) {
- return (V) fromNonNullValue(delegate.replace(key, (V) toNonNullValue(value)));
- }
-
- @Override
- public boolean replace(K key, V oldValue, V newValue) {
- return delegate.replace(key, (V) toNonNullValue(oldValue), (V) toNonNullValue(newValue));
- }
-
- private static class SetWithNullVals<T> implements Set<T> {
-
- private final Set<T> delegate;
-
- public SetWithNullVals(Set<T> delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public boolean add(T e) {
- return delegate.add(e); // unsupported; let delegate give exception
- }
-
- @Override
- public boolean addAll(Collection<? extends T> c) {
- return delegate.addAll(c); // unsupported; let delegate give exception
- }
-
- @Override
- public void clear() {
- delegate.clear();
- }
-
- @Override
- public boolean contains(Object o) {
- return delegate.contains(toNonNullValue(o));
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- for (Object e : c) {
- if (!delegate.contains(toNonNullValue(e))) return false;
- }
- return true;
- }
-
- @Override
- public boolean isEmpty() {
- return delegate.isEmpty();
- }
-
- @Override
- public Iterator<T> iterator() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean remove(Object o) {
- return delegate.remove(toNonNullValue(o));
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- boolean result = false;
- for (Object e : c) {
- result = result & delegate.remove(toNonNullValue(e));
- }
- return result;
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- boolean result = false;
- for (Iterator<T> iter = delegate.iterator(); iter.hasNext();) {
- T e = iter.next();
- if (!c.contains(fromNonNullValue(e))) {
- iter.remove();
- result = true;
- }
- }
- return result;
- }
-
- @Override
- public int size() {
- return delegate.size();
- }
-
- @Override
- public Object[] toArray() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- // TODO Auto-generated method stub
- return null;
- }
-
- }
-
- private static Object toNonNullValue(Object value) {
- return (value != null) ? value : Marker.NULL;
- }
-
- private static Object fromNonNullValue(Object value) {
- return (value == Marker.NULL) ? null : value;
- }
-
- @Override
- public boolean equals(@Nullable Object object) {
- // copied from guava's non-public method Maps.equalsImpl
- if (this == object) {
- return true;
- }
- if (object instanceof Map) {
- Map<?, ?> o = (Map<?, ?>) object;
- return entrySet().equals(o.entrySet());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- // copied from guava's ImmutableMap.hashCode
- return entrySet().hashCode();
- }
-
- @Override
- public String toString() {
- return delegate.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InMemoryDataGridFactory.java b/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
deleted file mode 100644
index 4f0fbac..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl.inmemory;
-
-import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
-
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.DataGridFactory;
-
-public class InMemoryDataGridFactory implements DataGridFactory {
-
- public static DataGridFactory ofInstance(final DataGrid datagrid) {
- return new DataGridFactory() {
- @Override
- public DataGrid newDataGrid(ManagementContextInternal managementContext) {
- return datagrid;
- }
- };
- }
-
- @Override
- public DataGrid newDataGrid(ManagementContextInternal managementContext) {
- return new InmemoryDatagrid();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InmemoryDatagrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InmemoryDatagrid.java b/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InmemoryDatagrid.java
deleted file mode 100644
index 3cfb7c7..0000000
--- a/core/src/main/java/brooklyn/internal/storage/impl/inmemory/InmemoryDatagrid.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 brooklyn.internal.storage.impl.inmemory;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.impl.ConcurrentMapAcceptingNullVals;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-/**
- * A simple implementation of datagrid backed by in-memory (unpersisted) maps, within a single JVM.
- *
- * @author aled
- */
-public class InmemoryDatagrid implements DataGrid {
-
- private final Map<String,Map<?,?>> maps = Maps.newLinkedHashMap();
- private final AtomicInteger creationCounter = new AtomicInteger();
-
- @SuppressWarnings("unchecked")
- @Override
- public <K, V> ConcurrentMap<K, V> getMap(String id) {
- synchronized (maps) {
- ConcurrentMap<K, V> result = (ConcurrentMap<K, V>) maps.get(id);
- if (result == null) {
- result = newMap();
- maps.put(id, result);
- creationCounter.incrementAndGet();
- }
- return result;
- }
- }
-
- // TODO Not doing Maps.newConcurrentMap() because needs to store null values.
- // Easy to avoid for Refererence<?> but harder for entity ConfigMap where the user
- // can insert null values.
- //
- // Could write a decorator that switches null values for a null marker, and back again.
- //
- private <K,V> ConcurrentMap<K,V> newMap() {
- //return Collections.synchronizedMap(new HashMap<K, V>());
- return new ConcurrentMapAcceptingNullVals<K,V>(Maps.<K,V>newConcurrentMap());
- }
-
- @Override
- public void remove(String id) {
- synchronized (maps) {
- maps.remove(id);
- }
- }
-
- @Override
- public void terminate() {
- synchronized (maps) {
- maps.clear();
- }
- }
-
- @Override
- public Map<String, Object> getDatagridMetrics() {
- synchronized (maps) {
- return ImmutableMap.<String, Object>of("size", maps.size(), "createCount", creationCounter.get());
- }
- }
-
- @Override
- public Set<String> getKeys() {
- return maps.keySet();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynFeatureEnablement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynFeatureEnablement.java b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynFeatureEnablement.java
index 686fd35..047e3a8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynFeatureEnablement.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/BrooklynFeatureEnablement.java
@@ -21,12 +21,12 @@ package org.apache.brooklyn.core.internal;
import java.util.Map;
import org.apache.brooklyn.api.management.ha.HighAvailabilityMode;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.util.internal.ssh.ShellTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brooklyn.config.BrooklynProperties;
-import brooklyn.internal.storage.BrooklynStorage;
import com.google.common.annotations.Beta;
import com.google.common.collect.Maps;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/BrooklynStorage.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/BrooklynStorage.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/BrooklynStorage.java
new file mode 100644
index 0000000..b1f9cdf
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/BrooklynStorage.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import com.google.common.annotations.Beta;
+import com.google.common.annotations.VisibleForTesting;
+
+public interface BrooklynStorage {
+
+ /**
+ * Creates a reference to a value, backed by the storage-medium. If a reference with this
+ * name has already been created, then that existing reference will be returned.
+ *
+ * The returned reference is a live view: changes made to the reference will be persisted,
+ * and changes that others make will be reflected in the reference.
+ *
+ * The reference is thread-safe. No additional synchronization is required when getting/setting
+ * the reference.
+ *
+ * @param id
+ */
+ <T> Reference<T> getReference(String id);
+
+ /**
+ * Creates a list backed by the storage-medium. If a list with this name has already been
+ * created, then that existing list will be returned.
+ *
+ * The returned list is not a live view. Changes are made by calling reference.set(), and
+ * the view is refreshed by calling reference.get(). Changes are thread-safe, but callers
+ * must be careful not to overwrite other's changes. For example, the code below could overwrite
+ * another threads changes that are made to the map between the call to get() and the subsequent
+ * call to set().
+ *
+ * <pre>
+ * {@code
+ * Reference<List<String>> ref = storage.<String>createNonConcurrentList("myid");
+ * List<String> newval = ImmutableList.<String>builder().addAll(ref.get()).add("another").builder();
+ * ref.set(newval);
+ * }
+ * </pre>
+ *
+ * TODO Aled says: Is getNonConcurrentList necessary?
+ * The purpose of this method, rather than just using
+ * {@code Reference ref = getReference(id); ref.set(ImmutableList.of())}
+ * is to allow control of the serialization of the things inside the list
+ * (e.g. switching the Location object to serialize a proxy object of some sort).
+ * I don't want us to have to do deep inspection of every object being added to any map/ref.
+ * Feels like we can use normal serialization unless the top-level object matches an
+ * instanceof for special things like Entity, Location, etc.
+ *
+ * Peter responds:
+ * What I'm a bit scared of is that we need to write some kind of meta serialization mechanism
+ * on top of the mechanisms provided by e.g. Hazelcast or Infinispan. Hazelcast has a very
+ * extensive serialization library where you can plug in all kinds of serialization mechanisms.
+ *
+ * @param id
+ */
+ @Beta
+ <T> Reference<List<T>> getNonConcurrentList(String id);
+
+ /**
+ * Creates a map backed by the storage-medium. If a map with this name has already been
+ * created, then that existing map will be returned.
+ *
+ * The returned map is a live view: changes made to the map will be persisted, and changes
+ * that others make will be reflected in the map.
+ *
+ * The map is thread-safe: {@link Map#keySet()} etc will iterate over a snapshot view of the
+ * contents.
+ *
+ * @param id
+ */
+ <K,V> ConcurrentMap<K,V> getMap(String id);
+
+ /**
+ * Removes the data stored against this id, whether it is a map, ref or whatever.
+ */
+ void remove(String id);
+
+ /**
+ * Terminates the BrooklynStorage.
+ */
+ void terminate();
+
+ /** asserts that some of the storage containers which should be empty are empty;
+ * this could do more thorough checks, but as it is it is useful to catch many leaks,
+ * and the things which aren't empty it's much harder to check whether they should be empty!
+ * <p>
+ * not meant for use outwith tests */
+ @VisibleForTesting
+ public boolean isMostlyEmpty();
+
+ Map<String, Object> getStorageMetrics();
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
new file mode 100644
index 0000000..09f50fb
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public interface DataGrid {
+
+ /**
+ * If a map already exists with this id, returns it; otherwise creates a new map stored
+ * in the datagrid.
+ */
+ <K,V> ConcurrentMap<K,V> getMap(String id);
+
+ /**
+ * Deletes the map for this id, if it exists; otherwise a no-op.
+ */
+ void remove(String id);
+
+ /**
+ * Terminates the DataGrid. If there is a real datagrid with multiple machines running, it doesn't mean that the
+ * datagrid is going to be terminated; it only means that all local resources of the datagrid are released.
+ */
+ void terminate();
+
+ Map<String, Object> getDatagridMetrics();
+
+ /** Returns snapshot of known keys at this datagrid */
+ @VisibleForTesting
+ Set<String> getKeys();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
new file mode 100644
index 0000000..c055efa
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage;
+
+import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
+
+/**
+ * A factory for creating a {@link DataGrid}.
+ *
+ * Implementations of this interface should have a public no arg constructor; this constructor will be
+ * called through reflection in the {@link org.apache.brooklyn.core.management.internal.LocalManagementContext}.
+ */
+public interface DataGridFactory {
+
+ /**
+ * Creates a {@link BrooklynStorage} instance.
+ *
+ * @param managementContext the ManagementContextInternal
+ * @return the created BrooklynStorage.
+ */
+ DataGrid newDataGrid(ManagementContextInternal managementContext);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/Reference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/Reference.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/Reference.java
new file mode 100644
index 0000000..3f2d846
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/Reference.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage;
+
+/**
+ * A reference to a value, backed by the storage-medium.
+ *
+ * @see BrooklynStorage#getReference(String)
+ *
+ * @author aled
+ */
+public interface Reference<T> {
+
+ // TODO We can add compareAndSet(T,T) as and when required
+
+ T get();
+
+ T set(T val);
+
+ /**
+ * @return true if the value is null; false otherwise.
+ */
+ boolean isNull();
+
+ /**
+ * Sets the value back to null. Similar to {@code set(null)}.
+ */
+ void clear();
+
+ /**
+ * @return true if the value equals the given parameter; false otherwise
+ */
+ boolean contains(Object other);
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BackedReference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BackedReference.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BackedReference.java
new file mode 100644
index 0000000..e51e782
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BackedReference.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+
+import org.apache.brooklyn.core.internal.storage.Reference;
+
+import com.google.common.base.Objects;
+
+class BackedReference<T> implements Reference<T> {
+ private final Map<String,? super T> backingMap;
+ private final String key;
+
+ BackedReference(Map<String,? super T> backingMap, String key) {
+ this.backingMap = checkNotNull(backingMap, "backingMap");
+ this.key = key;
+ }
+
+ @Override
+ public T get() {
+ // For happens-before (for different threads calling get and set), relies on
+ // underlying map (e.g. from datagrid) having some synchronization
+ return (T) backingMap.get(key);
+ }
+
+ @Override
+ public T set(T val) {
+ if (val == null) {
+ return (T) backingMap.remove(key);
+ } else {
+ return (T) backingMap.put(key, val);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return ""+get();
+ }
+
+ @Override
+ public boolean isNull() {
+ return get() == null;
+ }
+
+ @Override
+ public void clear() {
+ set(null);
+ }
+
+ @Override
+ public boolean contains(Object other) {
+ return Objects.equal(get(), other);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BasicReference.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BasicReference.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BasicReference.java
new file mode 100644
index 0000000..a01d61c
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BasicReference.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.brooklyn.core.internal.storage.Reference;
+
+import com.google.common.base.Objects;
+
+public class BasicReference<T> implements Reference<T >{
+
+ private final AtomicReference<T> ref = new AtomicReference<T>();
+
+ public BasicReference() {
+ }
+
+ public BasicReference(T val) {
+ set(val);
+ }
+
+ @Override
+ public T get() {
+ return ref.get();
+ }
+
+ @Override
+ public T set(T val) {
+ return ref.getAndSet(val);
+ }
+
+ @Override
+ public boolean isNull() {
+ return get() == null;
+ }
+
+ @Override
+ public void clear() {
+ set(null);
+ }
+
+ @Override
+ public boolean contains(Object other) {
+ return Objects.equal(get(), other);
+ }
+
+ @Override
+ public String toString() {
+ return ""+get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
new file mode 100644
index 0000000..188955a
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.Reference;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+public class BrooklynStorageImpl implements BrooklynStorage {
+
+ private final DataGrid datagrid;
+ private final ConcurrentMap<String, Object> refsMap;
+ private final ConcurrentMap<String, Object> listsMap;
+ private final ConcurrentMap<String, WeakReference<Reference<?>>> refsCache;
+ private final ConcurrentMap<String, WeakReference<Reference<?>>> listRefsCache;
+
+ public BrooklynStorageImpl(DataGrid datagrid) {
+ this.datagrid = datagrid;
+ this.refsMap = datagrid.getMap("refs");
+ this.listsMap = datagrid.getMap("lists");
+ this.refsCache = Maps.newConcurrentMap();
+ this.listRefsCache = Maps.newConcurrentMap();
+ }
+
+ /**
+ * Returns the DataGrid used by this BrooklynStorageImpl
+ *
+ * @return the DataGrid.
+ */
+ @VisibleForTesting
+ public DataGrid getDataGrid() {
+ return datagrid;
+ }
+
+ @Override
+ public <T> Reference<T> getReference(final String id) {
+ // Can use different ref instances; no need to always return same one. Caching is an
+ // optimisation to just avoid extra object creation.
+ WeakReference<Reference<?>> weakRef = refsCache.get(id);
+ Reference<?> ref = (weakRef != null) ? weakRef.get() : null;
+ if (ref == null) {
+ ref = new BackedReference<T>(refsMap, id) {
+ @Override protected void finalize() {
+ // TODO Don't like using finalize due to performance overhead, but not
+ // optimising yet. Could use PhantomReference instead; see
+ // http://java.dzone.com/articles/finalization-and-phantom
+ refsCache.remove(id);
+ }
+ };
+ refsCache.putIfAbsent(id, new WeakReference<Reference<?>>(ref));
+ }
+ return (Reference<T>) ref;
+ }
+
+ @Override
+ public <T> Reference<List<T>> getNonConcurrentList(final String id) {
+ WeakReference<Reference<?>> weakRef = listRefsCache.get(id);
+ Reference<?> ref = (weakRef != null) ? weakRef.get() : null;
+ if (ref == null) {
+ ref = new BackedReference<List<T>>(listsMap, id) {
+ @Override public List<T> get() {
+ List<T> result = super.get();
+ return (result == null ? ImmutableList.<T>of() : Collections.unmodifiableList(result));
+ }
+ @Override protected void finalize() {
+ listRefsCache.remove(id);
+ }
+ };
+ listRefsCache.putIfAbsent(id, new WeakReference<Reference<?>>(ref));
+ }
+ return (Reference<List<T>>) ref;
+ }
+
+ @Override
+ public <K, V> ConcurrentMap<K, V> getMap(final String id) {
+ return datagrid.<K,V>getMap(id);
+ }
+
+ @Override
+ public void remove(String id) {
+ datagrid.remove(id);
+ refsMap.remove(id);
+ listsMap.remove(id);
+ refsCache.remove(id);
+ listRefsCache.remove(id);
+ }
+
+ @Override
+ public void terminate() {
+ datagrid.terminate();
+ }
+
+ public boolean isMostlyEmpty() {
+ if (!refsMap.isEmpty() || !listsMap.isEmpty())
+ return false;
+ // the datagrid may have some standard bookkeeping entries
+ return true;
+ }
+
+ @Override
+ public Map<String, Object> getStorageMetrics() {
+ return ImmutableMap.of(
+ "datagrid", datagrid.getDatagridMetrics(),
+ "refsMapSize", ""+refsMap.size(),
+ "listsMapSize", ""+listsMap.size());
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + getStorageMetrics();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullVals.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
new file mode 100644
index 0000000..c0d02c2
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/ConcurrentMapAcceptingNullVals.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.annotation.Nullable;
+
+/**
+ * A decorator for a ConcurrentMap that allows null values to be used.
+ *
+ * However, {@link #values()} and {@link #entrySet()} return immutable snapshots
+ * of the map's contents. This may be revisited in a future version.
+ *
+ * @author aled
+ */
+public class ConcurrentMapAcceptingNullVals<K, V> implements ConcurrentMap<K, V> {
+
+ private static enum Marker {
+ NULL;
+ }
+
+ private final ConcurrentMap<K, V> delegate;
+
+ public ConcurrentMapAcceptingNullVals(ConcurrentMap<K,V> delegate) {
+ this.delegate = checkNotNull(delegate, "delegate");
+ }
+
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return delegate.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return delegate.containsValue(toNonNullValue(value));
+ }
+
+ @Override
+ public Set<Map.Entry<K, V>> entrySet() {
+ // Note that returns an immutable snapshot
+ Set<Map.Entry<K, V>> result = new LinkedHashSet<Map.Entry<K, V>>(delegate.size());
+ for (Map.Entry<K, V> entry : delegate.entrySet()) {
+ result.add(new AbstractMap.SimpleEntry<K,V>(entry.getKey(), (V)fromNonNullValue(entry.getValue())));
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @Override
+ public Collection<V> values() {
+ // Note that returns an immutable snapshot
+ List<V> result = new ArrayList<V>(delegate.size());
+ for (V v : delegate.values()) {
+ result.add((V)fromNonNullValue(v));
+ }
+ return Collections.unmodifiableCollection(result);
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return delegate.keySet();
+ }
+
+ @Override
+ public V get(Object key) {
+ return (V) fromNonNullValue(delegate.get(key));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public V put(K key, V value) {
+ return (V) fromNonNullValue(delegate.put(key, (V) toNonNullValue(value)));
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> vals) {
+ for (Map.Entry<? extends K, ? extends V> entry : vals.entrySet()) {
+ put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ @Override
+ public V remove(Object key) {
+ return (V) fromNonNullValue(delegate.remove(key));
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public V putIfAbsent(K key, V value) {
+ return (V) fromNonNullValue(delegate.putIfAbsent(key, (V) toNonNullValue(value)));
+ }
+
+ @Override
+ public boolean remove(Object key, Object value) {
+ return delegate.remove(key, (V) toNonNullValue(value));
+ }
+
+ @Override
+ public V replace(K key, V value) {
+ return (V) fromNonNullValue(delegate.replace(key, (V) toNonNullValue(value)));
+ }
+
+ @Override
+ public boolean replace(K key, V oldValue, V newValue) {
+ return delegate.replace(key, (V) toNonNullValue(oldValue), (V) toNonNullValue(newValue));
+ }
+
+ private static class SetWithNullVals<T> implements Set<T> {
+
+ private final Set<T> delegate;
+
+ public SetWithNullVals(Set<T> delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public boolean add(T e) {
+ return delegate.add(e); // unsupported; let delegate give exception
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends T> c) {
+ return delegate.addAll(c); // unsupported; let delegate give exception
+ }
+
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return delegate.contains(toNonNullValue(o));
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ for (Object e : c) {
+ if (!delegate.contains(toNonNullValue(e))) return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public Iterator<T> iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return delegate.remove(toNonNullValue(o));
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ boolean result = false;
+ for (Object e : c) {
+ result = result & delegate.remove(toNonNullValue(e));
+ }
+ return result;
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ boolean result = false;
+ for (Iterator<T> iter = delegate.iterator(); iter.hasNext();) {
+ T e = iter.next();
+ if (!c.contains(fromNonNullValue(e))) {
+ iter.remove();
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public Object[] toArray() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+
+ private static Object toNonNullValue(Object value) {
+ return (value != null) ? value : Marker.NULL;
+ }
+
+ private static Object fromNonNullValue(Object value) {
+ return (value == Marker.NULL) ? null : value;
+ }
+
+ @Override
+ public boolean equals(@Nullable Object object) {
+ // copied from guava's non-public method Maps.equalsImpl
+ if (this == object) {
+ return true;
+ }
+ if (object instanceof Map) {
+ Map<?, ?> o = (Map<?, ?>) object;
+ return entrySet().equals(o.entrySet());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ // copied from guava's ImmutableMap.hashCode
+ return entrySet().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
new file mode 100644
index 0000000..dec70ba
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl.inmemory;
+
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.DataGridFactory;
+import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
+
+public class InMemoryDataGridFactory implements DataGridFactory {
+
+ public static DataGridFactory ofInstance(final DataGrid datagrid) {
+ return new DataGridFactory() {
+ @Override
+ public DataGrid newDataGrid(ManagementContextInternal managementContext) {
+ return datagrid;
+ }
+ };
+ }
+
+ @Override
+ public DataGrid newDataGrid(ManagementContextInternal managementContext) {
+ return new InmemoryDatagrid();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
new file mode 100644
index 0000000..48600d9
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.internal.storage.impl.inmemory;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.impl.ConcurrentMapAcceptingNullVals;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+/**
+ * A simple implementation of datagrid backed by in-memory (unpersisted) maps, within a single JVM.
+ *
+ * @author aled
+ */
+public class InmemoryDatagrid implements DataGrid {
+
+ private final Map<String,Map<?,?>> maps = Maps.newLinkedHashMap();
+ private final AtomicInteger creationCounter = new AtomicInteger();
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <K, V> ConcurrentMap<K, V> getMap(String id) {
+ synchronized (maps) {
+ ConcurrentMap<K, V> result = (ConcurrentMap<K, V>) maps.get(id);
+ if (result == null) {
+ result = newMap();
+ maps.put(id, result);
+ creationCounter.incrementAndGet();
+ }
+ return result;
+ }
+ }
+
+ // TODO Not doing Maps.newConcurrentMap() because needs to store null values.
+ // Easy to avoid for Refererence<?> but harder for entity ConfigMap where the user
+ // can insert null values.
+ //
+ // Could write a decorator that switches null values for a null marker, and back again.
+ //
+ private <K,V> ConcurrentMap<K,V> newMap() {
+ //return Collections.synchronizedMap(new HashMap<K, V>());
+ return new ConcurrentMapAcceptingNullVals<K,V>(Maps.<K,V>newConcurrentMap());
+ }
+
+ @Override
+ public void remove(String id) {
+ synchronized (maps) {
+ maps.remove(id);
+ }
+ }
+
+ @Override
+ public void terminate() {
+ synchronized (maps) {
+ maps.clear();
+ }
+ }
+
+ @Override
+ public Map<String, Object> getDatagridMetrics() {
+ synchronized (maps) {
+ return ImmutableMap.<String, Object>of("size", maps.size(), "createCount", creationCounter.get());
+ }
+ }
+
+ @Override
+ public Set<String> getKeys() {
+ return maps.keySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
index 7c1e473..0936bb2 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
@@ -53,6 +53,11 @@ import org.apache.brooklyn.api.management.ha.HighAvailabilityManager;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
+import org.apache.brooklyn.core.internal.storage.DataGrid;
+import org.apache.brooklyn.core.internal.storage.DataGridFactory;
+import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
+import org.apache.brooklyn.core.internal.storage.impl.inmemory.InMemoryDataGridFactory;
import org.apache.brooklyn.core.management.classloading.JavaBrooklynClassLoadingContext;
import org.apache.brooklyn.core.management.entitlement.Entitlements;
import org.apache.brooklyn.core.management.ha.HighAvailabilityManagerImpl;
@@ -69,11 +74,6 @@ import brooklyn.entity.basic.EntityInternal;
import brooklyn.entity.drivers.BasicEntityDriverManager;
import brooklyn.entity.drivers.downloads.BasicDownloadsManager;
import brooklyn.entity.rebind.RebindManagerImpl;
-import brooklyn.internal.storage.BrooklynStorage;
-import brooklyn.internal.storage.DataGrid;
-import brooklyn.internal.storage.DataGridFactory;
-import brooklyn.internal.storage.impl.BrooklynStorageImpl;
-import brooklyn.internal.storage.impl.inmemory.InMemoryDataGridFactory;
import org.apache.brooklyn.location.basic.BasicLocationRegistry;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/BrooklynGarbageCollector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/BrooklynGarbageCollector.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/BrooklynGarbageCollector.java
index 45876c5..ad13d42 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/BrooklynGarbageCollector.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/BrooklynGarbageCollector.java
@@ -39,6 +39,7 @@ import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.management.HasTaskChildren;
import org.apache.brooklyn.api.management.Task;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.util.task.BasicExecutionManager;
import org.apache.brooklyn.core.util.task.ExecutionListener;
import org.apache.brooklyn.core.util.task.Tasks;
@@ -52,7 +53,6 @@ import brooklyn.entity.basic.BrooklynTaskTags.WrappedEntity;
import brooklyn.entity.basic.BrooklynTaskTags.WrappedStream;
import brooklyn.entity.basic.ConfigKeys;
import brooklyn.entity.basic.Entities;
-import brooklyn.internal.storage.BrooklynStorage;
import brooklyn.util.collections.MutableList;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.collections.MutableSet;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalEntityManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalEntityManager.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalEntityManager.java
index 23039ba..84afdba 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalEntityManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalEntityManager.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.api.policy.Enricher;
import org.apache.brooklyn.api.policy.EnricherSpec;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.policy.PolicySpec;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.util.task.Tasks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +60,6 @@ import brooklyn.entity.proxying.EntityProxyImpl;
import brooklyn.entity.proxying.InternalEntityFactory;
import brooklyn.entity.proxying.InternalPolicyFactory;
import brooklyn.entity.trait.Startable;
-import brooklyn.internal.storage.BrooklynStorage;
import brooklyn.util.collections.MutableSet;
import brooklyn.util.collections.SetFromLiveMap;
import brooklyn.util.exceptions.Exceptions;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3230e730/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalLocationManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalLocationManager.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalLocationManager.java
index f3e6aef..b22c5aa 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalLocationManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/LocalLocationManager.java
@@ -29,6 +29,7 @@ import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.location.ProvisioningLocation;
import org.apache.brooklyn.api.management.AccessController;
+import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
import org.apache.brooklyn.core.management.entitlement.Entitlements;
import org.apache.brooklyn.core.util.config.ConfigBag;
import org.apache.brooklyn.core.util.task.Tasks;
@@ -41,7 +42,6 @@ import brooklyn.config.ConfigKey;
import brooklyn.entity.basic.ConfigKeys;
import brooklyn.entity.basic.Lifecycle;
import brooklyn.entity.proxying.InternalLocationFactory;
-import brooklyn.internal.storage.BrooklynStorage;
import org.apache.brooklyn.location.basic.AbstractLocation;
import org.apache.brooklyn.location.basic.LocationInternal;