IGNITE-1522 - Made cache entry listener configurations transient in cache configuration
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e51fb420 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e51fb420 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e51fb420 Branch: refs/heads/ignite-1093-2 Commit: e51fb420d1284465c7cbe55a28c2374ddf67d495 Parents: 621eb0f Author: Valentin Kulichenko <[email protected]> Authored: Mon Sep 21 23:29:20 2015 -0700 Committer: Valentin Kulichenko <[email protected]> Committed: Mon Sep 21 23:29:20 2015 -0700 ---------------------------------------------------------------------- .../configuration/CacheConfiguration.java | 15 +++++ .../IgniteCacheEntryListenerAbstractTest.java | 65 +++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e51fb420/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index 7d1e14d..44a3fa9 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -19,6 +19,7 @@ package org.apache.ignite.configuration; import java.io.Serializable; import java.util.Collection; +import java.util.HashSet; import javax.cache.Cache; import javax.cache.configuration.CompleteConfiguration; import javax.cache.configuration.Factory; @@ -1799,6 +1800,20 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> { return this; } + /** + * Creates a copy of current configuration and removes all cache entry listeners. + * They are executed only locally and should never be sent to remote nodes. + * + * @return Configuration object that will be serialized. + */ + protected Object writeReplace() { + CacheConfiguration<K, V> cfg = new CacheConfiguration<>(this); + + cfg.listenerConfigurations = new HashSet<>(); + + return cfg; + } + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheConfiguration.class, this); http://git-wip-us.apache.org/repos/asf/ignite/blob/e51fb420/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java index 78a6700..3fdd7fc 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheEntryListenerAbstractTest.java @@ -17,6 +17,10 @@ package org.apache.ignite.internal.processors.cache; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,11 +36,13 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import javax.cache.configuration.CacheEntryListenerConfiguration; import javax.cache.configuration.Factory; +import javax.cache.configuration.FactoryBuilder; import javax.cache.configuration.MutableCacheEntryListenerConfiguration; import javax.cache.event.CacheEntryCreatedListener; import javax.cache.event.CacheEntryEvent; import javax.cache.event.CacheEntryExpiredListener; import javax.cache.event.CacheEntryListener; +import javax.cache.event.CacheEntryListenerException; import javax.cache.event.CacheEntryRemovedListener; import javax.cache.event.CacheEntryUpdatedListener; import javax.cache.event.EventType; @@ -358,6 +364,34 @@ public abstract class IgniteCacheEntryListenerAbstractTest extends IgniteCacheAb } /** + * @throws Exception If failed. + */ + public void testSerialization() throws Exception { + if (cacheMode() == LOCAL) + return; + + AtomicBoolean serialized = new AtomicBoolean(); + + NonSerializableListener lsnr = new NonSerializableListener(serialized); + + jcache(0).registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>( + FactoryBuilder.factoryOf(lsnr), + null, + true, + false + )); + + try { + startGrid(gridCount()); + } + finally { + stopGrid(gridCount()); + } + + assertFalse(serialized.get()); + } + + /** * @param key Key. * @param val Value. * @param cache Cache. @@ -1190,4 +1224,33 @@ public abstract class IgniteCacheEntryListenerAbstractTest extends IgniteCacheAb } } -} \ No newline at end of file + /** + */ + public static class NonSerializableListener implements CacheEntryCreatedListener<Object, Object>, Externalizable { + /** */ + private final AtomicBoolean serialized; + + /** + * @param serialized Serialized flag. + */ + public NonSerializableListener(AtomicBoolean serialized) { + this.serialized = serialized; + } + + /** {@inheritDoc} */ + @Override public void onCreated(Iterable<CacheEntryEvent<? extends Object, ? extends Object>> evts) + throws CacheEntryListenerException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + serialized.set(true); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // No-op. + } + } +}
