geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [4/6] incubator-geode git commit: GEODE-1938: Update with review comments. Cleaned up the error handling for getAllPools()
Date Wed, 28 Sep 2016 23:28:39 GMT
GEODE-1938: Update with review comments.
Cleaned up the error handling for getAllPools()


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/4345fda7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4345fda7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4345fda7

Branch: refs/heads/develop
Commit: 4345fda73f426755e05eaa5c8c17080bafddc4eb
Parents: 4609eac
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Wed Sep 28 07:44:23 2016 +1000
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Wed Sep 28 07:44:23 2016 +1000

----------------------------------------------------------------------
 .../pdx/internal/ClientTypeRegistration.java    | 57 ++++++--------------
 1 file changed, 17 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4345fda7/geode-core/src/main/java/org/apache/geode/pdx/internal/ClientTypeRegistration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/pdx/internal/ClientTypeRegistration.java
b/geode-core/src/main/java/org/apache/geode/pdx/internal/ClientTypeRegistration.java
index 261cc53..8957e7f 100644
--- a/geode-core/src/main/java/org/apache/geode/pdx/internal/ClientTypeRegistration.java
+++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/ClientTypeRegistration.java
@@ -41,9 +41,6 @@ import org.apache.geode.internal.cache.PoolManagerImpl;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.logging.log4j.Logger;
 
-/**
- *
- */
 public class ClientTypeRegistration implements TypeRegistration {
 
   private static final Logger logger = LogService.getLogger();
@@ -63,7 +60,7 @@ public class ClientTypeRegistration implements TypeRegistration {
       try {
         newTypeId = GetPDXIdForTypeOp.execute((ExecutablePool) pool, newType);
         newType.setTypeId(newTypeId);
-        sendTypeToAllPools(newType, newTypeId, pool);
+        sendTypeToPool(newType, newTypeId, pool);
         return newTypeId;
       } catch (ServerConnectivityException e) {
         //ignore, try the next pool.
@@ -73,7 +70,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     throw returnCorrectExceptionForFailure(pools, newTypeId, lastException);
   }
 
-  private void sendTypeToAllPools(PdxType type, int id, Pool pool) {
+  private void sendTypeToPool(PdxType type, int id, Pool pool) {
     try {
       AddPDXTypeOp.execute((ExecutablePool) pool, id, type);
     } catch (ServerConnectivityException serverConnectivityException) {
@@ -102,26 +99,26 @@ public class ClientTypeRegistration implements TypeRegistration {
     if (lastException != null) {
       throw lastException;
     } else {
-      if (pools.isEmpty()) {
-        if (this.cache.isClosed()) {
-          throw this.cache.getCacheClosedException("PDX detected cache was closed", null);
-        } else {
-          throw new CacheClosedException("Client pools have been closed so the PDX type registry
can not lookup a type.");
-        }
-      } else {
-        throw new InternalGemFireError("getType: Unable to determine PDXType for id " + typeId
+ " from existing client to server pools " + pools);
-      }
+      throw returnCorrectExceptionForFailure(pools, typeId, lastException);
     }
   }
 
-  private static Collection<Pool> getAllPools() {
+  private Collection<Pool> getAllPools() {
     Collection<Pool> pools = PoolManagerImpl.getPMI().getMap().values();
+
     for (Iterator<Pool> itr = pools.iterator(); itr.hasNext(); ) {
       PoolImpl pool = (PoolImpl) itr.next();
       if (pool.isUsedByGateway()) {
         itr.remove();
       }
     }
+
+    if (pools.isEmpty()) {
+      if (this.cache.isClosed()) {
+        throw new CacheClosedException("PDX detected cache was closed");
+      }
+      throw new CacheClosedException("Client pools have been closed so the PDX type registry
is not available.");
+    }
     return pools;
   }
 
@@ -160,7 +157,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     for (Pool pool : pools) {
       try {
         int result = GetPDXIdForEnumOp.execute((ExecutablePool) pool, enumInfo);
-        sendEnumIdToAllPools(enumInfo, result, pool);
+        sendEnumIdToPool(enumInfo, result, pool);
         return result;
       } catch (ServerConnectivityException e) {
         //ignore, try the next pool.
@@ -170,7 +167,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     throw returnCorrectExceptionForFailure(pools, -1, lastException);
   }
 
-  private void sendEnumIdToAllPools(EnumInfo enumInfo, int id, Pool pool) {
+  private void sendEnumIdToPool(EnumInfo enumInfo, int id, Pool pool) {
     try {
       AddPDXEnumOp.execute((ExecutablePool) pool, id, enumInfo);
     } catch (ServerConnectivityException serverConnectivityException) {
@@ -211,12 +208,6 @@ public class ClientTypeRegistration implements TypeRegistration {
   @Override
   public Map<Integer, PdxType> types() {
     Collection<Pool> pools = getAllPools();
-    if (pools.isEmpty()) {
-      if (this.cache.isClosed()) {
-        throw new CacheClosedException("PDX detected cache was closed");
-      }
-      throw new CacheClosedException("Client pools have been closed so the PDX type registry
is not available.");
-    }
 
     Map<Integer, PdxType> types = new HashMap<>();
     for (Pool p : pools) {
@@ -233,12 +224,6 @@ public class ClientTypeRegistration implements TypeRegistration {
   @Override
   public Map<Integer, EnumInfo> enums() {
     Collection<Pool> pools = getAllPools();
-    if (pools.isEmpty()) {
-      if (this.cache.isClosed()) {
-        throw new CacheClosedException("PDX detected cache was closed");
-      }
-      throw new CacheClosedException("Client pools have been closed so the PDX type registry
is not available.");
-    }
 
     Map<Integer, EnumInfo> enums = new HashMap<>();
     for (Pool p : pools) {
@@ -277,7 +262,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     ServerConnectivityException lastException = null;
     for (Pool pool : pools) {
       try {
-        sendTypeToAllPools(importedType, typeId, pool);
+        sendTypeToPool(importedType, typeId, pool);
         return;
       } catch (ServerConnectivityException e) {
         //ignore, try the next pool.
@@ -294,7 +279,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     ServerConnectivityException lastException = null;
     for (Pool pool : pools) {
       try {
-        sendEnumIdToAllPools(importedInfo, enumId, pool);
+        sendEnumIdToPool(importedInfo, enumId, pool);
       } catch (ServerConnectivityException e) {
         //ignore, try the next pool.
         lastException = e;
@@ -308,15 +293,7 @@ public class ClientTypeRegistration implements TypeRegistration {
     if (lastException != null) {
       throw lastException;
     } else {
-      if (pools.isEmpty()) {
-        if (this.cache.isClosed()) {
-          throw this.cache.getCacheClosedException("PDX detected cache was closed", null);
-        } else {
-          throw new CacheClosedException("Client pools have been closed so the PDX type registry
can not lookup a type.");
-        }
-      } else {
-        throw new InternalGemFireError("Unable to determine PDXType for id " + typeId);
-      }
+      throw new InternalGemFireError("Unable to determine PDXType for id " + typeId);
     }
   }
 


Mime
View raw message