geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [31/50] [abbrv] incubator-geode git commit: GEODE-795: Changed RegionEntryFactory code from complex nested if-else block to more maintainable bit masking.
Date Mon, 01 Feb 2016 20:55:48 GMT
GEODE-795: Changed RegionEntryFactory code from complex nested if-else block to more maintainable
bit masking.


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

Branch: refs/heads/feature/GEODE-773-2
Commit: 02c67e2578b31c8e3babb654e55fb97f688ef0b4
Parents: 554ecae
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Thu Jan 28 08:54:29 2016 +1100
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Mon Feb 1 14:14:40 2016 +1100

----------------------------------------------------------------------
 .../internal/cache/AbstractRegionMap.java       | 133 +------------------
 .../region/entry/RegionEntryFactoryBuilder.java | 103 ++++++++++++++
 .../RegionEntryFactoryBuilderJUnitTest.java     |  85 ++++++++++++
 3 files changed, 190 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02c67e25/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
index 096bd0a..3679519 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.gemstone.gemfire.internal.cache.region.entry.RegionEntryFactoryBuilder;
 import org.apache.logging.log4j.Logger;
 
 import com.gemstone.gemfire.GemFireIOException;
@@ -193,137 +194,7 @@ abstract class AbstractRegionMap implements RegionMap {
       }
     }
     else {
-      final RegionEntryFactory factory;
-      if (attr.statisticsEnabled) {
-        if (isLRU) {
-          if (isDisk) {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedStatsDiskLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedStatsDiskLRURegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMStatsDiskLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMStatsDiskLRURegionEntryHeap.getEntryFactory();
-              }
-            }
-          } else {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedStatsLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedStatsLRURegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMStatsLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMStatsLRURegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-        } else { // !isLRU
-          if (isDisk) {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedStatsDiskRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedStatsDiskRegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMStatsDiskRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMStatsDiskRegionEntryHeap.getEntryFactory();
-              }
-            }
-          } else {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedStatsRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedStatsRegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMStatsRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMStatsRegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-        }
-      }
-      else { // !statistics enabled
-        if (isLRU) {
-          if (isDisk) {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedThinDiskLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedThinDiskLRURegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMThinDiskLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMThinDiskLRURegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-          else {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedThinLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedThinLRURegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMThinLRURegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMThinLRURegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-        }
-        else { // !isLRU
-          if (isDisk) {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedThinDiskRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedThinDiskRegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMThinDiskRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMThinDiskRegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-          else {
-            if (withVersioning) {
-              if (offHeap) {
-                factory = VersionedThinRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VersionedThinRegionEntryHeap.getEntryFactory();
-              }
-            } else {
-              if (offHeap) {
-                factory = VMThinRegionEntryOffHeap.getEntryFactory();
-              } else {
-                factory = VMThinRegionEntryHeap.getEntryFactory();
-              }
-            }
-          }
-        }
-      }
-      setEntryFactory(factory);
+      setEntryFactory(new RegionEntryFactoryBuilder().getRegionEntryFactoryOrNull(attr.statisticsEnabled,isLRU,isDisk,withVersioning,offHeap));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02c67e25/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilder.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilder.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilder.java
new file mode 100644
index 0000000..f4e55ed
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilder.java
@@ -0,0 +1,103 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache.region.entry;
+
+import com.gemstone.gemfire.internal.cache.*;
+
+public class RegionEntryFactoryBuilder {
+  public RegionEntryFactory getRegionEntryFactoryOrNull(boolean statsEnabled, boolean isLRU,
boolean isDisk, boolean withVersioning, boolean offHeap) {
+    int bitRepresentation = 0;
+    bitRepresentation |= statsEnabled ? 1 : 0;
+    bitRepresentation |= isLRU ? 2 : 0;
+    bitRepresentation |= isDisk ? 4 : 0;
+    bitRepresentation |= withVersioning ? 8 : 0;
+    bitRepresentation |= offHeap ? 16 : 0;
+
+    /**
+     * The bits represent all options
+     * |offHeap|versioning|disk|lru|stats|
+     */
+    switch (bitRepresentation) {
+    case (0):
+      return VMThinRegionEntryHeap.getEntryFactory(); // Bits: 00000
+    case (1):
+      return VMStatsRegionEntryHeap.getEntryFactory(); // Bits: 00001
+    case (2):
+      return VMThinLRURegionEntryHeap.getEntryFactory(); // Bits: 00010
+    case (3):
+      return VMStatsLRURegionEntryHeap.getEntryFactory(); // Bits: 00011
+    case (4):
+      return VMThinDiskRegionEntryHeap.getEntryFactory(); // Bits: 00100
+    case (5):
+      return VMStatsDiskRegionEntryHeap.getEntryFactory(); // Bits: 00101
+    case (6):
+      return VMThinDiskLRURegionEntryHeap.getEntryFactory(); // Bits: 00110
+    case (7):
+      return VMStatsDiskLRURegionEntryHeap.getEntryFactory(); // Bits: 00111
+    case (8):
+      return VersionedThinRegionEntryHeap.getEntryFactory(); // Bits: 01000
+    case (9):
+      return VersionedStatsRegionEntryHeap.getEntryFactory(); // Bits: 01001
+    case (10):
+      return VersionedThinLRURegionEntryHeap.getEntryFactory(); // Bits: 01010
+    case (11):
+      return VersionedStatsLRURegionEntryHeap.getEntryFactory(); // Bits: 01011
+    case (12):
+      return VersionedThinDiskRegionEntryHeap.getEntryFactory(); // Bits: 01100
+    case (13):
+      return VersionedStatsDiskRegionEntryHeap.getEntryFactory(); // Bits: 01101
+    case (14):
+      return VersionedThinDiskLRURegionEntryHeap.getEntryFactory(); // Bits: 01110
+    case (15):
+      return VersionedStatsDiskLRURegionEntryHeap.getEntryFactory(); // Bits: 01111
+    case (16):
+      return VMThinRegionEntryOffHeap.getEntryFactory(); // Bits: 10000
+    case (17):
+      return VMStatsRegionEntryOffHeap.getEntryFactory(); // Bits: 10001
+    case (18):
+      return VMThinLRURegionEntryOffHeap.getEntryFactory(); // Bits: 10010
+    case (19):
+      return VMStatsLRURegionEntryOffHeap.getEntryFactory(); // Bits: 10011
+    case (20):
+      return VMThinDiskRegionEntryOffHeap.getEntryFactory(); // Bits: 10100
+    case (21):
+      return VMStatsDiskRegionEntryOffHeap.getEntryFactory(); // Bits: 10101
+    case (22):
+      return VMThinDiskLRURegionEntryOffHeap.getEntryFactory(); // Bits: 10110
+    case (23):
+      return VMStatsDiskLRURegionEntryOffHeap.getEntryFactory(); // Bits: 10111
+    case (24):
+      return VersionedThinRegionEntryOffHeap.getEntryFactory(); // Bits: 11000
+    case (25):
+      return VersionedStatsRegionEntryOffHeap.getEntryFactory(); // Bits: 11001
+    case (26):
+      return VersionedThinLRURegionEntryOffHeap.getEntryFactory(); // Bits: 11010
+    case (27):
+      return VersionedStatsLRURegionEntryOffHeap.getEntryFactory(); // Bits: 11011
+    case (28):
+      return VersionedThinDiskRegionEntryOffHeap.getEntryFactory(); // Bits: 11100
+    case (29):
+      return VersionedStatsDiskRegionEntryOffHeap.getEntryFactory(); // Bits: 11101
+    case (30):
+      return VersionedThinDiskLRURegionEntryOffHeap.getEntryFactory(); // Bits: 11110
+    case (31):
+      return VersionedStatsDiskLRURegionEntryOffHeap.getEntryFactory(); // Bits: 11111
+    default:
+      return null;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02c67e25/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilderJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilderJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilderJUnitTest.java
new file mode 100644
index 0000000..09fde8a
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/region/entry/RegionEntryFactoryBuilderJUnitTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache.region.entry;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+
+@Category(UnitTest.class)
+@RunWith(JUnitParamsRunner.class)
+public class RegionEntryFactoryBuilderJUnitTest {
+
+  private RegionEntryFactoryBuilder regionEntryFactoryBuilder;
+
+  @Before
+  public void setup() {
+    regionEntryFactoryBuilder = new RegionEntryFactoryBuilder();
+  }
+
+  /**
+   * This method will test that the correct RegionEntryFactory is created
+   * dependent on the 5 conditionals:
+   * enableStats, enableLRU, enableDisk, enableVersion, enableOffHeap
+   */
+  @Test
+  @Parameters({
+      "VMThinRegionEntryHeapFactory,false,false,false,false,false",
+      "VMThinRegionEntryOffHeapFactory,false,false,false,false,true",
+      "VersionedThinRegionEntryHeapFactory,false,false,false,true,false",
+      "VersionedThinRegionEntryOffHeapFactory,false,false,false,true,true",
+      "VMThinDiskRegionEntryHeapFactory,false,false,true,false,false",
+      "VMThinDiskRegionEntryOffHeapFactory,false,false,true,false,true",
+      "VersionedThinDiskRegionEntryHeapFactory,false,false,true,true,false",
+      "VersionedThinDiskRegionEntryOffHeapFactory,false,false,true,true,true",
+      "VMThinLRURegionEntryHeapFactory,false,true,false,false,false",
+      "VMThinLRURegionEntryOffHeapFactory,false,true,false,false,true",
+      "VersionedThinLRURegionEntryHeapFactory,false,true,false,true,false",
+      "VersionedThinLRURegionEntryOffHeapFactory,false,true,false,true,true",
+      "VMThinDiskLRURegionEntryHeapFactory,false,true,true,false,false",
+      "VMThinDiskLRURegionEntryOffHeapFactory,false,true,true,false,true",
+      "VersionedThinDiskLRURegionEntryHeapFactory,false,true,true,true,false",
+      "VersionedThinDiskLRURegionEntryOffHeapFactory,false,true,true,true,true",
+      "VMStatsRegionEntryHeapFactory,true,false,false,false,false",
+      "VMStatsRegionEntryOffHeapFactory,true,false,false,false,true",
+      "VersionedStatsRegionEntryHeapFactory,true,false,false,true,false",
+      "VersionedStatsRegionEntryOffHeapFactory,true,false,false,true,true",
+      "VMStatsDiskRegionEntryHeapFactory,true,false,true,false,false",
+      "VMStatsDiskRegionEntryOffHeapFactory,true,false,true,false,true",
+      "VersionedStatsDiskRegionEntryHeapFactory,true,false,true,true,false",
+      "VersionedStatsDiskRegionEntryOffHeapFactory,true,false,true,true,true",
+      "VMStatsLRURegionEntryHeapFactory,true,true,false,false,false",
+      "VMStatsLRURegionEntryOffHeapFactory,true,true,false,false,true",
+      "VersionedStatsLRURegionEntryHeapFactory,true,true,false,true,false",
+      "VersionedStatsLRURegionEntryOffHeapFactory,true,true,false,true,true",
+      "VMStatsDiskLRURegionEntryHeapFactory,true,true,true,false,false",
+      "VMStatsDiskLRURegionEntryOffHeapFactory,true,true,true,false,true",
+      "VersionedStatsDiskLRURegionEntryHeapFactory,true,true,true,true,false",
+      "VersionedStatsDiskLRURegionEntryOffHeapFactory,true,true,true,true,true"
+  })
+  public void testRegionEntryFactoryUnitTest(String factoryName, boolean enableStats, boolean
enableLRU, boolean enableDisk,
+      boolean enableVersioning, boolean enableOffHeap) {
+    assertEquals(factoryName,
+        regionEntryFactoryBuilder.getRegionEntryFactoryOrNull(enableStats, enableLRU, enableDisk,
enableVersioning, enableOffHeap).getClass().getSimpleName());
+  }
+}
\ No newline at end of file


Mime
View raw message