You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/02/09 17:11:01 UTC
[1/5] ignite git commit: IGNITE-1563 .NET: Implemented "atomics":
AtomicReference and AtomicSequence. This closes #455.
Repository: ignite
Updated Branches:
refs/heads/ignite-2587 ae82a23c2 -> dac641b42
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
index ad62f38..cdcddf0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -281,6 +281,40 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
}
}
+ internal static IUnmanagedTarget ProcessorAtomicSequence(IUnmanagedTarget target, string name, long initialValue,
+ bool create)
+ {
+ var name0 = IgniteUtils.StringToUtf8Unmanaged(name);
+
+ try
+ {
+ var res = JNI.ProcessorAtomicSequence(target.Context, target.Target, name0, initialValue, create);
+
+ return res == null ? null : target.ChangeTarget(res);
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(new IntPtr(name0));
+ }
+ }
+
+ internal static IUnmanagedTarget ProcessorAtomicReference(IUnmanagedTarget target, string name, long memPtr,
+ bool create)
+ {
+ var name0 = IgniteUtils.StringToUtf8Unmanaged(name);
+
+ try
+ {
+ var res = JNI.ProcessorAtomicReference(target.Context, target.Target, name0, memPtr, create);
+
+ return res == null ? null : target.ChangeTarget(res);
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(new IntPtr(name0));
+ }
+ }
+
internal static void ProcessorGetIgniteConfiguration(IUnmanagedTarget target, long memPtr)
{
JNI.ProcessorGetIgniteConfiguration(target.Context, target.Target, memPtr);
@@ -867,6 +901,51 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
JNI.AtomicLongClose(target.Context, target.Target);
}
+ internal static long AtomicSequenceGet(IUnmanagedTarget target)
+ {
+ return JNI.AtomicSequenceGet(target.Context, target.Target);
+ }
+
+ internal static long AtomicSequenceIncrementAndGet(IUnmanagedTarget target)
+ {
+ return JNI.AtomicSequenceIncrementAndGet(target.Context, target.Target);
+ }
+
+ internal static long AtomicSequenceAddAndGet(IUnmanagedTarget target, long value)
+ {
+ return JNI.AtomicSequenceAddAndGet(target.Context, target.Target, value);
+ }
+
+ internal static int AtomicSequenceGetBatchSize(IUnmanagedTarget target)
+ {
+ return JNI.AtomicSequenceGetBatchSize(target.Context, target.Target);
+ }
+
+ internal static void AtomicSequenceSetBatchSize(IUnmanagedTarget target, int size)
+ {
+ JNI.AtomicSequenceSetBatchSize(target.Context, target.Target, size);
+ }
+
+ internal static bool AtomicSequenceIsClosed(IUnmanagedTarget target)
+ {
+ return JNI.AtomicSequenceIsClosed(target.Context, target.Target);
+ }
+
+ internal static void AtomicSequenceClose(IUnmanagedTarget target)
+ {
+ JNI.AtomicSequenceClose(target.Context, target.Target);
+ }
+
+ internal static bool AtomicReferenceIsClosed(IUnmanagedTarget target)
+ {
+ return JNI.AtomicReferenceIsClosed(target.Context, target.Target);
+ }
+
+ internal static void AtomicReferenceClose(IUnmanagedTarget target)
+ {
+ JNI.AtomicReferenceClose(target.Context, target.Target);
+ }
+
internal static bool ListenableCancel(IUnmanagedTarget target)
{
return JNI.ListenableCancel(target.Context, target.Target);
[2/5] ignite git commit: IGNITE-1563 .NET: Implemented "atomics":
AtomicReference and AtomicSequence. This closes #455.
Posted by sb...@apache.org.
IGNITE-1563 .NET: Implemented "atomics": AtomicReference and AtomicSequence. This closes #455.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f7c1296c
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f7c1296c
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f7c1296c
Branch: refs/heads/ignite-2587
Commit: f7c1296cceba73ce1b61af605e476a905a0c8ab4
Parents: e2e216d
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Tue Feb 9 14:43:00 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Feb 9 14:43:00 2016 +0300
----------------------------------------------------------------------
.../GridCacheAtomicReferenceImpl.java | 68 ++----
.../platform/PlatformNoopProcessor.java | 10 +
.../processors/platform/PlatformProcessor.java | 20 ++
.../platform/PlatformProcessorImpl.java | 18 ++
.../callback/PlatformCallbackUtils.java | 1 -
.../datastructures/PlatformAtomicReference.java | 141 +++++++++++
.../datastructures/PlatformAtomicSequence.java | 122 ++++++++++
.../cpp/common/include/ignite/common/exports.h | 15 ++
.../cpp/common/include/ignite/common/java.h | 32 +++
.../platforms/cpp/common/project/vs/module.def | 15 +-
modules/platforms/cpp/common/src/exports.cpp | 52 ++++
modules/platforms/cpp/common/src/java.cpp | 181 ++++++++++++++
.../Apache.Ignite.Core.Tests.csproj | 2 +
.../DataStructures/AtomicReferenceTest.cs | 239 +++++++++++++++++++
.../DataStructures/AtomicSequenceTest.cs | 131 ++++++++++
.../Apache.Ignite.Core.csproj | 4 +
.../DataStructures/IAtomicReference.cs | 64 +++++
.../DataStructures/IAtomicSequence.cs | 69 ++++++
.../dotnet/Apache.Ignite.Core/IIgnite.cs | 28 +++
.../Impl/DataStructures/AtomicReference.cs | 92 +++++++
.../Impl/DataStructures/AtomicSequence.cs | 90 +++++++
.../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 50 ++++
.../Apache.Ignite.Core/Impl/IgniteProxy.cs | 12 +
.../Impl/Unmanaged/IgniteJniNativeMethods.cs | 37 +++
.../Impl/Unmanaged/UnmanagedUtils.cs | 79 ++++++
25 files changed, 1526 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java
index 37cdaea..e044138 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java
@@ -35,8 +35,6 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.ignite.lang.IgnitePredicate;
import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
@@ -153,10 +151,20 @@ public final class GridCacheAtomicReferenceImpl<T> implements GridCacheAtomicRef
/** {@inheritDoc} */
@Override public boolean compareAndSet(T expVal, T newVal) {
+ return compareAndSetAndGet(newVal, expVal) == expVal;
+ }
+
+ /**
+ * Compares current value with specified value for equality and, if they are equal, replaces current value.
+ *
+ * @param newVal New value to set.
+ * @return Original value.
+ */
+ public T compareAndSetAndGet(T newVal, T expVal) {
checkRemoved();
try {
- return CU.outTx(internalCompareAndSet(wrapperPredicate(expVal), wrapperClosure(newVal)), ctx);
+ return CU.outTx(internalCompareAndSetAndGet(expVal, newVal), ctx);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
@@ -197,34 +205,6 @@ public final class GridCacheAtomicReferenceImpl<T> implements GridCacheAtomicRef
}
/**
- * Method make wrapper predicate for existing value.
- *
- * @param val Value.
- * @return Predicate.
- */
- private IgnitePredicate<T> wrapperPredicate(final T val) {
- return new IgnitePredicate<T>() {
- @Override public boolean apply(T e) {
- return F.eq(val, e);
- }
- };
- }
-
- /**
- * Method make wrapper closure for existing value.
- *
- * @param val Value.
- * @return Closure.
- */
- private IgniteClosure<T, T> wrapperClosure(final T val) {
- return new IgniteClosure<T, T>() {
- @Override public T apply(T e) {
- return val;
- }
- };
- }
-
- /**
* Method returns callable for execution {@link #set(Object)} operation in async and sync mode.
*
* @param val Value will be set in reference .
@@ -260,39 +240,39 @@ public final class GridCacheAtomicReferenceImpl<T> implements GridCacheAtomicRef
* Conditionally sets the new value. It will be set if {@code expValPred} is
* evaluate to {@code true}.
*
- * @param expValPred Predicate which should evaluate to {@code true} for value to be set.
- * @param newValClos Closure which generates new value.
+ * @param expVal Expected value.
+ * @param newVal New value.
* @return Callable for execution in async and sync mode.
*/
- private Callable<Boolean> internalCompareAndSet(final IgnitePredicate<T> expValPred,
- final IgniteClosure<T, T> newValClos) {
-
- return retryTopologySafe(new Callable<Boolean>() {
- @Override public Boolean call() throws Exception {
+ private Callable<T> internalCompareAndSetAndGet(final T expVal, final T newVal) {
+ return retryTopologySafe(new Callable<T>() {
+ @Override public T call() throws Exception {
try (IgniteInternalTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ)) {
GridCacheAtomicReferenceValue<T> ref = atomicView.get(key);
if (ref == null)
throw new IgniteCheckedException("Failed to find atomic reference with given name: " + name);
- if (!expValPred.apply(ref.get())) {
+ T origVal = ref.get();
+
+ if (!F.eq(expVal, origVal)) {
tx.setRollbackOnly();
- return false;
+ return origVal;
}
else {
- ref.set(newValClos.apply(ref.get()));
+ ref.set(newVal);
atomicView.getAndPut(key, ref);
tx.commit();
- return true;
+ return expVal;
}
}
catch (Error | Exception e) {
- U.error(log, "Failed to compare and value [expValPred=" + expValPred + ", newValClos" +
- newValClos + ", atomicReference" + this + ']', e);
+ U.error(log, "Failed to compare and value [expVal=" + expVal + ", newVal" +
+ newVal + ", atomicReference" + this + ']', e);
throw e;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
index b25e32e..8fe17e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformNoopProcessor.java
@@ -148,4 +148,14 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf
@Override public void getIgniteConfiguration(long memPtr) {
// No-op.
}
+
+ /** {@inheritDoc} */
+ @Override public PlatformTarget atomicSequence(String name, long initVal, boolean create) throws IgniteException {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public PlatformTarget atomicReference(String name, long memPtr, boolean create) throws IgniteException {
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/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 b59d93d..2d51c69 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
@@ -208,6 +208,26 @@ public interface PlatformProcessor extends GridProcessor {
public PlatformTarget atomicLong(String name, long initVal, boolean create) throws IgniteException;
/**
+ * Get or create AtomicSequence.
+ * @param name Name.
+ * @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;
+
+ /**
+ * Get or create AtomicReference.
+ * @param name Name.
+ * @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;
+
+ /**
* Gets the configuration of the current Ignite instance.
*
* @param memPtr Stream to write data to.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/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 4ed8c25..d0e0a63 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
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.processors.platform;
import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteAtomicSequence;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteDataStreamer;
import org.apache.ignite.IgniteException;
@@ -39,6 +40,8 @@ import org.apache.ignite.internal.processors.platform.cluster.PlatformClusterGro
import org.apache.ignite.internal.processors.platform.compute.PlatformCompute;
import org.apache.ignite.internal.processors.platform.datastreamer.PlatformDataStreamer;
import org.apache.ignite.internal.processors.platform.datastructures.PlatformAtomicLong;
+import org.apache.ignite.internal.processors.platform.datastructures.PlatformAtomicReference;
+import org.apache.ignite.internal.processors.platform.datastructures.PlatformAtomicSequence;
import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetCacheStore;
import org.apache.ignite.internal.processors.platform.events.PlatformEvents;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -361,6 +364,21 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
}
/** {@inheritDoc} */
+ @Override public PlatformTarget atomicSequence(String name, long initVal, boolean create) throws IgniteException {
+ IgniteAtomicSequence atomicSeq = ignite().atomicSequence(name, initVal, create);
+
+ if (atomicSeq == null)
+ return null;
+
+ return new PlatformAtomicSequence(platformCtx, atomicSeq);
+ }
+
+ /** {@inheritDoc} */
+ @Override public PlatformTarget atomicReference(String name, long memPtr, boolean create) throws IgniteException {
+ return PlatformAtomicReference.createInstance(platformCtx, name, memPtr, create);
+ }
+
+ /** {@inheritDoc} */
@Override public void getIgniteConfiguration(long memPtr) {
PlatformOutputStream stream = platformCtx.memory().get(memPtr).output();
BinaryRawWriterEx writer = platformCtx.writer(stream);
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
index 7f3ba6f..3112e0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/callback/PlatformCallbackUtils.java
@@ -442,7 +442,6 @@ public class PlatformCallbackUtils {
static native void serviceCancel(long envPtr, long svcPtr, long memPtr);
/**
- /**
* Invokes service method.
*
* @param envPtr Environment pointer.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicReference.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicReference.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicReference.java
new file mode 100644
index 0000000..81b7570
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicReference.java
@@ -0,0 +1,141 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.datastructures.GridCacheAtomicReferenceImpl;
+import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
+
+/**
+ * Platform atomic reference wrapper.
+ */
+@SuppressWarnings("unchecked")
+public class PlatformAtomicReference extends PlatformAbstractTarget {
+ /** */
+ private static final int OP_GET = 1;
+
+ /** */
+ private static final int OP_SET = 2;
+
+ /** */
+ private static final int OP_COMPARE_AND_SET_AND_GET = 3;
+
+ /** */
+ private final GridCacheAtomicReferenceImpl atomicRef;
+
+ /**
+ * Creates an instance or returns null.
+ *
+ * @param ctx Context.
+ * @param name Name.
+ * @param memPtr Pointer to a stream with initial value. 0 for default value.
+ * @param create Create flag.
+ * @return Instance of a PlatformAtomicReference, or null when Ignite reference with specific name is null.
+ */
+ public static PlatformAtomicReference createInstance(PlatformContext ctx, String name, long memPtr,
+ boolean create) {
+ assert ctx != null;
+ assert name != null;
+
+ Object initVal = null;
+
+ if (memPtr != 0) {
+ try (PlatformMemory mem = ctx.memory().get(memPtr)) {
+ initVal = ctx.reader(mem).readObjectDetached();
+ }
+ }
+
+ GridCacheAtomicReferenceImpl atomicRef =
+ (GridCacheAtomicReferenceImpl)ctx.kernalContext().grid().atomicReference(name, initVal, create);
+
+ if (atomicRef == null)
+ return null;
+
+ return new PlatformAtomicReference(ctx, atomicRef);
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param ctx Context.
+ * @param ref Atomic reference to wrap.
+ */
+ private PlatformAtomicReference(PlatformContext ctx, GridCacheAtomicReferenceImpl ref) {
+ super(ctx);
+
+ assert ref != null;
+
+ atomicRef = ref;
+ }
+
+ /**
+ * Returns a value indicating whether this instance has been closed.
+ *
+ * @return Value indicating whether this instance has been closed.
+ */
+ public boolean isClosed() {
+ return atomicRef.removed();
+ }
+
+ /**
+ * Closes this instance.
+ */
+ public void close() {
+ atomicRef.close();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
+ if (type == OP_GET)
+ writer.writeObject(atomicRef.get());
+ else
+ super.processOutStream(type, writer);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader)
+ throws IgniteCheckedException {
+ if (type == OP_SET) {
+ atomicRef.set(reader.readObjectDetached());
+
+ return 0;
+ }
+
+ return super.processInStreamOutLong(type, reader);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader,
+ BinaryRawWriterEx writer) throws IgniteCheckedException {
+ if (type == OP_COMPARE_AND_SET_AND_GET) {
+ Object val = reader.readObjectDetached();
+ final Object cmp = reader.readObjectDetached();
+
+ Object res = atomicRef.compareAndSetAndGet(val, cmp);
+
+ writer.writeObject(res);
+ }
+ else
+ super.processInStreamOutStream(type, reader, writer);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicSequence.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicSequence.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicSequence.java
new file mode 100644
index 0000000..ce7e364
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicSequence.java
@@ -0,0 +1,122 @@
+/*
+ * 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.datastructures;
+
+import org.apache.ignite.IgniteAtomicSequence;
+import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
+import org.apache.ignite.internal.processors.platform.PlatformContext;
+
+/**
+ * Platform atomic sequence wrapper.
+ */
+public class PlatformAtomicSequence extends PlatformAbstractTarget {
+ /** */
+ private final IgniteAtomicSequence atomicSeq;
+
+ /**
+ * Ctor.
+ * @param ctx Context.
+ * @param atomicSeq AtomicSequence to wrap.
+ */
+ public PlatformAtomicSequence(PlatformContext ctx, IgniteAtomicSequence atomicSeq) {
+ super(ctx);
+
+ assert atomicSeq != null;
+
+ this.atomicSeq = atomicSeq;
+ }
+
+ /**
+ * Reads the value.
+ *
+ * @return Current atomic sequence value.
+ */
+ public long get() {
+ return atomicSeq.get();
+ }
+
+ /**
+ * Increments and reads the value.
+ *
+ * @return Current atomic sequence value.
+ */
+ public long incrementAndGet() {
+ return atomicSeq.incrementAndGet();
+ }
+
+ /**
+ * Reads and increments the value.
+ *
+ * @return Original atomic sequence value.
+ */
+ public long getAndIncrement() {
+ return atomicSeq.getAndIncrement();
+ }
+
+ /**
+ * Adds a value.
+ *
+ * @return Current atomic sequence value.
+ */
+ public long addAndGet(long l) {
+ return atomicSeq.addAndGet(l);
+ }
+
+ /**
+ * Adds a value.
+ *
+ * @return Original atomic sequence value.
+ */
+ public long getAndAdd(long l) {
+ return atomicSeq.getAndAdd(l);
+ }
+
+ /**
+ * Gets the batch size.
+ *
+ * @return Batch size.
+ */
+ public int getBatchSize() {
+ return atomicSeq.batchSize();
+ }
+
+ /**
+ * Sets the batch size.
+ *
+ * @param size Batch size.
+ */
+ public void setBatchSize(int size) {
+ atomicSeq.batchSize(size);
+ }
+
+ /**
+ * Gets status of atomic.
+ *
+ * @return {@code true} if atomic was removed from cache, {@code false} in other case.
+ */
+ public boolean isClosed() {
+ return atomicSeq.removed();
+ }
+
+ /**
+ * Removes this atomic.
+ */
+ public void close() {
+ atomicSeq.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/cpp/common/include/ignite/common/exports.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/include/ignite/common/exports.h b/modules/platforms/cpp/common/include/ignite/common/exports.h
index 66f918f..15911a6 100644
--- a/modules/platforms/cpp/common/include/ignite/common/exports.h
+++ b/modules/platforms/cpp/common/include/ignite/common/exports.h
@@ -48,6 +48,8 @@ extern "C" {
void* IGNITE_CALL IgniteProcessorServices(gcj::JniContext* ctx, void* obj, void* prj);
void* IGNITE_CALL IgniteProcessorExtensions(gcj::JniContext* ctx, void* obj);
void* IGNITE_CALL IgniteProcessorAtomicLong(gcj::JniContext* ctx, void* obj, char* name, long long initVal, bool create);
+ void* IGNITE_CALL IgniteProcessorAtomicSequence(gcj::JniContext* ctx, void* obj, char* name, long long initVal, bool create);
+ void* IGNITE_CALL IgniteProcessorAtomicReference(gcj::JniContext* ctx, void* obj, char* name, long long memPtr, bool create);
void IGNITE_CALL IgniteProcessorGetIgniteConfiguration(gcj::JniContext* ctx, void* obj, long memPtr);
long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr);
@@ -160,6 +162,19 @@ extern "C" {
bool IGNITE_CALL IgniteAtomicLongIsClosed(gcj::JniContext* ctx, void* obj);
void IGNITE_CALL IgniteAtomicLongClose(gcj::JniContext* ctx, void* obj);
+ long long IGNITE_CALL IgniteAtomicSequenceGet(gcj::JniContext* ctx, void* obj);
+ long long IGNITE_CALL IgniteAtomicSequenceIncrementAndGet(gcj::JniContext* ctx, void* obj);
+ long long IGNITE_CALL IgniteAtomicSequenceGetAndIncrement(gcj::JniContext* ctx, void* obj);
+ long long IGNITE_CALL IgniteAtomicSequenceAddAndGet(gcj::JniContext* ctx, void* obj, long long l);
+ long long IGNITE_CALL IgniteAtomicSequenceGetAndAdd(gcj::JniContext* ctx, void* obj, long long l);
+ int IGNITE_CALL IgniteAtomicSequenceGetBatchSize(gcj::JniContext* ctx, void* obj);
+ void IGNITE_CALL IgniteAtomicSequenceSetBatchSize(gcj::JniContext* ctx, void* obj, int size);
+ bool IGNITE_CALL IgniteAtomicSequenceIsClosed(gcj::JniContext* ctx, void* obj);
+ void IGNITE_CALL IgniteAtomicSequenceClose(gcj::JniContext* ctx, void* obj);
+
+ bool IGNITE_CALL IgniteAtomicReferenceIsClosed(gcj::JniContext* ctx, void* obj);
+ void IGNITE_CALL IgniteAtomicReferenceClose(gcj::JniContext* ctx, void* obj);
+
bool IGNITE_CALL IgniteListenableCancel(gcj::JniContext* ctx, void* obj);
bool IGNITE_CALL IgniteListenableIsCancelled(gcj::JniContext* ctx, void* obj);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/cpp/common/include/ignite/common/java.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/include/ignite/common/java.h b/modules/platforms/cpp/common/include/ignite/common/java.h
index 072a8ef..8f5823e 100644
--- a/modules/platforms/cpp/common/include/ignite/common/java.h
+++ b/modules/platforms/cpp/common/include/ignite/common/java.h
@@ -311,6 +311,8 @@ namespace ignite
jmethodID m_PlatformProcessor_extensions;
jmethodID m_PlatformProcessor_atomicLong;
jmethodID m_PlatformProcessor_getIgniteConfiguration;
+ jmethodID m_PlatformProcessor_atomicSequence;
+ jmethodID m_PlatformProcessor_atomicReference;
jclass c_PlatformTarget;
jmethodID m_PlatformTarget_inStreamOutLong;
@@ -353,6 +355,21 @@ namespace ignite
jmethodID m_PlatformAtomicLong_isClosed;
jmethodID m_PlatformAtomicLong_close;
+ jclass c_PlatformAtomicSequence;
+ jmethodID m_PlatformAtomicSequence_get;
+ jmethodID m_PlatformAtomicSequence_incrementAndGet;
+ jmethodID m_PlatformAtomicSequence_getAndIncrement;
+ jmethodID m_PlatformAtomicSequence_addAndGet;
+ jmethodID m_PlatformAtomicSequence_getAndAdd;
+ jmethodID m_PlatformAtomicSequence_getBatchSize;
+ jmethodID m_PlatformAtomicSequence_setBatchSize;
+ jmethodID m_PlatformAtomicSequence_isClosed;
+ jmethodID m_PlatformAtomicSequence_close;
+
+ jclass c_PlatformAtomicReference;
+ jmethodID m_PlatformAtomicReference_isClosed;
+ jmethodID m_PlatformAtomicReference_close;
+
jclass c_PlatformListenable;
jmethodID m_PlatformListenable_cancel;
jmethodID m_PlatformListenable_isCancelled;
@@ -507,6 +524,8 @@ namespace ignite
jobject ProcessorServices(jobject obj, jobject prj);
jobject ProcessorExtensions(jobject obj);
jobject ProcessorAtomicLong(jobject obj, char* name, long long initVal, bool create);
+ jobject ProcessorAtomicSequence(jobject obj, char* name, long long initVal, bool create);
+ jobject ProcessorAtomicReference(jobject obj, char* name, long long memPtr, bool create);
void ProcessorGetIgniteConfiguration(jobject obj, long memPtr);
long long TargetInStreamOutLong(jobject obj, int type, long long memPtr, JniErrorInfo* errInfo = NULL);
@@ -608,6 +627,19 @@ namespace ignite
bool AtomicLongIsClosed(jobject obj);
void AtomicLongClose(jobject obj);
+ long long AtomicSequenceGet(jobject obj);
+ long long AtomicSequenceIncrementAndGet(jobject obj);
+ long long AtomicSequenceGetAndIncrement(jobject obj);
+ long long AtomicSequenceAddAndGet(jobject obj, long long l);
+ long long AtomicSequenceGetAndAdd(jobject obj, long long l);
+ int AtomicSequenceGetBatchSize(jobject obj);
+ void AtomicSequenceSetBatchSize(jobject obj, int size);
+ bool AtomicSequenceIsClosed(jobject obj);
+ void AtomicSequenceClose(jobject obj);
+
+ bool AtomicReferenceIsClosed(jobject obj);
+ void AtomicReferenceClose(jobject obj);
+
bool ListenableCancel(jobject obj);
bool ListenableIsCancelled(jobject obj);
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/cpp/common/project/vs/module.def
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/project/vs/module.def b/modules/platforms/cpp/common/project/vs/module.def
index 81df027..21a4994 100644
--- a/modules/platforms/cpp/common/project/vs/module.def
+++ b/modules/platforms/cpp/common/project/vs/module.def
@@ -116,4 +116,17 @@ IgniteTargetListenFutureForOperationAndGet @113
IgniteProcessorCreateCacheFromConfig @114
IgniteProcessorGetOrCreateCacheFromConfig @115
IgniteProcessorGetIgniteConfiguration @116
-IgniteProcessorDestroyCache @117
\ No newline at end of file
+IgniteProcessorDestroyCache @117
+IgniteProcessorAtomicSequence @118
+IgniteAtomicSequenceGet @119
+IgniteAtomicSequenceIncrementAndGet @120
+IgniteAtomicSequenceGetAndIncrement @121
+IgniteAtomicSequenceAddAndGet @122
+IgniteAtomicSequenceGetAndAdd @123
+IgniteAtomicSequenceGetBatchSize @124
+IgniteAtomicSequenceSetBatchSize @125
+IgniteAtomicSequenceIsClosed @126
+IgniteAtomicSequenceClose @127
+IgniteProcessorAtomicReference @128
+IgniteAtomicReferenceIsClosed @129
+IgniteAtomicReferenceClose @130
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/cpp/common/src/exports.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/src/exports.cpp b/modules/platforms/cpp/common/src/exports.cpp
index e9ec519..fff2a16 100644
--- a/modules/platforms/cpp/common/src/exports.cpp
+++ b/modules/platforms/cpp/common/src/exports.cpp
@@ -114,6 +114,14 @@ extern "C" {
return ctx->ProcessorAtomicLong(static_cast<jobject>(obj), name, initVal, create);
}
+ void* IGNITE_CALL IgniteProcessorAtomicSequence(gcj::JniContext* ctx, void* obj, char* name, long long initVal, bool create) {
+ return ctx->ProcessorAtomicSequence(static_cast<jobject>(obj), name, initVal, create);
+ }
+
+ void* IGNITE_CALL IgniteProcessorAtomicReference(gcj::JniContext* ctx, void* obj, char* name, long long memPtr, bool create) {
+ return ctx->ProcessorAtomicReference(static_cast<jobject>(obj), name, memPtr, create);
+ }
+
void IGNITE_CALL IgniteProcessorGetIgniteConfiguration(gcj::JniContext* ctx, void* obj, long memPtr) {
return ctx->ProcessorGetIgniteConfiguration(static_cast<jobject>(obj), memPtr);
}
@@ -482,6 +490,50 @@ extern "C" {
void IGNITE_CALL IgniteAtomicLongClose(gcj::JniContext* ctx, void* obj) {
return ctx->AtomicLongClose(static_cast<jobject>(obj));
}
+
+ long long IGNITE_CALL IgniteAtomicSequenceGet(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceGet(static_cast<jobject>(obj));
+ }
+
+ long long IGNITE_CALL IgniteAtomicSequenceIncrementAndGet(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceIncrementAndGet(static_cast<jobject>(obj));
+ }
+
+ long long IGNITE_CALL IgniteAtomicSequenceGetAndIncrement(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceGetAndIncrement(static_cast<jobject>(obj));
+ }
+
+ long long IGNITE_CALL IgniteAtomicSequenceAddAndGet(gcj::JniContext* ctx, void* obj, long long l) {
+ return ctx->AtomicSequenceAddAndGet(static_cast<jobject>(obj), l);
+ }
+
+ long long IGNITE_CALL IgniteAtomicSequenceGetAndAdd(gcj::JniContext* ctx, void* obj, long long l) {
+ return ctx->AtomicSequenceGetAndAdd(static_cast<jobject>(obj), l);
+ }
+
+ int IGNITE_CALL IgniteAtomicSequenceGetBatchSize(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceGetBatchSize(static_cast<jobject>(obj));
+ }
+
+ void IGNITE_CALL IgniteAtomicSequenceSetBatchSize(gcj::JniContext* ctx, void* obj, int size) {
+ return ctx->AtomicSequenceSetBatchSize(static_cast<jobject>(obj), size);
+ }
+
+ bool IGNITE_CALL IgniteAtomicSequenceIsClosed(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceIsClosed(static_cast<jobject>(obj));
+ }
+
+ void IGNITE_CALL IgniteAtomicSequenceClose(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicSequenceClose(static_cast<jobject>(obj));
+ }
+
+ bool IGNITE_CALL IgniteAtomicReferenceIsClosed(gcj::JniContext* ctx, void* obj) {
+ return ctx->AtomicReferenceIsClosed(static_cast<jobject>(obj));
+ }
+
+ void IGNITE_CALL IgniteAtomicReferenceClose(gcj::JniContext* ctx, void* obj) {
+ ctx->AtomicReferenceClose(static_cast<jobject>(obj));
+ }
bool IGNITE_CALL IgniteListenableCancel(gcj::JniContext* ctx, void* obj) {
return ctx->ListenableCancel(static_cast<jobject>(obj));
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/cpp/common/src/java.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/src/java.cpp b/modules/platforms/cpp/common/src/java.cpp
index e36c1e0..d6f7ef0 100644
--- a/modules/platforms/cpp/common/src/java.cpp
+++ b/modules/platforms/cpp/common/src/java.cpp
@@ -203,6 +203,8 @@ namespace ignite
JniMethod M_PLATFORM_PROCESSOR_SERVICES = JniMethod("services", "(Lorg/apache/ignite/internal/processors/platform/PlatformTarget;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_EXTENSIONS = JniMethod("extensions", "()Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_ATOMIC_LONG = JniMethod("atomicLong", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
+ JniMethod M_PLATFORM_PROCESSOR_ATOMIC_SEQUENCE = JniMethod("atomicSequence", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
+ JniMethod M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE = JniMethod("atomicReference", "(Ljava/lang/String;JZ)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
JniMethod M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION = JniMethod("getIgniteConfiguration", "(J)V", false);
const char* C_PLATFORM_TARGET = "org/apache/ignite/internal/processors/platform/PlatformTarget";
@@ -396,6 +398,21 @@ namespace ignite
JniMethod M_PLATFORM_ATOMIC_LONG_IS_CLOSED = JniMethod("isClosed", "()Z", false);
JniMethod M_PLATFORM_ATOMIC_LONG_CLOSE = JniMethod("close", "()V", false);
+ const char* C_PLATFORM_ATOMIC_SEQUENCE = "org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicSequence";
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_GET = JniMethod("get", "()J", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_INCREMENT_AND_GET = JniMethod("incrementAndGet", "()J", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_GET_AND_INCREMENT = JniMethod("getAndIncrement", "()J", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_ADD_AND_GET = JniMethod("addAndGet", "(J)J", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_GET_AND_ADD = JniMethod("getAndAdd", "(J)J", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_GET_BATCH_SIZE = JniMethod("getBatchSize", "()I", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_SET_BATCH_SIZE = JniMethod("setBatchSize", "(I)V", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_IS_CLOSED = JniMethod("isClosed", "()Z", false);
+ JniMethod M_PLATFORM_ATOMIC_SEQUENCE_CLOSE = JniMethod("close", "()V", false);
+
+ const char* C_PLATFORM_ATOMIC_REFERENCE = "org/apache/ignite/internal/processors/platform/datastructures/PlatformAtomicReference";
+ JniMethod M_PLATFORM_ATOMIC_REFERENCE_IS_CLOSED = JniMethod("isClosed", "()Z", false);
+ JniMethod M_PLATFORM_ATOMIC_REFERENCE_CLOSE = JniMethod("close", "()V", false);
+
const char* C_PLATFORM_LISTENABLE = "org/apache/ignite/internal/processors/platform/utils/PlatformListenable";
JniMethod M_PLATFORM_LISTENABLE_CANCEL = JniMethod("cancel", "()Z", false);
JniMethod M_PLATFORM_LISTENABLE_IS_CANCELED = JniMethod("isCancelled", "()Z", false);
@@ -652,6 +669,8 @@ namespace ignite
m_PlatformProcessor_services = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_SERVICES);
m_PlatformProcessor_extensions = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_EXTENSIONS);
m_PlatformProcessor_atomicLong = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_LONG);
+ m_PlatformProcessor_atomicSequence = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_SEQUENCE);
+ m_PlatformProcessor_atomicReference = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_ATOMIC_REFERENCE);
m_PlatformProcessor_getIgniteConfiguration = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_IGNITE_CONFIGURATION);
c_PlatformTarget = FindClass(env, C_PLATFORM_TARGET);
@@ -695,6 +714,21 @@ namespace ignite
m_PlatformAtomicLong_isClosed = FindMethod(env, c_PlatformAtomicLong, M_PLATFORM_ATOMIC_LONG_IS_CLOSED);
m_PlatformAtomicLong_close = FindMethod(env, c_PlatformAtomicLong, M_PLATFORM_ATOMIC_LONG_CLOSE);
+ jclass c_PlatformAtomicSequence = FindClass(env, C_PLATFORM_ATOMIC_SEQUENCE);
+ m_PlatformAtomicSequence_get = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_GET);
+ m_PlatformAtomicSequence_incrementAndGet = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_INCREMENT_AND_GET);
+ m_PlatformAtomicSequence_getAndIncrement = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_GET_AND_INCREMENT);
+ m_PlatformAtomicSequence_addAndGet = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_ADD_AND_GET);
+ m_PlatformAtomicSequence_getAndAdd = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_GET_AND_ADD);
+ m_PlatformAtomicSequence_getBatchSize = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_GET_BATCH_SIZE);
+ m_PlatformAtomicSequence_setBatchSize = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_SET_BATCH_SIZE);
+ m_PlatformAtomicSequence_isClosed = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_IS_CLOSED);
+ m_PlatformAtomicSequence_close = FindMethod(env, c_PlatformAtomicSequence, M_PLATFORM_ATOMIC_SEQUENCE_CLOSE);
+
+ jclass c_PlatformAtomicReference = FindClass(env, C_PLATFORM_ATOMIC_REFERENCE);
+ m_PlatformAtomicReference_isClosed = FindMethod(env, c_PlatformAtomicReference, M_PLATFORM_ATOMIC_REFERENCE_IS_CLOSED);
+ m_PlatformAtomicReference_close = FindMethod(env, c_PlatformAtomicReference, M_PLATFORM_ATOMIC_REFERENCE_CLOSE);
+
c_PlatformListenable = FindClass(env, C_PLATFORM_LISTENABLE);
m_PlatformListenable_cancel = FindMethod(env, c_PlatformListenable, M_PLATFORM_LISTENABLE_CANCEL);
m_PlatformListenable_isCancelled = FindMethod(env, c_PlatformListenable, M_PLATFORM_LISTENABLE_IS_CANCELED);
@@ -1307,6 +1341,38 @@ namespace ignite
return LocalToGlobal(env, res);
}
+ jobject JniContext::ProcessorAtomicSequence(jobject obj, char* name, long long initVal, bool create)
+ {
+ JNIEnv* env = Attach();
+
+ jstring name0 = name != NULL ? env->NewStringUTF(name) : NULL;
+
+ jobject res = env->CallObjectMethod(obj, jvm->GetMembers().m_PlatformProcessor_atomicSequence, name0, initVal, create);
+
+ if (name0)
+ env->DeleteLocalRef(name0);
+
+ ExceptionCheck(env);
+
+ return LocalToGlobal(env, res);
+ }
+
+ jobject JniContext::ProcessorAtomicReference(jobject obj, char* name, long long memPtr, bool create)
+ {
+ JNIEnv* env = Attach();
+
+ jstring name0 = name != NULL ? env->NewStringUTF(name) : NULL;
+
+ jobject res = env->CallObjectMethod(obj, jvm->GetMembers().m_PlatformProcessor_atomicReference, name0, memPtr, create);
+
+ if (name0)
+ env->DeleteLocalRef(name0);
+
+ ExceptionCheck(env);
+
+ return LocalToGlobal(env, res);
+ }
+
void JniContext::ProcessorGetIgniteConfiguration(jobject obj, long memPtr)
{
JNIEnv* env = Attach();
@@ -2139,6 +2205,121 @@ namespace ignite
ExceptionCheck(env);
}
+ long long JniContext::AtomicSequenceGet(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ long long res = env->CallLongMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_get);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ long long JniContext::AtomicSequenceIncrementAndGet(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ long long res = env->CallLongMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_incrementAndGet);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ long long JniContext::AtomicSequenceGetAndIncrement(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ long long res = env->CallLongMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_getAndIncrement);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ long long JniContext::AtomicSequenceAddAndGet(jobject obj, long long l)
+ {
+ JNIEnv* env = Attach();
+
+ long long res = env->CallLongMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_addAndGet, l);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ long long JniContext::AtomicSequenceGetAndAdd(jobject obj, long long l)
+ {
+ JNIEnv* env = Attach();
+
+ long long res = env->CallLongMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_getAndAdd, l);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ int JniContext::AtomicSequenceGetBatchSize(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ int res = env->CallIntMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_getBatchSize);
+
+ ExceptionCheck(env);
+
+ return res;
+ }
+
+ void JniContext::AtomicSequenceSetBatchSize(jobject obj, int size)
+ {
+ JNIEnv* env = Attach();
+
+ env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_setBatchSize, size);
+
+ ExceptionCheck(env);
+ }
+
+ bool JniContext::AtomicSequenceIsClosed(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ jboolean res = env->CallBooleanMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_isClosed);
+
+ ExceptionCheck(env);
+
+ return res != 0;
+ }
+
+ void JniContext::AtomicSequenceClose(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformAtomicSequence_close);
+
+ ExceptionCheck(env);
+ }
+
+ bool JniContext::AtomicReferenceIsClosed(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ jboolean res = env->CallBooleanMethod(obj, jvm->GetMembers().m_PlatformAtomicReference_isClosed);
+
+ ExceptionCheck(env);
+
+ return res != 0;
+ }
+
+ void JniContext::AtomicReferenceClose(jobject obj)
+ {
+ JNIEnv* env = Attach();
+
+ env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformAtomicReference_close);
+
+ ExceptionCheck(env);
+ }
+
bool JniContext::ListenableCancel(jobject obj)
{
JNIEnv* env = Attach();
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 481adfb..f5e98c5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -107,6 +107,8 @@
<Compile Include="Compute\TaskResultTest.cs" />
<Compile Include="Dataload\DataStreamerTest.cs" />
<Compile Include="DataStructures\AtomicLongTest.cs" />
+ <Compile Include="DataStructures\AtomicReferenceTest.cs" />
+ <Compile Include="DataStructures\AtomicSequenceTest.cs" />
<Compile Include="EventsTest.cs" />
<Compile Include="Examples\Example.cs" />
<Compile Include="Examples\ExamplesTest.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicReferenceTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicReferenceTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicReferenceTest.cs
new file mode 100644
index 0000000..93375da
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicReferenceTest.cs
@@ -0,0 +1,239 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.DataStructures
+{
+ using System;
+ using System.Linq;
+ using Apache.Ignite.Core.Binary;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Atomic reference test.
+ /// </summary>
+ public class AtomicReferenceTest : IgniteTestBase
+ {
+ /** */
+ private const string AtomicRefName = "testAtomicRef";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AtomicReferenceTest"/> class.
+ /// </summary>
+ public AtomicReferenceTest() : base("config\\compute\\compute-grid1.xml")
+ {
+ // No-op.
+ }
+
+ /** <inheritdoc /> */
+ public override void TestSetUp()
+ {
+ base.TestSetUp();
+
+ // Close test atomic if there is any
+ Grid.GetAtomicReference(AtomicRefName, 0, true).Close();
+ }
+
+ /** <inheritdoc /> */
+ protected override IgniteConfiguration GetConfiguration(string springConfigUrl)
+ {
+ var cfg = base.GetConfiguration(springConfigUrl);
+
+ cfg.BinaryConfiguration = new BinaryConfiguration(typeof(BinaryObj));
+
+ return cfg;
+ }
+
+ /// <summary>
+ /// Tests lifecycle of the AtomicReference.
+ /// </summary>
+ [Test]
+ public void TestCreateClose()
+ {
+ Assert.IsNull(Grid.GetAtomicReference(AtomicRefName, 10, false));
+
+ // Nonexistent atomic returns null
+ Assert.IsNull(Grid.GetAtomicReference(AtomicRefName, 10, false));
+
+ // Create new
+ var al = Grid.GetAtomicReference(AtomicRefName, 10, true);
+ Assert.AreEqual(AtomicRefName, al.Name);
+ Assert.AreEqual(10, al.Read());
+ Assert.AreEqual(false, al.IsClosed);
+
+ // Get existing with create flag
+ var al2 = Grid.GetAtomicReference(AtomicRefName, 5, true);
+ Assert.AreEqual(AtomicRefName, al2.Name);
+ Assert.AreEqual(10, al2.Read());
+ Assert.AreEqual(false, al2.IsClosed);
+
+ // Get existing without create flag
+ var al3 = Grid.GetAtomicReference(AtomicRefName, 5, false);
+ Assert.AreEqual(AtomicRefName, al3.Name);
+ Assert.AreEqual(10, al3.Read());
+ Assert.AreEqual(false, al3.IsClosed);
+
+ al.Close();
+
+ Assert.AreEqual(true, al.IsClosed);
+ Assert.AreEqual(true, al2.IsClosed);
+ Assert.AreEqual(true, al3.IsClosed);
+
+ Assert.IsNull(Grid.GetAtomicReference(AtomicRefName, 10, false));
+ }
+
+ /// <summary>
+ /// Tests modification methods.
+ /// </summary>
+ [Test]
+ public void TestModify()
+ {
+ var atomics = Enumerable.Range(1, 10)
+ .Select(x => Grid.GetAtomicReference(AtomicRefName, 5, true)).ToList();
+
+ atomics.ForEach(x => Assert.AreEqual(5, x.Read()));
+
+ atomics[0].Write(15);
+ atomics.ForEach(x => Assert.AreEqual(15, x.Read()));
+
+ Assert.AreEqual(15, atomics[0].CompareExchange(42, 15));
+ atomics.ForEach(x => Assert.AreEqual(42, x.Read()));
+ }
+
+ /// <summary>
+ /// Tests primitives in the atomic.
+ /// </summary>
+ [Test]
+ public void TestPrimitives()
+ {
+ TestOperations(1, 2);
+ TestOperations("1", "2");
+ TestOperations(Guid.NewGuid(), Guid.NewGuid());
+ }
+
+ /// <summary>
+ /// Tests DateTime in the atomic.
+ /// </summary>
+ [Test]
+ [Ignore("IGNITE-2578")]
+ public void TestDateTime()
+ {
+ TestOperations(DateTime.Now, DateTime.Now.AddDays(-1));
+ }
+
+ /// <summary>
+ /// Tests serializable objects in the atomic.
+ /// </summary>
+ [Test]
+ [Ignore("IGNITE-2578")]
+ public void TestSerializable()
+ {
+ TestOperations(new SerializableObj {Foo = 16}, new SerializableObj {Foo = -5});
+ }
+
+ /// <summary>
+ /// Tests binarizable objects in the atomic.
+ /// </summary>
+ [Test]
+ public void TestBinarizable()
+ {
+ TestOperations(new BinaryObj {Foo = 16}, new BinaryObj {Foo = -5});
+ }
+
+ /// <summary>
+ /// Tests operations on specific object.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ private void TestOperations<T>(T x, T y)
+ {
+ Grid.GetAtomicReference(AtomicRefName, 0, true).Close();
+
+ var atomic = Grid.GetAtomicReference(AtomicRefName, x, true);
+
+ Assert.AreEqual(x, atomic.Read());
+
+ atomic.Write(y);
+ Assert.AreEqual(y, atomic.Read());
+
+ var old = atomic.CompareExchange(x, y);
+ Assert.AreEqual(y, old);
+ Assert.AreEqual(x, atomic.Read());
+
+ old = atomic.CompareExchange(x, y);
+ Assert.AreEqual(x, old);
+ Assert.AreEqual(x, atomic.Read());
+
+ // Check nulls
+ var nul = default(T);
+
+ old = atomic.CompareExchange(nul, x);
+ Assert.AreEqual(x, old);
+ Assert.AreEqual(nul, atomic.Read());
+
+ old = atomic.CompareExchange(y, nul);
+ Assert.AreEqual(nul, old);
+ Assert.AreEqual(y, atomic.Read());
+ }
+
+ /// <summary>
+ /// Serializable.
+ /// </summary>
+ [Serializable]
+ private class SerializableObj
+ {
+ /** */
+ public int Foo { get; set; }
+
+ /** <inheritdoc /> */
+ private bool Equals(SerializableObj other)
+ {
+ return Foo == other.Foo;
+ }
+
+ /** <inheritdoc /> */
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != GetType()) return false;
+ return Equals((SerializableObj) obj);
+ }
+
+ /** <inheritdoc /> */
+ public override int GetHashCode()
+ {
+ // ReSharper disable once NonReadonlyMemberInGetHashCode
+ return Foo;
+ }
+
+ /** <inheritdoc /> */
+ public override string ToString()
+ {
+ return base.ToString() + "[" + Foo + "]";
+ }
+ }
+
+ /// <summary>
+ /// Binary.
+ /// </summary>
+ private sealed class BinaryObj : SerializableObj
+ {
+ // No-op.
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicSequenceTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicSequenceTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicSequenceTest.cs
new file mode 100644
index 0000000..472dee2
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicSequenceTest.cs
@@ -0,0 +1,131 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.DataStructures
+{
+ using System.Linq;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Atomic sequence test.
+ /// </summary>
+ public class AtomicSequenceTest : IgniteTestBase
+ {
+ /** */
+ private const string AtomicSeqName = "testAtomicSeq";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AtomicSequenceTest"/> class.
+ /// </summary>
+ public AtomicSequenceTest() : base("config\\compute\\compute-grid1.xml")
+ {
+ // No-op.
+ }
+
+ /** <inheritdoc /> */
+ public override void TestSetUp()
+ {
+ base.TestSetUp();
+
+ // Close test atomic if there is any
+ Grid.GetAtomicSequence(AtomicSeqName, 0, true).Close();
+ }
+
+ /// <summary>
+ /// Tests lifecycle of the AtomicSequence.
+ /// </summary>
+ [Test]
+ public void TestCreateClose()
+ {
+ Assert.IsNull(Grid.GetAtomicSequence(AtomicSeqName, 10, false));
+
+ // Nonexistent atomic returns null
+ Assert.IsNull(Grid.GetAtomicSequence(AtomicSeqName, 10, false));
+
+ // Create new
+ var al = Grid.GetAtomicSequence(AtomicSeqName, 10, true);
+ Assert.AreEqual(AtomicSeqName, al.Name);
+ Assert.AreEqual(10, al.Read());
+ Assert.AreEqual(false, al.IsClosed);
+
+ // Get existing with create flag
+ var al2 = Grid.GetAtomicSequence(AtomicSeqName, 5, true);
+ Assert.AreEqual(AtomicSeqName, al2.Name);
+ Assert.AreEqual(10, al2.Read());
+ Assert.AreEqual(false, al2.IsClosed);
+
+ // Get existing without create flag
+ var al3 = Grid.GetAtomicSequence(AtomicSeqName, 5, false);
+ Assert.AreEqual(AtomicSeqName, al3.Name);
+ Assert.AreEqual(10, al3.Read());
+ Assert.AreEqual(false, al3.IsClosed);
+
+ al.Close();
+
+ Assert.AreEqual(true, al.IsClosed);
+ Assert.AreEqual(true, al2.IsClosed);
+ Assert.AreEqual(true, al3.IsClosed);
+
+ Assert.IsNull(Grid.GetAtomicSequence(AtomicSeqName, 10, false));
+ }
+
+ /// <summary>
+ /// Tests modification methods.
+ /// </summary>
+ [Test]
+ public void TestModify()
+ {
+ var atomics = Enumerable.Range(1, 10)
+ .Select(x => Grid.GetAtomicSequence(AtomicSeqName, 5, true)).ToList();
+
+ atomics.ForEach(x => Assert.AreEqual(5, x.Read()));
+
+ Assert.AreEqual(10, atomics[0].Add(5));
+ atomics.ForEach(x => Assert.AreEqual(10, x.Read()));
+
+ Assert.AreEqual(11, atomics[0].Increment());
+ atomics.ForEach(x => Assert.AreEqual(11, x.Read()));
+
+ atomics.ForEach(x => x.BatchSize = 42);
+ atomics.ForEach(x => Assert.AreEqual(42, x.BatchSize));
+ }
+
+ /// <summary>
+ /// Tests multithreaded scenario.
+ /// </summary>
+ [Test]
+ public void TestMultithreaded()
+ {
+ const int atomicCnt = 10;
+ const int threadCnt = 5;
+ const int iterations = 3000;
+
+ // 10 atomics with same name
+ var atomics = Enumerable.Range(1, atomicCnt)
+ .Select(x => Grid.GetAtomicSequence(AtomicSeqName, 0, true)).ToList();
+
+ // 5 threads increment 30000 times
+ TestUtils.RunMultiThreaded(() =>
+ {
+ for (var i = 0; i < iterations; i++)
+ atomics.ForEach(x => x.Increment());
+ }, threadCnt);
+
+ atomics.ForEach(x => Assert.AreEqual(atomicCnt*threadCnt*iterations, x.Read()));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index 1c83168..e2efd0a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -161,6 +161,8 @@
<Compile Include="Datastream\StreamTransformer.cs" />
<Compile Include="Datastream\StreamVisitor.cs" />
<Compile Include="DataStructures\IAtomicLong.cs" />
+ <Compile Include="DataStructures\IAtomicReference.cs" />
+ <Compile Include="DataStructures\IAtomicSequence.cs" />
<Compile Include="DataStructures\Package-Info.cs" />
<Compile Include="Events\CacheEvent.cs" />
<Compile Include="Events\CacheQueryExecutedEvent.cs" />
@@ -259,6 +261,8 @@
<Compile Include="Impl\Datastream\DataStreamerRemoveEntry.cs" />
<Compile Include="Impl\Datastream\StreamReceiverHolder.cs" />
<Compile Include="Impl\DataStructures\AtomicLong.cs" />
+ <Compile Include="Impl\DataStructures\AtomicReference.cs" />
+ <Compile Include="Impl\DataStructures\AtomicSequence.cs" />
<Compile Include="Impl\Events\Events.cs" />
<Compile Include="Impl\Events\RemoteListenEventFilter.cs" />
<Compile Include="Impl\ExceptionUtils.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicReference.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicReference.cs b/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicReference.cs
new file mode 100644
index 0000000..403c0ca
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicReference.cs
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.DataStructures
+{
+ /// <summary>
+ /// Represents a named value in the distributed cache.
+ /// </summary>
+ public interface IAtomicReference<T>
+ {
+ /// <summary>
+ /// Gets the name of this atomic reference.
+ /// </summary>
+ /// <value>
+ /// Name of this atomic reference.
+ /// </value>
+ string Name { get; }
+
+ /// <summary>
+ /// Reads current value of an atomic reference.
+ /// </summary>
+ /// <returns>Current value of an atomic reference.</returns>
+ T Read();
+
+ /// <summary>
+ /// Writes current value of an atomic reference.
+ /// </summary>
+ /// <param name="value">The value to set.</param>
+ void Write(T value);
+
+ /// <summary>
+ /// Compares current value with specified value for equality and, if they are equal, replaces current value.
+ /// </summary>
+ /// <param name="value">The value to set.</param>
+ /// <param name="comparand">The value that is compared to the current value.</param>
+ /// <returns>Original value of the atomic reference.</returns>
+ T CompareExchange(T value, T comparand);
+
+ /// <summary>
+ /// Determines whether this instance was removed from cache.
+ /// </summary>
+ /// <returns>True if this atomic was removed from cache; otherwise, false.</returns>
+ bool IsClosed { get; }
+
+ /// <summary>
+ /// Closes this instance.
+ /// </summary>
+ void Close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicSequence.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicSequence.cs b/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicSequence.cs
new file mode 100644
index 0000000..f5b1dad
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/DataStructures/IAtomicSequence.cs
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.DataStructures
+{
+ /// <summary>
+ /// Represents a distributed atomic sequence of numbers.
+ /// </summary>
+ public interface IAtomicSequence
+ {
+ /// <summary>
+ /// Gets the name of this atomic sequence.
+ /// </summary>
+ /// <value>
+ /// Name of this atomic sequence.
+ /// </value>
+ string Name { get; }
+
+ /// <summary>
+ /// Returns current value.
+ /// </summary>
+ /// <returns>Current value of the atomic sequence.</returns>
+ long Read();
+
+ /// <summary>
+ /// Increments current value and returns result.
+ /// </summary>
+ /// <returns>The new value of the atomic sequence.</returns>
+ long Increment();
+
+ /// <summary>
+ /// Adds specified value to the current value and returns result.
+ /// </summary>
+ /// <param name="value">The value to add.</param>
+ /// <returns>The new value of the atomic sequence.</returns>
+ long Add(long value);
+
+ /// <summary>
+ /// Gets local batch size for this atomic sequence.
+ /// </summary>
+ /// <returns>Sequence batch size.</returns>
+ int BatchSize { get; set; }
+
+ /// <summary>
+ /// Determines whether this instance was removed from cache.
+ /// </summary>
+ /// <returns>True if this atomic was removed from cache; otherwise, false.</returns>
+ bool IsClosed { get; }
+
+ /// <summary>
+ /// Closes this instance.
+ /// </summary>
+ void Close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
index d18e790..12ea09e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
@@ -192,6 +192,34 @@ namespace Apache.Ignite.Core
IAtomicLong GetAtomicLong(string name, long initialValue, bool create);
/// <summary>
+ /// Gets an atomic sequence with specified name from cache.
+ /// Creates new atomic sequence in cache if it does not exist and <paramref name="create"/> is true.
+ /// </summary>
+ /// <param name="name">Name of the atomic sequence.</param>
+ /// <param name="initialValue">
+ /// Initial value for the atomic sequence. Ignored if <paramref name="create"/> is false.
+ /// </param>
+ /// <param name="create">Flag indicating whether atomic sequence should be created if it does not exist.</param>
+ /// <returns>Atomic sequence instance with specified name,
+ /// or null if it does not exist and <paramref name="create"/> flag is not set.</returns>
+ /// <exception cref="IgniteException">If atomic sequence could not be fetched or created.</exception>
+ IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create);
+
+ /// <summary>
+ /// Gets an atomic reference with specified name from cache.
+ /// Creates new atomic reference in cache if it does not exist and <paramref name="create"/> is true.
+ /// </summary>
+ /// <param name="name">Name of the atomic reference.</param>
+ /// <param name="initialValue">
+ /// Initial value for the atomic reference. Ignored if <paramref name="create"/> is false.
+ /// </param>
+ /// <param name="create">Flag indicating whether atomic reference should be created if it does not exist.</param>
+ /// <returns>Atomic reference instance with specified name,
+ /// or null if it does not exist and <paramref name="create"/> flag is not set.</returns>
+ /// <exception cref="IgniteException">If atomic reference could not be fetched or created.</exception>
+ IAtomicReference<T> GetAtomicReference<T>(string name, T initialValue, bool create);
+
+ /// <summary>
/// Gets the configuration of this Ignite instance.
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Semantics.")]
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicReference.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicReference.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicReference.cs
new file mode 100644
index 0000000..e871412
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicReference.cs
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.DataStructures
+{
+ using System.Diagnostics;
+ using Apache.Ignite.Core.DataStructures;
+ using Apache.Ignite.Core.Impl.Binary;
+ using Apache.Ignite.Core.Impl.Unmanaged;
+
+ /// <summary>
+ /// Atomic reference.
+ /// </summary>
+ internal class AtomicReference<T> : PlatformTarget, IAtomicReference<T>
+ {
+ /** Opcodes. */
+ private enum Op
+ {
+ Get = 1,
+ Set = 2,
+ CompareAndSetAndGet = 3
+ }
+
+ /** */
+ private readonly string _name;
+
+ /** <inheritDoc /> */
+ public AtomicReference(IUnmanagedTarget target, Marshaller marsh, string name)
+ : base(target, marsh)
+ {
+ Debug.Assert(!string.IsNullOrEmpty(name));
+
+ _name = name;
+ }
+
+ /** <inheritDoc /> */
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ /** <inheritDoc /> */
+ public T Read()
+ {
+ return DoInOp<T>((int) Op.Get);
+ }
+
+ /** <inheritDoc /> */
+ public void Write(T value)
+ {
+ DoOutOp((int) Op.Set, value);
+ }
+
+ /** <inheritDoc /> */
+ public T CompareExchange(T value, T comparand)
+ {
+ return DoOutInOp((int) Op.CompareAndSetAndGet,
+ writer =>
+ {
+ writer.WriteObject(value);
+ writer.WriteObject(comparand);
+ },
+ stream => Marshaller.StartUnmarshal(stream).Deserialize<T>());
+ }
+
+ /** <inheritDoc /> */
+ public bool IsClosed
+ {
+ get { return UnmanagedUtils.AtomicReferenceIsClosed(Target); }
+ }
+
+ /** <inheritDoc /> */
+ public void Close()
+ {
+ UnmanagedUtils.AtomicReferenceClose(Target);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicSequence.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicSequence.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicSequence.cs
new file mode 100644
index 0000000..0835b9a
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/DataStructures/AtomicSequence.cs
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.DataStructures
+{
+ using System.Diagnostics;
+ using Apache.Ignite.Core.DataStructures;
+ using Apache.Ignite.Core.Impl.Binary;
+ using Apache.Ignite.Core.Impl.Unmanaged;
+
+ /// <summary>
+ /// Atomic long wrapper.
+ /// </summary>
+ internal sealed class AtomicSequence: PlatformTarget, IAtomicSequence
+ {
+ /** */
+ private readonly string _name;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Apache.Ignite.Core.Impl.DataStructures.AtomicLong"/> class.
+ /// </summary>
+ /// <param name="target">The target.</param>
+ /// <param name="marsh">The marshaller.</param>
+ /// <param name="name">The name.</param>
+ public AtomicSequence(IUnmanagedTarget target, Marshaller marsh, string name)
+ : base(target, marsh)
+ {
+ Debug.Assert(!string.IsNullOrEmpty(name));
+
+ _name = name;
+ }
+
+ /** <inheritDoc /> */
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ /** <inheritDoc /> */
+ public long Read()
+ {
+ return UnmanagedUtils.AtomicSequenceGet(Target);
+ }
+
+ /** <inheritDoc /> */
+ public long Increment()
+ {
+ return UnmanagedUtils.AtomicSequenceIncrementAndGet(Target);
+ }
+
+ /** <inheritDoc /> */
+ public long Add(long value)
+ {
+ return UnmanagedUtils.AtomicSequenceAddAndGet(Target, value);
+ }
+
+ /** <inheritDoc /> */
+ public int BatchSize
+ {
+ get { return UnmanagedUtils.AtomicSequenceGetBatchSize(Target); }
+ set { UnmanagedUtils.AtomicSequenceSetBatchSize(Target, value); }
+ }
+
+ /** <inheritDoc /> */
+ public bool IsClosed
+ {
+ get { return UnmanagedUtils.AtomicSequenceIsClosed(Target); }
+ }
+
+ /** <inheritDoc /> */
+ public void Close()
+ {
+ UnmanagedUtils.AtomicSequenceClose(Target);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
index 9d27117..be21d7f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -486,6 +486,56 @@ namespace Apache.Ignite.Core.Impl
}
/** <inheritdoc /> */
+ public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create)
+ {
+ IgniteArgumentCheck.NotNullOrEmpty(name, "name");
+
+ var nativeSeq = UU.ProcessorAtomicSequence(_proc, name, initialValue, create);
+
+ if (nativeSeq == null)
+ return null;
+
+ return new AtomicSequence(nativeSeq, Marshaller, name);
+ }
+
+ /** <inheritdoc /> */
+ public IAtomicReference<T> GetAtomicReference<T>(string name, T initialValue, bool create)
+ {
+ IgniteArgumentCheck.NotNullOrEmpty(name, "name");
+
+ var refTarget = GetAtomicReferenceUnmanaged(name, initialValue, create);
+
+ return refTarget == null ? null : new AtomicReference<T>(refTarget, Marshaller, name);
+ }
+
+ /// <summary>
+ /// Gets the unmanaged atomic reference.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <param name="initialValue">The initial value.</param>
+ /// <param name="create">Create flag.</param>
+ /// <returns>Unmanaged atomic reference, or null.</returns>
+ private IUnmanagedTarget GetAtomicReferenceUnmanaged<T>(string name, T initialValue, bool create)
+ {
+ IgniteArgumentCheck.NotNullOrEmpty(name, "name");
+
+ // Do not allocate memory when default is not used.
+ if (!create)
+ return UU.ProcessorAtomicReference(_proc, name, 0, false);
+
+ using (var stream = IgniteManager.Memory.Allocate().GetStream())
+ {
+ var writer = Marshaller.StartMarshal(stream);
+
+ writer.Write(initialValue);
+
+ var memPtr = stream.SynchronizeOutput();
+
+ return UU.ProcessorAtomicReference(_proc, name, memPtr, true);
+ }
+ }
+
+ /** <inheritdoc /> */
public IgniteConfiguration GetConfiguration()
{
using (var stream = IgniteManager.Memory.Allocate(1024).GetStream())
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
index 46bc3ca..a303783 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -340,6 +340,18 @@ namespace Apache.Ignite.Core.Impl
}
/** <inheritdoc /> */
+ public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create)
+ {
+ return _ignite.GetAtomicSequence(name, initialValue, create);
+ }
+
+ /** <inheritdoc /> */
+ public IAtomicReference<T> GetAtomicReference<T>(string name, T initialValue, bool create)
+ {
+ return _ignite.GetAtomicReference(name, initialValue, create);
+ }
+
+ /** <inheritdoc /> */
public void WriteBinary(IBinaryWriter writer)
{
// No-op.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f7c1296c/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
index 17df94a..28eb208 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
@@ -93,6 +93,14 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
public static extern void* ProcessorAtomicLong(void* ctx, void* obj, sbyte* name, long initVal,
[MarshalAs(UnmanagedType.U1)] bool create);
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorAtomicSequence")]
+ public static extern void* ProcessorAtomicSequence(void* ctx, void* obj, sbyte* name, long initVal,
+ [MarshalAs(UnmanagedType.U1)] bool create);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorAtomicReference")]
+ public static extern void* ProcessorAtomicReference(void* ctx, void* obj, sbyte* name, long memPtr,
+ [MarshalAs(UnmanagedType.U1)] bool create);
+
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetIgniteConfiguration")]
public static extern void ProcessorGetIgniteConfiguration(void* ctx, void* obj, long memPtr);
@@ -373,6 +381,35 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicLongClose")]
public static extern void AtomicLongClose(void* ctx, void* target);
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceGet")]
+ public static extern long AtomicSequenceGet(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceIncrementAndGet")]
+ public static extern long AtomicSequenceIncrementAndGet(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceAddAndGet")]
+ public static extern long AtomicSequenceAddAndGet(void* ctx, void* target, long value);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceGetBatchSize")]
+ public static extern int AtomicSequenceGetBatchSize(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceSetBatchSize")]
+ public static extern void AtomicSequenceSetBatchSize(void* ctx, void* target, int size);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceIsClosed")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool AtomicSequenceIsClosed(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicSequenceClose")]
+ public static extern void AtomicSequenceClose(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicReferenceIsClosed")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool AtomicReferenceIsClosed(void* ctx, void* target);
+
+ [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteAtomicReferenceClose")]
+ public static extern void AtomicReferenceClose(void* ctx, void* target);
+
[DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteListenableCancel")]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool ListenableCancel(void* ctx, void* target);
[4/5] ignite git commit: IGNITE-2380: Added ability to start Ignite
using configuration from app.config. This closes #417.
Posted by sb...@apache.org.
IGNITE-2380: Added ability to start Ignite using configuration from app.config. This closes #417.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a4d8a049
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a4d8a049
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a4d8a049
Branch: refs/heads/ignite-2587
Commit: a4d8a049138a4d4bc86a59ccb273f7e214baf694
Parents: f7c1296
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Tue Feb 9 14:54:20 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Feb 9 14:54:20 2016 +0300
----------------------------------------------------------------------
.../Apache.Ignite.Core.Tests.csproj | 4 +
.../Apache.Ignite.Core.Tests/FutureTest.cs | 1 +
.../IgniteConfigurationSectionTest.cs | 69 +++
.../IgniteConfigurationSerializerTest.cs | 554 +++++++++++++++++++
.../dotnet/Apache.Ignite.Core.Tests/app.config | 54 ++
.../Apache.Ignite.Core.csproj | 11 +
.../Binary/IBinarySerializer.cs | 6 +-
.../IgniteConfigurationSection.cs | 80 +++
.../IgniteConfigurationSection.xsd | 281 ++++++++++
.../dotnet/Apache.Ignite.Core/Ignition.cs | 39 ++
.../Impl/Common/BooleanLowerCaseConverter.cs | 60 ++
.../Common/IgniteConfigurationXmlSerializer.cs | 410 ++++++++++++++
.../Impl/Common/TypeStringConverter.cs | 115 ++++
.../Impl/Events/EventTypeConverter.cs | 133 +++++
14 files changed, 1814 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index f5e98c5..fb14ed5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -55,6 +55,7 @@
<HintPath>..\libs\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.XML" />
@@ -117,6 +118,8 @@
<Compile Include="ExceptionsTest.cs" />
<Compile Include="ExecutableTest.cs" />
<Compile Include="FutureTest.cs" />
+ <Compile Include="IgniteConfigurationSectionTest.cs" />
+ <Compile Include="IgniteConfigurationSerializerTest.cs" />
<Compile Include="IgniteConfigurationTest.cs" />
<Compile Include="IgniteTestBase.cs" />
<Compile Include="LifecycleTest.cs" />
@@ -251,6 +254,7 @@
<ItemGroup>
<None Include="Apache.Ignite.Core.Tests.nunit" />
<None Include="Apache.Ignite.Core.Tests.snk" />
+ <None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
index f18be8c..bc1f08f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/FutureTest.cs
@@ -67,6 +67,7 @@ namespace Apache.Ignite.Core.Tests
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
+ Ignition.StopAll(true);
TestUtils.KillProcesses();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
new file mode 100644
index 0000000..29aea90
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSectionTest.cs
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests
+{
+ using System;
+ using System.Configuration;
+ using System.Linq;
+ using Apache.Ignite.Core.Impl.Common;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests <see cref="IgniteConfigurationSection"/>.
+ /// </summary>
+ public class IgniteConfigurationSectionTest
+ {
+ /// <summary>
+ /// Tests the read.
+ /// </summary>
+ [Test]
+ public void TestRead()
+ {
+ var section = (IgniteConfigurationSection) ConfigurationManager.GetSection("igniteConfiguration");
+
+ Assert.AreEqual("myGrid1", section.IgniteConfiguration.GridName);
+ Assert.AreEqual("cacheName", section.IgniteConfiguration.CacheConfiguration.Single().Name);
+ }
+
+ /// <summary>
+ /// Tests the ignite start.
+ /// </summary>
+ [Test]
+ public void TestIgniteStart()
+ {
+ Environment.SetEnvironmentVariable(Classpath.EnvIgniteNativeTestClasspath, "true");
+
+ using (var ignite = Ignition.StartFromApplicationConfiguration("igniteConfiguration"))
+ {
+ Assert.AreEqual("myGrid1", ignite.Name);
+ Assert.IsNotNull(ignite.GetCache<int, int>("cacheName"));
+ }
+
+ using (var ignite = Ignition.StartFromApplicationConfiguration("igniteConfiguration2"))
+ {
+ Assert.AreEqual("myGrid2", ignite.Name);
+ Assert.IsNotNull(ignite.GetCache<int, int>("cacheName2"));
+ }
+
+ using (var ignite = Ignition.StartFromApplicationConfiguration())
+ {
+ Assert.IsTrue(ignite.Name.StartsWith("myGrid"));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
new file mode 100644
index 0000000..d8c52ee
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
@@ -0,0 +1,554 @@
+/*
+ * 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.
+ */
+
+// ReSharper disable UnusedAutoPropertyAccessor.Global
+// ReSharper disable MemberCanBePrivate.Global
+namespace Apache.Ignite.Core.Tests
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+ using System.Threading;
+ using System.Xml;
+ using System.Xml.Schema;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Store;
+ using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Discovery.Tcp;
+ using Apache.Ignite.Core.Discovery.Tcp.Multicast;
+ using Apache.Ignite.Core.Events;
+ using Apache.Ignite.Core.Impl.Common;
+ using Apache.Ignite.Core.Lifecycle;
+ using Apache.Ignite.Core.Tests.Binary;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests <see cref="IgniteConfiguration"/> serialization.
+ /// </summary>
+ public class IgniteConfigurationSerializerTest
+ {
+ /// <summary>
+ /// Tests the predefined XML.
+ /// </summary>
+ [Test]
+ public void TestPredefinedXml()
+ {
+ var xml = @"<igniteConfig workDirectory='c:' JvmMaxMemoryMb='1024' MetricsLogFrequency='0:0:10'>
+ <localhost>127.1.1.1</localhost>
+ <binaryConfiguration>
+ <defaultNameMapper type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+NameMapper, Apache.Ignite.Core.Tests' bar='testBar' />
+ <types>
+ <string>Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+FooClass, Apache.Ignite.Core.Tests</string>
+ </types>
+ </binaryConfiguration>
+ <discoverySpi type='TcpDiscoverySpi' joinTimeout='0:1:0'>
+ <ipFinder type='TcpDiscoveryMulticastIpFinder' addressRequestAttempts='7' />
+ </discoverySpi>
+ <jvmOptions><string>-Xms1g</string><string>-Xmx4g</string></jvmOptions>
+ <lifecycleBeans>
+ <iLifecycleBean type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+LifecycleBean, Apache.Ignite.Core.Tests' foo='15' />
+ </lifecycleBeans>
+ <cacheConfiguration>
+ <cacheConfiguration cacheMode='Replicated'>
+ <queryEntities>
+ <queryEntity keyType='System.Int32' valueType='System.String'>
+ <fields>
+ <queryField name='length' fieldType='System.Int32' />
+ </fields>
+ <aliases>
+ <queryAlias fullName='somefield.field' alias='shortField' />
+ </aliases>
+ <indexes>
+ <queryIndex name='idx' indexType='Geospatial'>
+ <fields>
+ <queryIndexField name='indexFld' isDescending='true' />
+ </fields>
+ </queryIndex>
+ </indexes>
+ </queryEntity>
+ </queryEntities>
+ </cacheConfiguration>
+ <cacheConfiguration name='secondCache' />
+ </cacheConfiguration>
+ <includedEventTypes>
+ <int>42</int>
+ <int>TaskFailed</int>
+ <int>JobFinished</int>
+ </includedEventTypes>
+ </igniteConfig>";
+ var reader = XmlReader.Create(new StringReader(xml));
+
+ var cfg = IgniteConfigurationXmlSerializer.Deserialize(reader);
+
+ Assert.AreEqual("c:", cfg.WorkDirectory);
+ Assert.AreEqual("127.1.1.1", cfg.Localhost);
+ Assert.AreEqual(1024, cfg.JvmMaxMemoryMb);
+ Assert.AreEqual(TimeSpan.FromSeconds(10), cfg.MetricsLogFrequency);
+ Assert.AreEqual(TimeSpan.FromMinutes(1), ((TcpDiscoverySpi)cfg.DiscoverySpi).JoinTimeout);
+ Assert.AreEqual(7,
+ ((TcpDiscoveryMulticastIpFinder) ((TcpDiscoverySpi) cfg.DiscoverySpi).IpFinder).AddressRequestAttempts);
+ Assert.AreEqual(new[] { "-Xms1g", "-Xmx4g" }, cfg.JvmOptions);
+ Assert.AreEqual(15, ((LifecycleBean) cfg.LifecycleBeans.Single()).Foo);
+ Assert.AreEqual("testBar", ((NameMapper) cfg.BinaryConfiguration.DefaultNameMapper).Bar);
+ Assert.AreEqual(
+ "Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+FooClass, Apache.Ignite.Core.Tests",
+ cfg.BinaryConfiguration.Types.Single());
+ Assert.AreEqual(new[] {42, EventType.TaskFailed, EventType.JobFinished}, cfg.IncludedEventTypes);
+
+ Assert.AreEqual("secondCache", cfg.CacheConfiguration.Last().Name);
+
+ var cacheCfg = cfg.CacheConfiguration.First();
+
+ Assert.AreEqual(CacheMode.Replicated, cacheCfg.CacheMode);
+
+ var queryEntity = cacheCfg.QueryEntities.Single();
+ Assert.AreEqual(typeof(int), queryEntity.KeyType);
+ Assert.AreEqual(typeof(string), queryEntity.ValueType);
+ Assert.AreEqual("length", queryEntity.Fields.Single().Name);
+ Assert.AreEqual(typeof(int), queryEntity.Fields.Single().FieldType);
+ Assert.AreEqual("somefield.field", queryEntity.Aliases.Single().FullName);
+ Assert.AreEqual("shortField", queryEntity.Aliases.Single().Alias);
+ Assert.AreEqual(QueryIndexType.Geospatial, queryEntity.Indexes.Single().IndexType);
+ Assert.AreEqual("indexFld", queryEntity.Indexes.Single().Fields.Single().Name);
+ Assert.AreEqual(true, queryEntity.Indexes.Single().Fields.Single().IsDescending);
+ }
+
+ /// <summary>
+ /// Tests the serialize deserialize.
+ /// </summary>
+ [Test]
+ public void TestSerializeDeserialize()
+ {
+ // Test custom
+ CheckSerializeDeserialize(GetTestConfig());
+
+ // Test custom with different culture to make sure numbers are serialized properly
+ RunWithCustomCulture(() => CheckSerializeDeserialize(GetTestConfig()));
+
+ // Test default
+ CheckSerializeDeserialize(new IgniteConfiguration());
+ }
+
+ /// <summary>
+ /// Tests the schema validation.
+ /// </summary>
+ [Test]
+ public void TestSchemaValidation()
+ {
+ CheckSchemaValidation();
+
+ RunWithCustomCulture(CheckSchemaValidation);
+
+ // Check invalid xml
+ const string invalidXml =
+ @"<igniteConfiguration xmlns='http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection'>
+ <binaryConfiguration /><binaryConfiguration />
+ </igniteConfiguration>";
+
+ Assert.Throws<XmlSchemaValidationException>(() => CheckSchemaValidation(invalidXml));
+ }
+
+ /// <summary>
+ /// Checks the schema validation.
+ /// </summary>
+ private static void CheckSchemaValidation()
+ {
+ var sb = new StringBuilder();
+
+ using (var xmlWriter = XmlWriter.Create(sb))
+ {
+ IgniteConfigurationXmlSerializer.Serialize(GetTestConfig(), xmlWriter, "igniteConfiguration");
+ }
+
+ CheckSchemaValidation(sb.ToString());
+ }
+
+ /// <summary>
+ /// Checks the schema validation.
+ /// </summary>
+ /// <param name="xml">The XML.</param>
+ private static void CheckSchemaValidation(string xml)
+ {
+ var document = new XmlDocument();
+
+ document.Schemas.Add("http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection",
+ XmlReader.Create("IgniteConfigurationSection.xsd"));
+
+ document.Load(new StringReader(xml));
+
+ document.Validate(null);
+ }
+
+ /// <summary>
+ /// Checks the serialize deserialize.
+ /// </summary>
+ /// <param name="cfg">The config.</param>
+ private static void CheckSerializeDeserialize(IgniteConfiguration cfg)
+ {
+ var resCfg = SerializeDeserialize(cfg);
+
+ AssertReflectionEqual(cfg, resCfg);
+ }
+
+ /// <summary>
+ /// Serializes and deserializes a config.
+ /// </summary>
+ private static IgniteConfiguration SerializeDeserialize(IgniteConfiguration cfg)
+ {
+ var sb = new StringBuilder();
+
+ using (var xmlWriter = XmlWriter.Create(sb))
+ {
+ IgniteConfigurationXmlSerializer.Serialize(cfg, xmlWriter, "igniteConfig");
+ }
+
+ var xml = sb.ToString();
+
+ using (var xmlReader = XmlReader.Create(new StringReader(xml)))
+ {
+ xmlReader.MoveToContent();
+ return IgniteConfigurationXmlSerializer.Deserialize(xmlReader);
+ }
+ }
+
+ /// <summary>
+ /// Asserts equality with reflection.
+ /// </summary>
+ private static void AssertReflectionEqual(object x, object y)
+ {
+ var type = x.GetType();
+
+ Assert.AreEqual(type, y.GetType());
+
+ if (type.IsValueType || type == typeof (string) || type.IsSubclassOf(typeof (Type)))
+ {
+ Assert.AreEqual(x, y);
+ return;
+ }
+
+ var props = type.GetProperties();
+
+ foreach (var propInfo in props)
+ {
+ var propType = propInfo.PropertyType;
+
+ var xVal = propInfo.GetValue(x, null);
+ var yVal = propInfo.GetValue(y, null);
+
+ if (xVal == null || yVal == null)
+ {
+ Assert.IsNull(xVal);
+ Assert.IsNull(yVal);
+ }
+ else if (propType != typeof(string) && propType.IsGenericType
+ && propType.GetGenericTypeDefinition() == typeof (ICollection<>))
+ {
+ var xCol = ((IEnumerable) xVal).OfType<object>().ToList();
+ var yCol = ((IEnumerable) yVal).OfType<object>().ToList();
+
+ Assert.AreEqual(xCol.Count, yCol.Count);
+
+ for (int i = 0; i < xCol.Count; i++)
+ AssertReflectionEqual(xCol[i], yCol[i]);
+ }
+ else
+ {
+ AssertReflectionEqual(xVal, yVal);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the test configuration.
+ /// </summary>
+ private static IgniteConfiguration GetTestConfig()
+ {
+ return new IgniteConfiguration
+ {
+ GridName = "gridName",
+ JvmOptions = new[] {"1", "2"},
+ Localhost = "localhost11",
+ JvmClasspath = "classpath",
+ Assemblies = new[] {"asm1", "asm2", "asm3"},
+ BinaryConfiguration = new BinaryConfiguration
+ {
+ TypeConfigurations = new[]
+ {
+ new BinaryTypeConfiguration
+ {
+ IsEnum = true,
+ KeepDeserialized = true,
+ AffinityKeyFieldName = "affKeyFieldName",
+ TypeName = "typeName",
+ IdMapper = new IdMapper(),
+ NameMapper = new NameMapper(),
+ Serializer = new TestSerializer()
+ }
+ },
+ DefaultIdMapper = new IdMapper(),
+ DefaultKeepDeserialized = true,
+ DefaultNameMapper = new NameMapper(),
+ DefaultSerializer = new TestSerializer()
+ },
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration("cacheName")
+ {
+ AtomicWriteOrderMode = CacheAtomicWriteOrderMode.Primary,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ Backups = 15,
+ CacheMode = CacheMode.Partitioned,
+ CacheStoreFactory = new TestCacheStoreFactory(),
+ CopyOnRead = true,
+ EagerTtl = true,
+ EnableSwap = true,
+ EvictSynchronized = true,
+ EvictSynchronizedConcurrencyLevel = 13,
+ EvictSynchronizedKeyBufferSize = 14,
+ EvictSynchronizedTimeout = TimeSpan.FromMinutes(3),
+ Invalidate = true,
+ KeepBinaryInStore = true,
+ LoadPreviousValue = true,
+ LockTimeout = TimeSpan.FromSeconds(56),
+ LongQueryWarningTimeout = TimeSpan.FromSeconds(99),
+ MaxConcurrentAsyncOperations = 24,
+ MaxEvictionOverflowRatio = 5.6F,
+ MemoryMode = CacheMemoryMode.OffheapValues,
+ OffHeapMaxMemory = 567,
+ QueryEntities = new[]
+ {
+ new QueryEntity
+ {
+ Fields = new[]
+ {
+ new QueryField("field", typeof (int))
+ },
+ Indexes = new[]
+ {
+ new QueryIndex("field") { IndexType = QueryIndexType.FullText }
+ },
+ Aliases = new[]
+ {
+ new QueryAlias("field.field", "fld")
+ },
+ KeyType = typeof (string),
+ ValueType = typeof (long)
+ },
+ },
+ ReadFromBackup = true,
+ RebalanceBatchSize = 33,
+ RebalanceDelay = TimeSpan.MaxValue,
+ RebalanceMode = CacheRebalanceMode.Sync,
+ RebalanceThrottle = TimeSpan.FromHours(44),
+ RebalanceTimeout = TimeSpan.FromMinutes(8),
+ SqlEscapeAll = true,
+ SqlOnheapRowCacheSize = 679,
+ StartSize = 1023,
+ WriteBehindBatchSize = 45,
+ WriteBehindEnabled = true,
+ WriteBehindFlushFrequency = TimeSpan.FromSeconds(5),
+ WriteBehindFlushSize = 66,
+ WriteBehindFlushThreadCount = 2,
+ WriteSynchronizationMode = CacheWriteSynchronizationMode.FullAsync
+ }
+ },
+ ClientMode = true,
+ DiscoverySpi = new TcpDiscoverySpi
+ {
+ NetworkTimeout = TimeSpan.FromSeconds(1),
+ SocketTimeout = TimeSpan.FromSeconds(2),
+ AckTimeout = TimeSpan.FromSeconds(3),
+ JoinTimeout = TimeSpan.FromSeconds(4),
+ MaxAckTimeout = TimeSpan.FromSeconds(5),
+ IpFinder = new TcpDiscoveryMulticastIpFinder
+ {
+ TimeToLive = 110,
+ MulticastGroup = "multicastGroup",
+ AddressRequestAttempts = 10,
+ MulticastPort = 987,
+ ResponseTimeout = TimeSpan.FromDays(1),
+ LocalAddress = "127.0.0.2",
+ Endpoints = new[] {"", "abc"}
+ }
+ },
+ IgniteHome = "igniteHome",
+ IncludedEventTypes = EventType.CacheQueryAll,
+ JvmDllPath = @"c:\jvm",
+ JvmInitialMemoryMb = 1024,
+ JvmMaxMemoryMb = 2048,
+ LifecycleBeans = new[] {new LifecycleBean(), new LifecycleBean() },
+ MetricsExpireTime = TimeSpan.FromSeconds(15),
+ MetricsHistorySize = 45,
+ MetricsLogFrequency = TimeSpan.FromDays(2),
+ MetricsUpdateFrequency = TimeSpan.MinValue,
+ NetworkSendRetryCount = 7,
+ NetworkSendRetryDelay = TimeSpan.FromSeconds(98),
+ NetworkTimeout = TimeSpan.FromMinutes(4),
+ SuppressWarnings = true,
+ WorkDirectory = @"c:\work"
+ };
+ }
+
+ /// <summary>
+ /// Runs the with custom culture.
+ /// </summary>
+ /// <param name="action">The action.</param>
+ private static void RunWithCustomCulture(Action action)
+ {
+ RunWithCulture(action, CultureInfo.InvariantCulture);
+ RunWithCulture(action, CultureInfo.GetCultureInfo("ru-RU"));
+ }
+
+ /// <summary>
+ /// Runs the with culture.
+ /// </summary>
+ /// <param name="action">The action.</param>
+ /// <param name="cultureInfo">The culture information.</param>
+ private static void RunWithCulture(Action action, CultureInfo cultureInfo)
+ {
+ var oldCulture = Thread.CurrentThread.CurrentCulture;
+
+ try
+ {
+ Thread.CurrentThread.CurrentCulture = cultureInfo;
+
+ action();
+ }
+ finally
+ {
+ Thread.CurrentThread.CurrentCulture = oldCulture;
+ }
+ }
+
+ /// <summary>
+ /// Test bean.
+ /// </summary>
+ public class LifecycleBean : ILifecycleBean
+ {
+ /// <summary>
+ /// Gets or sets the foo.
+ /// </summary>
+ /// <value>
+ /// The foo.
+ /// </value>
+ public int Foo { get; set; }
+
+ /// <summary>
+ /// This method is called when lifecycle event occurs.
+ /// </summary>
+ /// <param name="evt">Lifecycle event.</param>
+ public void OnLifecycleEvent(LifecycleEventType evt)
+ {
+ // No-op.
+ }
+ }
+
+ /// <summary>
+ /// Test mapper.
+ /// </summary>
+ public class NameMapper : IBinaryNameMapper
+ {
+ /// <summary>
+ /// Gets or sets the bar.
+ /// </summary>
+ /// <value>
+ /// The bar.
+ /// </value>
+ public string Bar { get; set; }
+
+ /// <summary>
+ /// Gets the type name.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <returns>
+ /// Type name.
+ /// </returns>
+ public string GetTypeName(string name)
+ {
+ return name;
+ }
+
+ /// <summary>
+ /// Gets the field name.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <returns>
+ /// Field name.
+ /// </returns>
+ public string GetFieldName(string name)
+ {
+ return name;
+ }
+ }
+
+ /// <summary>
+ /// Serializer.
+ /// </summary>
+ public class TestSerializer : IBinarySerializer
+ {
+ /// <summary>
+ /// Write portalbe object.
+ /// </summary>
+ /// <param name="obj">Object.</param>
+ /// <param name="writer">Poratble writer.</param>
+ public void WriteBinary(object obj, IBinaryWriter writer)
+ {
+ // No-op.
+ }
+
+ /// <summary>
+ /// Read binary object.
+ /// </summary>
+ /// <param name="obj">Instantiated empty object.</param>
+ /// <param name="reader">Poratble reader.</param>
+ public void ReadBinary(object obj, IBinaryReader reader)
+ {
+ // No-op.
+ }
+ }
+
+ /// <summary>
+ /// Test class.
+ /// </summary>
+ public class FooClass
+ {
+ // No-op.
+ }
+
+ /// <summary>
+ /// Test factory.
+ /// </summary>
+ public class TestCacheStoreFactory : IFactory<ICacheStore>
+ {
+ /// <summary>
+ /// Creates an instance of the cache store.
+ /// </summary>
+ /// <returns>
+ /// New instance of the cache store.
+ /// </returns>
+ public ICacheStore CreateInstance()
+ {
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config
new file mode 100644
index 0000000..c290c83
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ 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.
+-->
+
+<configuration>
+ <configSections>
+ <section name="igniteConfiguration" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" />
+ <section name="igniteConfiguration2" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" />
+ </configSections>
+
+ <igniteConfiguration xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection" gridName="myGrid1">
+ <discoverySpi type="TcpDiscoverySpi">
+ <ipFinder type="TcpDiscoveryStaticIpFinder">
+ <endpoints>
+ <string>127.0.0.1:47500..47501</string>
+ </endpoints>
+ </ipFinder>
+ </discoverySpi>
+
+ <cacheConfiguration>
+ <cacheConfiguration name="cacheName" />
+ </cacheConfiguration>
+ </igniteConfiguration>
+
+ <igniteConfiguration2 gridName="myGrid2">
+ <discoverySpi type="TcpDiscoverySpi">
+ <ipFinder type="TcpDiscoveryStaticIpFinder">
+ <endpoints>
+ <string>127.0.0.1:47500..47501</string>
+ </endpoints>
+ </ipFinder>
+ </discoverySpi>
+
+ <cacheConfiguration>
+ <cacheConfiguration name="cacheName2" />
+ </cacheConfiguration>
+ </igniteConfiguration2>
+
+</configuration>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
index e2efd0a..d0ef352 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -60,7 +60,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Binary\Package-Info.cs" />
@@ -183,6 +185,7 @@
<Compile Include="Events\TaskEvent.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IgniteConfiguration.cs" />
+ <Compile Include="IgniteConfigurationSection.cs" />
<Compile Include="Ignition.cs" />
<Compile Include="IIgnite.cs" />
<Compile Include="Impl\Binary\BinaryEnum.cs" />
@@ -222,11 +225,13 @@
<Compile Include="Impl\Collections\MultiValueDictionary.cs" />
<Compile Include="Impl\Collections\ReadOnlyCollection.cs" />
<Compile Include="Impl\Collections\ReadOnlyDictionary.cs" />
+ <Compile Include="Impl\Common\BooleanLowerCaseConverter.cs" />
<Compile Include="Impl\Common\CancelledTask.cs" />
<Compile Include="Impl\Common\Classpath.cs" />
<Compile Include="Impl\Common\CopyOnWriteConcurrentDictionary.cs" />
<Compile Include="Impl\Common\DelegateConverter.cs" />
<Compile Include="Impl\Common\DelegateTypeDescriptor.cs" />
+ <Compile Include="Impl\Events\EventTypeConverter.cs" />
<Compile Include="Impl\Common\Fnv1Hash.cs" />
<Compile Include="Impl\Common\Future.cs" />
<Compile Include="Impl\Common\FutureConverter.cs" />
@@ -234,10 +239,12 @@
<Compile Include="Impl\Common\IgniteArgumentCheck.cs" />
<Compile Include="Impl\Common\IFutureConverter.cs" />
<Compile Include="Impl\Common\IFutureInternal.cs" />
+ <Compile Include="Impl\Common\IgniteConfigurationXmlSerializer.cs" />
<Compile Include="Impl\Common\IgniteHome.cs" />
<Compile Include="Impl\Common\LoadedAssembliesResolver.cs" />
<Compile Include="Impl\Common\ResizeableArray.cs" />
<Compile Include="Impl\Common\TypeCaster.cs" />
+ <Compile Include="Impl\Common\TypeStringConverter.cs" />
<Compile Include="Impl\Compute\Closure\ComputeAbstractClosureTask.cs" />
<Compile Include="Impl\Compute\Closure\ComputeActionJob.cs" />
<Compile Include="Impl\Compute\Closure\ComputeFuncJob.cs" />
@@ -434,6 +441,10 @@
<ItemGroup>
<None Include="Apache.Ignite.Core.ruleset" />
<None Include="Apache.Ignite.Core.snk" />
+ <None Include="IgniteConfigurationSection.xsd">
+ <SubType>Designer</SubType>
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinarySerializer.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinarySerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinarySerializer.cs
index 23dc811..3f924eb 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinarySerializer.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinarySerializer.cs
@@ -23,17 +23,17 @@ namespace Apache.Ignite.Core.Binary
public interface IBinarySerializer
{
/// <summary>
- /// Write portalbe object.
+ /// Write binary object.
/// </summary>
/// <param name="obj">Object.</param>
- /// <param name="writer">Poratble writer.</param>
+ /// <param name="writer">Binary writer.</param>
void WriteBinary(object obj, IBinaryWriter writer);
/// <summary>
/// Read binary object.
/// </summary>
/// <param name="obj">Instantiated empty object.</param>
- /// <param name="reader">Poratble reader.</param>
+ /// <param name="reader">Binary reader.</param>
void ReadBinary(object obj, IBinaryReader reader);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.cs
new file mode 100644
index 0000000..51b963e
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.cs
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core
+{
+ using System.Configuration;
+ using System.Text;
+ using System.Xml;
+ using Apache.Ignite.Core.Impl.Common;
+
+ /// <summary>
+ /// Ignite configuration section for app.config and web.config files.
+ /// </summary>
+ public class IgniteConfigurationSection : ConfigurationSection
+ {
+ /// <summary>
+ /// Gets or sets the ignite configuration.
+ /// </summary>
+ /// <value>
+ /// The ignite configuration.
+ /// </value>
+ public IgniteConfiguration IgniteConfiguration { get; private set; }
+
+ /// <summary>
+ /// Reads XML from the configuration file.
+ /// </summary>
+ /// <param name="reader">The reader object, which reads from the configuration file.</param>
+ protected override void DeserializeSection(XmlReader reader)
+ {
+ IgniteArgumentCheck.NotNull(reader, "reader");
+
+ IgniteConfiguration = IgniteConfigurationXmlSerializer.Deserialize(reader);
+ }
+
+ /// <summary>
+ /// Creates an XML string containing an unmerged view of the <see cref="ConfigurationSection" />
+ /// object as a single section to write to a file.
+ /// </summary>
+ /// <param name="parentElement">The <see cref="ConfigurationElement" />
+ /// instance to use as the parent when performing the un-merge.</param>
+ /// <param name="name">The name of the section to create.</param>
+ /// <param name="saveMode">The <see cref="ConfigurationSaveMode" /> instance
+ /// to use when writing to a string.</param>
+ /// <returns>
+ /// An XML string containing an unmerged view of the <see cref="ConfigurationSection" /> object.
+ /// </returns>
+ protected override string SerializeSection(ConfigurationElement parentElement, string name,
+ ConfigurationSaveMode saveMode)
+ {
+ IgniteArgumentCheck.NotNull(parentElement, "parentElement");
+ IgniteArgumentCheck.NotNullOrEmpty(name, "name");
+
+ if (IgniteConfiguration == null)
+ return string.Format("<{0} />", name);
+
+ var sb = new StringBuilder();
+
+ using (var xmlWriter = XmlWriter.Create(sb))
+ {
+ IgniteConfigurationXmlSerializer.Serialize(IgniteConfiguration, xmlWriter, name);
+
+ return sb.ToString();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
new file mode 100644
index 0000000..5181217
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
@@ -0,0 +1,281 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ 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.
+-->
+
+<xs:schema id="IgniteConfigurationSection"
+ targetNamespace="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection"
+ elementFormDefault="qualified"
+ xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection"
+ xmlns:mstns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:element name="igniteConfiguration">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="binaryConfiguration" minOccurs="0">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="typeConfigurations" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="binaryTypeConfiguration">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="nameMapper" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="idMapper" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="serializer" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="typeName" type="xs:string" />
+ <xs:attribute name="affinityKeyFieldName" type="xs:string" />
+ <xs:attribute name="keepDeserialized" type="xs:string" />
+ <xs:attribute name="isEnum" type="xs:boolean" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="defaultNameMapper" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="defaultIdMapper" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="defaultSerializer" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="defaultKeepDeserialized" type="xs:boolean" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="cacheConfiguration" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="cacheConfiguration" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="cacheStoreFactory" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="queryEntities" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="queryEntity" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:all>
+ <xs:element name="fields" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="queryField" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="fieldType" type="xs:string" />
+ <xs:attribute name="fieldTypeName" type="xs:string" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="aliases" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="queryAlias" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="fullName" type="xs:string" use="required" />
+ <xs:attribute name="alias" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="indexes" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="queryIndex" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="fields" minOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="queryIndexField" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="isDescending" type="xs:boolean" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string" />
+ <xs:attribute name="indexType" type="xs:string" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="keyTypeName" type="xs:string"/>
+ <xs:attribute name="keyType" type="xs:string" />
+ <xs:attribute name="valueTypeName" type="xs:string" />
+ <xs:attribute name="valueType" type="xs:string" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="name" type="xs:string" />
+ <xs:attribute name="writeSynchronizationMode" type="xs:string" />
+ <xs:attribute name="evictSynchronized" type="xs:boolean" />
+ <xs:attribute name="evictSynchronizedKeyBufferSize" type="xs:int" />
+ <xs:attribute name="evictSynchronizedConcurrencyLevel" type="xs:int" />
+ <xs:attribute name="evictSynchronizedTimeout" type="xs:string" />
+ <xs:attribute name="maxEvictionOverflowRatio" type="xs:decimal" />
+ <xs:attribute name="startSize" type="xs:int" />
+ <xs:attribute name="loadPreviousValue" type="xs:string" />
+ <xs:attribute name="atomicityMode" type="xs:string" />
+ <xs:attribute name="atomicWriteOrderMode" type="xs:string" />
+ <xs:attribute name="backups" type="xs:int" />
+ <xs:attribute name="lockTimeout" type="xs:string" />
+ <xs:attribute name="invalidate" type="xs:boolean" />
+ <xs:attribute name="rebalanceMode" type="xs:string" />
+ <xs:attribute name="rebalanceBatchSize" type="xs:int" />
+ <xs:attribute name="enableSwap" type="xs:boolean" />
+ <xs:attribute name="maxConcurrentAsyncOperations" type="xs:int" />
+ <xs:attribute name="writeBehindEnabled" type="xs:boolean" />
+ <xs:attribute name="writeBehindFlushSize" type="xs:int" />
+ <xs:attribute name="writeBehindFlushThreadCount" type="xs:int" />
+ <xs:attribute name="writeBehindBatchSize" type="xs:int" />
+ <xs:attribute name="rebalanceTimeout" type="xs:string" />
+ <xs:attribute name="rebalanceDelay" type="xs:string" />
+ <xs:attribute name="rebalanceThrottle" type="xs:string" />
+ <xs:attribute name="offHeapMaxMemory" type="xs:int" />
+ <xs:attribute name="memoryMode" type="xs:string" />
+ <xs:attribute name="longQueryWarningTimeout" type="xs:string" />
+ <xs:attribute name="sqlEscapeAll" type="xs:boolean" />
+ <xs:attribute name="sqlOnheapRowCacheSize" type="xs:int" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="jvmOptions" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" name="string" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="assemblies" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" name="string" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="lifecycleBeans" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" name="iLifecycleBean">
+ <xs:complexType>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="discoverySpi" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="ipFinder" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="endpoints" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" name="string" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="type" type="xs:string" use="required" />
+ <xs:attribute name="localAddress" type="xs:string" />
+ <xs:attribute name="multicastGroup" type="xs:string" />
+ <xs:attribute name="multicastPort" type="xs:int" />
+ <xs:attribute name="addressRequestAttempts" type="xs:int" />
+ <xs:attribute name="responseTimeout" type="xs:string" />
+ <xs:attribute name="timeToLive" type="xs:byte" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="socketTimeout" type="xs:string" />
+ <xs:attribute name="ackTimeout" type="xs:string" />
+ <xs:attribute name="maxAckTimeout" type="xs:string" />
+ <xs:attribute name="networkTimeout" type="xs:string" />
+ <xs:attribute name="joinTimeout" type="xs:string" />
+ <xs:attribute name="type" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="includedEventTypes" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" name="int" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
+ <xs:attribute name="gridName" type="xs:string" />
+ <xs:attribute name="jvmDllPath" type="xs:string" />
+ <xs:attribute name="igniteHome" type="xs:string" />
+ <xs:attribute name="jvmClasspath" type="xs:string" />
+ <xs:attribute name="suppressWarnings" type="xs:boolean" />
+ <xs:attribute name="jvmInitialMemoryMb" type="xs:int" />
+ <xs:attribute name="jvmMaxMemoryMb" type="xs:int" />
+ <xs:attribute name="clientMode" type="xs:boolean" />
+ <xs:attribute name="metricsExpireTime" type="xs:string" />
+ <xs:attribute name="metricsHistorySize" type="xs:int" />
+ <xs:attribute name="metricsLogFrequency" type="xs:string" />
+ <xs:attribute name="metricsUpdateFrequency" type="xs:string" />
+ <xs:attribute name="networkSendRetryCount" type="xs:int" />
+ <xs:attribute name="networkSendRetryDelay" type="xs:string" />
+ <xs:attribute name="networkTimeout" type="xs:string" />
+ <xs:attribute name="workDirectory" type="xs:string" />
+ <xs:attribute name="localhost" type="xs:string" />
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
index 0549010..70d7422 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs
@@ -20,6 +20,7 @@ namespace Apache.Ignite.Core
{
using System;
using System.Collections.Generic;
+ using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
@@ -116,6 +117,44 @@ namespace Apache.Ignite.Core
}
/// <summary>
+ /// Reads <see cref="IgniteConfiguration"/> from first <see cref="IgniteConfigurationSection"/> in the
+ /// application configuration and starts Ignite.
+ /// </summary>
+ /// <returns>Started Ignite.</returns>
+ public static IIgnite StartFromApplicationConfiguration()
+ {
+ var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
+
+ var section = cfg.Sections.OfType<IgniteConfigurationSection>().FirstOrDefault();
+
+ if (section == null)
+ throw new ConfigurationErrorsException(
+ string.Format("Could not find {0} in current application configuration",
+ typeof(IgniteConfigurationSection).Name));
+
+ return Start(section.IgniteConfiguration);
+ }
+
+ /// <summary>
+ /// Reads <see cref="IgniteConfiguration"/> from application configuration
+ /// <see cref="IgniteConfigurationSection"/> with specified name and starts Ignite.
+ /// </summary>
+ /// <param name="sectionName">Name of the section.</param>
+ /// <returns>Started Ignite.</returns>
+ public static IIgnite StartFromApplicationConfiguration(string sectionName)
+ {
+ IgniteArgumentCheck.NotNullOrEmpty(sectionName, "sectionName");
+
+ var section = ConfigurationManager.GetSection(sectionName) as IgniteConfigurationSection;
+
+ if (section == null)
+ throw new ConfigurationErrorsException(string.Format("Could not find {0} with name '{1}'",
+ typeof(IgniteConfigurationSection).Name, sectionName));
+
+ return Start(section.IgniteConfiguration);
+ }
+
+ /// <summary>
/// Starts Ignite with given configuration.
/// </summary>
/// <returns>Started Ignite.</returns>
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/BooleanLowerCaseConverter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/BooleanLowerCaseConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/BooleanLowerCaseConverter.cs
new file mode 100644
index 0000000..e8cced2
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/BooleanLowerCaseConverter.cs
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Common
+{
+ using System;
+ using System.ComponentModel;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Globalization;
+
+ /// <summary>
+ /// Bollean converter that returns lower-case strings, for XML serialization.
+ /// </summary>
+ internal class BooleanLowerCaseConverter : BooleanConverter
+ {
+ /// <summary>
+ /// Default instance.
+ /// </summary>
+ public static readonly BooleanLowerCaseConverter Instance = new BooleanLowerCaseConverter();
+
+ /// <summary>
+ /// Converts the given value object to the specified type, using the specified context and culture information.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="culture">
+ /// A <see cref="CultureInfo" />. If null is passed, the current culture is assumed.
+ /// </param>
+ /// <param name="value">The <see cref="object" /> to convert.</param>
+ /// <param name="destinationType">
+ /// The <see cref="Type" /> to convert the <paramref name="value" /> parameter to.
+ /// </param>
+ /// <returns>
+ /// An <see cref="object" /> that represents the converted value.
+ /// </returns>
+ [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
+ [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "2")]
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
+ Type destinationType)
+ {
+ if (destinationType == typeof (string))
+ return value.ToString().ToLowerInvariant();
+
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs
new file mode 100644
index 0000000..af25bfa
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/IgniteConfigurationXmlSerializer.cs
@@ -0,0 +1,410 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Common
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Configuration;
+ using System.Diagnostics;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
+ using System.Reflection;
+ using System.Xml;
+ using Apache.Ignite.Core.Impl.Events;
+
+ /// <summary>
+ /// Serializes <see cref="IgniteConfiguration"/> to XML.
+ /// </summary>
+ internal static class IgniteConfigurationXmlSerializer
+ {
+ /** Attribute that specifies a type for abstract properties, such as IpFinder. */
+ private const string TypNameAttribute = "type";
+
+ /** Xmlns. */
+ private const string XmlnsAttribute = "xmlns";
+
+ /** Schema. */
+ private const string Schema = "http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection";
+
+ /// <summary>
+ /// Deserializes <see cref="IgniteConfiguration"/> from specified <see cref="XmlReader"/>.
+ /// </summary>
+ /// <param name="reader">The reader.</param>
+ /// <returns>Resulting <see cref="IgniteConfiguration"/>.</returns>
+ public static IgniteConfiguration Deserialize(XmlReader reader)
+ {
+ IgniteArgumentCheck.NotNull(reader, "reader");
+
+ var cfg = new IgniteConfiguration();
+
+ if (reader.NodeType == XmlNodeType.Element || reader.Read())
+ ReadElement(reader, cfg);
+
+ return cfg;
+ }
+
+ /// <summary>
+ /// Serializes specified <see cref="IgniteConfiguration" /> to <see cref="XmlWriter" />.
+ /// </summary>
+ /// <param name="configuration">The configuration.</param>
+ /// <param name="writer">The writer.</param>
+ /// <param name="rootElementName">Name of the root element.</param>
+ public static void Serialize(IgniteConfiguration configuration, XmlWriter writer, string rootElementName)
+ {
+ IgniteArgumentCheck.NotNull(configuration, "configuration");
+ IgniteArgumentCheck.NotNull(writer, "writer");
+ IgniteArgumentCheck.NotNullOrEmpty(rootElementName, "rootElementName");
+
+ WriteElement(configuration, writer, rootElementName, typeof(IgniteConfiguration));
+ }
+
+ /// <summary>
+ /// Writes new element.
+ /// </summary>
+ private static void WriteElement(object obj, XmlWriter writer, string rootElementName, Type valueType,
+ PropertyInfo property = null)
+ {
+ if (valueType == typeof(IgniteConfiguration))
+ writer.WriteStartElement(rootElementName, Schema); // write xmlns for the root element
+ else
+ writer.WriteStartElement(rootElementName);
+
+ if (IsBasicType(valueType))
+ WriteBasicProperty(obj, writer, valueType, property);
+ else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof (ICollection<>))
+ WriteCollectionProperty(obj, writer, valueType, property);
+ else
+ WriteComplexProperty(obj, writer, valueType);
+
+ writer.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Writes the property of a basic type (primitives, strings, types).
+ /// </summary>
+ [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
+ private static void WriteBasicProperty(object obj, XmlWriter writer, Type valueType, PropertyInfo property)
+ {
+ var converter = GetConverter(property, valueType);
+
+ var stringValue = converter.ConvertToInvariantString(obj);
+
+ writer.WriteString(stringValue);
+ }
+
+ /// <summary>
+ /// Writes the collection property.
+ /// </summary>
+ private static void WriteCollectionProperty(object obj, XmlWriter writer, Type valueType, PropertyInfo property)
+ {
+ var elementType = valueType.GetGenericArguments().Single();
+
+ var elementTypeName = PropertyNameToXmlName(elementType.Name);
+
+ foreach (var element in (IEnumerable)obj)
+ WriteElement(element, writer, elementTypeName, elementType, property);
+ }
+
+ /// <summary>
+ /// Writes the complex property (nested object).
+ /// </summary>
+ [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")]
+ private static void WriteComplexProperty(object obj, XmlWriter writer, Type valueType)
+ {
+ var props = GetNonDefaultProperties(obj).ToList();
+
+ // Specify type for interfaces and abstract classes
+ if (valueType.IsAbstract)
+ writer.WriteAttributeString(TypNameAttribute, TypeStringConverter.Convert(obj.GetType()));
+
+ // Write attributes
+ foreach (var prop in props.Where(p => IsBasicType(p.PropertyType)))
+ {
+ var converter = GetConverter(prop, prop.PropertyType);
+ var stringValue = converter.ConvertToInvariantString(prop.GetValue(obj, null));
+ writer.WriteAttributeString(PropertyNameToXmlName(prop.Name), stringValue);
+ }
+
+ // Write elements
+ foreach (var prop in props.Where(p => !IsBasicType(p.PropertyType)))
+ WriteElement(prop.GetValue(obj, null), writer, PropertyNameToXmlName(prop.Name),
+ prop.PropertyType, prop);
+ }
+
+ /// <summary>
+ /// Reads the element.
+ /// </summary>
+ private static void ReadElement(XmlReader reader, object target)
+ {
+ var targetType = target.GetType();
+
+ // Read attributes
+ while (reader.MoveToNextAttribute())
+ {
+ var name = reader.Name;
+ var val = reader.Value;
+
+ SetProperty(target, name, val);
+ }
+
+ // Read content
+ reader.MoveToElement();
+
+ while (reader.Read())
+ {
+ if (reader.NodeType != XmlNodeType.Element)
+ continue;
+
+ var name = reader.Name;
+ var prop = GetPropertyOrThrow(name, reader.Value, targetType);
+ var propType = prop.PropertyType;
+
+ if (IsBasicType(propType))
+ {
+ // Regular property in xmlElement form
+ SetProperty(target, name, reader.ReadString());
+ }
+ else if (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof (ICollection<>))
+ {
+ // Collection
+ ReadCollectionProperty(reader, prop, target);
+ }
+ else
+ {
+ // Nested object (complex property)
+ prop.SetValue(target, ReadComplexProperty(reader, propType, prop.Name, targetType), null);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Reads the complex property (nested object).
+ /// </summary>
+ private static object ReadComplexProperty(XmlReader reader, Type propType, string propName, Type targetType)
+ {
+ if (propType.IsAbstract)
+ {
+ var typeName = reader.GetAttribute(TypNameAttribute);
+
+ var derivedTypes = GetConcreteDerivedTypes(propType);
+
+ propType = typeName == null
+ ? null
+ : Type.GetType(typeName, false) ?? derivedTypes.FirstOrDefault(x => x.Name == typeName);
+
+ if (propType == null)
+ {
+ var message = string.Format("'type' attribute is required for '{0}.{1}' property", targetType.Name,
+ propName);
+
+ if (typeName != null)
+ {
+ message += ", specified type cannot be resolved: " + typeName;
+ }
+ else if (derivedTypes.Any())
+ message += ", possible values are: " + string.Join(", ", derivedTypes.Select(x => x.Name));
+
+ throw new ConfigurationErrorsException(message);
+ }
+ }
+
+ var nestedVal = Activator.CreateInstance(propType);
+
+ using (var subReader = reader.ReadSubtree())
+ {
+ subReader.Read(); // read first element
+
+ ReadElement(subReader, nestedVal);
+ }
+
+ return nestedVal;
+ }
+
+ /// <summary>
+ /// Reads the collection.
+ /// </summary>
+ private static void ReadCollectionProperty(XmlReader reader, PropertyInfo prop, object target)
+ {
+ var elementType = prop.PropertyType.GetGenericArguments().Single();
+
+ var listType = typeof (List<>).MakeGenericType(elementType);
+
+ var list = (IList) Activator.CreateInstance(listType);
+
+ var converter = IsBasicType(elementType) ? GetConverter(prop, elementType) : null;
+
+ using (var subReader = reader.ReadSubtree())
+ {
+ subReader.Read(); // skip list head
+ while (subReader.Read())
+ {
+ if (subReader.NodeType != XmlNodeType.Element)
+ continue;
+
+ if (subReader.Name != PropertyNameToXmlName(elementType.Name))
+ throw new ConfigurationErrorsException(
+ string.Format("Invalid list element in IgniteConfiguration: expected '{0}', but was '{1}'",
+ PropertyNameToXmlName(elementType.Name), subReader.Name));
+
+ list.Add(converter != null
+ ? converter.ConvertFromInvariantString(subReader.ReadString())
+ : ReadComplexProperty(subReader, elementType, prop.Name, target.GetType()));
+ }
+ }
+
+ prop.SetValue(target, list, null);
+ }
+
+ /// <summary>
+ /// Sets the property.
+ /// </summary>
+ private static void SetProperty(object target, string propName, string propVal)
+ {
+ if (propName == TypNameAttribute || propName == XmlnsAttribute)
+ return;
+
+ var type = target.GetType();
+ var property = GetPropertyOrThrow(propName, propVal, type);
+
+ var converter = GetConverter(property, property.PropertyType);
+
+ var convertedVal = converter.ConvertFromInvariantString(propVal);
+
+ property.SetValue(target, convertedVal, null);
+ }
+
+ /// <summary>
+ /// Gets concrete derived types.
+ /// </summary>
+ private static List<Type> GetConcreteDerivedTypes(Type type)
+ {
+ return type.Assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract && type.IsAssignableFrom(t)).ToList();
+ }
+
+ /// <summary>
+ /// Gets specified property from a type or throws an exception.
+ /// </summary>
+ private static PropertyInfo GetPropertyOrThrow(string propName, string propVal, Type type)
+ {
+ var property = type.GetProperty(XmlNameToPropertyName(propName));
+
+ if (property == null)
+ throw new ConfigurationErrorsException(
+ string.Format(
+ "Invalid IgniteConfiguration attribute '{0}={1}', there is no such property on '{2}'",
+ propName, propVal, type));
+
+ return property;
+ }
+
+ /// <summary>
+ /// Converts an XML name to CLR name.
+ /// </summary>
+ private static string XmlNameToPropertyName(string name)
+ {
+ Debug.Assert(name.Length > 0);
+
+ if (name == "int")
+ return "Int32"; // allow aliases
+
+ return char.ToUpperInvariant(name[0]) + name.Substring(1);
+ }
+
+ /// <summary>
+ /// Converts a CLR name to XML name.
+ /// </summary>
+ private static string PropertyNameToXmlName(string name)
+ {
+ Debug.Assert(name.Length > 0);
+
+ if (name == "Int32")
+ return "int"; // allow aliases
+
+ return char.ToLowerInvariant(name[0]) + name.Substring(1);
+ }
+
+ /// <summary>
+ /// Determines whether specified type is a basic built-in type.
+ /// </summary>
+ private static bool IsBasicType(Type propertyType)
+ {
+ Debug.Assert(propertyType != null);
+
+ return propertyType.IsValueType || propertyType == typeof(string) || propertyType == typeof(Type);
+ }
+
+ /// <summary>
+ /// Gets converter for a property.
+ /// </summary>
+ private static TypeConverter GetConverter(PropertyInfo property, Type propertyType)
+ {
+ Debug.Assert(property != null);
+ Debug.Assert(propertyType != null);
+
+ if (propertyType.IsEnum)
+ return new GenericEnumConverter(propertyType);
+
+ if (propertyType == typeof (Type))
+ return TypeStringConverter.Instance;
+
+ if (propertyType == typeof(bool))
+ return BooleanLowerCaseConverter.Instance;
+
+ if (property.DeclaringType == typeof (IgniteConfiguration) && property.Name == "IncludedEventTypes")
+ return EventTypeConverter.Instance;
+
+ var converter = TypeDescriptor.GetConverter(propertyType);
+
+ if (converter == null || !converter.CanConvertFrom(typeof(string)) ||
+ !converter.CanConvertTo(typeof(string)))
+ throw new ConfigurationErrorsException("No converter for type " + propertyType);
+
+ return converter;
+ }
+
+ /// <summary>
+ /// Gets properties with non-default value.
+ /// </summary>
+ private static IEnumerable<PropertyInfo> GetNonDefaultProperties(object obj)
+ {
+ Debug.Assert(obj != null);
+
+ return obj.GetType().GetProperties().Where(p => !Equals(p.GetValue(obj, null), GetDefaultValue(p)));
+ }
+
+ /// <summary>
+ /// Gets the default value for a property.
+ /// </summary>
+ private static object GetDefaultValue(PropertyInfo property)
+ {
+ var attr = property.GetCustomAttributes(true).OfType<DefaultValueAttribute>().FirstOrDefault();
+
+ if (attr != null)
+ return attr.Value;
+
+ var propertyType = property.PropertyType;
+
+ if (propertyType.IsValueType)
+ return Activator.CreateInstance(propertyType);
+
+ return null;
+ }
+ }
+}
[3/5] ignite git commit: IGNITE-2380: Added ability to start Ignite
using configuration from app.config. This closes #417.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/TypeStringConverter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/TypeStringConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/TypeStringConverter.cs
new file mode 100644
index 0000000..e7e8b8f
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/TypeStringConverter.cs
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Common
+{
+ using System;
+ using System.ComponentModel;
+ using System.Globalization;
+
+ /// <summary>
+ /// Converts string to <see cref="Type"/>.
+ /// </summary>
+ internal class TypeStringConverter : TypeConverter
+ {
+ /// <summary>
+ /// Default instance.
+ /// </summary>
+ public static readonly TypeStringConverter Instance = new TypeStringConverter();
+
+ /// <summary>
+ /// Returns whether this converter can convert an object of the given type to the type of this converter,
+ /// using the specified context.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="sourceType">A <see cref="Type" /> that represents the type you want to convert from.</param>
+ /// <returns>
+ /// true if this converter can perform the conversion; otherwise, false.
+ /// </returns>
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ return sourceType == typeof (string);
+ }
+
+ /// <summary>
+ /// Returns whether this converter can convert the object to the specified type, using the specified context.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="destinationType">
+ /// A <see cref="Type" /> that represents the type you want to convert to.
+ /// </param>
+ /// <returns>
+ /// true if this converter can perform the conversion; otherwise, false.
+ /// </returns>
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
+ {
+ return destinationType == typeof(string);
+ }
+
+ /// <summary>
+ /// Converts the given object to the type of this converter,
+ /// using the specified context and culture information.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="culture">The <see cref="CultureInfo" /> to use as the current culture.</param>
+ /// <param name="value">The <see cref="Object" /> to convert.</param>
+ /// <returns>
+ /// An <see cref="Object" /> that represents the converted value.
+ /// </returns>
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ return value == null ? null : Type.GetType(value.ToString(), false);
+ }
+
+ /// <summary>
+ /// Converts the given value object to the specified type, using the specified context and culture information.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="culture">
+ /// A <see cref="CultureInfo" />. If null is passed, the current culture is assumed.
+ /// </param>
+ /// <param name="value">The <see cref="Object" /> to convert.</param>
+ /// <param name="destinationType">
+ /// The <see cref="Type" /> to convert the <paramref name="value" /> parameter to.
+ /// </param>
+ /// <returns>
+ /// An <see cref="Object" /> that represents the converted value.
+ /// </returns>
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
+ Type destinationType)
+ {
+ return Convert(value);
+ }
+
+ /// <summary>
+ /// Converts Type to string.
+ /// </summary>
+ /// <param name="value">The value to convert.</param>
+ /// <returns>Resulting string.</returns>
+ public static string Convert(object value)
+ {
+ var type = value as Type;
+ if (type == null)
+ return null;
+
+ if (type.Assembly == typeof (int).Assembly)
+ return type.FullName;
+
+ return type.AssemblyQualifiedName;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d8a049/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventTypeConverter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventTypeConverter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventTypeConverter.cs
new file mode 100644
index 0000000..6b8f935
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Events/EventTypeConverter.cs
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Impl.Events
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Globalization;
+ using System.Linq;
+ using Apache.Ignite.Core.Events;
+
+ /// <summary>
+ /// Converts string to <see cref="EventType"/> member value.
+ /// </summary>
+ internal class EventTypeConverter : TypeConverter
+ {
+ /// <summary>
+ /// Default instance.
+ /// </summary>
+ public static readonly EventTypeConverter Instance = new EventTypeConverter();
+
+ /// <summary>
+ /// The event type map.
+ /// </summary>
+ private static readonly Dictionary<int, string> EvtIdToNameMap =
+ typeof (EventType).GetFields()
+ .Where(p => p.FieldType == typeof (int))
+ .ToDictionary(f => (int) f.GetValue(null), f => f.Name);
+
+ /// <summary>
+ /// The event type map.
+ /// </summary>
+ private static readonly Dictionary<string, int> EvtNameToIdMap =
+ EvtIdToNameMap.ToDictionary(p => p.Value, p => p.Key, StringComparer.OrdinalIgnoreCase);
+
+ /// <summary>
+ /// Returns whether this converter can convert an object of the given type to the type of this converter,
+ /// using the specified context.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="sourceType">A <see cref="Type" /> that represents the type you want to convert from.</param>
+ /// <returns>
+ /// true if this converter can perform the conversion; otherwise, false.
+ /// </returns>
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ return sourceType == typeof(string);
+ }
+
+ /// <summary>
+ /// Returns whether this converter can convert the object to the specified type, using the specified context.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="destinationType">
+ /// A <see cref="Type" /> that represents the type you want to convert to.
+ /// </param>
+ /// <returns>
+ /// true if this converter can perform the conversion; otherwise, false.
+ /// </returns>
+ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
+ {
+ return destinationType == typeof(string);
+ }
+
+ /// <summary>
+ /// Converts the given object to the type of this converter,
+ /// using the specified context and culture information.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="culture">The <see cref="CultureInfo" /> to use as the current culture.</param>
+ /// <param name="value">The <see cref="Object" /> to convert.</param>
+ /// <returns>
+ /// An <see cref="object" /> that represents the converted value.
+ /// </returns>
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (value == null)
+ return null;
+
+ var s = value.ToString();
+ int intResult;
+
+ if (int.TryParse(s, out intResult) || EvtNameToIdMap.TryGetValue(s, out intResult))
+ return intResult;
+
+ throw new InvalidOperationException(string.Format("Cannot convert value to {0}: {1}",
+ typeof (EventType).Name, s));
+ }
+
+ /// <summary>
+ /// Converts the given value object to the specified type, using the specified context and culture information.
+ /// </summary>
+ /// <param name="context">An <see cref="ITypeDescriptorContext" /> that provides a format context.</param>
+ /// <param name="culture">
+ /// A <see cref="CultureInfo" />. If null is passed, the current culture is assumed.
+ /// </param>
+ /// <param name="value">The <see cref="Object" /> to convert.</param>
+ /// <param name="destinationType">
+ /// The <see cref="Type" /> to convert the <paramref name="value" /> parameter to.
+ /// </param>
+ /// <returns>
+ /// An <see cref="object" /> that represents the converted value.
+ /// </returns>
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
+ Type destinationType)
+ {
+ if (!(value is int))
+ return null;
+
+ string eventName;
+
+ if (EvtIdToNameMap.TryGetValue((int)value, out eventName))
+ return eventName;
+
+ return value.ToString();
+ }
+ }
+}
\ No newline at end of file
[5/5] ignite git commit: Merge remote-tracking branch
'remotes/origin/master' into ignite-2587
Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into ignite-2587
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dac641b4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dac641b4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dac641b4
Branch: refs/heads/ignite-2587
Commit: dac641b4282e6195310b56dc5f184a14dae45958
Parents: ae82a23 a4d8a04
Author: sboikov <sb...@gridgain.com>
Authored: Tue Feb 9 19:10:06 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Feb 9 19:10:06 2016 +0300
----------------------------------------------------------------------
.../GridCacheAtomicReferenceImpl.java | 68 +--
.../platform/PlatformNoopProcessor.java | 10 +
.../processors/platform/PlatformProcessor.java | 20 +
.../platform/PlatformProcessorImpl.java | 18 +
.../callback/PlatformCallbackUtils.java | 1 -
.../datastructures/PlatformAtomicReference.java | 141 +++++
.../datastructures/PlatformAtomicSequence.java | 122 ++++
.../cpp/common/include/ignite/common/exports.h | 15 +
.../cpp/common/include/ignite/common/java.h | 32 ++
.../platforms/cpp/common/project/vs/module.def | 15 +-
modules/platforms/cpp/common/src/exports.cpp | 52 ++
modules/platforms/cpp/common/src/java.cpp | 181 ++++++
.../Apache.Ignite.Core.Tests.csproj | 6 +
.../DataStructures/AtomicReferenceTest.cs | 239 ++++++++
.../DataStructures/AtomicSequenceTest.cs | 131 +++++
.../Apache.Ignite.Core.Tests/FutureTest.cs | 1 +
.../IgniteConfigurationSectionTest.cs | 69 +++
.../IgniteConfigurationSerializerTest.cs | 554 +++++++++++++++++++
.../dotnet/Apache.Ignite.Core.Tests/app.config | 54 ++
.../Apache.Ignite.Core.csproj | 15 +
.../Binary/IBinarySerializer.cs | 6 +-
.../DataStructures/IAtomicReference.cs | 64 +++
.../DataStructures/IAtomicSequence.cs | 69 +++
.../dotnet/Apache.Ignite.Core/IIgnite.cs | 28 +
.../IgniteConfigurationSection.cs | 80 +++
.../IgniteConfigurationSection.xsd | 281 ++++++++++
.../dotnet/Apache.Ignite.Core/Ignition.cs | 39 ++
.../Impl/Common/BooleanLowerCaseConverter.cs | 60 ++
.../Common/IgniteConfigurationXmlSerializer.cs | 410 ++++++++++++++
.../Impl/Common/TypeStringConverter.cs | 115 ++++
.../Impl/DataStructures/AtomicReference.cs | 92 +++
.../Impl/DataStructures/AtomicSequence.cs | 90 +++
.../Impl/Events/EventTypeConverter.cs | 133 +++++
.../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 50 ++
.../Apache.Ignite.Core/Impl/IgniteProxy.cs | 12 +
.../Impl/Unmanaged/IgniteJniNativeMethods.cs | 37 ++
.../Impl/Unmanaged/UnmanagedUtils.cs | 79 +++
37 files changed, 3340 insertions(+), 49 deletions(-)
----------------------------------------------------------------------