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 2015/11/20 02:07:51 UTC
[16/20] incubator-geode git commit: moved all LifeCycleListener
static methods to that interface
moved all LifeCycleListener static methods to that interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/cd4ebb76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/cd4ebb76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/cd4ebb76
Branch: refs/heads/feature/GEODE-580
Commit: cd4ebb76c72b847293abdc085ce8599524ac7823
Parents: 8c5d5a7
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:35:51 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:35:51 2015 -0800
----------------------------------------------------------------------
.../internal/offheap/LifecycleListener.java | 43 ++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 52 ++------------------
...moryAllocatorLifecycleListenerJUnitTest.java | 8 +--
3 files changed, 51 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
index b171408..613b12a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
@@ -16,6 +16,10 @@
*/
package com.gemstone.gemfire.internal.offheap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
/**
* Used by tests to get notifications about the lifecycle of a
* SimpleMemoryAllocatorImpl.
@@ -23,6 +27,7 @@ package com.gemstone.gemfire.internal.offheap;
* @author Kirk Lund
*/
public interface LifecycleListener {
+
/**
* Callback is invoked after creating a new SimpleMemoryAllocatorImpl.
*
@@ -52,4 +57,42 @@ public interface LifecycleListener {
* @param allocator the instance that is about to be closed
*/
public void beforeClose(SimpleMemoryAllocatorImpl allocator);
+
+ static void invokeBeforeClose(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.beforeClose(allocator);
+ }
+ }
+ static void invokeAfterReuse(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.afterReuse(allocator);
+ }
+ }
+ static void invokeAfterCreate(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.afterCreate(allocator);
+ }
+ }
+ /**
+ * Removes a LifecycleListener. Does nothing if the instance has not been added.
+ * @param listener the instance to remove
+ */
+ public static void removeLifecycleListener(LifecycleListener listener) {
+ lifecycleListeners.remove(listener);
+ }
+ /**
+ * Adds a LifecycleListener.
+ * @param listener the instance to add
+ */
+ public static void addLifecycleListener(LifecycleListener listener) {
+ LifecycleListener.lifecycleListeners.add(listener);
+ }
+
+ /**
+ * Following should be private but java 8 does not support that.
+ */
+ static final List<LifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<LifecycleListener>();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
index e761a10..b0d2b07 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
@@ -26,18 +26,14 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
-import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
@@ -50,7 +46,6 @@ import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
import com.gemstone.gemfire.internal.cache.BucketRegion;
-import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
@@ -137,7 +132,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
result.reuse(ooohml, lw, stats, offHeapMemorySize);
lw.config("Reusing " + result.getTotalMemory() + " bytes of off-heap memory. The maximum size of a single off-heap object is " + result.largestSlab + " bytes.");
created = true;
- invokeAfterReuse(result);
+ LifecycleListener.invokeAfterReuse(result);
} else {
// allocate memory chunks
//SimpleMemoryAllocatorImpl.cleanupPreviousAllocator();
@@ -169,7 +164,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
result = new SimpleMemoryAllocatorImpl(ooohml, stats, slabs);
created = true;
singleton = result;
- invokeAfterCreate(result);
+ LifecycleListener.invokeAfterCreate(result);
}
} finally {
if (!created) {
@@ -183,7 +178,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public static SimpleMemoryAllocatorImpl create(OutOfOffHeapMemoryListener oooml, OffHeapMemoryStats stats, UnsafeMemoryChunk[] slabs) {
SimpleMemoryAllocatorImpl result = new SimpleMemoryAllocatorImpl(oooml, stats, slabs);
singleton = result;
- invokeAfterCreate(result);
+ LifecycleListener.invokeAfterCreate(result);
return result;
}
@@ -437,7 +432,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
@Override
public void close() {
try {
- invokeBeforeClose(this);
+ LifecycleListener.invokeBeforeClose(this);
} finally {
this.ooohml.close();
if (Boolean.getBoolean(FREE_OFF_HEAP_MEMORY_PROPERTY)) {
@@ -1913,43 +1908,4 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public static void forceCompaction() {
getAllocator().freeList.compact(0);
}
-
- private static final List<LifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<LifecycleListener>();
-
- /**
- * Adds a LifecycleListener.
- * @param listener the instance to add
- */
- public static void addLifecycleListener(LifecycleListener listener) {
- lifecycleListeners.add(listener);
- }
-
- /**
- * Removes a LifecycleListener. Does nothing if the instance has not been added.
- * @param listener the instance to remove
- */
- public static void removeLifecycleListener(LifecycleListener listener) {
- lifecycleListeners.remove(listener);
- }
-
- static void invokeAfterCreate(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.afterCreate(allocator);
- }
- }
-
- static void invokeAfterReuse(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.afterReuse(allocator);
- }
- }
-
- static void invokeBeforeClose(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.beforeClose(allocator);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
index 4ace307..2df8656 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
@@ -44,7 +44,7 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@After
public void tearDown() throws Exception {
- SimpleMemoryAllocatorImpl.removeLifecycleListener(this.listener);
+ LifecycleListener.removeLifecycleListener(this.listener);
this.afterCreateCallbacks.clear();
this.afterReuseCallbacks.clear();
this.beforeCloseCallbacks.clear();
@@ -53,8 +53,8 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@Test
public void testAddRemoveListener() {
- SimpleMemoryAllocatorImpl.addLifecycleListener(this.listener);
- SimpleMemoryAllocatorImpl.removeLifecycleListener(this.listener);
+ LifecycleListener.addLifecycleListener(this.listener);
+ LifecycleListener.removeLifecycleListener(this.listener);
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{slab});
@@ -72,7 +72,7 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@Test
public void testCallbacksAreCalledAfterCreate() {
- SimpleMemoryAllocatorImpl.addLifecycleListener(this.listener);
+ LifecycleListener.addLifecycleListener(this.listener);
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{slab});