Repository: ignite Updated Branches: refs/heads/ignite-3199-1 5ebe43edd -> 097dc1b10
WIP on extensions framework in Java. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/097dc1b1 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/097dc1b1 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/097dc1b1 Branch: refs/heads/ignite-3199-1 Commit: 097dc1b105e5d75726b488dc7b5354314e95b103 Parents: 5ebe43e Author: vozerov-gridgain <[email protected]> Authored: Tue Sep 13 13:50:00 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Tue Sep 13 13:50:00 2016 +0300 ---------------------------------------------------------------------- .../platform/PlatformConfigurationEx.java | 7 ++ .../platform/PlatformContextImpl.java | 3 - .../processors/platform/PlatformProcessor.java | 10 +-- .../platform/PlatformProcessorImpl.java | 53 +++++++++++- .../platform/cache/PlatformCache.java | 89 ++++++++++++++------ .../platform/cache/PlatformCacheExtension.java | 28 ++++-- .../cache/PlatformCacheExtensionResult.java | 54 ------------ .../cpp/PlatformCppConfigurationEx.java | 7 ++ .../dotnet/PlatformDotNetConfigurationEx.java | 9 ++ .../PlatformDotnetSessionCacheExtension.java | 45 +++++++--- 10 files changed, 187 insertions(+), 118 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java index 96e4643..a58510d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformConfigurationEx.java @@ -18,8 +18,10 @@ package org.apache.ignite.internal.processors.platform; import org.apache.ignite.internal.logger.platform.PlatformLogger; +import org.apache.ignite.internal.processors.platform.cache.PlatformCacheExtension; import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway; import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -51,4 +53,9 @@ public interface PlatformConfigurationEx { * @return Platform logger. */ public PlatformLogger logger(); + + /** + * @return Available cache extensions. + */ + @Nullable public Collection<PlatformCacheExtension> cacheExtensions(); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java index d544fff..e7fdb0a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java @@ -118,9 +118,6 @@ public class PlatformContextImpl implements PlatformContext { /** Platform name. */ private final String platform; - /** - * Static initializer. - */ static { Set<Integer> evtTyps0 = new HashSet<>(); http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java index fdc66cb..1d9d3cd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessor.java @@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.platform; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteException; import org.apache.ignite.internal.processors.GridProcessor; import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore; import org.jetbrains.annotations.Nullable; @@ -203,9 +202,8 @@ public interface PlatformProcessor extends GridProcessor { * @param initVal Initial value. * @param create Create flag. * @return Platform atomic long. - * @throws IgniteException */ - public PlatformTarget atomicLong(String name, long initVal, boolean create) throws IgniteException; + public PlatformTarget atomicLong(String name, long initVal, boolean create); /** * Get or create AtomicSequence. @@ -213,9 +211,8 @@ public interface PlatformProcessor extends GridProcessor { * @param initVal Initial value. * @param create Create flag. * @return Platform atomic long. - * @throws IgniteException */ - public PlatformTarget atomicSequence(String name, long initVal, boolean create) throws IgniteException; + public PlatformTarget atomicSequence(String name, long initVal, boolean create); /** * Get or create AtomicReference. @@ -223,9 +220,8 @@ public interface PlatformProcessor extends GridProcessor { * @param memPtr Pointer to a stream with initial value. 0 for null initial value. * @param create Create flag. * @return Platform atomic long. - * @throws IgniteException */ - public PlatformTarget atomicReference(String name, long memPtr, boolean create) throws IgniteException; + public PlatformTarget atomicReference(String name, long memPtr, boolean create); /** * Gets the configuration of the current Ignite instance. http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java index 351e4e8..52e682b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java @@ -54,7 +54,6 @@ import org.apache.ignite.internal.processors.platform.services.PlatformServices; import org.apache.ignite.internal.processors.platform.transactions.PlatformTransactions; import org.apache.ignite.internal.processors.platform.utils.PlatformConfigurationUtils; import org.apache.ignite.internal.processors.platform.utils.PlatformUtils; -import org.apache.ignite.internal.processors.platform.websession.PlatformDotnetSessionCacheExtension; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteFuture; @@ -62,6 +61,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.locks.ReadWriteLock; @@ -82,6 +83,7 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf private final ReadWriteLock storeLock = new ReentrantReadWriteLock(); /** Logger. */ + @SuppressWarnings("FieldCanBeLocal") private final IgniteLogger log; /** Context. */ @@ -96,8 +98,8 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf /** Whether processor if stopped (or stopping). */ private volatile boolean stopped; - /** Session state extension. */ - private final PlatformCacheExtension sessionExt = new PlatformDotnetSessionCacheExtension(); + /** Cache extensions. */ + private final PlatformCacheExtension[] cacheExts; /** * Constructor. @@ -127,6 +129,9 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf if (interopCfg.logger() != null) interopCfg.logger().setContext(platformCtx); + + // Initialize cache extensions (if any). + cacheExts = prepareCacheExtensions(interopCfg.cacheExtensions()); } /** {@inheritDoc} */ @@ -481,7 +486,7 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf * Creates new platform cache. */ private PlatformTarget createPlatformCache(IgniteCacheProxy cache) { - return new PlatformCache(platformCtx, cache, false, sessionExt); + return new PlatformCache(platformCtx, cache, false, cacheExts); } /** @@ -515,6 +520,46 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf } /** + * Prepare cache extensions. + * + * @param cacheExts Original extensions. + * @return Prepared extensions. + */ + private static PlatformCacheExtension[] prepareCacheExtensions(Collection<PlatformCacheExtension> cacheExts) { + if (!F.isEmpty(cacheExts)) { + int maxExtId = 0; + + Map<Integer, PlatformCacheExtension> idToExt = new HashMap<>(); + + for (PlatformCacheExtension cacheExt : cacheExts) { + if (cacheExt == null) + throw new IgniteException("Platform cache extension cannot be null."); + + if (cacheExt.id() < 0) + throw new IgniteException("Platform cache extension ID cannot be negative: " + cacheExt); + + PlatformCacheExtension oldCacheExt = idToExt.put(cacheExt.id(), cacheExt); + + if (oldCacheExt != null) + throw new IgniteException("Platform cache extensions cannot have the same ID [" + + "id=" + cacheExt.id() + ", first=" + oldCacheExt + ", second=" + cacheExt + ']'); + + if (cacheExt.id() > maxExtId) + maxExtId = cacheExt.id(); + } + + PlatformCacheExtension[] res = new PlatformCacheExtension[maxExtId]; + + for (PlatformCacheExtension cacheExt : cacheExts) + res[cacheExt.id()]= cacheExt; + + return res; + } + else + return new PlatformCacheExtension[0]; + } + + /** * Store and manager pair. */ private static class StoreInfo { http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java index f9598d6..5c4bf23 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.platform.cache; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; import org.apache.ignite.binary.BinaryRawReader; import org.apache.ignite.cache.CacheEntryProcessor; import org.apache.ignite.cache.CacheMetrics; @@ -202,7 +203,7 @@ public class PlatformCache extends PlatformAbstractTarget { private final IgniteCacheProxy cache; /** Initial JCache (not in binary mode). */ - private final IgniteCache cacheRaw; + private final IgniteCache rawCache; /** Whether this cache is created with "keepBinary" flag on the other side. */ private final boolean keepBinary; @@ -223,7 +224,7 @@ public class PlatformCache extends PlatformAbstractTarget { private static final AtomicLong LOCK_ID_GEN = new AtomicLong(); /** Extensions. */ - private final PlatformCacheExtension[] extensions; + private final PlatformCacheExtension[] exts; /** * Constructor. @@ -232,15 +233,30 @@ public class PlatformCache extends PlatformAbstractTarget { * @param cache Underlying cache. * @param keepBinary Keep binary flag. */ + public PlatformCache(PlatformContext platformCtx, IgniteCache cache, boolean keepBinary) { + this(platformCtx, cache, keepBinary, new PlatformCacheExtension[0]); + } + + /** + * Constructor. + * + * @param platformCtx Context. + * @param cache Underlying cache. + * @param keepBinary Keep binary flag. + * @param exts Extensions. + */ public PlatformCache(PlatformContext platformCtx, IgniteCache cache, boolean keepBinary, - PlatformCacheExtension... extensions) { + PlatformCacheExtension[] exts) { super(platformCtx); - cacheRaw = cache; + assert cache != null; + assert exts != null; + + rawCache = cache; this.cache = (IgniteCacheProxy)cache.withKeepBinary(); this.keepBinary = keepBinary; - this.extensions = extensions; + this.exts = exts; } /** @@ -252,7 +268,7 @@ public class PlatformCache extends PlatformAbstractTarget { if (cache.delegate().skipStore()) return this; - return clone(cacheRaw.withSkipStore(), keepBinary); + return copy(rawCache.withSkipStore(), keepBinary); } /** @@ -264,7 +280,7 @@ public class PlatformCache extends PlatformAbstractTarget { if (keepBinary) return this; - return clone(cacheRaw.withKeepBinary(), true); + return copy(rawCache.withKeepBinary(), true); } /** @@ -276,9 +292,9 @@ public class PlatformCache extends PlatformAbstractTarget { * @return Cache. */ public PlatformCache withExpiryPolicy(final long create, final long update, final long access) { - IgniteCache cache0 = cacheRaw.withExpiryPolicy(new InteropExpiryPolicy(create, update, access)); + IgniteCache cache0 = rawCache.withExpiryPolicy(new InteropExpiryPolicy(create, update, access)); - return clone(cache0, keepBinary); + return copy(cache0, keepBinary); } /** @@ -290,7 +306,7 @@ public class PlatformCache extends PlatformAbstractTarget { if (cache.isAsync()) return this; - return clone(cacheRaw.withAsync(), keepBinary); + return copy(rawCache.withAsync(), keepBinary); } /** @@ -304,11 +320,19 @@ public class PlatformCache extends PlatformAbstractTarget { if (opCtx != null && opCtx.noRetries()) return this; - return clone(cacheRaw.withNoRetries(), keepBinary); + return copy(rawCache.withNoRetries(), keepBinary); + } + + /** + * @return Raw cache. + */ + public IgniteCache rawCache() { + return rawCache; } /** {@inheritDoc} */ - @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader, PlatformMemory mem) throws IgniteCheckedException { + @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader, PlatformMemory mem) + throws IgniteCheckedException { try { switch (type) { case OP_PUT: @@ -469,19 +493,9 @@ public class PlatformCache extends PlatformAbstractTarget { return registerLock(cache.lockAll(PlatformUtils.readCollection(reader))); case OP_EXTENSION: - int opCode = reader.readInt(); - - if (extensions == null) - throw new IgniteCheckedException("Cache extensions are not defined."); - - for (PlatformCacheExtension extension : extensions) { - PlatformCacheExtensionResult res = extension.invoke(opCode, reader, cacheRaw); - - if (res.isMatch()) - return writeResult(mem, res.result()); - } + PlatformCacheExtension ext = extension(reader.readInt()); - throw new IgniteCheckedException("Unsupported cache extension type: " + type); + return ext.processInOutStreamLong(this, reader.readInt(), reader, mem); } } catch (Exception e) { @@ -504,7 +518,7 @@ public class PlatformCache extends PlatformAbstractTarget { /** * Writes the result to reused stream, if any. */ - private long writeResult(PlatformMemory mem, Object obj) { + public long writeResult(PlatformMemory mem, Object obj) { return writeResult(mem, obj, null); } @@ -1035,9 +1049,30 @@ public class PlatformCache extends PlatformAbstractTarget { /** * Clones this instance. + * + * @param cache Cache. + * @param keepBinary Keep binary flag. + * @return Cloned instance. + */ + private PlatformCache copy(IgniteCache cache, boolean keepBinary) { + return new PlatformCache(platformCtx, cache, keepBinary, exts); + } + + /** + * Get extension by ID. + * + * @param id ID. + * @return Extension. */ - private PlatformCache clone(IgniteCache cache, boolean keepBinary) { - return new PlatformCache(platformCtx, cache, keepBinary, extensions); + private PlatformCacheExtension extension(int id) { + if (exts != null && id < exts.length) { + PlatformCacheExtension ext = exts[id]; + + if (ext != null) + return ext; + } + + throw new IgniteException("Platform cache extension is not registered [id=" + id + ']'); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtension.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtension.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtension.java index 8e65331..5d2040c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtension.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtension.java @@ -17,21 +17,31 @@ package org.apache.ignite.internal.processors.platform.cache; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.binary.BinaryRawReader; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.binary.BinaryRawReaderEx; +import org.apache.ignite.internal.processors.platform.memory.PlatformMemory; /** - * Platform cache extension. + * Platform cache extension. Decouples other modules from cache. */ public interface PlatformCacheExtension { /** - * Invokes the extension. + * Get extension ID. Must be unique among all extensions. * - * @param opCode Operation code. - * @param reader Reader. - * @param cache Cache. + * @return Extension ID. + */ + public int id(); + + /** + * Invokes in-out operation with long return type. * - * @return Invocation result: whether this extension handled the operation and resulting object. + * @param target Target cache. + * @param type Operation type. + * @param reader Reader. + * @param mem Memory. + * @return Result. + * @throws IgniteCheckedException If failed. */ - PlatformCacheExtensionResult invoke(int opCode, BinaryRawReader reader, IgniteCache cache); + long processInOutStreamLong(PlatformCache target, int type, BinaryRawReaderEx reader, PlatformMemory mem) + throws IgniteCheckedException; } http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtensionResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtensionResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtensionResult.java deleted file mode 100644 index bec5f46..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheExtensionResult.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.platform.cache; - -/** - * Result of {@link PlatformCacheExtension} invocation. - */ -public class PlatformCacheExtensionResult { - /** Whether extension handled the case. */ - private final boolean isMatch; - - /** Result. */ - private final Object result; - - /** - * Ctor. - * - * @param isMatch Whether extension handled the case. - * @param result Invocation result. - */ - public PlatformCacheExtensionResult(boolean isMatch, Object result) { - this.isMatch = isMatch; - this.result = result; - } - - /** - * @return Whether extension handled the case. - */ - public boolean isMatch() { - return isMatch; - } - - /** - * @return Invocation result. - */ - public Object result() { - return result; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java index 75c48ef..4f6bb2d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationEx.java @@ -19,10 +19,12 @@ package org.apache.ignite.internal.processors.platform.cpp; import org.apache.ignite.internal.logger.platform.PlatformLogger; import org.apache.ignite.internal.processors.platform.PlatformConfigurationEx; +import org.apache.ignite.internal.processors.platform.cache.PlatformCacheExtension; import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway; import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl; import org.apache.ignite.internal.processors.platform.utils.PlatformUtils; import org.apache.ignite.platform.cpp.PlatformCppConfiguration; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -79,6 +81,11 @@ public class PlatformCppConfigurationEx extends PlatformCppConfiguration impleme return null; } + /** {@inheritDoc} */ + @Override @Nullable public Collection<PlatformCacheExtension> cacheExtensions() { + return null; + } + /** * @param warnings Warnings. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java index 906080e..9d68a1e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationEx.java @@ -19,12 +19,16 @@ package org.apache.ignite.internal.processors.platform.dotnet; import org.apache.ignite.internal.logger.platform.PlatformLogger; import org.apache.ignite.internal.processors.platform.PlatformConfigurationEx; +import org.apache.ignite.internal.processors.platform.cache.PlatformCacheExtension; import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway; import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl; import org.apache.ignite.internal.processors.platform.utils.PlatformUtils; +import org.apache.ignite.internal.processors.platform.websession.PlatformDotnetSessionCacheExtension; import org.apache.ignite.platform.dotnet.PlatformDotNetConfiguration; +import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Collections; /** * Extended .Net configuration. @@ -83,6 +87,11 @@ public class PlatformDotNetConfigurationEx extends PlatformDotNetConfiguration i return logger; } + /** {@inheritDoc} */ + @Nullable @Override public Collection<PlatformCacheExtension> cacheExtensions() { + return Collections.<PlatformCacheExtension>singleton(new PlatformDotnetSessionCacheExtension()); + } + /** * @param warnings Warnings. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/097dc1b1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionCacheExtension.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionCacheExtension.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionCacheExtension.java index 7776c13..20a5dbd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionCacheExtension.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionCacheExtension.java @@ -17,10 +17,12 @@ package org.apache.ignite.internal.processors.platform.websession; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.binary.BinaryRawReader; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.binary.BinaryRawReaderEx; +import org.apache.ignite.internal.processors.platform.cache.PlatformCache; import org.apache.ignite.internal.processors.platform.cache.PlatformCacheExtension; -import org.apache.ignite.internal.processors.platform.cache.PlatformCacheExtensionResult; +import org.apache.ignite.internal.processors.platform.memory.PlatformMemory; +import org.apache.ignite.internal.util.typedef.internal.S; import java.sql.Timestamp; import java.util.UUID; @@ -29,25 +31,35 @@ import java.util.UUID; * Custom entry processor invoker. */ public class PlatformDotnetSessionCacheExtension implements PlatformCacheExtension { - /** */ - public static final int OP_SESSION_LOCK = 1; + /** Extension ID. */ + private static final int EXT_ID = 0; - /** */ - public static final int OP_SESSION_SET_AND_UNLOCK = 2; + /** Operation: session lock. */ + private static final int OP_SESSION_LOCK = 1; + + /** Operation: session set/unlock. */ + private static final int OP_SESSION_SET_AND_UNLOCK = 2; + + /** {@inheritDoc} */ + @Override public int id() { + return EXT_ID; + } /** {@inheritDoc} */ @SuppressWarnings("unchecked") - @Override public PlatformCacheExtensionResult invoke(int opCode, BinaryRawReader reader, IgniteCache cache) { - switch (opCode) { + @Override public long processInOutStreamLong(PlatformCache target, int type, BinaryRawReaderEx reader, + PlatformMemory mem) throws IgniteCheckedException { + switch (type) { case OP_SESSION_LOCK: { String key = reader.readString(); UUID lockNodeId = reader.readUuid(); long lockId = reader.readLong(); Timestamp lockTime = reader.readTimestamp(); - Object res = cache.invoke(key, new PlatformDotnetSessionLockProcessor(lockNodeId, lockId, lockTime)); + Object res = target.rawCache().invoke(key, + new PlatformDotnetSessionLockProcessor(lockNodeId, lockId, lockTime)); - return new PlatformCacheExtensionResult(true, res); + return target.writeResult(mem, res); } case OP_SESSION_SET_AND_UNLOCK: @@ -67,11 +79,16 @@ public class PlatformDotnetSessionCacheExtension implements PlatformCacheExtensi proc = new PlatformDotnetSessionSetAndUnlockProcessor(lockNodeId, lockId); } - cache.invoke(key, proc); + target.rawCache().invoke(key, proc); - return new PlatformCacheExtensionResult(true, null); + return target.writeResult(mem, null); } - return new PlatformCacheExtensionResult(false, null); + throw new IgniteCheckedException("Unsupported operation type: " + type); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformDotnetSessionCacheExtension.class, this); } }
