You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mh...@apache.org on 2019/12/18 21:46:30 UTC
[geode] 03/03: GEODE-7159: Amending emergencyClose to type check
before casting. Also included Optional instead of null checks (#4493)
This is an automated email from the ASF dual-hosted git repository.
mhanson pushed a commit to branch release/1.11.0
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 0890c4f950e27cc5bf74b534b5cc9fe8076126b5
Author: Udo Kohlmeyer <ko...@users.noreply.github.com>
AuthorDate: Tue Dec 17 14:51:08 2019 -0800
GEODE-7159: Amending emergencyClose to type check before casting. Also included Optional instead of null checks (#4493)
(cherry picked from commit 0f05e9ccd94c04a205ace82de6616e9bffa92fa7)
---
.../geode/internal/cache/PoolManagerImpl.java | 25 +++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PoolManagerImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PoolManagerImpl.java
index 1d6f2f8..67488ee 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PoolManagerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PoolManagerImpl.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import org.apache.logging.log4j.Logger;
@@ -63,7 +64,7 @@ public class PoolManagerImpl {
}
private volatile Map<String, Pool> pools = Collections.emptyMap();
- private volatile Iterator<Map.Entry<String, Pool>> itrForEmergencyClose = null;
+ private volatile Optional<Iterator<Pool>> itrForEmergencyClose = Optional.empty();
private final Object poolLock = new Object();
/**
* True if this manager is a normal one owned by the PoolManager. False if this is a special one
@@ -123,7 +124,7 @@ public class PoolManagerImpl {
}
pools = Collections.emptyMap();
- itrForEmergencyClose = null;
+ itrForEmergencyClose = Optional.empty();
if (foundClientPool) {
// Now that the client has all the pools destroyed free up the pooled comm buffers
ServerConnection.emptyCommBufferPool();
@@ -159,7 +160,7 @@ public class PoolManagerImpl {
// + " and more than one pool already exists in client.");
// }
pools = Collections.unmodifiableMap(copy);
- itrForEmergencyClose = copy.entrySet().iterator();
+ itrForEmergencyClose = Optional.of(copy.values().iterator());
}
}
@@ -188,7 +189,7 @@ public class PoolManagerImpl {
return false;
} else {
pools = Collections.unmodifiableMap(copy);
- itrForEmergencyClose = copy.entrySet().iterator();
+ itrForEmergencyClose = Optional.of(copy.values().iterator());
return true;
}
}
@@ -289,14 +290,14 @@ public class PoolManagerImpl {
if (impl == null) {
return;
}
- Iterator<Map.Entry<String, Pool>> itr = impl.itrForEmergencyClose;
- if (itr == null) {
- return;
- }
- while (itr.hasNext()) {
- Entry<String, Pool> next = itr.next();
- ((PoolImpl) next.getValue()).emergencyClose();
- }
+ impl.itrForEmergencyClose.ifPresent(poolIterator -> {
+ while (poolIterator.hasNext()) {
+ Pool pool = poolIterator.next();
+ if (pool instanceof PoolImpl) {
+ ((PoolImpl) pool).emergencyClose();
+ }
+ }
+ });
}
public static void loadEmergencyClasses() {