You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2019/05/06 16:08:37 UTC
[geode] branch develop updated: GEODE-6670: remove getCacheServers
allocation
This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 0e342fd GEODE-6670: remove getCacheServers allocation
0e342fd is described below
commit 0e342fd3515e92a99c44bd05c661624d180045dd
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Mon May 6 09:08:26 2019 -0700
GEODE-6670: remove getCacheServers allocation
getCacheServers now returns a canonical instance instead of creating a new instance for each call.
---
.../java/org/apache/geode/internal/cache/GemFireCacheImpl.java | 7 ++++++-
.../org/apache/geode/internal/cache/GemFireCacheImplTest.java | 8 ++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 53211a5..a512b76 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -397,6 +397,11 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
* outnumber the mutative operations such as add, remove.
*/
private final List<InternalCacheServer> allCacheServers = new CopyOnWriteArrayList<>();
+ /**
+ * Unmodifiable view of "allCacheServers".
+ */
+ private final List<CacheServer> unmodifiableAllCacheServers =
+ Collections.unmodifiableList(allCacheServers);
/**
* Controls updates to the list of all gateway senders
@@ -3957,7 +3962,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
@Override
public List<CacheServer> getCacheServers() {
- return Collections.unmodifiableList(allCacheServers);
+ return this.unmodifiableAllCacheServers;
}
@Override
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
index 246e757..6a3546f 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
@@ -554,6 +554,14 @@ public class GemFireCacheImplTest {
assertThat(value).isFalse();
}
+ @Test
+ public void getCacheServersIsCanonical() {
+ gemFireCacheImpl = createGemFireCacheImpl();
+ List<CacheServer> list1 = gemFireCacheImpl.getCacheServers();
+ List<CacheServer> list2 = gemFireCacheImpl.getCacheServers();
+ assertThat(list1).isSameAs(list2);
+ }
+
private static GemFireCacheImpl createGemFireCacheImpl() {
return (GemFireCacheImpl) new InternalCacheBuilder().create(Fakes.distributedSystem());
}