IGNITE-51 Changed CacheInterceptor API. Added CacheLazyEntry,
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/43c04a0f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/43c04a0f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/43c04a0f Branch: refs/heads/ignite-user-req Commit: 43c04a0f3609871e37d1c9d584db91425c9461c6 Parents: 736158d Author: nikolay_tikhonov <ntikho...@gridgain.com> Authored: Tue Mar 3 19:22:22 2015 +0300 Committer: nikolay_tikhonov <ntikho...@gridgain.com> Committed: Tue Mar 3 19:22:22 2015 +0300 ---------------------------------------------------------------------- .../apache/ignite/cache/CacheInterceptor.java | 22 ++-- .../ignite/cache/CacheInterceptorAdapter.java | 12 +- .../processors/cache/CacheLazyEntry.java | 111 +++++++++++++++++++ .../processors/cache/GridCacheAdapter.java | 2 +- .../processors/cache/GridCacheMapEntry.java | 54 ++++----- .../dht/atomic/GridDhtAtomicCache.java | 27 +++-- .../local/atomic/GridLocalAtomicCache.java | 28 ++--- .../transactions/IgniteTxLocalAdapter.java | 14 +-- .../GridCacheInterceptorAbstractSelfTest.java | 104 +++++++++-------- .../cache/GridCacheLifecycleAwareSelfTest.java | 10 +- 10 files changed, 248 insertions(+), 136 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java index a167215..e10fc38 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptor.java @@ -21,6 +21,8 @@ import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.lang.*; import org.jetbrains.annotations.*; +import javax.cache.*; + /** * Cache interceptor. Cache interceptor can be used for getting callbacks before * and after cache {@code get(...)}, {@code put(...)}, and {@code remove(...)} @@ -61,13 +63,12 @@ public interface CacheInterceptor<K, V> { * <p> * This method should not throw any exception. * - * @param key Key. - * @param oldVal Old value. + * @param entry Old entry. * @param newVal New value. * @return Value to be put to cache. Returning {@code null} cancels the update. * @see CacheProjection#put(Object, Object, IgnitePredicate[]) */ - @Nullable public V onBeforePut(K key, @Nullable V oldVal, V newVal); + @Nullable public V onBeforePut(Cache.Entry<K, V> entry, V newVal); /** * This method is called after new value has been stored. @@ -79,10 +80,9 @@ public interface CacheInterceptor<K, V> { * <p> * This method should not throw any exception. * - * @param key Key. - * @param val Current value. + * @param entry Current entry. */ - public void onAfterPut(K key, V val); + public void onAfterPut(Cache.Entry<K, V> entry); /** * This method is called within {@link CacheProjection#remove(Object, IgnitePredicate[])} @@ -95,14 +95,13 @@ public interface CacheInterceptor<K, V> { * <p> * This method should not throw any exception. * - * @param key Key. - * @param val Old value. + * @param entry Old entry. * @return Tuple. The first value is the flag whether remove should be cancelled or not. * The second is the value to be returned as result of {@code remove()} operation, * may be {@code null}. * @see CacheProjection#remove(Object, IgnitePredicate[]) */ - @Nullable public IgniteBiTuple<Boolean, V> onBeforeRemove(K key, @Nullable V val); + @Nullable public IgniteBiTuple<Boolean, V> onBeforeRemove(Cache.Entry<K, V> entry); /** * This method is called after value has been removed. @@ -114,8 +113,7 @@ public interface CacheInterceptor<K, V> { * <p> * This method should not throw any exception. * - * @param key Key. - * @param val Removed value. + * @param entry Removed entry. */ - public void onAfterRemove(K key, V val); + public void onAfterRemove(Cache.Entry<K, V> entry); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptorAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptorAdapter.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptorAdapter.java index 390e5b1..8139d79 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptorAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheInterceptorAdapter.java @@ -20,6 +20,8 @@ package org.apache.ignite.cache; import org.apache.ignite.lang.*; import org.jetbrains.annotations.*; +import javax.cache.*; + /** * Cache interceptor convenience adapter. It provides no-op implementations for all * interceptor callbacks. @@ -31,22 +33,22 @@ public class CacheInterceptorAdapter<K, V> implements CacheInterceptor<K, V> { } /** {@inheritDoc} */ - @Nullable @Override public V onBeforePut(K key, @Nullable V oldVal, V newVal) { + @Nullable @Override public V onBeforePut(Cache.Entry<K, V> entry, V newVal) { return newVal; } /** {@inheritDoc} */ - @Override public void onAfterPut(K key, V val) { + @Override public void onAfterPut(Cache.Entry<K, V> entry) { // No-op. } /** {@inheritDoc} */ - @Nullable @Override public IgniteBiTuple<Boolean, V> onBeforeRemove(K key, @Nullable V val) { - return new IgniteBiTuple<>(false, val); + @Nullable @Override public IgniteBiTuple<Boolean, V> onBeforeRemove(Cache.Entry<K, V> entry) { + return new IgniteBiTuple<>(false, entry.getValue()); } /** {@inheritDoc} */ - @Override public void onAfterRemove(K key, V val) { + @Override public void onAfterRemove(Cache.Entry<K, V> entry) { // No-op. } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java new file mode 100644 index 0000000..7b696ec --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java @@ -0,0 +1,111 @@ +/* + * 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 org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.internal.util.typedef.internal.*; + +import javax.cache.*; + +/** + * + */ +public class CacheLazyEntry<K, V> implements Cache.Entry<K, V> { + /** Cache context. */ + private GridCacheContext<K, V> cctx; + + /** Key cache object. */ + private KeyCacheObject keyObj; + + /** Cache object value. */ + private CacheObject valObj; + + /** Key. */ + private K key; + + /** Value. */ + private V val; + + /** + * @param keyObj Key cache object. + * @param valObj Cache object value. + * @param cctx Cache context. + */ + public CacheLazyEntry(KeyCacheObject keyObj, CacheObject valObj, GridCacheContext<K, V> cctx) { + this.keyObj = keyObj; + this.valObj = valObj; + this.cctx = cctx; + } + + /** + * @param key Key. + * @param val Value. + */ + public CacheLazyEntry(K key, V val) { + this.key = key; + this.val = val; + } + + /** + * @param keyObj Key cache object. + * @param valObj Cache object value. + * @param key Key. + * @param val Value. + * @param cctx Cache context. + */ + public CacheLazyEntry(KeyCacheObject keyObj, + CacheObject valObj, + K key, + V val, + GridCacheContext<K, V> cctx) { + this.keyObj = keyObj; + this.valObj = valObj; + this.val = val; + this.key = key; + this.cctx = cctx; + } + + /** {@inheritDoc} */ + @Override public K getKey() { + if (key == null) + key = CU.value(keyObj, cctx, true); + + return key; + } + + /** {@inheritDoc} */ + @Override public V getValue() { + if (val == null) + val = CU.value(valObj, cctx, true); + + return val; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public <T> T unwrap(Class<T> cls) { + if(cls.isAssignableFrom(getClass())) + return cls.cast(this); + + throw new IllegalArgumentException("Unwrapping to class is not supported: " + cls); + } + + /** {@inheritDoc} */ + public String toString() { + return "CacheEntry [key=" + getKey() + ", val=" + getValue() + ']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/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 cd8052d..8df4207 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 @@ -3320,7 +3320,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, V retVal = CU.value(ret, ctx, true); if (ctx.config().getInterceptor() != null) - return (V)ctx.config().getInterceptor().onBeforeRemove(key, retVal).get2(); + return (V)ctx.config().getInterceptor().onBeforeRemove(new CacheEntryImpl(key, retVal)).get2(); return retVal; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index 6dd4cae..0b7b0df 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -1002,7 +1002,6 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { boolean intercept = cctx.config().getInterceptor() != null; - Object key0 = null; Object val0 = null; synchronized (this) { @@ -1030,11 +1029,9 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { old = (retval || intercept) ? rawGetOrUnmarshalUnlocked(!retval) : this.val; if (intercept) { - key0 = key.value(cctx, false); - val0 = CU.value(val, cctx, false); + val0 = CU.value(val, cctx, true); - Object interceptorVal = cctx.config().getInterceptor().onBeforePut(key0, - CU.value(old, cctx, false), + Object interceptorVal = cctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(key, old, cctx), val0); if (interceptorVal == null) @@ -1117,7 +1114,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { cctx.store().putToStore(tx, key, val, newVer); if (intercept) - cctx.config().getInterceptor().onAfterPut(key0, val0); + cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(key, val, cctx)); return valid ? new GridCacheUpdateTxResult(true, retval ? old : null) : new GridCacheUpdateTxResult(false, null); @@ -1157,8 +1154,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { IgniteBiTuple<Boolean, Object> interceptRes = null; - Object key0 = null; - Object old0 = null; + Cache.Entry entry0 = null; synchronized (this) { checkObsolete(); @@ -1181,10 +1177,9 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { old = (retval || intercept) ? rawGetOrUnmarshalUnlocked(!retval) : val; if (intercept) { - key0 = key.value(cctx, false); - old0 = CU.value(old, cctx, false); + entry0 = new CacheLazyEntry(key, old, cctx); - interceptRes = cctx.config().getInterceptor().onBeforeRemove(key0, old0); + interceptRes = cctx.config().getInterceptor().onBeforeRemove(entry0); if (cctx.cancelRemove(interceptRes)) { CacheObject ret = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2())); @@ -1296,7 +1291,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { } if (intercept) - cctx.config().getInterceptor().onAfterRemove(key0, old0); + cctx.config().getInterceptor().onAfterRemove(entry0); if (valid) { CacheObject ret; @@ -1460,12 +1455,11 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { if (intercept) { if (op == GridCacheOperation.UPDATE) { - key0 = value(key0, key, false); updated0 = value(updated0, updated, false); old0 = value(old0, old, false); - Object interceptorVal - = cctx.config().getInterceptor().onBeforePut(key0, old0, updated0); + Object interceptorVal = cctx.config().getInterceptor() + .onBeforePut(new CacheLazyEntry(key, old, key0, old0, cctx), updated0); if (interceptorVal == null) return new GridTuple3<>(false, cctx.unwrapTemporary(old0), invokeRes); @@ -1476,10 +1470,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { } } else { - key0 = value(key0, key, false); - old0 = value(old0, old, false); - - interceptorRes = cctx.config().getInterceptor().onBeforeRemove(key0, old0); + interceptorRes = cctx.config().getInterceptor() + .onBeforeRemove(new CacheLazyEntry(key, old, key0, old0, cctx)); if (cctx.cancelRemove(interceptorRes)) return new GridTuple3<>(false, cctx.unwrapTemporary(interceptorRes.get2()), invokeRes); @@ -1590,9 +1582,9 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { if (intercept) { if (op == GridCacheOperation.UPDATE) - cctx.config().getInterceptor().onAfterPut(key0, updated0); + cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(key, null, key0, updated0, cctx)); else - cctx.config().getInterceptor().onAfterRemove(key0, old0); + cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(key, old, key0, old0, cctx)); } } @@ -1992,11 +1984,10 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { // Actual update. if (op == GridCacheOperation.UPDATE) { if (intercept) { - key0 = value(key0, key, false); - old0 = value(old0, oldVal, false); updated0 = value(updated0, updated, false); - Object interceptorVal = cctx.config().getInterceptor().onBeforePut(key0, old0, updated0); + Object interceptorVal = cctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(key, oldVal, + key0, old0, cctx), updated0); if (interceptorVal == null) return new GridCacheUpdateAtomicResult(false, @@ -2071,10 +2062,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { } else { if (intercept) { - key0 = value(key0, key, false); - old0 = value(old0, oldVal, false); - - interceptRes = cctx.config().getInterceptor().onBeforeRemove(key0, old0); + interceptRes = cctx.config().getInterceptor().onBeforeRemove(new CacheLazyEntry(key, oldVal, key0, + old0, cctx)); if (cctx.cancelRemove(interceptRes)) return new GridCacheUpdateAtomicResult(false, @@ -2170,12 +2159,9 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx { if (intercept) { if (op == GridCacheOperation.UPDATE) - cctx.config().getInterceptor().onAfterPut(key0, updated0); - else { - old0 = value(old0, oldVal, false); - - cctx.config().getInterceptor().onAfterRemove(key0, old0); - } + cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(key, null, key0, updated0, cctx)); + else + cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(key, oldVal, null, old0, cctx)); if (interceptRes != null) oldVal = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2())); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index e4212de..8d7b390 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -1368,7 +1368,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { if (updated == null) { if (intercept) { IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove( - keyVal, oldVal); + new CacheEntryImpl(keyVal, oldVal)); if (ctx.cancelRemove(interceptorRes)) continue; @@ -1410,7 +1410,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { } else { if (intercept) { - Object val = ctx.config().getInterceptor().onBeforePut(keyVal, oldVal, updatedVal); + Object val = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(keyVal, oldVal), + updatedVal); if (val == null) continue; @@ -1475,8 +1476,10 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { taskName, null); - Object val = ctx.config().getInterceptor().onBeforePut(entry.key().value(ctx, false), - CU.value(old, ctx, false), + Object val = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry( + entry.key(), + old, + ctx), updated.value(ctx, false)); if (val == null) @@ -1510,9 +1513,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { taskName, null); - IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove( - entry.key().value(ctx, false), - CU.value(old, ctx, false)); + IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor() + .onBeforeRemove(new CacheLazyEntry(entry.key(), old, ctx)); if (ctx.cancelRemove(interceptorRes)) continue; @@ -1980,16 +1982,17 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { if (intercept) { if (op == UPDATE) { - ctx.config().getInterceptor().onAfterPut( - entry.key().value(ctx, false), - CU.value(updRes.newValue(), ctx, false)); + ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry( + entry.key(), + updRes.newValue(), + ctx)); } else { assert op == DELETE : op; // Old value should be already loaded for 'CacheInterceptor.onBeforeRemove'. - ctx.config().getInterceptor().onAfterRemove(entry.key().value(ctx, false), - CU.value(updRes.oldValue(), ctx, false)); + ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(entry.key(), + updRes.oldValue(), ctx)); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java index 588d987..d7ad717 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java @@ -1205,8 +1205,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { if (updated == null) { if (intercept) { - IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove( - keyVal, oldVal); + IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor() + .onBeforeRemove(new CacheEntryImpl(keyVal, oldVal)); if (ctx.cancelRemove(interceptorRes)) continue; @@ -1237,8 +1237,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { } else { if (intercept) { - Object interceptorVal = - ctx.config().getInterceptor().onBeforePut(keyVal, oldVal, updatedVal); + Object interceptorVal = ctx.config().getInterceptor() + .onBeforePut(new CacheLazyEntry(keyVal, oldVal), updatedVal); if (interceptorVal == null) continue; @@ -1286,10 +1286,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { taskName, null); - Object interceptorVal = ctx.config().getInterceptor().onBeforePut( - entry.key().value(ctx, false), - CU.value(old, ctx, false), - val); + Object interceptorVal = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry( + entry.key(), old, ctx), val); if (interceptorVal == null) continue; @@ -1319,9 +1317,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { taskName, null); - IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove( - entry.key().value(ctx, false), - CU.value(old, ctx, false)); + IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor() + .onBeforeRemove(new CacheLazyEntry(entry.key(), old, ctx)); if (ctx.cancelRemove(interceptorRes)) continue; @@ -1468,12 +1465,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { taskName); if (intercept) { - if (op == UPDATE) { - ctx.config().getInterceptor().onAfterPut(entry.key().value(ctx, false), - writeVal.value(ctx, false)); - } + if (op == UPDATE) + ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(entry.key(), writeVal, ctx)); else - ctx.config().getInterceptor().onAfterRemove(entry.key().value(ctx, false), t.get2()); + ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(entry.key(), null, null, + t.get2(), ctx)); } } catch (GridCacheEntryRemovedException ignore) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java index 699e239..efc3c06 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java @@ -536,12 +536,10 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter } if (intercept) { - Object oldVal = CU.value(e.cached().rawGetOrUnmarshal(true), cacheCtx, false); - - Object interceptorVal = cacheCtx.config().getInterceptor().onBeforePut( - key.value(cacheCtx, false), - oldVal, - CU.value(val, cacheCtx, false)); + Object interceptorVal = cacheCtx.config().getInterceptor() + .onBeforePut(new CacheLazyEntry( + key, e.cached().rawGetOrUnmarshal(true), cacheCtx), + CU.value(val, cacheCtx, false)); if (interceptorVal == null) continue; @@ -582,7 +580,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter Object oldVal = CU.value(e.cached().rawGetOrUnmarshal(true), cacheCtx, false); IgniteBiTuple<Boolean, Object> t = cacheCtx.config().getInterceptor() - .onBeforeRemove(key.value(cacheCtx, false), oldVal); + .onBeforeRemove(new CacheLazyEntry(key, + e.cached().rawGetOrUnmarshal(true), + cacheCtx)); if (cacheCtx.cancelRemove(t)) continue; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java index c20279d..0b8ee4a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheInterceptorAbstractSelfTest.java @@ -23,10 +23,14 @@ import org.apache.ignite.cache.affinity.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.transactions.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; +import javax.cache.*; import javax.cache.processor.*; import java.util.*; import java.util.concurrent.atomic.*; @@ -40,6 +44,9 @@ import static org.apache.ignite.cache.CacheMode.*; */ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbstractSelfTest { /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ private static Interceptor interceptor; /** {@inheritDoc} */ @@ -73,6 +80,12 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration c = super.getConfiguration(gridName); + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + + spi.setIpFinder(IP_FINDER); + + c.setDiscoverySpi(spi); + c.getTransactionConfiguration().setTxSerializableEnabled(true); return c; @@ -423,7 +436,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst private void testCancelUpdate(String key, Operation op) throws Exception { // Interceptor returns null to disabled update. CacheInterceptor retInterceptor = new InterceptorAdapter() { - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { return null; } }; @@ -505,7 +518,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst private void testModifyUpdate(String key, Operation op) throws Exception { // Interceptor returns incremented new value. CacheInterceptor retInterceptor = new InterceptorAdapter() { - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { return (Integer)newVal + 1; } }; @@ -585,7 +598,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst private void testCancelRemove(String key, Operation op) throws Exception { // Interceptor disables remove and returns null. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(true, null); } }; @@ -610,7 +623,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor disables remove and changes return value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(true, 900); } }; @@ -647,7 +660,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor disables remove and returns null. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(true, null); } }; @@ -668,7 +681,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor disables remove and changes return value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(true, 1000); } }; @@ -712,7 +725,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst private void testRemove(String key, Operation op) throws Exception { // Interceptor changes return value to null. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, null); } }; @@ -737,7 +750,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor changes return value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, 900); } }; @@ -774,7 +787,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor changes return value to null. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, null); } }; @@ -813,7 +826,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor changes return value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, 1000); } }; @@ -867,7 +880,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst @Nullable TransactionIsolation txIsolation, @Nullable Operation op) throws Exception { // Interceptor returns incremented new value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { return (Integer)newVal + 1; } }; @@ -924,7 +937,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst private void testBatchUpdate(Operation op) throws Exception { // Interceptor returns incremented new value. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { return (Integer)newVal + 1; } }; @@ -975,8 +988,8 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor returns incremented new value, cancels update for one key. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { - if (key.equals(key1)) + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { + if (entry.getKey().equals(key1)) return null; return (Integer)newVal + 1; @@ -1048,7 +1061,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor does not cancel update. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, 999); } }; @@ -1078,7 +1091,7 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor does not cancel update. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { return new IgniteBiTuple(false, 999); } }; @@ -1115,8 +1128,8 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst // Interceptor cancels update for one key. interceptor.retInterceptor = new InterceptorAdapter() { - @Nullable@Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { - return new IgniteBiTuple(key.equals(key1), 999); + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { + return new IgniteBiTuple(entry.getKey().equals(key1), 999); } }; @@ -1493,26 +1506,26 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst } /** */ - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { fail("onBeforePut not expected"); return null; } /** */ - @Override public void onAfterPut(Object key, Object val) { + @Override public void onAfterPut(Cache.Entry entry) { fail("onAfterPut not expected"); } /** */ - @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { fail("onBeforeRemove not expected"); return null; } /** */ - @Override public void onAfterRemove(Object key, Object val) { + @Override public void onAfterRemove(Cache.Entry entry) { fail("onAfterRemove not expected"); } } @@ -1570,81 +1583,84 @@ public abstract class GridCacheInterceptorAbstractSelfTest extends GridCacheAbst /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { if (disabled) return newVal; assertNotNull(retInterceptor); - Object ret = retInterceptor.onBeforePut(key, oldVal, newVal); + Object ret = retInterceptor.onBeforePut(entry, newVal); - log.info("Before put [key=" + key + ", oldVal=" + oldVal + ", newVal=" + newVal + ", ret=" + ret + ']'); + log.info("Before put [key=" + entry.getKey() + ", oldVal=" + entry.getValue()+ ", newVal=" + newVal + + ", ret=" + ret + ']'); invokeCnt.incrementAndGet(); - IgniteBiTuple t = beforePutMap.put(key, new IgniteBiTuple(oldVal, newVal)); + IgniteBiTuple t = beforePutMap.put(entry.getKey(), new IgniteBiTuple(entry.getValue(), newVal)); if (t != null) { - assertEquals("Interceptor called with different old values for key " + key, t.get1(), oldVal); - assertEquals("Interceptor called with different new values for key " + key, t.get2(), newVal); + assertEquals("Interceptor called with different old values for key " + entry.getKey(), t.get1(), + entry.getValue()); + assertEquals("Interceptor called with different new values for key " + entry.getKey(), t.get2(), + newVal); } return ret; } /** {@inheritDoc} */ - @Override public void onAfterPut(Object key, Object val) { + @Override public void onAfterPut(Cache.Entry entry) { if (disabled) return; - log.info("After put [key=" + key + ", val=" + val + ']'); + log.info("After put [key=" + entry.getKey() + ", val=" + entry.getValue() + ']'); invokeCnt.incrementAndGet(); - Object old = afterPutMap.put(key, val); + Object old = afterPutMap.put(entry.getKey(), entry.getValue()); if (old != null) - assertEquals(old, val); + assertEquals(old, entry.getValue()); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override @Nullable public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { + @Override @Nullable public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { if (disabled) - return new IgniteBiTuple(false, val); + return new IgniteBiTuple(false, entry.getValue()); assertNotNull(retInterceptor); - IgniteBiTuple ret = retInterceptor.onBeforeRemove(key, val); + IgniteBiTuple ret = retInterceptor.onBeforeRemove(entry); - log.info("Before remove [key=" + key + ", val=" + val + ", ret=" + ret + ']'); + log.info("Before remove [key=" + entry.getKey() + ", val=" + entry.getValue() + ", ret=" + ret + ']'); invokeCnt.incrementAndGet(); - if (val != null) { - Object old = beforeRmvMap.put(key, val); + if (entry.getValue() != null) { + Object old = beforeRmvMap.put(entry.getKey(), entry.getValue()); if (old != null) - assertEquals(old, val); + assertEquals(old, entry.getValue()); } return ret; } /** {@inheritDoc} */ - @Override public void onAfterRemove(Object key, Object val) { + @Override public void onAfterRemove(Cache.Entry entry) { if (disabled) return; - log.info("After remove [key=" + key + ", val=" + val + ']'); + log.info("After remove [key=" + entry.getKey() + ", val=" + entry.getValue() + ']'); invokeCnt.incrementAndGet(); - if (val != null) { - Object old = afterRmvMap.put(key, val); + if (entry.getValue() != null) { + Object old = afterRmvMap.put(entry.getKey(), entry.getValue()); if (old != null) - assertEquals(old, val); + assertEquals(old, entry.getValue()); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/43c04a0f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java index 9f4b8f2..67ad896 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLifecycleAwareSelfTest.java @@ -225,22 +225,22 @@ public class GridCacheLifecycleAwareSelfTest extends GridAbstractLifecycleAwareS } /** {@inheritDoc} */ - @Nullable @Override public Object onBeforePut(Object key, @Nullable Object oldVal, Object newVal) { + @Nullable @Override public Object onBeforePut(Cache.Entry entry, Object newVal) { return newVal; } /** {@inheritDoc} */ - @Override public void onAfterPut(Object key, Object val) { + @Override public void onAfterPut(Cache.Entry entry) { // No-op. } /** {@inheritDoc} */ - @SuppressWarnings("unchecked") @Nullable @Override public IgniteBiTuple onBeforeRemove(Object key, @Nullable Object val) { - return new IgniteBiTuple(false, val); + @SuppressWarnings("unchecked") @Nullable @Override public IgniteBiTuple onBeforeRemove(Cache.Entry entry) { + return new IgniteBiTuple(false, entry.getValue()); } /** {@inheritDoc} */ - @Override public void onAfterRemove(Object key, Object val) { + @Override public void onAfterRemove(Cache.Entry entry) { // No-op. } }