ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [47/50] [abbrv] incubator-ignite git commit: #IGNITE-45 - Added events, fixed build.
Date Mon, 16 Mar 2015 09:23:34 GMT
#IGNITE-45 - Added events, fixed build.


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

Branch: refs/heads/ignite-421
Commit: ce38fd42a3907142e6eb412777d71672e8d8e348
Parents: 72f9038
Author: Alexey Goncharuk <agoncharuk@gridgain.com>
Authored: Mon Mar 16 00:14:19 2015 -0700
Committer: Alexey Goncharuk <agoncharuk@gridgain.com>
Committed: Mon Mar 16 00:14:19 2015 -0700

----------------------------------------------------------------------
 .../eviction/fifo/CacheFifoEvictionPolicy.java  |  3 ++
 .../eviction/igfs/CacheIgfsEvictionFilter.java  |  3 ++
 .../CacheIgfsPerBlockLruEvictionPolicy.java     |  3 ++
 .../eviction/lru/CacheLruEvictionPolicy.java    |  3 ++
 .../random/CacheRandomEvictionPolicy.java       |  3 ++
 .../org/apache/ignite/events/EventType.java     | 26 +++++++++
 .../processors/cache/GridCacheAdapter.java      |  1 +
 .../processors/cache/GridCacheEventManager.java | 26 +++++++--
 .../processors/cache/GridCacheProcessor.java    |  7 +++
 .../cache/IgniteDynamicCacheStartSelfTest.java  | 57 ++++++++++++++++++++
 10 files changed, 129 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java
index 5cfdd88..32a2160 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/CacheFifoEvictionPolicy.java
@@ -34,6 +34,9 @@ import java.util.*;
  */
 public class CacheFifoEvictionPolicy<K, V> implements CacheEvictionPolicy<K, V>,
     CacheFifoEvictionPolicyMBean, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
     /** Maximum size. */
     private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsEvictionFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsEvictionFilter.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsEvictionFilter.java
index f09a1b3..c09609f 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsEvictionFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsEvictionFilter.java
@@ -27,6 +27,9 @@ import java.io.*;
  * IGFS eviction filter which will not evict blocks of particular files.
  */
 public class CacheIgfsEvictionFilter implements CacheEvictionFilter, Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
     /** {@inheritDoc} */
     @Override public boolean evictAllowed(Cache.Entry entry) {
         Object key = entry.getKey();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsPerBlockLruEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsPerBlockLruEvictionPolicy.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsPerBlockLruEvictionPolicy.java
index cd4009a..fcd2c78 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsPerBlockLruEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/igfs/CacheIgfsPerBlockLruEvictionPolicy.java
@@ -36,6 +36,9 @@ import java.util.regex.*;
  */
 public class CacheIgfsPerBlockLruEvictionPolicy implements CacheEvictionPolicy<IgfsBlockKey,
byte[]>,
     CacheIgfsPerBlockLruEvictionPolicyMXBean, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
     /** Maximum size. When reached, eviction begins. */
     private volatile long maxSize;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
index 188eb2f..90e4aac 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/CacheLruEvictionPolicy.java
@@ -34,6 +34,9 @@ import java.util.*;
  */
 public class CacheLruEvictionPolicy<K, V> implements CacheEvictionPolicy<K, V>,
     CacheLruEvictionPolicyMBean, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
     /** Maximum size. */
     private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
index 83f2e6d..0cc63bc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/CacheRandomEvictionPolicy.java
@@ -36,6 +36,9 @@ import java.io.*;
  */
 public class CacheRandomEvictionPolicy<K, V> implements CacheEvictionPolicy<K, V>,
     CacheRandomEvictionPolicyMBean, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
     /** Maximum size. */
     private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/events/EventType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/events/EventType.java b/modules/core/src/main/java/org/apache/ignite/events/EventType.java
index 2ce47eb..3573ba4 100644
--- a/modules/core/src/main/java/org/apache/ignite/events/EventType.java
+++ b/modules/core/src/main/java/org/apache/ignite/events/EventType.java
@@ -624,6 +624,22 @@ public interface EventType {
     public static final int EVT_CACHE_QUERY_OBJECT_READ = 97;
 
     /**
+     * Built-in event type: cache started.
+     * <p>
+     * NOTE: all types in range <b>from 1 to 1000 are reserved</b> for
+     * internal Ignite events and should not be used by user-defined events.
+     */
+    public static final int EVT_CACHE_STARTED = 98;
+
+    /**
+     * Built-in event type: cache started.
+     * <p>
+     * NOTE: all types in range <b>from 1 to 1000 are reserved</b> for
+     * internal Ignite events and should not be used by user-defined events.
+     */
+    public static final int EVT_CACHE_STOPPED = 99;
+
+    /**
      * Built-in event type: Visor detects that some events were evicted from events buffer
since last poll.
      * <p>
      * NOTE: all types in range <b>from 1 to 1000 are reserved</b> for
@@ -931,6 +947,16 @@ public interface EventType {
     };
 
     /**
+     * All cache lifecycle events. This array can be directly passed into
+     * {@link org.apache.ignite.IgniteEvents#localListen(org.apache.ignite.lang.IgnitePredicate,
int...)} method to
+     * subscribe to all cache lifecycle events.
+     */
+    public static final int[] EVTS_CACHE_LIFECYCLE = {
+        EVT_CACHE_STARTED,
+        EVT_CACHE_STOPPED
+    };
+
+    /**
      * All cache query events. This array can be directly passed into
      * {@link org.apache.ignite.IgniteEvents#localListen(org.apache.ignite.lang.IgnitePredicate,
int...)} method to
      * subscribe to all cache query events.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 09bb1f1..43ccc81 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.compute.*;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
index 003ee54..f543e3b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
@@ -104,6 +104,26 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
     }
 
     /**
+     * @param type Event type (start or stop).
+     */
+    public void addEvent(int type) {
+        addEvent(
+            0,
+            null,
+            locNodeId,
+            (IgniteUuid)null,
+            null,
+            type,
+            null,
+            false,
+            null,
+            false,
+            null,
+            null,
+            null);
+    }
+
+    /**
      * @param part Partition.
      * @param key Key for the event.
      * @param nodeId Node ID.
@@ -220,13 +240,13 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
         @Nullable String cloClsName,
         @Nullable String taskName
     ) {
-        assert key != null;
+        assert key != null || type == EVT_CACHE_STARTED || type == EVT_CACHE_STOPPED;
 
         if (!cctx.events().isRecordable(type))
             LT.warn(log, null, "Added event without checking if event is recordable: " +
U.gridEventName(type));
 
         // Events are not fired for internal entry.
-        if (!key.internal()) {
+        if (key == null || !key.internal()) {
             ClusterNode evtNode = cctx.discovery().node(evtNodeId);
 
             if (evtNode == null)
@@ -244,7 +264,7 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
                 type,
                 part,
                 cctx.isNear(),
-                key.value(cctx.cacheObjectContext(), false),
+                key == null ? null : key.value(cctx.cacheObjectContext(), false),
                 xid,
                 lockId,
                 CU.value(newVal, cctx, false),

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index b9e766c..d556b5b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -25,6 +25,7 @@ import org.apache.ignite.cache.affinity.rendezvous.*;
 import org.apache.ignite.cache.store.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.affinity.*;
@@ -918,6 +919,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         cache.onKernalStart();
 
+        if (ctx.events().isRecordable(EventType.EVT_CACHE_STARTED))
+            ctx.events().addEvent(EventType.EVT_CACHE_STARTED);
+
         if (log.isDebugEnabled())
             log.debug("Executed onKernalStart() callback for cache [name=" + cache.name()
+ ", mode=" +
                 cache.configuration().getCacheMode() + ']');
@@ -957,6 +961,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         }
 
         cache.onKernalStop();
+
+        if (ctx.events().isRecordable(EventType.EVT_CACHE_STOPPED))
+            ctx.events().addEvent(EventType.EVT_CACHE_STOPPED);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce38fd42/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
index 2d1d39f..1bc2a0d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.managers.discovery.*;
 import org.apache.ignite.internal.util.typedef.*;
@@ -77,6 +78,8 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest
{
 
         cfg.setCacheConfiguration(cacheCfg);
 
+        cfg.setIncludeEventTypes(EventType.EVT_CACHE_STARTED, EventType.EVT_CACHE_STOPPED);
+
         return cfg;
     }
 
@@ -563,6 +566,60 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest
{
     /**
      * @throws Exception If failed.
      */
+    public void testEvents() throws Exception {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(DYNAMIC_CACHE_NAME);
+
+        final CountDownLatch[] starts = new CountDownLatch[nodeCount()];
+        final CountDownLatch[] stops = new CountDownLatch[nodeCount()];
+
+        IgnitePredicate[] lsnrs = new IgnitePredicate[nodeCount()];
+
+        for (int i = 0; i < nodeCount(); i++) {
+            final int idx = i;
+
+            starts[i] = new CountDownLatch(1);
+            stops[i] = new CountDownLatch(1);
+
+            lsnrs[i] = new IgnitePredicate<CacheEvent>() {
+                @Override public boolean apply(CacheEvent e) {
+                    switch (e.type()) {
+                        case EventType.EVT_CACHE_STARTED:
+                            starts[idx].countDown();
+
+                            break;
+
+                        case EventType.EVT_CACHE_STOPPED:
+                            stops[idx].countDown();
+
+                            break;
+
+                        default:
+                            assert false;
+                    }
+
+                    assertEquals(DYNAMIC_CACHE_NAME, e.cacheName());
+
+                    return true;
+                }
+            };
+
+            ignite(i).events().localListen(lsnrs[i], EventType.EVTS_CACHE_LIFECYCLE);
+        }
+
+        try (IgniteCache<Object, Object> ignored = ignite(0).createCache(cfg)) {
+            for (CountDownLatch start : starts)
+                start.await();
+        }
+
+        for (CountDownLatch stop : stops)
+            stop.await();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testNearNodesCache() throws Exception {
         try {
             testAttribute = false;


Mime
View raw message