You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sh...@apache.org on 2016/11/01 02:37:20 UTC

[01/50] [abbrv] ignite git commit: IGNITE-2397 Returned more informative message.

Repository: ignite
Updated Branches:
  refs/heads/ignite-2788 127f459fa -> 3ade1cb18


IGNITE-2397 Returned more informative message.


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

Branch: refs/heads/ignite-2788
Commit: 73649cca7cfb4ae6027bc42bb63140839b46aca9
Parents: f1d35aa
Author: Andrey Novikov <an...@gridgain.com>
Authored: Tue Apr 26 09:26:08 2016 +0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../processors/rest/handlers/query/QueryCommandHandler.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/73649cca/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 0c44077..67e146b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.handlers.query;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -45,6 +46,7 @@ import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandle
 import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
 import org.apache.ignite.internal.processors.rest.request.RestQueryRequest;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiPredicate;
 
@@ -263,6 +265,7 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
         }
 
         /** {@inheritDoc} */
+        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
         @Override public GridRestResponse call() throws Exception {
             final long qryId = qryIdGen.getAndIncrement();
 
@@ -346,7 +349,10 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
             catch (Exception e) {
                 removeQueryCursor(qryId, qryCurs);
 
-                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+                SQLException sqlErr = X.cause(e, SQLException.class);
+
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED,
+                    sqlErr != null ? sqlErr.getMessage() : e.getMessage());
             }
         }
 


[21/50] [abbrv] ignite git commit: IGNITE-2977: .NET: Added ability to use Java filter in .NET continuous queries. This closes #668.

Posted by sh...@apache.org.
IGNITE-2977: .NET: Added ability to use Java filter in .NET continuous queries. This closes #668.


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

Branch: refs/heads/ignite-2788
Commit: 73948df834d3f89ac4eb46d214a5933f2defe409
Parents: 0b7470b
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Apr 27 11:22:13 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java   |   4 +
 .../internal/binary/GridBinaryMarshaller.java   |   3 +
 .../PlatformDefaultJavaObjectFactory.java       |  62 ++++
 .../platform/PlatformJavaObjectFactoryEx.java   |  36 +++
 .../PlatformJavaObjectFactoryProxy.java         | 192 +++++++++++
 .../PlatformJavaObjectSingletonFactory.java     |  48 +++
 .../query/PlatformContinuousQueryImpl.java      |  50 ++-
 .../platform/utils/PlatformUtils.java           |  69 ++++
 .../ignite/internal/util/IgniteUtils.java       |   5 +-
 .../platform/PlatformJavaObjectFactory.java     |  36 +++
 .../platform/PlatformCacheEntryEventFilter.java | 193 +++++++++++
 .../PlatformCacheEntryEventFilterFactory.java   |  59 ++++
 ...latformDefaultJavaObjectFactorySelfTest.java | 185 +++++++++++
 .../PlatformJavaObjectFactoryProxySelfTest.java | 220 +++++++++++++
 .../platform/PlatformStartIgniteTask.java       |   1 +
 .../ignite/platform/PlatformStopIgniteTask.java |   1 +
 .../platform/javaobject/TestJavaObject.java     | 271 ++++++++++++++++
 .../javaobject/TestJavaObjectNoDefaultCtor.java |  49 +++
 .../TestJavaObjectNoDefaultCtorFactory.java     |  68 ++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +
 .../testsuites/IgnitePlatformsTestSuite.java    |  41 +++
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/Query/CacheLinqTest.cs                |   2 -
 .../Continuous/ContinuousQueryJavaFilterTest.cs | 323 +++++++++++++++++++
 .../Apache.Ignite.Core.csproj                   |  11 +-
 .../Continuous/ContinuousQueryExtensions.cs     |  42 +++
 .../Impl/Binary/BinaryUtils.cs                  |   3 +
 .../Impl/Binary/Marshaller.cs                   |   2 +
 .../Cache/Event/JavaCacheEntryEventFilter.cs    |  49 +++
 .../Continuous/ContinuousQueryHandleImpl.cs     |  17 +-
 .../Common/PlatformJavaObjectFactoryProxy.cs    | 106 ++++++
 .../Apache.Ignite.Core/Interop/JavaObject.cs    |  80 +++++
 32 files changed, 2218 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index 4d8c293..8754795 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -83,6 +83,7 @@ import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileReserveSpaceP
 import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileUnlockProcessor;
 import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdatePropertiesProcessor;
 import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor;
+import org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.lang.GridMapEntry;
 import org.apache.ignite.internal.util.typedef.F;
@@ -275,6 +276,9 @@ public class BinaryContext {
         registerPredefinedType(IgniteBiTuple.class, 61);
         registerPredefinedType(T2.class, 62);
 
+        registerPredefinedType(PlatformJavaObjectFactoryProxy.class,
+            GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY);
+
         registerPredefinedType(BinaryObjectImpl.class, 0);
         registerPredefinedType(BinaryObjectOffheapImpl.class, 0);
         registerPredefinedType(BinaryMetadataKey.class, 0);

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
index 00d8871..ad63521 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -181,6 +181,9 @@ public class GridBinaryMarshaller {
     public static final byte LINKED_HASH_MAP = 2;
 
     /** */
+    public static final byte PLATFORM_JAVA_OBJECT_FACTORY_PROXY = 99;
+
+    /** */
     public static final int OBJECT_TYPE_ID = -1;
 
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
new file mode 100644
index 0000000..011088c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+/**
+ * Default Java object factory implementation.
+ */
+public class PlatformDefaultJavaObjectFactory<T> implements PlatformJavaObjectFactoryEx<T> {
+    /** Class name. */
+    private String clsName;
+
+    /** Properties. */
+    private Map<String, Object> props;
+
+    /** {@inheritDoc} */
+    @Override public void initialize(@Nullable Object payload, @Nullable Map<String, Object> props) {
+        if (payload == null)
+            throw new IgniteException("Java object class name is not provided.");
+
+        assert payload instanceof String;
+
+        clsName = (String)payload;
+
+        this.props = props;
+    }
+
+    /** {@inheritDoc} */
+    @Override public T create() {
+        T res = PlatformUtils.createJavaObject(clsName);
+
+        PlatformUtils.initializeJavaObject(res, clsName, props, null);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PlatformDefaultJavaObjectFactory.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryEx.java
new file mode 100644
index 0000000..9c56e34
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryEx.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import org.apache.ignite.platform.PlatformJavaObjectFactory;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+/**
+ * Extended Java object factory interface to handle special cases.
+ */
+public interface PlatformJavaObjectFactoryEx<T> extends PlatformJavaObjectFactory<T> {
+    /**
+     * Initialize factory.
+     *
+     * @param payload Optional payload.
+     * @param props Optional properties.
+     */
+    public void initialize(@Nullable Object payload, @Nullable Map<String, Object> props);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
new file mode 100644
index 0000000..cdf553b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
@@ -0,0 +1,192 @@
+/*
+ * 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;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.platform.PlatformJavaObjectFactory;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Wrapper for Java object factory.
+ */
+public class PlatformJavaObjectFactoryProxy implements Externalizable, Binarylizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** User-defined type. */
+    public static final int TYP_USER = 0;
+
+    /** Default factory. */
+    public static final int TYP_DEFAULT = 1;
+
+    /** Factory type. */
+    private int factoryTyp;
+
+    /** Class name. */
+    private String clsName;
+
+    /** Optional payload for special factory types. */
+    @GridToStringExclude
+    private Object payload;
+
+    /** Properties. */
+    @GridToStringExclude
+    private Map<String, Object> props;
+
+    /**
+     * Default constructor.
+     */
+    public PlatformJavaObjectFactoryProxy() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param factoryTyp Factory type.
+     * @param clsName Class name.
+     * @param payload Payload.
+     * @param props Properties.
+     */
+    public PlatformJavaObjectFactoryProxy(int factoryTyp, @Nullable String clsName, @Nullable Object payload,
+        @Nullable Map<String, Object> props) {
+        this.factoryTyp = factoryTyp;
+        this.clsName = clsName;
+        this.payload = payload;
+        this.props = props;
+    }
+
+    /**
+     * Get factory instance.
+     *
+     * @param ctx Kernal context for injections.
+     * @return Factory instance.
+     */
+    public PlatformJavaObjectFactory factory(GridKernalContext ctx) {
+        // Create factory.
+        Object res;
+
+        switch (factoryTyp) {
+            case TYP_DEFAULT:
+                res = new PlatformDefaultJavaObjectFactory();
+
+                break;
+
+            case TYP_USER:
+                res = PlatformUtils.createJavaObject(clsName);
+
+                break;
+
+            default:
+                throw new IgniteException("Unsupported Java object factory type: " + factoryTyp);
+        }
+
+        // Initialize factory.
+        if (res instanceof PlatformJavaObjectFactoryEx)
+            ((PlatformJavaObjectFactoryEx)res).initialize(payload, props);
+        else {
+            PlatformUtils.initializeJavaObject(res, clsName, props, ctx);
+
+            if (!(res instanceof PlatformJavaObjectFactory))
+                res = new PlatformJavaObjectSingletonFactory<>(res);
+        }
+
+        return (PlatformJavaObjectFactory)res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+        BinaryRawWriterEx rawWriter = (BinaryRawWriterEx)writer.rawWriter();
+
+        rawWriter.writeInt(factoryTyp);
+        rawWriter.writeString(clsName);
+        rawWriter.writeObjectDetached(payload);
+
+        if (props != null) {
+            rawWriter.writeInt(props.size());
+
+            for (Map.Entry<String, Object> prop : props.entrySet()) {
+                rawWriter.writeString(prop.getKey());
+                rawWriter.writeObjectDetached(prop.getValue());
+            }
+        }
+        else
+            rawWriter.writeInt(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+        BinaryRawReaderEx rawReader = (BinaryRawReaderEx)reader.rawReader();
+
+        factoryTyp = rawReader.readInt();
+        clsName = rawReader.readString();
+        payload = rawReader.readObjectDetached();
+
+        int propsSize = rawReader.readInt();
+
+        if (propsSize > 0) {
+            props = new HashMap<>(propsSize);
+
+            for (int i = 0; i < propsSize; i++) {
+                String key = rawReader.readString();
+                Object val = rawReader.readObjectDetached();
+
+                props.put(key, val);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(factoryTyp);
+        U.writeString(out, clsName);
+        out.writeObject(payload);
+        U.writeMap(out, props);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        factoryTyp = in.readInt();
+        clsName = U.readString(in);
+        payload = in.readObject();
+        props = U.readMap(in);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PlatformJavaObjectFactoryProxy.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectSingletonFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectSingletonFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectSingletonFactory.java
new file mode 100644
index 0000000..165b7d1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectSingletonFactory.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.platform.PlatformJavaObjectFactory;
+
+/**
+ * Singleton factory.
+ */
+public class PlatformJavaObjectSingletonFactory<T> implements PlatformJavaObjectFactory<T> {
+    /** Instance. */
+    private final T instance;
+
+    /**
+     * Constructor.
+     *
+     * @param instance Instance.
+     */
+    public PlatformJavaObjectSingletonFactory(T instance) {
+        this.instance = instance;
+    }
+
+    /** {@inheritDoc} */
+    @Override public T create() {
+        return instance;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PlatformJavaObjectSingletonFactory.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
index 453e233..abe5b76 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryImpl.java
@@ -24,14 +24,21 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.cache.Cache;
 import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
 import javax.cache.event.CacheEntryListenerException;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
 import org.apache.ignite.cache.query.ContinuousQuery;
 import org.apache.ignite.cache.query.Query;
 import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
+import org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
 import org.apache.ignite.internal.processors.platform.PlatformTarget;
 import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
 import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata;
@@ -52,6 +59,9 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
     /** Native filter in serialized form. If null, then filter is either not set, or this is local query. */
     protected final Object filter;
 
+    /** Java filter. */
+    protected final CacheEntryEventFilter javaFilter;
+
     /** Pointer to native counterpart; zero if closed. */
     private long ptr;
 
@@ -79,6 +89,33 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
         this.ptr = ptr;
         this.hasFilter = hasFilter;
         this.filter = filter;
+
+        javaFilter = getJavaFilter(filter, platformCtx.kernalContext());
+
+        if (javaFilter != null && !(javaFilter instanceof CacheEntryEventSerializableFilter))
+            throw new IgniteException("Java event filter must implement " +
+                CacheEntryEventSerializableFilter.class.getName() + " interface: " + javaFilter.getClass().getName());
+    }
+
+    /**
+     * Gets the Java filter if present.
+     *
+     * @param filter Filter object.
+     * @param ctx Context.
+     * @return Java filter or null.
+     */
+    private static CacheEntryEventFilter getJavaFilter(Object filter, GridKernalContext ctx) {
+        if (filter instanceof BinaryObjectImpl) {
+            BinaryObjectImpl bo = (BinaryObjectImpl)filter;
+
+            if (bo.typeId() == GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY) {
+                PlatformJavaObjectFactoryProxy prx = bo.deserialize();
+
+                return (CacheEntryEventFilter)prx.factory(ctx).create();
+            }
+        }
+
+        return null;
     }
 
     /**
@@ -92,10 +129,8 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
      * @param initialQry Initial query.
      */
     @SuppressWarnings("unchecked")
-    public void start(IgniteCacheProxy cache, boolean loc, int bufSize, long timeInterval, boolean autoUnsubscribe,
-        Query initialQry) throws IgniteCheckedException {
-        assert !loc || filter == null;
-
+    @Override public void start(IgniteCacheProxy cache, boolean loc, int bufSize, long timeInterval,
+        boolean autoUnsubscribe, Query initialQry) throws IgniteCheckedException {
         lock.writeLock().lock();
 
         try {
@@ -170,7 +205,11 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
     @Override public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
+        if (javaFilter != null)
+            return javaFilter.evaluate(evt);
+
         lock.readLock().lock();
 
         try {
@@ -230,6 +269,9 @@ public class PlatformContinuousQueryImpl implements PlatformContinuousQuery {
      * @throws ObjectStreamException If failed.
      */
     Object writeReplace() throws ObjectStreamException {
+        if (javaFilter != null)
+            return javaFilter;
+
         return filter == null ? null : platformCtx.createContinuousQueryFilter(filter);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
index 04b1a17..b31bbd3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
@@ -55,6 +55,7 @@ import javax.cache.event.CacheEntryEvent;
 import javax.cache.event.CacheEntryListenerException;
 import java.math.BigDecimal;
 import java.security.Timestamp;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -920,6 +921,74 @@ public class PlatformUtils {
         return map0;
     }
     /**
+     * Create Java object.
+     *
+     * @param clsName Class name.
+     * @return Instance.
+     */
+    public static <T> T createJavaObject(String clsName) {
+        if (clsName == null)
+            throw new IgniteException("Java object/factory class name is not set.");
+
+        Class cls = U.classForName(clsName, null);
+
+        if (cls == null)
+            throw new IgniteException("Java object/factory class is not found (is it in the classpath?): " +
+                clsName);
+
+        try {
+            return (T)cls.newInstance();
+        }
+        catch (ReflectiveOperationException e) {
+            throw new IgniteException("Failed to instantiate Java object/factory class (does it have public " +
+                "default constructor?): " + clsName, e);
+        }
+    }
+
+    /**
+     * Initialize Java object or object factory.
+     *
+     * @param obj Object.
+     * @param clsName Class name.
+     * @param props Properties (optional).
+     * @param ctx Kernal context (optional).
+     */
+    public static void initializeJavaObject(Object obj, String clsName, @Nullable Map<String, Object> props,
+        @Nullable GridKernalContext ctx) {
+        if (props != null) {
+            for (Map.Entry<String, Object> prop : props.entrySet()) {
+                String fieldName = prop.getKey();
+
+                if (fieldName == null)
+                    throw new IgniteException("Java object/factory field name cannot be null: " + clsName);
+
+                Field field = U.findField(obj.getClass(), fieldName);
+
+                if (field == null)
+                    throw new IgniteException("Java object/factory class field is not found [" +
+                        "className=" + clsName + ", fieldName=" + fieldName + ']');
+
+                try {
+                    field.set(obj, prop.getValue());
+                }
+                catch (Exception e) {
+                    throw new IgniteException("Failed to set Java object/factory field [className=" + clsName +
+                        ", fieldName=" + fieldName + ", fieldValue=" + prop.getValue() + ']', e);
+                }
+            }
+        }
+
+        if (ctx != null) {
+            try {
+                ctx.resource().injectGeneric(obj);
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to inject resources to Java factory: " + clsName, e);
+            }
+        }
+    }
+
+    /**
      * Private constructor.
      */
     private PlatformUtils() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 8a313cb..6958b9e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -9252,12 +9252,13 @@ public abstract class IgniteUtils {
      * @param name Name of a field to get.
      * @return Field or {@code null}.
      */
-    @Nullable public static Field findNonPublicField(Class<?> cls, String name) {
+    @Nullable public static Field findField(Class<?> cls, String name) {
         while (cls != null) {
             try {
                 Field fld = cls.getDeclaredField(name);
 
-                fld.setAccessible(true);
+                if (!fld.isAccessible())
+                    fld.setAccessible(true);
 
                 return fld;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/main/java/org/apache/ignite/platform/PlatformJavaObjectFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/platform/PlatformJavaObjectFactory.java b/modules/core/src/main/java/org/apache/ignite/platform/PlatformJavaObjectFactory.java
new file mode 100644
index 0000000..cd97470
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/platform/PlatformJavaObjectFactory.java
@@ -0,0 +1,36 @@
+/*
+ * 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.platform;
+
+/**
+ * Object factory used for advanced interop between platform and Java.
+ * <p>
+ * Use it when you need Java component for some Ignite feature in platform code. E.g. Java-based continuous
+ * query filter.
+ * <p>
+ * You should implement the factory, compile it and then place it into node's classpath. Then you can reference
+ * the factory form platform code using it's fully-qualified Java class name.
+ */
+public interface PlatformJavaObjectFactory<T> {
+    /**
+     * Constructs and returns a fully configured instance of T.
+     *
+     * @return An instance of T.
+     */
+    public T create();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilter.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilter.java
new file mode 100644
index 0000000..36c22e6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilter.java
@@ -0,0 +1,193 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.UUID;
+
+/**
+ * Test filter.
+ */
+@SuppressWarnings({"FieldCanBeLocal", "FloatingPointEquality", "MismatchedReadAndWriteOfArray", "unused",
+    "SpellCheckingInspection"})
+public class PlatformCacheEntryEventFilter implements CacheEntryEventSerializableFilter {
+    /** Property to be set from platform. */
+    private String startsWith = "-";
+
+    /** Property to be set from platform. */
+    private char charField;
+
+    /** Property to be set from platform. */
+    private byte byteField;
+
+    /** Property to be set from platform. */
+    private byte sbyteField;
+
+    /** Property to be set from platform. */
+    private short shortField;
+
+    /** Property to be set from platform. */
+    private short ushortField;
+
+    /** Property to be set from platform. */
+    private int intField;
+
+    /** Property to be set from platform. */
+    private int uintField;
+
+    /** Property to be set from platform. */
+    private long longField;
+
+    /** Property to be set from platform. */
+    private long ulongField;
+
+    /** Property to be set from platform. */
+    private float floatField;
+
+    /** Property to be set from platform. */
+    private double doubleField;
+
+    /** Property to be set from platform. */
+    private BigDecimal decimalField;
+
+    /** Property to be set from platform. */
+    private boolean boolField;
+
+    /** Property to be set from platform. */
+    private UUID guidField;
+
+    /** Property to be set from platform. */
+    private BinaryObject objField;
+
+    /** Property to be set from platform. */
+    private char[] charArr;
+
+    /** Property to be set from platform. */
+    private byte[] byteArr;
+
+    /** Property to be set from platform. */
+    private byte[] sbyteArr;
+
+    /** Property to be set from platform. */
+    private short[] shortArr;
+
+    /** Property to be set from platform. */
+    private short[] ushortArr;
+
+    /** Property to be set from platform. */
+    private int[] intArr;
+
+    /** Property to be set from platform. */
+    private int[] uintArr;
+
+    /** Property to be set from platform. */
+    private long[] longArr;
+
+    /** Property to be set from platform. */
+    private long[] ulongArr;
+
+    /** Property to be set from platform. */
+    private float[] floatArr;
+
+    /** Property to be set from platform. */
+    private double[] doubleArr;
+
+    /** Property to be set from platform. */
+    private boolean[] boolArr;
+
+    /** Property to be set from platform. */
+    private Object[] objArr;
+
+    /** Property to be set from platform. */
+    private ArrayList arrayList;
+
+    /** Property to be set from platform. */
+    private HashMap hashTable;
+
+    /** Injected instance. */
+    @IgniteInstanceResource
+    private Ignite ignite;
+
+    /** {@inheritDoc} */
+    @Override public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
+        // check injection
+        assert ignite != null;
+
+        // check fields
+        assert charField == 'a';
+        assert byteField == 1;
+        assert sbyteField == 2;
+        assert shortField == 3;
+        assert ushortField == 4;
+        assert intField == 5;
+        assert uintField == 6;
+        assert longField == 7;
+        assert ulongField == 8;
+        assert floatField == (float)9.99;
+        assert doubleField == 10.123;
+        assert "11.245".equals(decimalField.toString());
+        assert boolField;
+        assert guidField.equals(UUID.fromString("1c579241-509d-47c6-a1a0-87462ae31e59"));
+
+        // check arrays
+        assert charArr[0] == 'a';
+        assert byteArr[0] == 1;
+        assert sbyteArr[0] == 2;
+        assert shortArr[0] == 3;
+        assert ushortArr[0] == 4;
+        assert intArr[0] == 5;
+        assert uintArr[0] == 6;
+        assert longArr[0] == 7;
+        assert ulongArr[0] == 8;
+        assert floatArr[0] == (float)9.99;
+        assert doubleArr[0] == 10.123;
+        assert boolArr[0];
+
+        // check collections
+        assert "x".equals(arrayList.get(0));
+        assert "2".equals(hashTable.get(1));
+
+        // check binary object
+        assert objField != null;
+        assert Integer.valueOf(1).equals(objField.field("Int"));
+        assert "2".equals(objField.field("String"));
+
+        assert objArr != null;
+        assert objArr.length == 1;
+        assert Integer.valueOf(1).equals(((BinaryObject)objArr[0]).field("Int"));
+        assert "2".equals(((BinaryObject)objArr[0]).field("String"));
+
+        Object value = event.getValue();
+
+        if (value instanceof String)
+            return ((String)value).startsWith(startsWith);
+
+        assert value instanceof BinaryObject;
+
+        return ((String)((BinaryObject)value).field("String")).startsWith(startsWith);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilterFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilterFactory.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilterFactory.java
new file mode 100644
index 0000000..14f2931
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformCacheEntryEventFilterFactory.java
@@ -0,0 +1,59 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import java.io.Serializable;
+
+/**
+ * Test filter factory
+ */
+public class PlatformCacheEntryEventFilterFactory implements Serializable,
+    PlatformJavaObjectFactory<CacheEntryEventSerializableFilter> {
+    /** Property to be set from platform. */
+    @SuppressWarnings("FieldCanBeLocal")
+    private String startsWith = "-";
+
+    /** Injected instance. */
+    @IgniteInstanceResource
+    private Ignite ignite;
+
+    /** {@inheritDoc} */
+    @Override public CacheEntryEventSerializableFilter create() {
+        assert ignite != null;
+
+        return new CacheEntryEventSerializableFilter() {
+            @Override public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
+                Object value = event.getValue();
+
+                if (value instanceof String)
+                    return ((String)value).startsWith(startsWith);
+
+                assert value instanceof BinaryObject;
+
+                return ((String)((BinaryObject)value).field("String")).startsWith(startsWith);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
new file mode 100644
index 0000000..45fda4f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.platform.PlatformDefaultJavaObjectFactory;
+import org.apache.ignite.platform.javaobject.TestJavaObject;
+import org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtor;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+/**
+ * Dedicated tests for {@link PlatformDefaultJavaObjectFactory}.
+ */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+public class PlatformDefaultJavaObjectFactorySelfTest extends GridCommonAbstractTest {
+    /** Name of the class. */
+    private static final String CLS_NAME = TestJavaObject.class.getName();
+
+    /** Name of the class without default constructor. */
+    private static final String NO_DFLT_CTOR_CLS_NAME = TestJavaObjectNoDefaultCtor.class.getName();
+
+    /**
+     * Test normal object creation.
+     */
+    public void testNormal() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        factory.initialize(CLS_NAME, props);
+
+        Object val = factory.create();
+
+        TestJavaObject expVal = new TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            .setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+    }
+
+    /**
+     * Test object creation with boxed property.
+     */
+    public void testBoxedProperty() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("fIntBoxed", 1));
+
+        Object val = factory.create();
+
+        assertEquals(val, new TestJavaObject().setIntBoxed(1));
+    }
+
+    /**
+     * Test object creation without properties.
+     */
+    public void testNoProperties() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.emptyMap());
+
+        Object val = factory.create();
+
+        assertEquals(val, new TestJavaObject());
+    }
+
+    /**
+     * Test object creation with invalid property name.
+     */
+    public void testInvalidPropertyName() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("invalid", 1));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid property value.
+     */
+    public void testInvalidPropertyValue() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("fInt", 1L));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation without default constructor.
+     */
+    public void testNoDefaultConstructor() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(NO_DFLT_CTOR_CLS_NAME, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with null class name.
+     */
+    public void testNullClassName() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                factory.initialize(null, null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                factory.initialize(null, new HashMap<String, Object>());
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid class name.
+     */
+    public void testInvalidClassName() {
+        final PlatformDefaultJavaObjectFactory factory = new PlatformDefaultJavaObjectFactory();
+
+        factory.initialize("invalid", null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
new file mode 100644
index 0000000..18fb806
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
@@ -0,0 +1,220 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
+import org.apache.ignite.platform.javaobject.TestJavaObject;
+import org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtor;
+import org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtorFactory;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+/**
+ * Dedicated tests for {@link PlatformJavaObjectFactoryProxy}.
+ */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+public class PlatformJavaObjectFactoryProxySelfTest extends GridCommonAbstractTest {
+    /** Name of the class. */
+    private static final String CLS_NAME = TestJavaObject.class.getName();
+
+    /** Name of the factory class to create object without default constructor. */
+    private static final String NO_DFLT_CTOR_FACTORY_CLS_NAME = TestJavaObjectNoDefaultCtorFactory.class.getName();
+
+    /** Kernal context. */
+    private GridKernalContext ctx;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        ctx = ((IgniteKernal)Ignition.start(getConfiguration(PlatformJavaObjectFactoryProxySelfTest.class.getName())))
+            .context();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ctx = null;
+
+        Ignition.stopAll(true);
+    }
+
+    /**
+     * Test normal object creation using default factory.
+     */
+    public void testDefaultFactoryNormal() {
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        PlatformJavaObjectFactoryProxy proxy =
+            new PlatformJavaObjectFactoryProxy(PlatformJavaObjectFactoryProxy.TYP_DEFAULT, null, CLS_NAME, props);
+
+        TestJavaObject val = (TestJavaObject)proxy.factory(ctx).create();
+
+        TestJavaObject expVal = new TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            .setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+    }
+
+    /**
+     * Test normal object creation using custom factory.
+     */
+    public void testCustomFactoryNormal() {
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        PlatformJavaObjectFactoryProxy proxy = proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME, props);
+
+        TestJavaObjectNoDefaultCtor val = (TestJavaObjectNoDefaultCtor)proxy.factory(ctx).create();
+
+        TestJavaObject expVal = new TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            .setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+
+        assertNotNull(val.node);
+        assertEquals(val.node.name(), ctx.gridName());
+    }
+
+    /**
+     * Test object creation with boxed property.
+     */
+    public void testCustomFactoryBoxedProperty() {
+        PlatformJavaObjectFactoryProxy proxy = proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("fIntBoxed", (Object)1));
+
+        Object val = proxy.factory(ctx).create();
+
+        assertEquals(val, new TestJavaObject().setIntBoxed(1));
+    }
+
+    /**
+     * Test object creation without properties.
+     */
+    public void testCustomFactoryNoProperties() {
+        PlatformJavaObjectFactoryProxy proxy = proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.<String, Object>emptyMap());
+
+        Object val = proxy.factory(ctx).create();
+
+        assertEquals(val, new TestJavaObject());
+    }
+
+    /**
+     * Test object creation with invalid property name.
+     */
+    public void testCustomFactoryInvalidPropertyName() {
+        final PlatformJavaObjectFactoryProxy proxy = proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("invalid", (Object)1));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxy.factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid property value.
+     */
+    public void testCustomFactoryInvalidPropertyValue() {
+        final PlatformJavaObjectFactoryProxy proxy = proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("fInt", (Object)1L));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxy.factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with null class name.
+     */
+    public void testCustomFactoryNullClassName() {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom(null, null).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom(null, new HashMap<String, Object>()).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid class name.
+     */
+    public void testCustomFactoryInvalidClassName() {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom("invalid", null).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Create proxy for user-defined factory.
+     *
+     * @param clsName Class name.
+     * @param props Properties.
+     * @return Proxy.
+     */
+    private static PlatformJavaObjectFactoryProxy proxyForCustom(String clsName, Map<String, Object> props) {
+        return new PlatformJavaObjectFactoryProxy(PlatformJavaObjectFactoryProxy.TYP_USER, clsName, null, props);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformStartIgniteTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformStartIgniteTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformStartIgniteTask.java
index c8eb13f..e703431 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformStartIgniteTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformStartIgniteTask.java
@@ -61,6 +61,7 @@ public class PlatformStartIgniteTask extends ComputeTaskAdapter<String, String>
 
         /**
          * Ctor.
+         *
          * @param springConfig Config.
          */
         private PlatformStartIgniteJob(String springConfig) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/PlatformStopIgniteTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformStopIgniteTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformStopIgniteTask.java
index c0319ab..238f058 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformStopIgniteTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformStopIgniteTask.java
@@ -60,6 +60,7 @@ public class PlatformStopIgniteTask extends ComputeTaskAdapter<String, Boolean>
 
         /**
          * Ctor.
+         *
          * @param gridName Name.
          */
         private PlatformStopIgniteJob(String gridName) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
new file mode 100644
index 0000000..3c76798
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
@@ -0,0 +1,271 @@
+/*
+ * 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.platform.javaobject;
+
+/**
+ * Test object.
+ */
+public class TestJavaObject {
+    /** */
+    protected boolean fBoolean;
+
+    /** */
+    protected byte fByte;
+
+    /** */
+    protected short fShort;
+
+    /** */
+    protected char fChar;
+
+    /** */
+    protected int fInt;
+
+    /** */
+    protected long fLong;
+
+    /** */
+    protected float fFloat;
+
+    /** */
+    protected double fDouble;
+
+    /** */
+    protected Object fObj;
+
+    /** Integer field. */
+    protected Integer fIntBoxed;
+
+    /**
+     * Default constructor.
+     */
+    public TestJavaObject() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param fBoolean Boolean field.
+     * @param fByte Byte field.
+     * @param fShort Short field.
+     * @param fChar Char field.
+     * @param fInt Integer field.
+     * @param fLong Long field.
+     * @param fDouble Double field.
+     * @param fFloat Float field.
+     * @param fObj Object field.
+     * @param fIntBoxed Integer boxed field.
+     */
+    public TestJavaObject(boolean fBoolean, byte fByte, short fShort, char fChar, int fInt, long fLong, float fFloat,
+        double fDouble, Object fObj, Integer fIntBoxed) {
+        this.fBoolean = fBoolean;
+        this.fByte = fByte;
+        this.fShort = fShort;
+        this.fChar = fChar;
+        this.fInt = fInt;
+        this.fLong = fLong;
+        this.fDouble = fDouble;
+        this.fFloat = fFloat;
+        this.fObj = fObj;
+        this.fIntBoxed = fIntBoxed;
+    }
+
+    /**
+     * Set boolean field.
+     *
+     * @param fBoolean Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setBoolean(boolean fBoolean) {
+        this.fBoolean = fBoolean;
+
+        return this;
+    }
+
+    /**
+     * Set byte field.
+     *
+     * @param fByte Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setByte(byte fByte) {
+        this.fByte = fByte;
+
+        return this;
+    }
+
+    /**
+     * Set short field.
+     *
+     * @param fShort Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setShort(short fShort) {
+        this.fShort = fShort;
+
+        return this;
+    }
+
+    /**
+     * Set char field.
+     *
+     * @param fChar Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setChar(char fChar) {
+        this.fChar = fChar;
+
+        return this;
+    }
+
+    /**
+     * Set int field.
+     *
+     * @param fInt Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setInt(int fInt) {
+        this.fInt = fInt;
+
+        return this;
+    }
+
+    /**
+     * Set long field.
+     *
+     * @param fLong Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setLong(long fLong) {
+        this.fLong = fLong;
+
+        return this;
+    }
+
+    /**
+     * Set float field.
+     *
+     * @param fFloat Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setFloat(float fFloat) {
+        this.fFloat = fFloat;
+
+        return this;
+    }
+
+    /**
+     * Set double field.
+     *
+     * @param fDouble Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setDouble(double fDouble) {
+        this.fDouble = fDouble;
+
+        return this;
+    }
+
+    /**
+     * Set object field.
+     *
+     * @param fObj Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setObject(Object fObj) {
+        this.fObj = fObj;
+
+        return this;
+    }
+
+    /**
+     * Set wrapped integer field.
+     *
+     * @param fInteger Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setIntBoxed(Integer fInteger) {
+        this.fIntBoxed = fInteger;
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass", "SimplifiableIfStatement"})
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null)
+            return false;
+
+        TestJavaObject that = (TestJavaObject) o;
+
+        if (fBoolean != that.fBoolean)
+            return false;
+
+        if (fByte != that.fByte)
+            return false;
+
+        if (fShort != that.fShort)
+            return false;
+
+        if (fChar != that.fChar)
+            return false;
+
+        if (fInt != that.fInt)
+            return false;
+
+        if (fLong != that.fLong)
+            return false;
+
+        if (Double.compare(that.fDouble, fDouble) != 0)
+            return false;
+
+        if (Float.compare(that.fFloat, fFloat) != 0)
+            return false;
+
+        if (fObj != null ? !fObj.equals(that.fObj) : that.fObj != null)
+            return false;
+
+        return fIntBoxed != null ? fIntBoxed.equals(that.fIntBoxed) : that.fIntBoxed == null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res;
+        long tmp;
+
+        res = (fBoolean ? 1 : 0);
+        res = 31 * res + (int) fByte;
+        res = 31 * res + (int) fShort;
+        res = 31 * res + (int) fChar;
+        res = 31 * res + fInt;
+        res = 31 * res + (int) (fLong ^ (fLong >>> 32));
+
+        tmp = Double.doubleToLongBits(fDouble);
+
+        res = 31 * res + (int) (tmp ^ (tmp >>> 32));
+        res = 31 * res + (fFloat != +0.0f ? Float.floatToIntBits(fFloat) : 0);
+        res = 31 * res + (fObj != null ? fObj.hashCode() : 0);
+        res = 31 * res + (fIntBoxed != null ? fIntBoxed.hashCode() : 0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
new file mode 100644
index 0000000..1d7ed07
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
@@ -0,0 +1,49 @@
+/*
+ * 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.platform.javaobject;
+
+import org.apache.ignite.Ignite;
+
+/**
+ * Test Java object without default constructor.
+ */
+public class TestJavaObjectNoDefaultCtor extends TestJavaObject {
+    /** Node. */
+    public Ignite node;
+
+    /**
+     * Constructor.
+     *
+     * @param fBoolean Boolean field.
+     * @param fByte Byte field.
+     * @param fShort Short field.
+     * @param fChar Char field.
+     * @param fInt Integer field.
+     * @param fLong Long field.
+     * @param fDouble Double field.
+     * @param fFloat Float field.
+     * @param fObj Object field.
+     * @param fIntBoxed Integer boxed field.
+     */
+    public TestJavaObjectNoDefaultCtor(boolean fBoolean, byte fByte, short fShort, char fChar, int fInt, long fLong,
+        float fFloat, double fDouble, Object fObj, Integer fIntBoxed, Ignite node) {
+        super(fBoolean, fByte, fShort, fChar, fInt, fLong, fFloat, fDouble, fObj, fIntBoxed);
+
+        this.node = node;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
new file mode 100644
index 0000000..0e6dd99
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
@@ -0,0 +1,68 @@
+/*
+ * 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.platform.javaobject;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.platform.PlatformJavaObjectFactory;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+/**
+ * Test factory.
+ */
+@SuppressWarnings("unused")
+public class TestJavaObjectNoDefaultCtorFactory implements PlatformJavaObjectFactory {
+    /** Injected node. */
+    @IgniteInstanceResource
+    public Ignite node;
+
+    /** */
+    private boolean fBoolean;
+
+    /** */
+    private byte fByte;
+
+    /** */
+    private short fShort;
+
+    /** */
+    private char fChar;
+
+    /** */
+    private int fInt;
+
+    /** */
+    private long fLong;
+
+    /** */
+    private float fFloat;
+
+    /** */
+    private double fDouble;
+
+    /** */
+    private Object fObj;
+
+    /** Integer field. */
+    private Integer fIntBoxed;
+
+    /** {@inheritDoc} */
+    @Override public Object create() {
+        return new TestJavaObjectNoDefaultCtor(fBoolean, fByte, fShort, fChar, fInt, fLong, fFloat, fDouble, fObj,
+            fIntBoxed, node);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 9e2324c..c67a07d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -86,6 +86,8 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTest(IgniteCacheP2pUnmarshallingErrorTestSuite.suite(ignoredTests));
         suite.addTest(IgniteStreamSelfTestSuite.suite());
 
+        suite.addTest(IgnitePlatformsTestSuite.suite());
+
         suite.addTest(new TestSuite(GridSelfTest.class));
         suite.addTest(new TestSuite(ClusterGroupHostsSelfTest.class));
         suite.addTest(new TestSuite(IgniteMessagingWithClientTest.class));

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
new file mode 100644
index 0000000..f7021d8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
@@ -0,0 +1,41 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.platform.PlatformDefaultJavaObjectFactorySelfTest;
+import org.apache.ignite.platform.PlatformJavaObjectFactoryProxySelfTest;
+
+/**
+ * Suite for platform tests.
+ */
+public class IgnitePlatformsTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Ignite Deployment SPI Test Suite");
+
+        // LocalDeploymentSpi tests
+        suite.addTest(new TestSuite(PlatformDefaultJavaObjectFactorySelfTest.class));
+        suite.addTest(new TestSuite(PlatformJavaObjectFactoryProxySelfTest.class));
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/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 cba7d9e..de21765 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
@@ -101,6 +101,7 @@
     <Compile Include="Compute\BinarizableClosureTaskTest.cs" />
     <Compile Include="Compute\BinarizableTaskTest.cs" />
     <Compile Include="Compute\MixedClusterTest.cs" />
+    <Compile Include="Cache\Query\Continuous\ContinuousQueryJavaFilterTest.cs" />
     <Compile Include="Compute\ResourceTaskTest.cs" />
     <Compile Include="Compute\SerializableClosureTaskTest.cs" />
     <Compile Include="Compute\TaskAdapterTest.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
index 218ebef..a47f3f0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
@@ -35,8 +35,6 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Configuration;
-    using Apache.Ignite.Core.Discovery.Tcp;
-    using Apache.Ignite.Core.Discovery.Tcp.Static;
     using Apache.Ignite.Linq;
     using NUnit.Framework;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
new file mode 100644
index 0000000..ed9d2ad
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
@@ -0,0 +1,323 @@
+\ufeff/*
+ * 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.Local
+#pragma warning disable 618  // SpringConfigUrl
+namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous
+{
+    using System;
+    using System.Collections;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Cache.Event;
+    using Apache.Ignite.Core.Cache.Query.Continuous;
+    using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Interop;
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Tests query in a cluster with Java-only and .NET nodes.
+    /// </summary>
+    public class ContinuousQueryJavaFilterTest
+    {
+        /** */
+        private const string SpringConfig = @"Config\Compute\compute-grid1.xml";
+
+        /** */
+        private const string SpringConfig2 = @"Config\Compute\compute-grid2.xml";
+
+        /** */
+        private const string StartTask = "org.apache.ignite.platform.PlatformStartIgniteTask";
+
+        /** */
+        private const string StopTask = "org.apache.ignite.platform.PlatformStopIgniteTask";
+
+        /** */
+        private const string PlatformFilter = "org.apache.ignite.platform.PlatformCacheEntryEventFilter";
+
+        /** */
+        private const string PlatformFilterFactory = "org.apache.ignite.platform.PlatformCacheEntryEventFilterFactory";
+
+        /** */
+        private IIgnite _ignite;
+        
+        /** */
+        private string _javaNodeName;
+
+        /** */
+        private static volatile Tuple<int, object> _lastEvent;
+
+        /// <summary>
+        /// Fixture set up.
+        /// </summary>
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            // Main .NET nodes
+            var jvmOpts = TestUtils.TestJavaOptions();
+
+            _ignite = Ignition.Start(new IgniteConfiguration
+            {
+                JvmClasspath = TestUtils.CreateTestClasspath(),
+                JvmOptions = jvmOpts,
+                SpringConfigUrl = SpringConfig,
+                BinaryConfiguration = new BinaryConfiguration
+                {
+                    TypeConfigurations = new List<BinaryTypeConfiguration>
+                    {
+                        new BinaryTypeConfiguration(typeof(TestBinary)) 
+                    }
+                }
+            });
+
+            // Second .NET node
+            Ignition.Start(new IgniteConfiguration
+            {
+                JvmClasspath = TestUtils.CreateTestClasspath(),
+                JvmOptions = jvmOpts,
+                SpringConfigUrl = SpringConfig2,
+                GridName = "dotNet2"
+            });
+
+            // Java-only node
+            _javaNodeName = _ignite.GetCompute().ExecuteJavaTask<string>(StartTask, SpringConfig2);
+
+            Assert.IsTrue(_ignite.WaitTopology(3, 5000));
+        }
+
+        /// <summary>
+        /// Fixture tear down.
+        /// </summary>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            _ignite.GetCompute().ExecuteJavaTask<object>(StopTask, _javaNodeName);
+            Ignition.StopAll(true);
+        }
+
+        /// <summary>
+        /// Tests the filter.
+        /// </summary>
+        [Test]
+        public void TestFilter()
+        {
+            var javaObj = new JavaObject(PlatformFilter)
+            {
+                Properties =
+                {
+                    {"startsWith", "valid"},
+                    {"charField", 'a'},
+                    {"byteField", (byte) 1},
+                    {"sbyteField", (sbyte) 2},
+                    {"shortField", (short) 3},
+                    {"ushortField", (ushort) 4},
+                    {"intField", 5},
+                    {"uintField", (uint) 6},
+                    {"longField", (long) 7},
+                    {"ulongField", (ulong) 8},
+                    {"floatField", (float) 9.99},
+                    {"doubleField", 10.123},
+                    {"decimalField", (decimal) 11.245},
+                    {"boolField", true},
+                    {"guidField", Guid.Parse("1c579241-509d-47c6-a1a0-87462ae31e59")},
+                    {
+                        "objField", new TestBinary(1, "2")
+
+                    },
+                    {"charArr", new[] {'a'}},
+                    {"byteArr", new[] {(byte) 1}},
+                    {"sbyteArr", new[] {(sbyte) 2}},
+                    {"shortArr", new[] {(short) 3}},
+                    {"ushortArr", new[] {(ushort) 4}},
+                    {"intArr", new[] {5}},
+                    {"uintArr", new[] {(uint) 6}},
+                    {"longArr", new[] {(long) 7}},
+                    {"ulongArr", new[] {(ulong) 8}},
+                    {"floatArr", new[] {(float) 9.99}},
+                    {"doubleArr", new[] {10.123}},
+                    {"boolArr", new[] {true}},
+                    {
+                        "objArr", new object[]
+                        {
+                            new TestBinary(1, "2")
+                        }
+                    },
+                    {"arrayList", new ArrayList {"x"}},
+                    {"hashTable", new Hashtable {{1, "2"}}}
+                }
+            };
+
+            TestFilter(javaObj);
+        }
+
+        /// <summary>
+        /// Tests the factory class.
+        /// </summary>
+        [Test]
+        public void TestFactory()
+        {
+            var javaObj = new JavaObject(PlatformFilterFactory,
+                new Dictionary<string, object> {{"startsWith", "valid"}});
+
+            TestFilter(javaObj);
+        }
+
+        /// <summary>
+        /// Tests the invalid class name
+        /// </summary>
+        [Test]
+        public void TestInvalidClassName()
+        {
+            var javaObj = new JavaObject("blabla");
+
+            var ex = Assert.Throws<IgniteException>(() => TestFilter(javaObj));
+
+            Assert.IsTrue(ex.Message.StartsWith("Java object/factory class is not found"));
+        }
+
+        /// <summary>
+        /// Tests the invalid class name
+        /// </summary>
+        [Test]
+        public void TestInvalidProperty()
+        {
+            var javaObject = new JavaObject(PlatformFilter)
+            {
+                Properties = {{"invalidProp", "123"}}
+            };
+
+            var ex = Assert.Throws<IgniteException>(() => TestFilter(javaObject));
+
+            Assert.IsTrue(ex.Message.StartsWith("Java object/factory class field is not found"));
+        }
+
+        /// <summary>
+        /// Tests the specified filter.
+        /// </summary>
+        private void TestFilter(JavaObject obj)
+        {
+            TestFilter(obj, true);
+            TestFilter(obj, false);
+        }
+
+        /// <summary>
+        /// Tests the specified filter.
+        /// </summary>
+        private void TestFilter(JavaObject obj, bool local)
+        {
+            // Test with cache of strings
+            var pred = obj.ToCacheEntryEventFilter<int, string>();
+
+            TestFilter(pred, local, "validValue", "invalidValue");
+
+            // Test with cache of binary objects
+            var objPred = obj.ToCacheEntryEventFilter<int, TestBinary>();
+
+            TestFilter(objPred, local, new TestBinary(1, "validValue"), new TestBinary(2, "invalidValue"));
+        }
+
+        /// <summary>
+        /// Tests the specified filter.
+        /// </summary>
+        private void TestFilter<T>(ICacheEntryEventFilter<int, T> pred, bool local, T validVal, T invalidVal)
+        {
+            var cache = _ignite.GetOrCreateCache<int, T>("qry");
+            cache.Clear();
+
+            var qry = new ContinuousQuery<int, T>(new QueryListener<T>(), pred, local);
+            var aff = _ignite.GetAffinity("qry");
+            var localNode = _ignite.GetCluster().GetLocalNode();
+
+            // Get one key per node
+            var keyMap = aff.MapKeysToNodes(Enumerable.Range(1, 100));
+            Assert.AreEqual(3, keyMap.Count);
+            var keys = local
+                ? keyMap[localNode].Take(1)
+                : keyMap.Select(x => x.Value.First());
+
+            using (cache.QueryContinuous(qry))
+            {
+                // Run on many keys to test all nodes
+                foreach (var key in keys)
+                {
+                    _lastEvent = null;
+                    cache[key] = validVal;
+
+                    TestUtils.WaitForCondition(() => _lastEvent != null, 2000);
+                    Assert.IsNotNull(_lastEvent);
+                    Assert.AreEqual(cache[key], _lastEvent.Item2);
+
+                    _lastEvent = null;
+                    cache[key] = invalidVal;
+
+                    Thread.Sleep(2000);
+                    Assert.IsNull(_lastEvent);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Test listener.
+        /// </summary>
+        private class QueryListener<T> : ICacheEntryEventListener<int, T>
+        {
+            /** <inheritdoc /> */
+            public void OnEvent(IEnumerable<ICacheEntryEvent<int, T>> evts)
+            {
+                _lastEvent = evts.Select(e => Tuple.Create(e.Key, (object) e.Value)).FirstOrDefault();
+            }
+        }
+
+        /// <summary>
+        /// Test binary object.
+        /// </summary>
+        private class TestBinary
+        {
+            public TestBinary(int i, string s)
+            {
+                Int = i;
+                String = s;
+            }
+
+            private int Int { get; }
+            private string String { get; }
+
+            private bool Equals(TestBinary other)
+            {
+                return Int == other.Int && string.Equals(String, other.String);
+            }
+
+            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((TestBinary) obj);
+            }
+
+            public override int GetHashCode()
+            {
+                unchecked
+                {
+                    return (Int*397) ^ (String != null ? String.GetHashCode() : 0);
+                }
+            }
+        }
+    }
+}


[38/50] [abbrv] ignite git commit: IGNITE-2957 .NET: Added IIgnite.CacheNames() method. This closes #675.

Posted by sh...@apache.org.
IGNITE-2957 .NET: Added IIgnite.CacheNames() method. This closes #675.


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

Branch: refs/heads/ignite-2788
Commit: 1aa9ef7f57122ab2dcdb7770f9656d8fca15f359
Parents: ffbde05
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Fri Apr 29 10:26:57 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../platform/PlatformNoopProcessor.java           |  5 +++++
 .../processors/platform/PlatformProcessor.java    |  7 +++++++
 .../platform/PlatformProcessorImpl.java           | 15 +++++++++++++++
 .../cpp/common/include/ignite/common/exports.h    |  1 +
 .../cpp/common/include/ignite/common/java.h       |  2 ++
 .../platforms/cpp/common/project/vs/module.def    |  1 +
 modules/platforms/cpp/common/src/exports.cpp      |  4 ++++
 modules/platforms/cpp/common/src/java.cpp         | 11 +++++++++++
 .../Cache/CacheAbstractTest.cs                    | 18 ++++++++++++++++++
 .../dotnet/Apache.Ignite.Core/IIgnite.cs          |  8 ++++++++
 .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs      | 18 ++++++++++++++++++
 .../dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs |  7 +++++++
 .../Impl/Unmanaged/IgniteJniNativeMethods.cs      |  3 +++
 .../Impl/Unmanaged/UnmanagedUtils.cs              |  5 +++++
 14 files changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 155981c..cdf418f 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
@@ -152,6 +152,11 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf
     }
 
     /** {@inheritDoc} */
+    @Override public void getCacheNames(long memPtr) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
     @Override public PlatformTarget atomicSequence(String name, long initVal, boolean create) throws IgniteException {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 cca29d8..fc42b68 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
@@ -235,6 +235,13 @@ public interface PlatformProcessor extends GridProcessor {
     public void getIgniteConfiguration(long memPtr);
 
     /**
+     * Gets the cache names.
+     *
+     * @param memPtr Stream to write data to.
+     */
+    public void getCacheNames(long memPtr);
+
+    /**
      * Starts a near cache on local node if cache was previously started.
      *
      * @param cacheName Cache name.

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 e294735..5830d37 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
@@ -415,6 +415,21 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
     }
 
     /** {@inheritDoc} */
+    @Override public void getCacheNames(long memPtr) {
+        PlatformOutputStream stream = platformCtx.memory().get(memPtr).output();
+        BinaryRawWriterEx writer = platformCtx.writer(stream);
+
+        Collection<String> names = ignite().cacheNames();
+
+        writer.writeInt(names.size());
+
+        for (String name : names)
+            writer.writeString(name);
+
+        stream.synchronize();
+    }
+
+    /** {@inheritDoc} */
     @Override public PlatformTarget createNearCache(@Nullable String cacheName, long memPtr) {
         NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 c62b365..5798c83 100644
--- a/modules/platforms/cpp/common/include/ignite/common/exports.h
+++ b/modules/platforms/cpp/common/include/ignite/common/exports.h
@@ -53,6 +53,7 @@ extern "C" {
     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 long memPtr);
+    void IGNITE_CALL IgniteProcessorGetCacheNames(gcj::JniContext* ctx, void* obj, long long memPtr);
     
     long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr);
     void IGNITE_CALL IgniteTargetInStreamOutStream(gcj::JniContext* ctx, void* obj, int opType, long long inMemPtr, long long outMemPtr);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 f2007cb..7deb5ef 100644
--- a/modules/platforms/cpp/common/include/ignite/common/java.h
+++ b/modules/platforms/cpp/common/include/ignite/common/java.h
@@ -319,6 +319,7 @@ namespace ignite
                 jmethodID m_PlatformProcessor_extensions;
                 jmethodID m_PlatformProcessor_atomicLong;
                 jmethodID m_PlatformProcessor_getIgniteConfiguration;
+                jmethodID m_PlatformProcessor_getCacheNames;
                 jmethodID m_PlatformProcessor_atomicSequence;
                 jmethodID m_PlatformProcessor_atomicReference;
 
@@ -537,6 +538,7 @@ namespace ignite
                 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 long memPtr);
+				void ProcessorGetCacheNames(jobject obj, long long memPtr);
                 
                 long long TargetInStreamOutLong(jobject obj, int type, long long memPtr, JniErrorInfo* errInfo = NULL);
                 void TargetInStreamOutStream(jobject obj, int opType, long long inMemPtr, long long outMemPtr, JniErrorInfo* errInfo = NULL);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 57e58f3..5f2e941 100644
--- a/modules/platforms/cpp/common/project/vs/module.def
+++ b/modules/platforms/cpp/common/project/vs/module.def
@@ -132,3 +132,4 @@ IgniteAtomicReferenceIsClosed @129
 IgniteAtomicReferenceClose @130
 IgniteProcessorCreateNearCache @131
 IgniteProcessorGetOrCreateNearCache @132
+IgniteProcessorGetCacheNames @133

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 0d951b6..43ccb7a 100644
--- a/modules/platforms/cpp/common/src/exports.cpp
+++ b/modules/platforms/cpp/common/src/exports.cpp
@@ -134,6 +134,10 @@ extern "C" {
         return ctx->ProcessorGetIgniteConfiguration(static_cast<jobject>(obj), memPtr);
     }
 
+	void IGNITE_CALL IgniteProcessorGetCacheNames(gcj::JniContext* ctx, void* obj, long long memPtr) {
+        return ctx->ProcessorGetCacheNames(static_cast<jobject>(obj), memPtr);
+    }
+
     long long IGNITE_CALL IgniteTargetInStreamOutLong(gcj::JniContext* ctx, void* obj, int opType, long long memPtr) {
         return ctx->TargetInStreamOutLong(static_cast<jobject>(obj), opType, memPtr);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 081a606..663e2b1 100644
--- a/modules/platforms/cpp/common/src/java.cpp
+++ b/modules/platforms/cpp/common/src/java.cpp
@@ -208,6 +208,7 @@ namespace ignite
             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);
+            JniMethod M_PLATFORM_PROCESSOR_GET_CACHE_NAMES = JniMethod("getCacheNames", "(J)V", false);
 
             const char* C_PLATFORM_TARGET = "org/apache/ignite/internal/processors/platform/PlatformTarget";
             JniMethod M_PLATFORM_TARGET_IN_STREAM_OUT_LONG = JniMethod("inStreamOutLong", "(IJ)J", false);
@@ -679,6 +680,7 @@ namespace ignite
                 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);
+				m_PlatformProcessor_getCacheNames = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_CACHE_NAMES);
 
                 c_PlatformTarget = FindClass(env, C_PLATFORM_TARGET);
                 m_PlatformTarget_inStreamOutLong = FindMethod(env, c_PlatformTarget, M_PLATFORM_TARGET_IN_STREAM_OUT_LONG);
@@ -1462,6 +1464,15 @@ namespace ignite
                 ExceptionCheck(env);
             }
 
+            void JniContext::ProcessorGetCacheNames(jobject obj, long long memPtr)
+            {
+                JNIEnv* env = Attach();
+
+                env->CallVoidMethod(obj, jvm->GetMembers().m_PlatformProcessor_getCacheNames, memPtr);
+
+                ExceptionCheck(env);
+            }
+
             long long JniContext::TargetInStreamOutLong(jobject obj, int opType, long long memPtr, JniErrorInfo* err) {
                 JNIEnv* env = Attach();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
index 9f0528c..62dc2df 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
@@ -3062,8 +3062,10 @@ namespace Apache.Ignite.Core.Tests.Cache
 
             // Can't get non-existent cache with Cache method
             Assert.Throws<ArgumentException>(() => GetIgnite(0).GetCache<int, int>(randomName));
+            Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(randomName));
 
             var cache = GetIgnite(0).CreateCache<int, int>(randomName);
+            Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(randomName));
 
             cache.Put(1, 10);
 
@@ -3111,9 +3113,12 @@ namespace Apache.Ignite.Core.Tests.Cache
             var cache = ignite.CreateCache<int, int>(cacheName);
 
             Assert.IsNotNull(ignite.GetCache<int, int>(cacheName));
+            Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(cacheName));
 
             ignite.DestroyCache(cache.Name);
 
+            Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(cacheName));
+
             var ex = Assert.Throws<ArgumentException>(() => ignite.GetCache<int, int>(cacheName));
 
             Assert.IsTrue(ex.Message.StartsWith("Cache doesn't exist"));
@@ -3121,6 +3126,19 @@ namespace Apache.Ignite.Core.Tests.Cache
             Assert.Throws<InvalidOperationException>(() => cache.Get(1));
         }
 
+        [Test]
+        public void TestCacheNames()
+        {
+            var cacheNames = GetIgnite(0).GetCacheNames();
+            var expectedNames = new[]
+            {
+                "local", "local_atomic", "partitioned", "partitioned_atomic",
+                "partitioned_near", "partitioned_atomic_near", "replicated", "replicated_atomic"
+            };
+
+            Assert.AreEqual(0, expectedNames.Except(cacheNames).Count());
+        }
+
 
         [Test]
         public void TestIndexer()

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 428c1a8..b45c625 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
@@ -18,6 +18,7 @@
 namespace Apache.Ignite.Core
 {
     using System;
+    using System.Collections.Generic;
     using System.Diagnostics.CodeAnalysis;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache;
@@ -266,5 +267,12 @@ namespace Apache.Ignite.Core
         /// <typeparam name="TV">Cache value type.</typeparam>
         /// <returns>Near cache instance.</returns>
         ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration);
+
+        /// <summary>
+        /// Gets the collection of names of currently available caches, or empty collection if there are no caches.
+        /// Note that null string is a valid cache name.
+        /// </summary>
+        /// <returns>Collection of names of currently available caches.</returns>
+        ICollection<string> GetCacheNames();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 b84ff29..aee82a7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -622,6 +622,24 @@ namespace Apache.Ignite.Core.Impl
             return GetOrCreateNearCache0<TK, TV>(name, configuration, UU.ProcessorGetOrCreateNearCache);
         }
 
+        /** <inheritdoc /> */
+        public ICollection<string> GetCacheNames()
+        {
+            using (var stream = IgniteManager.Memory.Allocate(1024).GetStream())
+            {
+                UU.ProcessorGetCacheNames(_proc, stream.MemoryPointer);
+                stream.SynchronizeInput();
+
+                var reader = _marsh.StartUnmarshal(stream);
+                var res = new string[stream.ReadInt()];
+
+                for (int i = 0; i < res.Length; i++)
+                    res[i] = reader.ReadString();
+
+                return res;
+            }
+        }
+
         /// <summary>
         /// Gets or creates near cache.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 a767077..0ad056a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -366,12 +366,19 @@ namespace Apache.Ignite.Core.Impl
             return _ignite.CreateNearCache<TK, TV>(name, configuration);
         }
 
+        /** <inheritdoc /> */
         public ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
         {
             return _ignite.GetOrCreateNearCache<TK, TV>(name, configuration);
         }
 
         /** <inheritdoc /> */
+        public ICollection<string> GetCacheNames()
+        {
+            return _ignite.GetCacheNames();
+        }
+
+        /** <inheritdoc /> */
         public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create)
         {
             return _ignite.GetAtomicSequence(name, initialValue, create);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 2603841..bb26382 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
@@ -110,6 +110,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
         [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetIgniteConfiguration")]
         public static extern void ProcessorGetIgniteConfiguration(void* ctx, void* obj, long memPtr);
 
+        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetCacheNames")]
+        public static extern void ProcessorGetCacheNames(void* ctx, void* obj, long memPtr);
+
         [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteTargetInStreamOutLong")]
         public static extern long TargetInStreamOutLong(void* ctx, void* target, int opType, long memPtr);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1aa9ef7f/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 f8b5256..a0abfaa 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -356,6 +356,11 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
             JNI.ProcessorGetIgniteConfiguration(target.Context, target.Target, memPtr);
         }
 
+        internal static void ProcessorGetCacheNames(IUnmanagedTarget target, long memPtr)
+        {
+            JNI.ProcessorGetCacheNames(target.Context, target.Target, memPtr);
+        }
+
         #endregion
 
         #region NATIVE METHODS: TARGET


[04/50] [abbrv] ignite git commit: IGNITE-2004 Fixed "Asynchronous execution of ContinuousQuery's remote filter & local list".

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
index c01f636..9efc456 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
@@ -54,11 +54,13 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
 import org.apache.ignite.internal.processors.continuous.GridContinuousHandler;
 import org.apache.ignite.internal.processors.continuous.GridContinuousProcessor;
 import org.apache.ignite.internal.util.typedef.CI2;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteAsyncCallback;
 import org.apache.ignite.lang.IgniteClosure;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.plugin.security.SecurityPermission;
@@ -166,23 +168,8 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
      * @param key Entry key.
      * @param partId Partition id.
      * @param updCntr Updated counter.
-     * @param topVer Topology version.
-     */
-    public void skipUpdateEvent(Map<UUID, CacheContinuousQueryListener> lsnrs,
-        KeyCacheObject key,
-        int partId,
-        long updCntr,
-        AffinityTopologyVersion topVer) {
-        skipUpdateEvent(lsnrs, key, partId, updCntr, true, topVer);
-    }
-
-    /**
-     * @param lsnrs Listeners to notify.
-     * @param key Entry key.
-     * @param partId Partition id.
-     * @param updCntr Updated counter.
-     * @param topVer Topology version.
      * @param primary Primary.
+     * @param topVer Topology version.
      */
     public void skipUpdateEvent(Map<UUID, CacheContinuousQueryListener> lsnrs,
         KeyCacheObject key,
@@ -241,6 +228,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
      * @param primary {@code True} if called on primary node.
      * @param preload Whether update happened during preloading.
      * @param updateCntr Update counter.
+     * @param fut Dht atomic future.
      * @param topVer Topology version.
      * @throws IgniteCheckedException In case of error.
      */
@@ -253,7 +241,9 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
         boolean primary,
         boolean preload,
         long updateCntr,
-        AffinityTopologyVersion topVer) throws IgniteCheckedException {
+        @Nullable GridDhtAtomicUpdateFuture fut,
+        AffinityTopologyVersion topVer
+    ) throws IgniteCheckedException {
         Map<UUID, CacheContinuousQueryListener> lsnrCol = updateListeners(internal, preload);
 
         if (lsnrCol != null) {
@@ -267,6 +257,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                 primary,
                 preload,
                 updateCntr,
+                fut,
                 topVer);
         }
     }
@@ -282,6 +273,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
      * @param preload Whether update happened during preloading.
      * @param updateCntr Update counter.
      * @param topVer Topology version.
+     * @param fut Dht atomic future.
      * @throws IgniteCheckedException In case of error.
      */
     public void onEntryUpdated(
@@ -294,6 +286,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
         boolean primary,
         boolean preload,
         long updateCntr,
+        @Nullable GridDhtAtomicUpdateFuture fut,
         AffinityTopologyVersion topVer)
         throws IgniteCheckedException
     {
@@ -347,7 +340,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
             CacheContinuousQueryEvent evt = new CacheContinuousQueryEvent<>(
                 cctx.kernalContext().cache().jcache(cctx.name()), cctx, e0);
 
-            lsnr.onEntryUpdated(evt, primary, recordIgniteEvt);
+            lsnr.onEntryUpdated(evt, primary, recordIgniteEvt, fut);
         }
     }
 
@@ -401,7 +394,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                 CacheContinuousQueryEvent evt = new CacheContinuousQueryEvent(
                     cctx.kernalContext().cache().jcache(cctx.name()), cctx, e0);
 
-                lsnr.onEntryUpdated(evt, primary, recordIgniteEvt);
+                lsnr.onEntryUpdated(evt, primary, recordIgniteEvt, null);
             }
         }
     }
@@ -511,7 +504,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
         return executeQuery0(
             locLsnr,
             new IgniteClosure<Boolean, CacheContinuousQueryHandler>() {
-                @Override public CacheContinuousQueryHandler apply(Boolean aBoolean) {
+                @Override public CacheContinuousQueryHandler apply(Boolean v2) {
                     return new CacheContinuousQueryHandler(
                         cctx.name(),
                         TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()),
@@ -800,6 +793,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
     }
 
     /**
+     *
      */
     private class JCacheQuery {
         /** */
@@ -931,9 +925,9 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
     /**
      *
      */
-    private static class JCacheQueryLocalListener<K, V> implements CacheEntryUpdatedListener<K, V> {
+    static class JCacheQueryLocalListener<K, V> implements CacheEntryUpdatedListener<K, V> {
         /** */
-        private final CacheEntryListener<K, V> impl;
+        final CacheEntryListener<K, V> impl;
 
         /** */
         private final IgniteLogger log;
@@ -957,28 +951,28 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
                 try {
                     switch (evt.getEventType()) {
                         case CREATED:
-                            assert impl instanceof CacheEntryCreatedListener;
+                            assert impl instanceof CacheEntryCreatedListener : evt;
 
                             ((CacheEntryCreatedListener<K, V>)impl).onCreated(singleton(evt));
 
                             break;
 
                         case UPDATED:
-                            assert impl instanceof CacheEntryUpdatedListener;
+                            assert impl instanceof CacheEntryUpdatedListener : evt;
 
                             ((CacheEntryUpdatedListener<K, V>)impl).onUpdated(singleton(evt));
 
                             break;
 
                         case REMOVED:
-                            assert impl instanceof CacheEntryRemovedListener;
+                            assert impl instanceof CacheEntryRemovedListener : evt;
 
                             ((CacheEntryRemovedListener<K, V>)impl).onRemoved(singleton(evt));
 
                             break;
 
                         case EXPIRED:
-                            assert impl instanceof CacheEntryExpiredListener;
+                            assert impl instanceof CacheEntryExpiredListener : evt;
 
                             ((CacheEntryExpiredListener<K, V>)impl).onExpired(singleton(evt));
 
@@ -1009,6 +1003,13 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
 
             return evts;
         }
+
+        /**
+         * @return {@code True} if listener should be executed in non-system thread.
+         */
+        protected boolean async() {
+            return U.hasAnnotation(impl, IgniteAsyncCallback.class);
+        }
     }
 
     /**
@@ -1019,7 +1020,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
         private static final long serialVersionUID = 0L;
 
         /** */
-        private CacheEntryEventFilter impl;
+        protected CacheEntryEventFilter impl;
 
         /** */
         private byte types;
@@ -1072,6 +1073,13 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
         }
 
         /**
+         * @return {@code True} if filter should be executed in non-system thread.
+         */
+        protected boolean async() {
+            return U.hasAnnotation(impl, IgniteAsyncCallback.class);
+        }
+
+        /**
          * @param evtType Type.
          * @return Flag value.
          */

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncCallback.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncCallback.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncCallback.java
new file mode 100644
index 0000000..1e04ce6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncCallback.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.lang;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryListener;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.configuration.IgniteConfiguration;
+
+/**
+ * If callback has this annotation then it will be executing in another thread.
+ * <p>
+ * Currently this annotation is supported for:
+ * <ol>
+ *     <li>{@link ContinuousQuery} - {@link CacheEntryUpdatedListener} and {@link CacheEntryEventFilter}.</li>
+ * </ol>
+ * <p>
+ * For example, if {@link CacheEntryEventFilter filter} or {@link CacheEntryListener}
+ * has the annotation then callbacks will be executing to asyncCallback thread pool. It allows to use cache API
+ * in a callbacks. This thread pool can be configured by {@link IgniteConfiguration#setAsyncCallbackPoolSize(int)}.
+ * <h1 class="header">Example</h1>
+ * As an example, suppose we have cache with {@code 'Person'} objects and we need
+ * to query all persons with salary above then 1000. Also remote filter will update some entries.
+ * <p>
+ * Here is the {@code Person} class:
+ * <pre name="code" class="java">
+ * public class Person {
+ *     // Name.
+ *     private String name;
+ *
+ *     // Salary.
+ *     private double salary;
+ *
+ *     ...
+ * }
+ * </pre>
+ * <p>
+ * Here is the {@code ExampleCacheEntryFilter} class:
+ * <pre name="code" class="java">
+ * &#064;IgniteAsyncCallback
+ * public class ExampleCacheEntryFilter implements CacheEntryEventFilter&lt;Integer, Person&gt; {
+ *     &#064;IgniteInstanceResource
+ *     private Ignite ignite;
+ *
+ *     // Continuous listener will be notified for persons with salary above 1000.
+ *     // Filter increases salary for some person on 100. Without &#064;IgniteAsyncCallback annotation
+ *     // this operation is not safe.
+ *     public boolean evaluate(CacheEntryEvent&lt;? extends K, ? extends V&gt; evt) throws CacheEntryListenerException {
+ *         Person p = evt.getValue();
+ *
+ *         if (p.getSalary() &gt; 1000)
+ *             return true;
+ *
+ *         ignite.cache("Person").put(evt.getKey(), new Person(p.getName(), p.getSalary() + 100));
+ *
+ *         return false;
+ *     }
+ * }
+ * </pre>
+ * <p>
+ * Query with asynchronous callback execute as usually:
+ * <pre name="code" class="java">
+ * // Create new continuous query.
+ * ContinuousQuery&lt;Long, Person&gt; qry = new ContinuousQuery&lt;&gt;();
+ *
+ * // Callback that is called locally when update notifications are received.
+ * // It simply prints out information about all created persons.
+ * qry.setLocalListener((evts) -> {
+ *     for (CacheEntryEvent&lt;? extends Long, ? extends Person&gt; e : evts) {
+ *         Person p = e.getValue();
+ *
+ *         System.out.println(p.getFirstName() + " " + p.getLastName() + "'s salary is " + p.getSalary());
+ *     }
+ * });
+ *
+ * // Sets remote filter.
+ * qry.setRemoteFilterFactory(() -> new ExampleCacheEntryFilter());
+ *
+ * // Execute query.
+ * QueryCursor&lt;Cache.Entry&lt;Long, Person&gt;&gt; cur = cache.query(qry);
+ * </pre>
+ *
+ * @see IgniteConfiguration#getAsyncCallbackPoolSize
+ * @see ContinuousQuery#getRemoteFilterFactory()
+ * @see ContinuousQuery#getLocalListener()
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface IgniteAsyncCallback {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/thread/IgniteStripedThreadPoolExecutor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/thread/IgniteStripedThreadPoolExecutor.java b/modules/core/src/main/java/org/apache/ignite/thread/IgniteStripedThreadPoolExecutor.java
index 35882b9..9f7c381 100644
--- a/modules/core/src/main/java/org/apache/ignite/thread/IgniteStripedThreadPoolExecutor.java
+++ b/modules/core/src/main/java/org/apache/ignite/thread/IgniteStripedThreadPoolExecutor.java
@@ -17,62 +17,63 @@
 
 package org.apache.ignite.thread;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.NotNull;
 
 /**
  * An {@link ExecutorService} that executes submitted tasks using pooled grid threads.
  */
 public class IgniteStripedThreadPoolExecutor implements ExecutorService {
     /** */
-    public static final int DFLT_SEG_POOL_SIZE = 8;
-
-    /** */
-    public static final int DFLT_CONCUR_LVL = 16;
-
-    /** */
     private final ExecutorService[] execs;
 
-    /** */
-    private final int segShift;
-
-    /** */
-    private final int segMask;
-
     /**
+     * Create striped thread pool.
      *
+     * @param concurrentLvl Concurrency level.
+     * @param gridName Node name.
+     * @param threadNamePrefix Thread name prefix.
      */
-    public IgniteStripedThreadPoolExecutor() {
-        execs = new ExecutorService[DFLT_CONCUR_LVL];
-
-        ThreadFactory factory = new IgniteThreadFactory(null);
-
-        for (int i = 0; i < DFLT_CONCUR_LVL; i++)
-            execs[i] = Executors.newFixedThreadPool(DFLT_SEG_POOL_SIZE, factory);
+    public IgniteStripedThreadPoolExecutor(int concurrentLvl, String gridName, String threadNamePrefix) {
+        execs = new ExecutorService[concurrentLvl];
 
-        // Find power-of-two sizes best matching arguments
-        int sshift = 0;
-        int ssize = 1;
+        ThreadFactory factory = new IgniteThreadFactory(gridName, threadNamePrefix);
 
-        while (ssize < DFLT_CONCUR_LVL) {
-            ++sshift;
-
-            ssize <<= 1;
-        }
+        for (int i = 0; i < concurrentLvl; i++)
+            execs[i] = Executors.newSingleThreadExecutor(factory);
+    }
 
-        segShift = 32 - sshift;
-        segMask = ssize - 1;
+    /**
+     * Executes the given command at some time in the future. The command with the same {@code index}
+     * will be executed in the same thread.
+     *
+     * @param task the runnable task
+     * @param idx Striped index.
+     * @throws RejectedExecutionException if this task cannot be
+     * accepted for execution.
+     * @throws NullPointerException If command is null
+     */
+    public void execute(Runnable task, int idx) {
+        execs[threadId(idx)].execute(task);
+    }
 
+    /**
+     * @param idx Index.
+     * @return Stripped thread ID.
+     */
+    public int threadId(int idx) {
+        return idx < execs.length ? idx : idx % execs.length;
     }
 
     /** {@inheritDoc} */
@@ -83,7 +84,10 @@ public class IgniteStripedThreadPoolExecutor implements ExecutorService {
 
     /** {@inheritDoc} */
     @Override public List<Runnable> shutdownNow() {
-        List<Runnable> res = new LinkedList<>();
+        if (execs.length == 0)
+            return Collections.emptyList();
+
+        List<Runnable> res = new ArrayList<>(execs.length);
 
         for (ExecutorService exec : execs) {
             for (Runnable r : exec.shutdownNow())
@@ -124,105 +128,45 @@ public class IgniteStripedThreadPoolExecutor implements ExecutorService {
     }
 
     /** {@inheritDoc} */
-    @Override public <T> Future<T> submit(Callable<T> task) {
-        return execForTask(task).submit(task);
+    @NotNull @Override public <T> Future<T> submit(Callable<T> task) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public <T> Future<T> submit(Runnable task, T result) {
-        return execForTask(task).submit(task, result);
+    @NotNull @Override public <T> Future<T> submit(Runnable task, T res) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public Future<?> submit(Runnable task) {
-        return execForTask(task).submit(task);
+    @NotNull @Override public Future<?> submit(Runnable task) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
-        throws InterruptedException {
-        List<Future<T>> futs = new LinkedList<>();
-
-        for (Callable<T> task : tasks)
-            futs.add(execForTask(task).submit(task));
-
-        boolean done = false;
-
-        try {
-            for (Future<T> fut : futs) {
-                try {
-                    fut.get();
-                }
-                catch (ExecutionException | InterruptedException ignored) {
-                    // No-op.
-                }
-            }
-
-            done = true;
-
-            return futs;
-        }
-        finally {
-            if (!done) {
-                for (Future<T> fut : futs)
-                    fut.cancel(true);
-            }
-        }
+    @NotNull @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
-        TimeUnit unit) throws InterruptedException {
-        throw new RuntimeException("Not implemented.");
+    @NotNull @Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
+        long timeout,
+        TimeUnit unit) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException,
-        ExecutionException {
-        throw new RuntimeException("Not implemented.");
+    @NotNull @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
-    @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
-        throws InterruptedException, ExecutionException, TimeoutException {
-        throw new RuntimeException("Not implemented.");
+    @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) {
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
     @Override public void execute(Runnable cmd) {
-        execForTask(cmd).execute(cmd);
-    }
-
-    /**
-     * Applies a supplemental hash function to a given hashCode, which
-     * defends against poor quality hash functions.  This is critical
-     * because ConcurrentHashMap uses power-of-two length hash tables,
-     * that otherwise encounter collisions for hashCodes that do not
-     * differ in lower or upper bits.
-     *
-     * @param h Hash code.
-     * @return Enhanced hash code.
-     */
-    private int hash(int h) {
-        // Spread bits to regularize both segment and index locations,
-        // using variant of single-word Wang/Jenkins hash.
-        h += (h <<  15) ^ 0xffffcd7d;
-        h ^= (h >>> 10);
-        h += (h <<   3);
-        h ^= (h >>>  6);
-        h += (h <<   2) + (h << 14);
-        return h ^ (h >>> 16);
-    }
-
-    /**
-     * @param cmd Command.
-     * @return Service.
-     */
-    private <T> ExecutorService execForTask(T cmd) {
-        assert cmd != null;
-
-        //return execs[ThreadLocalRandom8.current().nextInt(DFLT_CONCUR_LVL)];
-        return execs[(hash(cmd.hashCode()) >>> segShift) & segMask];
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index 6e404b4..a1153cd 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -26,6 +26,7 @@ import javax.cache.processor.EntryProcessorResult;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.eviction.EvictableEntry;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -540,7 +541,8 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
         UUID subjId,
         String taskName,
         @Nullable CacheObject prevVal,
-        @Nullable Long updateCntr) throws IgniteCheckedException,
+        @Nullable Long updateCntr,
+        @Nullable GridDhtAtomicUpdateFuture fut) throws IgniteCheckedException,
         GridCacheEntryRemovedException {
         assert false;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest.java
new file mode 100644
index 0000000..62fd984
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+
+/**
+ *
+ */
+public class CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest
+    extends CacheContinuousQueryFailoverAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode writeOrderMode() {
+        return PRIMARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean asyncCallback() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest.java
new file mode 100644
index 0000000..4460498
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import org.apache.ignite.cache.CacheMode;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ *
+ */
+public class CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest extends CacheContinuousQueryFailoverTxSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean asyncCallback() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxSelfTest.java
new file mode 100644
index 0000000..8f0bd0e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFailoverTxSelfTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class CacheContinuousQueryAsyncFailoverTxSelfTest extends CacheContinuousQueryFailoverAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean asyncCallback() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFilterListenerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFilterListenerTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFilterListenerTest.java
new file mode 100644
index 0000000..0605bc8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryAsyncFilterListenerTest.java
@@ -0,0 +1,986 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
+import javax.cache.event.CacheEntryCreatedListener;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_VALUES;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ *
+ */
+public class CacheContinuousQueryAsyncFilterListenerTest extends GridCommonAbstractTest {
+    /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int NODES = 5;
+
+    /** */
+    public static final int ITERATION_CNT = 100;
+
+    /** */
+    private boolean client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        cfg.setClientMode(client);
+
+        MemoryEventStorageSpi storeSpi = new MemoryEventStorageSpi();
+        storeSpi.setExpireCount(1000);
+
+        cfg.setEventStorageSpi(storeSpi);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGridsMultiThreaded(NODES - 1);
+
+        client = true;
+
+        startGrid(NODES - 1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    ///
+    /// ASYNC FILTER AND LISTENER. TEST LISTENER.
+    ///
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerTx() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerTxJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerTxOffHeap() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerTxOffHeapJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerTxOffHeapValues() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_VALUES), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomic() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomicJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerReplicatedAtomic() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerReplicatedAtomicJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, ATOMIC, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerReplicatedAtomicOffHeapValues() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomicOffHeap() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomicOffHeapValues() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomicWithoutBackup() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 0, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerAtomicWithoutBackupJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 0, ATOMIC, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListener() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerReplicated() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInListenerReplicatedJCacheApi() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, true);
+    }
+
+    ///
+    /// ASYNC FILTER AND LISTENER. TEST FILTER.
+    ///
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTx() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxJCacheApi() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxOffHeap() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxOffHeapJCacheApi() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxOffHeapValues() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_VALUES), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomic() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicJCacheApi() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, ATOMIC, ONHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterReplicatedAtomic() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(REPLICATED, 2, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicOffHeap() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicOffHeapJCacheApi() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), true, true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicOffHeapValues() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicWithoutBackup() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 0, ATOMIC, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilter() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterReplicated() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterReplicatedJCacheApi() throws Exception {
+        testNonDeadLockInFilter(cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, ONHEAP_TIERED), true, true, false);
+    }
+
+    ///
+    /// ASYNC LISTENER. TEST LISTENER.
+    ///
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxOffHeapSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterTxOffHeapValuesSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, OFFHEAP_VALUES), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterReplicatedAtomicSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, ATOMIC, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicOffHeapSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicOffHeapValuesSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, ATOMIC, OFFHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterAtomicWithoutBackupSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 0, ATOMIC, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNonDeadLockInFilterReplicatedSyncFilter() throws Exception {
+        testNonDeadLockInListener(cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, ONHEAP_TIERED), false, true, false);
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     * @param asyncFltr Async filter.
+     * @param asyncLsnr Async listener.
+     * @param jcacheApi Use JCache api for registration entry update listener.
+     * @throws Exception If failed.
+     */
+    private void testNonDeadLockInListener(CacheConfiguration ccfg,
+        final boolean asyncFltr,
+        boolean asyncLsnr,
+        boolean jcacheApi) throws Exception {
+        ignite(0).createCache(ccfg);
+
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        try {
+            for (int i = 0; i < ITERATION_CNT; i++) {
+                log.info("Start iteration: " + i);
+
+                int nodeIdx = i % NODES;
+
+                final IgniteCache cache = grid(nodeIdx).cache(ccfg.getName());
+
+                final QueryTestKey key = NODES - 1 != nodeIdx ? affinityKey(cache) : new QueryTestKey(1);
+
+                final QueryTestValue val0 = new QueryTestValue(1);
+                final QueryTestValue newVal = new QueryTestValue(2);
+
+                final CountDownLatch latch = new CountDownLatch(1);
+                final CountDownLatch evtFromLsnrLatch = new CountDownLatch(1);
+
+                IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> fltrClsr =
+                    new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
+                        @Override public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey,
+                            ? extends QueryTestValue> e) {
+                            if (asyncFltr) {
+                                assertFalse("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("sys-"));
+
+                                assertTrue("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("callback-"));
+                            }
+                        }
+                    };
+
+                IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> lsnrClsr =
+                    new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
+                        @Override public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey,
+                            ? extends QueryTestValue> e) {
+                            IgniteCache<Object, Object> cache0 = ignite.cache(cache.getName());
+
+                            QueryTestValue val = e.getValue();
+
+                            if (val == null)
+                                return;
+                            else if (val.equals(newVal)) {
+                                evtFromLsnrLatch.countDown();
+
+                                return;
+                            }
+                            else if (!val.equals(val0))
+                                return;
+
+                            Transaction tx = null;
+
+                            try {
+                                if (cache0.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL)
+                                    tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
+
+                                assertEquals(val, val0);
+
+                                cache0.put(key, newVal);
+
+                                if (tx != null)
+                                    tx.commit();
+
+                                latch.countDown();
+                            }
+                            catch (Exception exp) {
+                                log.error("Failed: ", exp);
+
+                                throw new IgniteException(exp);
+                            }
+                            finally {
+                                if (tx != null)
+                                    tx.close();
+                            }
+                        }
+                    };
+
+                QueryCursor qry = null;
+                MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg = null;
+
+                CacheInvokeListener locLsnr = asyncLsnr ? new CacheInvokeListenerAsync(lsnrClsr)
+                    : new CacheInvokeListener(lsnrClsr);
+
+                CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> rmtFltr = asyncFltr ?
+                    new CacheTestRemoteFilterAsync(fltrClsr) : new CacheTestRemoteFilter(fltrClsr);
+
+                if (jcacheApi) {
+                    lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
+                        FactoryBuilder.factoryOf(locLsnr),
+                        FactoryBuilder.factoryOf(rmtFltr),
+                        true,
+                        false
+                    );
+
+                    cache.registerCacheEntryListener(lsnrCfg);
+                }
+                else {
+                    ContinuousQuery<QueryTestKey, QueryTestValue> conQry = new ContinuousQuery<>();
+
+                    conQry.setLocalListener(locLsnr);
+
+                    conQry.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFltr));
+
+                    qry = cache.query(conQry);
+                }
+
+                try {
+                    if (rnd.nextBoolean())
+                        cache.put(key, val0);
+                    else {
+                        cache.invoke(key, new CacheEntryProcessor() {
+                            @Override public Object process(MutableEntry entry, Object... arguments)
+                                throws EntryProcessorException {
+                                entry.setValue(val0);
+
+                                return null;
+                            }
+                        });
+                    }
+
+                    assertTrue("Failed to waiting event.", U.await(latch, 3, SECONDS));
+
+                    assertEquals(cache.get(key), new QueryTestValue(2));
+
+                    assertTrue("Failed to waiting event from listener.", U.await(latch, 3, SECONDS));
+                }
+                finally {
+                    if (qry != null)
+                        qry.close();
+
+                    if (lsnrCfg != null)
+                        cache.deregisterCacheEntryListener(lsnrCfg);
+                }
+
+                log.info("Iteration finished: " + i);
+            }
+        }
+        finally {
+            ignite(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     * @param asyncFilter Async filter.
+     * @param asyncLsnr Async listener.
+     * @param jcacheApi Use JCache api for start update listener.
+     * @throws Exception If failed.
+     */
+    private void testNonDeadLockInFilter(CacheConfiguration ccfg,
+        final boolean asyncFilter,
+        final boolean asyncLsnr,
+        boolean jcacheApi) throws Exception {
+        ignite(0).createCache(ccfg);
+
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        try {
+            for (int i = 0; i < ITERATION_CNT; i++) {
+                log.info("Start iteration: " + i);
+
+                int nodeIdx = i % NODES;
+
+                final IgniteCache cache = grid(nodeIdx).cache(ccfg.getName());
+
+                final QueryTestKey key = NODES - 1 != nodeIdx ? affinityKey(cache) : new QueryTestKey(1);
+
+                final QueryTestValue val0 = new QueryTestValue(1);
+                final QueryTestValue newVal = new QueryTestValue(2);
+
+                final CountDownLatch latch = new CountDownLatch(1);
+                final CountDownLatch evtFromLsnrLatch = new CountDownLatch(1);
+
+                IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> fltrClsr =
+                    new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
+                        @Override public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey,
+                            ? extends QueryTestValue> e) {
+                            if (asyncFilter) {
+                                assertFalse("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("sys-"));
+
+                                assertTrue("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("callback-"));
+                            }
+
+                            IgniteCache<Object, Object> cache0 = ignite.cache(cache.getName());
+
+                            QueryTestValue val = e.getValue();
+
+                            if (val == null)
+                                return;
+                            else if (val.equals(newVal)) {
+                                evtFromLsnrLatch.countDown();
+
+                                return;
+                            }
+                            else if (!val.equals(val0))
+                                return;
+
+                            Transaction tx = null;
+
+                            try {
+                                if (cache0.getConfiguration(CacheConfiguration.class)
+                                    .getAtomicityMode() == TRANSACTIONAL)
+                                    tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
+
+                                assertEquals(val, val0);
+
+                                cache0.put(key, newVal);
+
+                                if (tx != null)
+                                    tx.commit();
+
+                                latch.countDown();
+                            }
+                            catch (Exception exp) {
+                                log.error("Failed: ", exp);
+
+                                throw new IgniteException(exp);
+                            }
+                            finally {
+                                if (tx != null)
+                                    tx.close();
+                            }
+                        }
+                    };
+
+                IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> lsnrClsr =
+                    new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
+                        @Override public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey,
+                            ? extends QueryTestValue> e) {
+                            if (asyncLsnr) {
+                                assertFalse("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("sys-"));
+
+                                assertTrue("Failed: " + Thread.currentThread().getName(),
+                                    Thread.currentThread().getName().contains("callback-"));
+                            }
+
+                            QueryTestValue val = e.getValue();
+
+                            if (val == null || !val.equals(new QueryTestValue(1)))
+                                return;
+
+                            assertEquals(val, val0);
+
+                            latch.countDown();
+                        }
+                    };
+
+
+                QueryCursor qry = null;
+                MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg = null;
+
+                CacheInvokeListener locLsnr = asyncLsnr ? new CacheInvokeListenerAsync(lsnrClsr)
+                    : new CacheInvokeListener(lsnrClsr);
+
+                CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> rmtFltr = asyncFilter ?
+                    new CacheTestRemoteFilterAsync(fltrClsr) : new CacheTestRemoteFilter(fltrClsr);
+
+                if (jcacheApi) {
+                    lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
+                        FactoryBuilder.factoryOf(locLsnr),
+                        FactoryBuilder.factoryOf(rmtFltr),
+                        true,
+                        false
+                    );
+
+                    cache.registerCacheEntryListener(lsnrCfg);
+                }
+                else {
+                    ContinuousQuery<QueryTestKey, QueryTestValue> conQry = new ContinuousQuery<>();
+
+                    conQry.setLocalListener(locLsnr);
+
+                    conQry.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFltr));
+
+                    qry = cache.query(conQry);
+                }
+
+                try {
+                    if (rnd.nextBoolean())
+                        cache.put(key, val0);
+                    else
+                        cache.invoke(key, new CacheEntryProcessor() {
+                            @Override public Object process(MutableEntry entry, Object... arguments)
+                                throws EntryProcessorException {
+                                entry.setValue(val0);
+
+                                return null;
+                            }
+                        });
+
+                    assert U.await(latch, 3, SECONDS) : "Failed to waiting event.";
+
+                    assertEquals(cache.get(key), new QueryTestValue(2));
+
+                    assertTrue("Failed to waiting event from filter.", U.await(latch, 3, SECONDS));
+                }
+                finally {
+                    if (qry != null)
+                        qry.close();
+
+                    if (lsnrCfg != null)
+                        cache.deregisterCacheEntryListener(lsnrCfg);
+                }
+
+                log.info("Iteration finished: " + i);
+            }
+        }
+        finally {
+            ignite(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @return Key.
+     */
+    private QueryTestKey affinityKey(IgniteCache cache) {
+        Affinity aff = affinity(cache);
+
+        for (int i = 0; i < 10_000; i++) {
+            QueryTestKey key = new QueryTestKey(i);
+
+            if (aff.isPrimary(localNode(cache), key))
+                return key;
+        }
+
+        throw new IgniteException("Failed to found primary key.");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return TimeUnit.SECONDS.toMillis(15);
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class CacheTestRemoteFilterAsync extends CacheTestRemoteFilter {
+        /**
+         * @param clsr Closure.
+         */
+        public CacheTestRemoteFilterAsync(
+            IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> clsr) {
+            super(clsr);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class CacheTestRemoteFilter implements
+        CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> {
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        private IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> clsr;
+
+        /**
+         * @param clsr Closure.
+         */
+        public CacheTestRemoteFilter(IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> clsr) {
+            this.clsr = clsr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e)
+            throws CacheEntryListenerException {
+            clsr.apply(ignite, e);
+
+            return true;
+        }
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class CacheInvokeListenerAsync extends CacheInvokeListener {
+        /**
+         * @param clsr Closure.
+         */
+        public CacheInvokeListenerAsync(
+            IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> clsr) {
+            super(clsr);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class CacheInvokeListener implements CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>,
+        CacheEntryCreatedListener<QueryTestKey, QueryTestValue>, Serializable {
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        private IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> clsr;
+
+        /**
+         * @param clsr Closure.
+         */
+        public CacheInvokeListener(IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> clsr) {
+            this.clsr = clsr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> events)
+            throws CacheEntryListenerException {
+            for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events)
+                clsr.apply(ignite, e);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onCreated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> events) throws CacheEntryListenerException {
+            for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events)
+                clsr.apply(ignite, e);
+        }
+    }
+
+    /**
+     * @param cacheMode Cache mode.
+     * @param backups Number of backups.
+     * @param atomicityMode Cache atomicity mode.
+     * @param memoryMode Cache memory mode.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode) {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setName("test-cache-" + atomicityMode + "-" + cacheMode + "-" + memoryMode + "-" + backups);
+        ccfg.setAtomicityMode(atomicityMode);
+        ccfg.setCacheMode(cacheMode);
+        ccfg.setMemoryMode(memoryMode);
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setAtomicWriteOrderMode(PRIMARY);
+
+        if (cacheMode == PARTITIONED)
+            ccfg.setBackups(backups);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestKey implements Serializable, Comparable {
+        /** */
+        private final Integer key;
+
+        /**
+         * @param key Key.
+         */
+        public QueryTestKey(Integer key) {
+            this.key = key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestKey that = (QueryTestKey)o;
+
+            return key.equals(that.key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return key.hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestKey.class, this);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int compareTo(Object o) {
+            return key - ((QueryTestKey)o).key;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestValue implements Serializable {
+        /** */
+        @GridToStringInclude
+        protected final Integer val1;
+
+        /** */
+        @GridToStringInclude
+        protected final String val2;
+
+        /**
+         * @param val Value.
+         */
+        public QueryTestValue(Integer val) {
+            this.val1 = val;
+            this.val2 = String.valueOf(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestValue that = (QueryTestValue)o;
+
+            return val1.equals(that.val1) && val2.equals(that.val2);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = val1.hashCode();
+
+            res = 31 * res + val2.hashCode();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestValue.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryAsyncFilterRandomOperationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryAsyncFilterRandomOperationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryAsyncFilterRandomOperationTest.java
new file mode 100644
index 0000000..928cfda
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryAsyncFilterRandomOperationTest.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ *
+ */
+public class CacheContinuousQueryFactoryAsyncFilterRandomOperationTest
+    extends CacheContinuousQueryFactoryFilterRandomOperationTest {
+    /** {@inheritDoc} */
+    @NotNull @Override protected Factory<? extends CacheEntryEventFilter<QueryTestKey, QueryTestValue>>
+        createFilterFactory() {
+        return new AsyncFilterFactory();
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    protected static class NonSerializableAsyncFilter implements
+        CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue>, Externalizable {
+        /** */
+        public NonSerializableAsyncFilter() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> evt) {
+            assertTrue("Failed. Current thread name: " + Thread.currentThread().getName(),
+                Thread.currentThread().getName().contains("callback-"));
+
+            assertFalse("Failed. Current thread name: " + Thread.currentThread().getName(),
+                Thread.currentThread().getName().contains("sys-"));
+
+            return isAccepted(evt.getValue());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            fail("Entry filter should not be marshaled.");
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            fail("Entry filter should not be marshaled.");
+        }
+
+        /**
+         * @param val Value.
+         * @return {@code True} if value is even.
+         */
+        public static boolean isAccepted(QueryTestValue val) {
+            return val == null || val.val1 % 2 == 0;
+        }
+    }
+
+    /**
+     *
+     */
+    protected static class AsyncFilterFactory implements Factory<NonSerializableAsyncFilter> {
+        /** {@inheritDoc} */
+        @Override public NonSerializableAsyncFilter create() {
+            return new NonSerializableAsyncFilter();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Factory<? extends CacheEntryEventFilter<QueryTestKey, QueryTestValue>> noOpFilterFactory() {
+        return FactoryBuilder.factoryOf(NoopAsyncFilter.class);
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    protected static class NoopAsyncFilter implements
+        CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue>, Externalizable {
+        /** */
+        public NoopAsyncFilter() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> evt) {
+            assertTrue("Failed. Current thread name: " + Thread.currentThread().getName(),
+                Thread.currentThread().getName().contains("callback-"));
+
+            assertFalse("Failed. Current thread name: " + Thread.currentThread().getName(),
+                Thread.currentThread().getName().contains("sys-"));
+
+            return true;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            // No-op.
+        }
+    }
+}


[03/50] [abbrv] ignite git commit: IGNITE-2004 Fixed "Asynchronous execution of ContinuousQuery's remote filter & local list".

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterRandomOperationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterRandomOperationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterRandomOperationTest.java
new file mode 100644
index 0000000..dbaafe1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterRandomOperationTest.java
@@ -0,0 +1,725 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import javax.cache.configuration.CacheEntryListenerConfiguration;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
+import javax.cache.event.CacheEntryCreatedListener;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryExpiredListener;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryRemovedListener;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cache.query.CacheQueryEntryEvent;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.jetbrains.annotations.NotNull;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryFilterRandomOperationTest.NonSerializableFilter.isAccepted;
+import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest.ContinuousDeploy.CLIENT;
+import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest.ContinuousDeploy.SERVER;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE;
+
+/**
+ *
+ */
+public class CacheContinuousQueryFactoryFilterRandomOperationTest extends CacheContinuousQueryRandomOperationsTest {
+    /** */
+    private static final int NODES = 5;
+
+    /** */
+    private static final int KEYS = 50;
+
+    /** */
+    private static final int VALS = 10;
+
+    /** */
+    public static final int ITERATION_CNT = 40;
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInternalQuery() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED,
+            1,
+            ATOMIC,
+            ONHEAP_TIERED,
+            false);
+
+        final IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
+
+        UUID uuid = null;
+
+        try {
+            for (int i = 0; i < 10; i++)
+                cache.put(i, i);
+
+            final CountDownLatch latch = new CountDownLatch(5);
+
+            CacheEntryUpdatedListener lsnr = new CacheEntryUpdatedListener() {
+                @Override public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
+                    for (Object evt : iterable) {
+                        latch.countDown();
+
+                        log.info("Received event: " + evt);
+                    }
+                }
+            };
+
+            uuid = grid(0).context().cache().cache(cache.getName()).context().continuousQueries()
+                .executeInternalQuery(lsnr, new SerializableFilter(), false, true, true);
+
+            for (int i = 10; i < 20; i++)
+                cache.put(i, i);
+
+            assertTrue(latch.await(3, SECONDS));
+        }
+        finally {
+            if (uuid != null)
+                grid(0).context().cache().cache(cache.getName()).context().continuousQueries()
+                    .cancelInternalQuery(uuid);
+
+            grid(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doTestContinuousQuery(CacheConfiguration<Object, Object> ccfg, ContinuousDeploy deploy)
+        throws Exception {
+        ignite(0).createCache(ccfg);
+
+        try {
+            long seed = System.currentTimeMillis();
+
+            Random rnd = new Random(seed);
+
+            log.info("Random seed: " + seed);
+
+            List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues = new ArrayList<>();
+
+            Collection<QueryCursor<?>> curs = new ArrayList<>();
+
+            Collection<T2<Integer, MutableCacheEntryListenerConfiguration>> lsnrCfgs = new ArrayList<>();
+
+            if (deploy == CLIENT)
+                evtsQueues.add(registerListener(ccfg.getName(), NODES - 1, curs, lsnrCfgs, rnd.nextBoolean()));
+            else if (deploy == SERVER)
+                evtsQueues.add(registerListener(ccfg.getName(), rnd.nextInt(NODES - 1), curs, lsnrCfgs,
+                    rnd.nextBoolean()));
+            else {
+                boolean isSync = rnd.nextBoolean();
+
+                for (int i = 0; i < NODES - 1; i++)
+                    evtsQueues.add(registerListener(ccfg.getName(), i, curs, lsnrCfgs, isSync));
+            }
+
+            ConcurrentMap<Object, Object> expData = new ConcurrentHashMap<>();
+
+            Map<Integer, Long> partCntr = new ConcurrentHashMap<>();
+
+            try {
+                for (int i = 0; i < ITERATION_CNT; i++) {
+                    if (i % 10 == 0)
+                        log.info("Iteration: " + i);
+
+                    for (int idx = 0; idx < NODES; idx++)
+                        randomUpdate(rnd, evtsQueues, expData, partCntr, grid(idx).cache(ccfg.getName()));
+                }
+            }
+            finally {
+                for (QueryCursor<?> cur : curs)
+                    cur.close();
+
+                for (T2<Integer, MutableCacheEntryListenerConfiguration> e : lsnrCfgs)
+                    grid(e.get1()).cache(ccfg.getName()).deregisterCacheEntryListener(e.get2());
+            }
+        }
+        finally {
+            ignite(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @param nodeIdx Node index.
+     * @param curs Cursors.
+     * @param lsnrCfgs Listener configurations.
+     * @return Event queue
+     */
+    private BlockingQueue<CacheEntryEvent<?, ?>> registerListener(String cacheName,
+        int nodeIdx,
+        Collection<QueryCursor<?>> curs,
+        Collection<T2<Integer, MutableCacheEntryListenerConfiguration>> lsnrCfgs,
+        boolean sync) {
+        final BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue = new ArrayBlockingQueue<>(50_000);
+
+        if (ThreadLocalRandom.current().nextBoolean()) {
+            MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg =
+                new MutableCacheEntryListenerConfiguration<>(
+                    FactoryBuilder.factoryOf(new LocalNonSerialiseListener() {
+                        @Override protected void onEvents(Iterable<CacheEntryEvent<? extends QueryTestKey,
+                            ? extends QueryTestValue>> evts) {
+                            for (CacheEntryEvent<?, ?> evt : evts)
+                                evtsQueue.add(evt);
+                        }
+                    }),
+                    createFilterFactory(),
+                    true,
+                    sync
+                );
+
+            grid(nodeIdx).cache(cacheName).registerCacheEntryListener((CacheEntryListenerConfiguration)lsnrCfg);
+
+            lsnrCfgs.add(new T2<Integer, MutableCacheEntryListenerConfiguration>(nodeIdx, lsnrCfg));
+        }
+        else {
+            ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
+
+            qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
+                @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+                    ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
+                    for (CacheEntryEvent<?, ?> evt : evts)
+                        evtsQueue.add(evt);
+                }
+            });
+
+            qry.setRemoteFilterFactory(createFilterFactory());
+
+            QueryCursor<?> cur = grid(nodeIdx).cache(cacheName).query(qry);
+
+            curs.add(cur);
+        }
+
+        return evtsQueue;
+    }
+
+    /**
+     * @return Filter factory.
+     */
+    @NotNull protected Factory<? extends CacheEntryEventFilter<QueryTestKey, QueryTestValue>> createFilterFactory() {
+        return new FilterFactory();
+    }
+
+    /**
+     * @param rnd Random generator.
+     * @param evtsQueues Events queue.
+     * @param expData Expected cache data.
+     * @param partCntr Partition counter.
+     * @param cache Cache.
+     * @throws Exception If failed.
+     */
+    private void randomUpdate(
+        Random rnd,
+        List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues,
+        ConcurrentMap<Object, Object> expData,
+        Map<Integer, Long> partCntr,
+        IgniteCache<Object, Object> cache)
+        throws Exception {
+        Object key = new QueryTestKey(rnd.nextInt(KEYS));
+        Object newVal = value(rnd);
+        Object oldVal = expData.get(key);
+
+        int op = rnd.nextInt(11);
+
+        Ignite ignite = cache.unwrap(Ignite.class);
+
+        Transaction tx = null;
+
+        if (cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL && rnd.nextBoolean())
+            tx = ignite.transactions().txStart(txRandomConcurrency(rnd), txRandomIsolation(rnd));
+
+        try {
+            // log.info("Random operation [key=" + key + ", op=" + op + ']');
+
+            switch (op) {
+                case 0: {
+                    cache.put(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                    expData.put(key, newVal);
+
+                    break;
+                }
+
+                case 1: {
+                    cache.getAndPut(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                    expData.put(key, newVal);
+
+                    break;
+                }
+
+                case 2: {
+                    cache.remove(key);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
+
+                    expData.remove(key);
+
+                    break;
+                }
+
+                case 3: {
+                    cache.getAndRemove(key);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
+
+                    expData.remove(key);
+
+                    break;
+                }
+
+                case 4: {
+                    cache.invoke(key, new EntrySetValueProcessor(newVal, rnd.nextBoolean()));
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                    expData.put(key, newVal);
+
+                    break;
+                }
+
+                case 5: {
+                    cache.invoke(key, new EntrySetValueProcessor(null, rnd.nextBoolean()));
+
+                    if (tx != null)
+                        tx.commit();
+
+                    updatePartitionCounter(cache, key, partCntr);
+
+                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
+
+                    expData.remove(key);
+
+                    break;
+                }
+
+                case 6: {
+                    cache.putIfAbsent(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    if (oldVal == null) {
+                        updatePartitionCounter(cache, key, partCntr);
+
+                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, null);
+
+                        expData.put(key, newVal);
+                    }
+                    else
+                        checkNoEvent(evtsQueues);
+
+                    break;
+                }
+
+                case 7: {
+                    cache.getAndPutIfAbsent(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    if (oldVal == null) {
+                        updatePartitionCounter(cache, key, partCntr);
+
+                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, null);
+
+                        expData.put(key, newVal);
+                    }
+                    else
+                        checkNoEvent(evtsQueues);
+
+                    break;
+                }
+
+                case 8: {
+                    cache.replace(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    if (oldVal != null) {
+                        updatePartitionCounter(cache, key, partCntr);
+
+                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                        expData.put(key, newVal);
+                    }
+                    else
+                        checkNoEvent(evtsQueues);
+
+                    break;
+                }
+
+                case 9: {
+                    cache.getAndReplace(key, newVal);
+
+                    if (tx != null)
+                        tx.commit();
+
+                    if (oldVal != null) {
+                        updatePartitionCounter(cache, key, partCntr);
+
+                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                        expData.put(key, newVal);
+                    }
+                    else
+                        checkNoEvent(evtsQueues);
+
+                    break;
+                }
+
+                case 10: {
+                    if (oldVal != null) {
+                        Object replaceVal = value(rnd);
+
+                        boolean success = replaceVal.equals(oldVal);
+
+                        if (success) {
+                            cache.replace(key, replaceVal, newVal);
+
+                            if (tx != null)
+                                tx.commit();
+
+                            updatePartitionCounter(cache, key, partCntr);
+
+                            waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
+
+                            expData.put(key, newVal);
+                        }
+                        else {
+                            cache.replace(key, replaceVal, newVal);
+
+                            if (tx != null)
+                                tx.commit();
+
+                            checkNoEvent(evtsQueues);
+                        }
+                    }
+                    else {
+                        cache.replace(key, value(rnd), newVal);
+
+                        if (tx != null)
+                            tx.commit();
+
+                        checkNoEvent(evtsQueues);
+                    }
+
+                    break;
+                }
+
+                default:
+                    fail("Op:" + op);
+            }
+        }
+        finally {
+            if (tx != null)
+                tx.close();
+        }
+    }
+
+    /**
+     * @param rnd {@link Random}.
+     * @return {@link TransactionIsolation}.
+     */
+    private TransactionIsolation txRandomIsolation(Random rnd) {
+        int val = rnd.nextInt(3);
+
+        if (val == 0)
+            return READ_COMMITTED;
+        else if (val == 1)
+            return REPEATABLE_READ;
+        else
+            return SERIALIZABLE;
+    }
+
+    /**
+     * @param rnd {@link Random}.
+     * @return {@link TransactionConcurrency}.
+     */
+    private TransactionConcurrency txRandomConcurrency(Random rnd) {
+        return rnd.nextBoolean() ? TransactionConcurrency.OPTIMISTIC : TransactionConcurrency.PESSIMISTIC;
+    }
+
+    /**
+     * @param cache Cache.
+     * @param key Key
+     * @param cntrs Partition counters.
+     */
+    private void updatePartitionCounter(IgniteCache<Object, Object> cache, Object key, Map<Integer, Long> cntrs) {
+        Affinity<Object> aff = cache.unwrap(Ignite.class).affinity(cache.getName());
+
+        int part = aff.partition(key);
+
+        Long partCntr = cntrs.get(part);
+
+        if (partCntr == null)
+            partCntr = 0L;
+
+        cntrs.put(part, ++partCntr);
+    }
+
+    /**
+     * @param rnd Random generator.
+     * @return Cache value.
+     */
+    private static Object value(Random rnd) {
+        return new QueryTestValue(rnd.nextInt(VALS));
+    }
+
+    /**
+     * @param evtsQueues Event queue.
+     * @param partCntrs Partition counters.
+     * @param aff Affinity function.
+     * @param key Key.
+     * @param val Value.
+     * @param oldVal Old value.
+     * @throws Exception If failed.
+     */
+    private void waitAndCheckEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues,
+        Map<Integer, Long> partCntrs,
+        Affinity<Object> aff,
+        Object key,
+        Object val,
+        Object oldVal)
+        throws Exception {
+        if ((val == null && oldVal == null
+            || (val != null && !isAccepted((QueryTestValue)val)))) {
+            checkNoEvent(evtsQueues);
+
+            return;
+        }
+
+        for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
+            CacheEntryEvent<?, ?> evt = evtsQueue.poll(5, SECONDS);
+
+            assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', evt);
+            assertEquals(key, evt.getKey());
+            assertEquals(val, evt.getValue());
+            assertEquals(oldVal, evt.getOldValue());
+
+            long cntr = partCntrs.get(aff.partition(key));
+            CacheQueryEntryEvent qryEntryEvt = evt.unwrap(CacheQueryEntryEvent.class);
+
+            assertNotNull(cntr);
+            assertNotNull(qryEntryEvt);
+
+            assertEquals(cntr, qryEntryEvt.getPartitionUpdateCounter());
+        }
+    }
+
+    /**
+     * @param evtsQueues Event queue.
+     * @throws Exception If failed.
+     */
+    private void checkNoEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues) throws Exception {
+        for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
+            CacheEntryEvent<?, ?> evt = evtsQueue.poll(50, MILLISECONDS);
+
+            assertNull(evt);
+        }
+    }
+
+    /**
+     *
+     */
+    protected static class NonSerializableFilter
+        implements CacheEntryEventSerializableFilter<CacheContinuousQueryRandomOperationsTest.QueryTestKey,
+            CacheContinuousQueryRandomOperationsTest.QueryTestValue>, Externalizable {
+        /** */
+        public NonSerializableFilter() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> evt) {
+            return isAccepted(evt.getValue());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            fail("Entry filter should not be marshaled.");
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            fail("Entry filter should not be marshaled.");
+        }
+
+        /**
+         * @param val Value.
+         * @return {@code True} if value is even.
+         */
+        public static boolean isAccepted(QueryTestValue val) {
+            return val == null || val.val1 % 2 == 0;
+        }
+    }
+
+    /**
+     *
+     */
+    protected static class SerializableFilter implements CacheEntryEventSerializableFilter<Integer, Integer> {
+        /** */
+        public SerializableFilter() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> evt)
+            throws CacheEntryListenerException {
+            return isAccepted(evt.getValue());
+        }
+
+        /**
+         * @return {@code True} if value is even.
+         */
+        public static boolean isAccepted(Integer val) {
+            return val == null || val % 2 == 0;
+        }
+    }
+
+    /**
+     *
+     */
+    protected static class FilterFactory implements Factory<NonSerializableFilter> {
+        /** {@inheritDoc} */
+        @Override public NonSerializableFilter create() {
+            return new NonSerializableFilter();
+        }
+    }
+
+    /**
+     *
+     */
+    public abstract class LocalNonSerialiseListener implements
+        CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>,
+        CacheEntryCreatedListener<QueryTestKey, QueryTestValue>,
+        CacheEntryExpiredListener<QueryTestKey, QueryTestValue>,
+        CacheEntryRemovedListener<QueryTestKey, QueryTestValue>,
+        Externalizable {
+        /** */
+        public LocalNonSerialiseListener() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onCreated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
+            onEvents(evts);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onExpired(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
+            onEvents(evts);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onRemoved(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
+            onEvents(evts);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
+            onEvents(evts);
+        }
+
+        /**
+         * @param evts Events.
+         */
+        protected abstract void onEvents(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts);
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            throw new UnsupportedOperationException("Failed. Listener should not be marshaled.");
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            throw new UnsupportedOperationException("Failed. Listener should not be unmarshaled.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterTest.java
deleted file mode 100644
index 55340d5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFactoryFilterTest.java
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.cache.query.continuous;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.UUID;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ThreadLocalRandom;
-import javax.cache.configuration.CacheEntryListenerConfiguration;
-import javax.cache.configuration.Factory;
-import javax.cache.configuration.FactoryBuilder;
-import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
-import javax.cache.event.CacheEntryCreatedListener;
-import javax.cache.event.CacheEntryEvent;
-import javax.cache.event.CacheEntryExpiredListener;
-import javax.cache.event.CacheEntryListenerException;
-import javax.cache.event.CacheEntryRemovedListener;
-import javax.cache.event.CacheEntryUpdatedListener;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.cache.query.CacheQueryEntryEvent;
-import org.apache.ignite.cache.query.ContinuousQuery;
-import org.apache.ignite.cache.query.QueryCursor;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.transactions.Transaction;
-import org.apache.ignite.transactions.TransactionConcurrency;
-import org.apache.ignite.transactions.TransactionIsolation;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
-import static org.apache.ignite.cache.CacheMode.REPLICATED;
-import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryFilterTest.NonSerializableFilter.isAccepted;
-import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest.ContinuousDeploy.CLIENT;
-import static org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest.ContinuousDeploy.SERVER;
-import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE;
-
-/**
- *
- */
-public class CacheContinuousQueryFactoryFilterTest extends CacheContinuousQueryRandomOperationsTest {
-    /** */
-    private static final int NODES = 5;
-
-    /** */
-    private static final int KEYS = 50;
-
-    /** */
-    private static final int VALS = 10;
-
-    /** */
-    public static final int ITERATION_CNT = 40;
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testInternalQuery() throws Exception {
-        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED,
-            1,
-            ATOMIC,
-            ONHEAP_TIERED,
-            false);
-
-        final IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
-
-        UUID uuid = null;
-
-        try {
-            for (int i = 0; i < 10; i++)
-                cache.put(i, i);
-
-            final CountDownLatch latch = new CountDownLatch(5);
-
-            CacheEntryUpdatedListener lsnr = new CacheEntryUpdatedListener() {
-                @Override public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
-                    for (Object evt : iterable) {
-                        latch.countDown();
-
-                        log.info("Received event: " + evt);
-                    }
-                }
-            };
-
-            uuid = grid(0).context().cache().cache(cache.getName()).context().continuousQueries()
-                .executeInternalQuery(lsnr, new SerializableFilter(), false, true, true);
-
-            for (int i = 10; i < 20; i++)
-                cache.put(i, i);
-
-            assertTrue(latch.await(3, SECONDS));
-        }
-        finally {
-            if (uuid != null)
-                grid(0).context().cache().cache(cache.getName()).context().continuousQueries()
-                    .cancelInternalQuery(uuid);
-
-            grid(0).destroyCache(ccfg.getName());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void doTestContinuousQuery(CacheConfiguration<Object, Object> ccfg, ContinuousDeploy deploy)
-        throws Exception {
-        ignite(0).createCache(ccfg);
-
-        try {
-            long seed = System.currentTimeMillis();
-
-            Random rnd = new Random(seed);
-
-            log.info("Random seed: " + seed);
-
-            List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues = new ArrayList<>();
-
-            Collection<QueryCursor<?>> curs = new ArrayList<>();
-
-            Collection<T2<Integer, MutableCacheEntryListenerConfiguration>> lsnrCfgs = new ArrayList<>();
-
-            if (deploy == CLIENT)
-                evtsQueues.add(registerListener(ccfg.getName(), NODES - 1, curs, lsnrCfgs, rnd.nextBoolean()));
-            else if (deploy == SERVER)
-                evtsQueues.add(registerListener(ccfg.getName(), rnd.nextInt(NODES - 1), curs, lsnrCfgs,
-                    rnd.nextBoolean()));
-            else {
-                boolean isSync = rnd.nextBoolean();
-
-                for (int i = 0; i < NODES - 1; i++)
-                    evtsQueues.add(registerListener(ccfg.getName(), i, curs, lsnrCfgs, isSync));
-            }
-
-            ConcurrentMap<Object, Object> expData = new ConcurrentHashMap<>();
-
-            Map<Integer, Long> partCntr = new ConcurrentHashMap<>();
-
-            try {
-                for (int i = 0; i < ITERATION_CNT; i++) {
-                    if (i % 10 == 0)
-                        log.info("Iteration: " + i);
-
-                    for (int idx = 0; idx < NODES; idx++)
-                        randomUpdate(rnd, evtsQueues, expData, partCntr, grid(idx).cache(ccfg.getName()));
-                }
-            }
-            finally {
-                for (QueryCursor<?> cur : curs)
-                    cur.close();
-
-                for (T2<Integer, MutableCacheEntryListenerConfiguration> e : lsnrCfgs)
-                    grid(e.get1()).cache(ccfg.getName()).deregisterCacheEntryListener(e.get2());
-            }
-        }
-        finally {
-            ignite(0).destroyCache(ccfg.getName());
-        }
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @param nodeIdx Node index.
-     * @param curs Cursors.
-     * @param lsnrCfgs Listener configurations.
-     * @return Event queue
-     */
-    private BlockingQueue<CacheEntryEvent<?, ?>> registerListener(String cacheName,
-        int nodeIdx,
-        Collection<QueryCursor<?>> curs,
-        Collection<T2<Integer, MutableCacheEntryListenerConfiguration>> lsnrCfgs,
-        boolean sync) {
-        final BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue = new ArrayBlockingQueue<>(50_000);
-
-        if (ThreadLocalRandom.current().nextBoolean()) {
-            MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg =
-                new MutableCacheEntryListenerConfiguration<>(
-                    FactoryBuilder.factoryOf(new LocalNonSerialiseListener() {
-                        @Override protected void onEvents(Iterable<CacheEntryEvent<? extends QueryTestKey,
-                            ? extends QueryTestValue>> evts) {
-                            for (CacheEntryEvent<?, ?> evt : evts)
-                                evtsQueue.add(evt);
-                        }
-                    }),
-                    new FilterFactory(),
-                    true,
-                    sync
-                );
-
-            grid(nodeIdx).cache(cacheName).registerCacheEntryListener((CacheEntryListenerConfiguration)lsnrCfg);
-
-            lsnrCfgs.add(new T2<Integer, MutableCacheEntryListenerConfiguration>(nodeIdx, lsnrCfg));
-        }
-        else {
-            ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
-
-            qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
-                @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
-                    ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
-                    for (CacheEntryEvent<?, ?> evt : evts)
-                        evtsQueue.add(evt);
-                }
-            });
-
-            qry.setRemoteFilterFactory(new FilterFactory());
-
-            QueryCursor<?> cur = grid(nodeIdx).cache(cacheName).query(qry);
-
-            curs.add(cur);
-        }
-
-        return evtsQueue;
-    }
-
-    /**
-     * @param rnd Random generator.
-     * @param evtsQueues Events queue.
-     * @param expData Expected cache data.
-     * @param partCntr Partition counter.
-     * @param cache Cache.
-     * @throws Exception If failed.
-     */
-    private void randomUpdate(
-        Random rnd,
-        List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues,
-        ConcurrentMap<Object, Object> expData,
-        Map<Integer, Long> partCntr,
-        IgniteCache<Object, Object> cache)
-        throws Exception {
-        Object key = new QueryTestKey(rnd.nextInt(KEYS));
-        Object newVal = value(rnd);
-        Object oldVal = expData.get(key);
-
-        int op = rnd.nextInt(11);
-
-        Ignite ignite = cache.unwrap(Ignite.class);
-
-        Transaction tx = null;
-
-        if (cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL && rnd.nextBoolean())
-            tx = ignite.transactions().txStart(txRandomConcurrency(rnd), txRandomIsolation(rnd));
-
-        try {
-            // log.info("Random operation [key=" + key + ", op=" + op + ']');
-
-            switch (op) {
-                case 0: {
-                    cache.put(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                    expData.put(key, newVal);
-
-                    break;
-                }
-
-                case 1: {
-                    cache.getAndPut(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                    expData.put(key, newVal);
-
-                    break;
-                }
-
-                case 2: {
-                    cache.remove(key);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
-
-                    expData.remove(key);
-
-                    break;
-                }
-
-                case 3: {
-                    cache.getAndRemove(key);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
-
-                    expData.remove(key);
-
-                    break;
-                }
-
-                case 4: {
-                    cache.invoke(key, new EntrySetValueProcessor(newVal, rnd.nextBoolean()));
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                    expData.put(key, newVal);
-
-                    break;
-                }
-
-                case 5: {
-                    cache.invoke(key, new EntrySetValueProcessor(null, rnd.nextBoolean()));
-
-                    if (tx != null)
-                        tx.commit();
-
-                    updatePartitionCounter(cache, key, partCntr);
-
-                    waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, null, oldVal);
-
-                    expData.remove(key);
-
-                    break;
-                }
-
-                case 6: {
-                    cache.putIfAbsent(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    if (oldVal == null) {
-                        updatePartitionCounter(cache, key, partCntr);
-
-                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, null);
-
-                        expData.put(key, newVal);
-                    }
-                    else
-                        checkNoEvent(evtsQueues);
-
-                    break;
-                }
-
-                case 7: {
-                    cache.getAndPutIfAbsent(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    if (oldVal == null) {
-                        updatePartitionCounter(cache, key, partCntr);
-
-                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, null);
-
-                        expData.put(key, newVal);
-                    }
-                    else
-                        checkNoEvent(evtsQueues);
-
-                    break;
-                }
-
-                case 8: {
-                    cache.replace(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    if (oldVal != null) {
-                        updatePartitionCounter(cache, key, partCntr);
-
-                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                        expData.put(key, newVal);
-                    }
-                    else
-                        checkNoEvent(evtsQueues);
-
-                    break;
-                }
-
-                case 9: {
-                    cache.getAndReplace(key, newVal);
-
-                    if (tx != null)
-                        tx.commit();
-
-                    if (oldVal != null) {
-                        updatePartitionCounter(cache, key, partCntr);
-
-                        waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                        expData.put(key, newVal);
-                    }
-                    else
-                        checkNoEvent(evtsQueues);
-
-                    break;
-                }
-
-                case 10: {
-                    if (oldVal != null) {
-                        Object replaceVal = value(rnd);
-
-                        boolean success = replaceVal.equals(oldVal);
-
-                        if (success) {
-                            cache.replace(key, replaceVal, newVal);
-
-                            if (tx != null)
-                                tx.commit();
-
-                            updatePartitionCounter(cache, key, partCntr);
-
-                            waitAndCheckEvent(evtsQueues, partCntr, affinity(cache), key, newVal, oldVal);
-
-                            expData.put(key, newVal);
-                        }
-                        else {
-                            cache.replace(key, replaceVal, newVal);
-
-                            if (tx != null)
-                                tx.commit();
-
-                            checkNoEvent(evtsQueues);
-                        }
-                    }
-                    else {
-                        cache.replace(key, value(rnd), newVal);
-
-                        if (tx != null)
-                            tx.commit();
-
-                        checkNoEvent(evtsQueues);
-                    }
-
-                    break;
-                }
-
-                default:
-                    fail("Op:" + op);
-            }
-        } finally {
-            if (tx != null)
-                tx.close();
-        }
-    }
-
-    /**
-     * @param rnd {@link Random}.
-     * @return {@link TransactionIsolation}.
-     */
-    private TransactionIsolation txRandomIsolation(Random rnd) {
-        int val = rnd.nextInt(3);
-
-        if (val == 0)
-            return READ_COMMITTED;
-        else if (val == 1)
-            return REPEATABLE_READ;
-        else
-            return SERIALIZABLE;
-    }
-
-    /**
-     * @param rnd {@link Random}.
-     * @return {@link TransactionConcurrency}.
-     */
-    private TransactionConcurrency txRandomConcurrency(Random rnd) {
-        return rnd.nextBoolean() ? TransactionConcurrency.OPTIMISTIC : TransactionConcurrency.PESSIMISTIC;
-    }
-
-    /**
-     * @param cache Cache.
-     * @param key Key
-     * @param cntrs Partition counters.
-     */
-    private void updatePartitionCounter(IgniteCache<Object, Object> cache, Object key, Map<Integer, Long> cntrs) {
-        Affinity<Object> aff = cache.unwrap(Ignite.class).affinity(cache.getName());
-
-        int part = aff.partition(key);
-
-        Long partCntr = cntrs.get(part);
-
-        if (partCntr == null)
-            partCntr = 0L;
-
-        cntrs.put(part, ++partCntr);
-    }
-
-    /**
-     * @param rnd Random generator.
-     * @return Cache value.
-     */
-    private static Object value(Random rnd) {
-        return new QueryTestValue(rnd.nextInt(VALS));
-    }
-
-    /**
-     * @param evtsQueues Event queue.
-     * @param partCntrs Partition counters.
-     * @param aff Affinity function.
-     * @param key Key.
-     * @param val Value.
-     * @param oldVal Old value.
-     * @throws Exception If failed.
-     */
-    private void waitAndCheckEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues,
-        Map<Integer, Long> partCntrs,
-        Affinity<Object> aff,
-        Object key,
-        Object val,
-        Object oldVal)
-        throws Exception {
-        if ((val == null && oldVal == null
-            || (val != null && !isAccepted((QueryTestValue)val)))) {
-            checkNoEvent(evtsQueues);
-
-            return;
-        }
-
-        for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
-            CacheEntryEvent<?, ?> evt = evtsQueue.poll(5, SECONDS);
-
-            assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', evt);
-            assertEquals(key, evt.getKey());
-            assertEquals(val, evt.getValue());
-            assertEquals(oldVal, evt.getOldValue());
-
-            long cntr = partCntrs.get(aff.partition(key));
-            CacheQueryEntryEvent qryEntryEvt = evt.unwrap(CacheQueryEntryEvent.class);
-
-            assertNotNull(cntr);
-            assertNotNull(qryEntryEvt);
-
-            assertEquals(cntr, qryEntryEvt.getPartitionUpdateCounter());
-        }
-    }
-
-    /**
-     * @param evtsQueues Event queue.
-     * @throws Exception If failed.
-     */
-    private void checkNoEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues) throws Exception {
-        for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
-            CacheEntryEvent<?, ?> evt = evtsQueue.poll(50, MILLISECONDS);
-
-            assertNull(evt);
-        }
-    }
-
-    /**
-     *
-     */
-    protected static class NonSerializableFilter
-        implements CacheEntryEventSerializableFilter<CacheContinuousQueryRandomOperationsTest.QueryTestKey,
-            CacheContinuousQueryRandomOperationsTest.QueryTestValue>, Externalizable {
-        /** */
-        public NonSerializableFilter() {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> event)
-            throws CacheEntryListenerException {
-            return isAccepted(event.getValue());
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            fail("Entry filter should not be marshaled.");
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            fail("Entry filter should not be marshaled.");
-        }
-
-        /**
-         * @return {@code True} if value is even.
-         */
-        public static boolean isAccepted(QueryTestValue val) {
-            return val == null || val.val1 % 2 == 0;
-        }
-    }
-
-    /**
-     *
-     */
-    protected static class SerializableFilter implements CacheEntryEventSerializableFilter<Integer, Integer>{
-        /** */
-        public SerializableFilter() {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> event)
-            throws CacheEntryListenerException {
-            return isAccepted(event.getValue());
-        }
-
-        /**
-         * @return {@code True} if value is even.
-         */
-        public static boolean isAccepted(Integer val) {
-            return val == null || val % 2 == 0;
-        }
-    }
-
-    /**
-     *
-     */
-    protected static class FilterFactory implements Factory<NonSerializableFilter> {
-        @Override public NonSerializableFilter create() {
-            return new NonSerializableFilter();
-        }
-    }
-
-    /**
-     *
-     */
-    public abstract class LocalNonSerialiseListener implements
-        CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>,
-        CacheEntryCreatedListener<QueryTestKey, QueryTestValue>,
-        CacheEntryExpiredListener<QueryTestKey, QueryTestValue>,
-        CacheEntryRemovedListener<QueryTestKey, QueryTestValue>,
-        Externalizable {
-        /** */
-        public LocalNonSerialiseListener() {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onCreated(Iterable<CacheEntryEvent<? extends QueryTestKey,
-            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
-            onEvents(evts);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onExpired(Iterable<CacheEntryEvent<? extends QueryTestKey,
-            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
-            onEvents(evts);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onRemoved(Iterable<CacheEntryEvent<? extends QueryTestKey,
-            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
-            onEvents(evts);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
-            ? extends QueryTestValue>> evts) throws CacheEntryListenerException {
-            onEvents(evts);
-        }
-
-        /**
-         * @param evts Events.
-         */
-        protected abstract void onEvents(Iterable<CacheEntryEvent<? extends QueryTestKey,
-            ? extends QueryTestValue>> evts);
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            throw new UnsupportedOperationException("Failed. Listener should not be marshaled.");
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            throw new UnsupportedOperationException("Failed. Listener should not be unmarshaled.");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
index 4226537..083367c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryFailoverAbstractSelfTest.java
@@ -81,6 +81,7 @@ import org.apache.ignite.internal.util.typedef.PA;
 import org.apache.ignite.internal.util.typedef.PAX;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.T3;
+import org.apache.ignite.lang.IgniteAsyncCallback;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.plugin.extensions.communication.Message;
@@ -99,7 +100,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.MINUTES;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
-import static org.apache.ignite.cache.CacheMemoryMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
 import static org.apache.ignite.cache.CacheMode.REPLICATED;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
 import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
@@ -167,6 +168,13 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     }
 
     /**
+     * @return Async callback flag.
+     */
+    protected boolean asyncCallback() {
+        return false;
+    }
+
+    /**
      * @return Near cache configuration.
      */
     protected NearCacheConfiguration nearCacheConfiguration() {
@@ -476,7 +484,8 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
         for (int j = 0; j < 50; ++j) {
             ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
 
-            final CacheEventListener3 lsnr = new CacheEventListener3();
+            final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3()
+                : new CacheEventListener3();
 
             qry.setLocalListener(lsnr);
 
@@ -560,7 +569,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
 
-        final CacheEventListener3 lsnr = new CacheEventListener3();
+        final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3() : new CacheEventListener3();
 
         qry.setLocalListener(lsnr);
 
@@ -721,7 +730,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
 
-        final CacheEventListener3 lsnr = new CacheEventListener3();
+        final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3() : new CacheEventListener3();
 
         qry.setLocalListener(lsnr);
 
@@ -841,7 +850,8 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         Affinity<Object> aff = qryClient.affinity(null);
 
-        CacheEventListener1 lsnr = new CacheEventListener1(false);
+        CacheEventListener1 lsnr = asyncCallback() ? new CacheEventAsyncListener1(false)
+            : new CacheEventListener1(false);
 
         ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
 
@@ -1545,7 +1555,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         qry.setLocalListener(lsnr);
 
-        qry.setRemoteFilter(new CacheEventFilter());
+        qry.setRemoteFilter(asyncCallback() ? new CacheEventAsyncFilter() : new CacheEventFilter());
 
         QueryCursor<?> cur = qryClnCache.query(qry);
 
@@ -1639,7 +1649,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
                     newQry.setLocalListener(dinLsnr);
 
-                    newQry.setRemoteFilter(new CacheEventFilter());
+                    newQry.setRemoteFilter(asyncCallback() ? new CacheEventAsyncFilter() : new CacheEventFilter());
 
                     dinQry = qryClnCache.query(newQry);
 
@@ -1786,7 +1796,7 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
 
         final IgniteCache<Object, Object> qryClnCache = qryCln.cache(null);
 
-        final CacheEventListener2 lsnr = new CacheEventListener2();
+        final CacheEventListener2 lsnr = asyncCallback() ? new CacheEventAsyncListener2() : new CacheEventListener2();
 
         ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
 
@@ -2144,6 +2154,19 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     /**
      *
      */
+    @IgniteAsyncCallback
+    private static class CacheEventAsyncListener1 extends CacheEventListener1 {
+        /**
+         * @param saveAll Save all events flag.
+         */
+        CacheEventAsyncListener1(boolean saveAll) {
+            super(saveAll);
+        }
+    }
+
+    /**
+     *
+     */
     private static class CacheEventListener1 implements CacheEntryUpdatedListener<Object, Object> {
         /** */
         private volatile CountDownLatch latch;
@@ -2208,6 +2231,14 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     /**
      *
      */
+    @IgniteAsyncCallback
+    private static class CacheEventAsyncListener2 extends CacheEventListener2 {
+        // No-op.
+    }
+
+    /**
+     *
+     */
     private static class CacheEventListener2 implements CacheEntryUpdatedListener<Object, Object> {
         /** */
         @LoggerResource
@@ -2275,6 +2306,14 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     /**
      *
      */
+    @IgniteAsyncCallback
+    public static class CacheEventAsyncListener3 extends CacheEventListener3 {
+        // No-op.
+    }
+
+    /**
+     *
+     */
     public static class CacheEventListener3 implements CacheEntryUpdatedListener<Object, Object>,
         CacheEntryEventSerializableFilter<Object, Object> {
         /** Keys. */
@@ -2303,6 +2342,14 @@ public abstract class CacheContinuousQueryFailoverAbstractSelfTest extends GridC
     /**
      *
      */
+    @IgniteAsyncCallback
+    private static class CacheEventAsyncFilter extends CacheEventFilter {
+        // No-op.
+    }
+
+    /**
+     *
+     */
     public static class CacheEventFilter implements CacheEntryEventSerializableFilter<Object, Object> {
         /** {@inheritDoc} */
         @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryLostPartitionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryLostPartitionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryLostPartitionTest.java
index 025dd80..b469a86 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryLostPartitionTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryLostPartitionTest.java
@@ -60,6 +60,12 @@ public class CacheContinuousQueryLostPartitionTest extends GridCommonAbstractTes
         super.beforeTest();
 
         startGridsMultiThreaded(2);
+
+        assert GridTestUtils.waitForCondition(new PA() {
+            @Override public boolean apply() {
+                return grid(0).cluster().nodes().size() == 2;
+            }
+        }, 10000L);
     }
 
     /** {@inheritDoc} */
@@ -140,6 +146,14 @@ public class CacheContinuousQueryLostPartitionTest extends GridCommonAbstractTes
         // node2 now becomes the primary for the key.
         stopGrid(0);
 
+        final int prevSize = grid(1).cluster().nodes().size();
+
+        GridTestUtils.waitForCondition(new PA() {
+            @Override public boolean apply() {
+                return prevSize - 1 == grid(1).cluster().nodes().size();
+            }
+        }, 5000L);
+
         cache2.put(key, "2");
 
         // Sanity check.

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOperationFromCallbackTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOperationFromCallbackTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOperationFromCallbackTest.java
new file mode 100644
index 0000000..0d027a9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOperationFromCallbackTest.java
@@ -0,0 +1,627 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ *
+ */
+public class CacheContinuousQueryOperationFromCallbackTest extends GridCommonAbstractTest {
+    /** */
+    public static final int KEYS = 10;
+
+    /** */
+    public static final int KEYS_FROM_CALLBACK = 20;
+
+    /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int NODES = 5;
+
+    /** */
+    public static final int ITERATION_CNT = 20;
+
+    /** */
+    public static final int SYSTEM_POOL_SIZE = 10;
+
+    /** */
+    private boolean client;
+
+    /** */
+    private static AtomicInteger filterCbCntr = new AtomicInteger(0);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSystemThreadPoolSize(SYSTEM_POOL_SIZE);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+        ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
+
+        cfg.setClientMode(client);
+
+        MemoryEventStorageSpi storeSpi = new MemoryEventStorageSpi();
+        storeSpi.setExpireCount(100);
+
+        cfg.setEventStorageSpi(storeSpi);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGridsMultiThreaded(NODES - 1);
+
+        client = true;
+
+        startGrid(NODES - 1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        filterCbCntr.set(0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicTwoBackups() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC, FULL_SYNC);
+
+        doTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxTwoBackupsFilter() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, FULL_SYNC);
+
+        doTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxTwoBackupsFilterPrimary() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, PRIMARY_SYNC);
+
+        doTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxReplicatedFilter() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 0, TRANSACTIONAL, FULL_SYNC);
+
+        doTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxTwoBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL, FULL_SYNC);
+
+        doTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxReplicated() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, FULL_SYNC);
+
+        doTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxReplicatedPrimary() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 2, TRANSACTIONAL, PRIMARY_SYNC);
+
+        doTest(ccfg, true);
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     * @throws Exception If failed.
+     */
+    protected void doTest(final CacheConfiguration ccfg, boolean fromLsnr) throws Exception {
+        ignite(0).createCache(ccfg);
+
+        List<QueryCursor<?>> qries = new ArrayList<>();
+
+        assertEquals(0, filterCbCntr.get());
+
+        try {
+            List<Set<T2<QueryTestKey, QueryTestValue>>> rcvdEvts = new ArrayList<>(NODES);
+            List<Set<T2<QueryTestKey, QueryTestValue>>> evtsFromCallbacks = new ArrayList<>(NODES);
+
+            final AtomicInteger qryCntr = new AtomicInteger(0);
+
+            final AtomicInteger cbCntr = new AtomicInteger(0);
+
+            final int threadCnt = SYSTEM_POOL_SIZE * 2;
+
+            for (int idx = 0; idx < NODES; idx++) {
+                Set<T2<QueryTestKey, QueryTestValue>> evts = Collections.
+                    newSetFromMap(new ConcurrentHashMap<T2<QueryTestKey, QueryTestValue>, Boolean>());
+                Set<T2<QueryTestKey, QueryTestValue>> evtsFromCb = Collections.
+                    newSetFromMap(new ConcurrentHashMap<T2<QueryTestKey, QueryTestValue>, Boolean>());
+
+                IgniteCache<Object, Object> cache = grid(idx).getOrCreateCache(ccfg.getName());
+
+                ContinuousQuery qry = new ContinuousQuery();
+
+                qry.setLocalListener(new TestCacheAsyncEventListener(evts, evtsFromCb,
+                    fromLsnr ? cache : null, qryCntr, cbCntr));
+
+                if (!fromLsnr)
+                    qry.setRemoteFilterFactory(
+                        FactoryBuilder.factoryOf(new CacheTestRemoteFilterAsync(ccfg.getName())));
+
+                rcvdEvts.add(evts);
+                evtsFromCallbacks.add(evtsFromCb);
+
+                QueryCursor qryCursor = cache.query(qry);
+
+                qries.add(qryCursor);
+            }
+
+            IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {
+                @Override public void run() {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    for (int i = 0; i < ITERATION_CNT; i++) {
+                        IgniteCache<QueryTestKey, QueryTestValue> cache =
+                            grid(rnd.nextInt(NODES)).cache(ccfg.getName());
+
+                        QueryTestKey key = new QueryTestKey(rnd.nextInt(KEYS));
+
+                        boolean startTx = cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() ==
+                            TRANSACTIONAL && rnd.nextBoolean();
+
+                        Transaction tx = null;
+
+                        if (startTx)
+                            tx = cache.unwrap(Ignite.class).transactions().txStart();
+
+                        try {
+                            if ((cache.get(key) == null) || rnd.nextBoolean())
+                                cache.invoke(key, new IncrementTestEntryProcessor());
+                            else {
+                                QueryTestValue val;
+                                QueryTestValue newVal;
+
+                                do {
+                                    val = cache.get(key);
+
+                                    newVal = val == null ?
+                                        new QueryTestValue(0) : new QueryTestValue(val.val1 + 1);
+                                }
+                                while (!cache.replace(key, val, newVal));
+                            }
+                        }
+                        finally {
+                            if (tx != null)
+                                tx.commit();
+                        }
+                    }
+                }
+            }, threadCnt, "put-thread");
+
+            f.get(30, TimeUnit.SECONDS);
+
+            assert GridTestUtils.waitForCondition(new PA() {
+                @Override public boolean apply() {
+                    return qryCntr.get() >= ITERATION_CNT * threadCnt * NODES;
+                }
+            }, TimeUnit.MINUTES.toMillis(2));
+
+            for (Set<T2<QueryTestKey, QueryTestValue>> set : rcvdEvts)
+                checkEvents(set, ITERATION_CNT * threadCnt, grid(0).cache(ccfg.getName()), false);
+
+            if (fromLsnr) {
+                final int expCnt = qryCntr.get() * NODES * KEYS_FROM_CALLBACK;
+
+                boolean res = GridTestUtils.waitForCondition(new PA() {
+                    @Override public boolean apply() {
+                        return cbCntr.get() >= expCnt;
+                    }
+                }, TimeUnit.SECONDS.toMillis(60));
+
+                assertTrue("Failed to wait events [exp=" + expCnt + ", act=" + cbCntr.get() + "]", res);
+
+                assertEquals(expCnt, cbCntr.get());
+
+                for (Set<T2<QueryTestKey, QueryTestValue>> set : evtsFromCallbacks)
+                    checkEvents(set, qryCntr.get() * KEYS_FROM_CALLBACK, grid(0).cache(ccfg.getName()), true);
+            }
+            else {
+                final int expInvkCnt = ITERATION_CNT * threadCnt *
+                    (ccfg.getCacheMode() != REPLICATED ? (ccfg.getBackups() + 1) : NODES - 1) * NODES;
+
+                GridTestUtils.waitForCondition(new PA() {
+                    @Override public boolean apply() {
+                        return filterCbCntr.get() >= expInvkCnt;
+                    }
+                }, TimeUnit.SECONDS.toMillis(60));
+
+                assertEquals(expInvkCnt, filterCbCntr.get());
+
+                for (Set<T2<QueryTestKey, QueryTestValue>> set : evtsFromCallbacks)
+                    checkEvents(set, expInvkCnt * KEYS_FROM_CALLBACK, grid(0).cache(ccfg.getName()), true);
+            }
+        }
+        finally {
+            for (QueryCursor<?> qry : qries)
+                qry.close();
+
+            ignite(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param expCnt Expected count.
+     * @param cache Cache.
+     * @param set Received events.
+     * @throws Exception If failed.
+     */
+    private void checkEvents(final Set<T2<QueryTestKey, QueryTestValue>> set, final int expCnt, IgniteCache cache,
+        boolean cb) throws Exception {
+        assertTrue("Expected size: " + expCnt + ", actual: " + set.size(), GridTestUtils.waitForCondition(new PA() {
+            @Override public boolean apply() {
+                return set.size() >= expCnt;
+            }
+        }, 10000L));
+
+        int startKey = cb ? KEYS : 0;
+        int endKey = cb ? KEYS + KEYS_FROM_CALLBACK : KEYS;
+
+        for (int i = startKey; i < endKey; i++) {
+            QueryTestKey key = new QueryTestKey(i);
+
+            QueryTestValue maxVal = (QueryTestValue)cache.get(key);
+
+            for (int val = 0; val <= maxVal.val1; val++)
+                assertTrue(set.remove(new T2<>(key, new QueryTestValue(val))));
+        }
+
+        assertTrue(set.isEmpty());
+    }
+
+    /**
+     *
+     */
+    private static class IncrementTestEntryProcessor implements
+        CacheEntryProcessor<QueryTestKey, QueryTestValue, Object> {
+        /** {@inheritDoc} */
+        @Override public Object process(MutableEntry<QueryTestKey, QueryTestValue> entry, Object... arguments)
+            throws EntryProcessorException {
+            if (entry.exists())
+                entry.setValue(new QueryTestValue(entry.getValue().val1 + 1));
+            else
+                entry.setValue(new QueryTestValue(0));
+
+            return null;
+        }
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class CacheTestRemoteFilterAsync implements
+        CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> {
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        private String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        public CacheTestRemoteFilterAsync(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e)
+            throws CacheEntryListenerException {
+            if (e.getKey().compareTo(new QueryTestKey(KEYS)) < 0) {
+                IgniteCache<QueryTestKey, QueryTestValue> cache = ignite.cache(cacheName);
+
+                if (ThreadLocalRandom.current().nextBoolean()) {
+                    Set<QueryTestKey> keys = new LinkedHashSet<>();
+
+                    for (int key = KEYS; key < KEYS + KEYS_FROM_CALLBACK; key++)
+                        keys.add(new QueryTestKey(key));
+
+                    cache.invokeAll(keys, new IncrementTestEntryProcessor());
+                }
+                else {
+                    for (int key = KEYS; key < KEYS + KEYS_FROM_CALLBACK; key++)
+                        cache.invoke(new QueryTestKey(key), new IncrementTestEntryProcessor());
+                }
+
+                filterCbCntr.incrementAndGet();
+            }
+
+            return true;
+        }
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class TestCacheAsyncEventListener
+        implements CacheEntryUpdatedListener<QueryTestKey, QueryTestValue> {
+        /** */
+        private final Set<T2<QueryTestKey, QueryTestValue>> rcvsEvts;
+
+        /** */
+        private final AtomicInteger cntr;
+
+        /** */
+        private final AtomicInteger cbCntr;
+
+        /** */
+        private final Set<T2<QueryTestKey, QueryTestValue>> evtsFromCb;
+
+        /** */
+        private IgniteCache<QueryTestKey, QueryTestValue> cache;
+
+        /**
+         * @param rcvsEvts Set for received events.
+         * @param evtsFromCb Set for received events.
+         * @param cache Ignite cache.
+         * @param cntr Received events counter.
+         * @param cbCntr Received events counter from callbacks.
+         */
+        public TestCacheAsyncEventListener(Set<T2<QueryTestKey, QueryTestValue>> rcvsEvts,
+            Set<T2<QueryTestKey, QueryTestValue>> evtsFromCb,
+            @Nullable IgniteCache cache,
+            AtomicInteger cntr,
+            AtomicInteger cbCntr) {
+            this.rcvsEvts = rcvsEvts;
+            this.evtsFromCb = evtsFromCb;
+            this.cache = cache;
+            this.cntr = cntr;
+            this.cbCntr = cbCntr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts)
+            throws CacheEntryListenerException {
+            for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : evts) {
+                if (e.getKey().compareTo(new QueryTestKey(KEYS)) < 0) {
+                    rcvsEvts.add(new T2<>(e.getKey(), e.getValue()));
+
+                    cntr.incrementAndGet();
+
+                    if (cache != null) {
+                        if (ThreadLocalRandom.current().nextBoolean()) {
+                            Set<QueryTestKey> keys = new LinkedHashSet<>();
+
+                            for (int key = KEYS; key < KEYS + KEYS_FROM_CALLBACK; key++)
+                                keys.add(new QueryTestKey(key));
+
+                            cache.invokeAll(keys, new IncrementTestEntryProcessor());
+                        }
+                        else {
+                            for (int key = KEYS; key < KEYS + KEYS_FROM_CALLBACK; key++)
+                                cache.invoke(new QueryTestKey(key), new IncrementTestEntryProcessor());
+                        }
+                    }
+                }
+                else {
+                    evtsFromCb.add(new T2<>(e.getKey(), e.getValue()));
+
+                    cbCntr.incrementAndGet();
+                }
+            }
+        }
+    }
+
+    /**
+     * @param cacheMode Cache mode.
+     * @param backups Number of backups.
+     * @param atomicityMode Cache atomicity mode.
+     * @param writeMode Write sync mode.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheWriteSynchronizationMode writeMode) {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setName("test-cache-" + atomicityMode + "-" + cacheMode + "-" + writeMode + "-" + backups);
+        ccfg.setAtomicityMode(atomicityMode);
+        ccfg.setCacheMode(cacheMode);
+        ccfg.setWriteSynchronizationMode(writeMode);
+        ccfg.setAtomicWriteOrderMode(PRIMARY);
+
+        if (cacheMode == PARTITIONED)
+            ccfg.setBackups(backups);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestKey implements Serializable, Comparable {
+        /** */
+        private final Integer key;
+
+        /**
+         * @param key Key.
+         */
+        public QueryTestKey(Integer key) {
+            this.key = key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestKey that = (QueryTestKey)o;
+
+            return key.equals(that.key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return key.hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestKey.class, this);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int compareTo(Object o) {
+            return key - ((QueryTestKey)o).key;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestValue implements Serializable {
+        /** */
+        @GridToStringInclude
+        protected final Integer val1;
+
+        /** */
+        @GridToStringInclude
+        protected final String val2;
+
+        /**
+         * @param val Value.
+         */
+        public QueryTestValue(Integer val) {
+            this.val1 = val;
+            this.val2 = String.valueOf(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestValue that = (QueryTestValue) o;
+
+            return val1.equals(that.val1) && val2.equals(that.val2);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = val1.hashCode();
+
+            res = 31 * res + val2.hashCode();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestValue.class, this);
+        }
+    }
+}


[45/50] [abbrv] ignite git commit: IGNITE-1384 Fixed

Posted by sh...@apache.org.
IGNITE-1384 Fixed


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

Branch: refs/heads/ignite-2788
Commit: 6d75fe6b8a22ef48eb0a7265234e690a693ea6d2
Parents: 6e1d45e
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Fri Apr 29 14:46:41 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../processors/task/GridTaskWorker.java         |  2 +-
 .../java/org/apache/ignite/lang/IgniteUuid.java |  2 +-
 .../internal/GridTaskExecutionSelfTest.java     | 76 +++++++++++++++++++-
 3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6d75fe6b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
index 659d5a6..05970ed 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
@@ -558,7 +558,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
             if (node == null)
                 throw new IgniteCheckedException("Node can not be null [mappedJob=" + mappedJob + ", ses=" + ses + ']');
 
-            IgniteUuid jobId = IgniteUuid.fromUuid(node.id());
+            IgniteUuid jobId = IgniteUuid.fromUuid(ctx.localNodeId());
 
             GridJobSiblingImpl sib = new GridJobSiblingImpl(ses.getId(), jobId, node.id(), ctx);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6d75fe6b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
index 5c6bb9a..7de389e 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
@@ -216,4 +216,4 @@ public final class IgniteUuid implements Comparable<IgniteUuid>, Iterable<Ignite
     @Override public String toString() {
         return shortString() + '-' + gid.toString();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6d75fe6b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java
index 31d0ffa..142b9db 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java
@@ -17,10 +17,18 @@
 
 package org.apache.ignite.internal;
 
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.GridTestTask;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.compute.ComputeJobContext;
 import org.apache.ignite.compute.ComputeTaskFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.resources.JobContextResource;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.testframework.junits.common.GridCommonTest;
 
@@ -68,4 +76,70 @@ public class GridTaskExecutionSelfTest extends GridCommonAbstractTest {
 
         info("Task result: " + fut.get());
     }
-}
\ No newline at end of file
+
+    /**
+     * Test for https://issues.apache.org/jira/browse/IGNITE-1384
+     *
+     * @throws Exception If failed.
+     */
+    public void testJobIdCollision() throws Exception {
+        long locId = IgniteUuid.lastLocalId();
+
+        ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
+
+        IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id())).withAsync();
+
+        for (int i = 0; i < 1000; i++) {
+            compute.call(new IgniteCallable<Object>() {
+                @JobContextResource
+                ComputeJobContext ctx;
+
+                boolean held;
+
+                @Override public Object call() throws Exception {
+                    if (!held) {
+                        ctx.holdcc(1000);
+
+                        held = true;
+                    }
+
+                    return null;
+                }
+            });
+
+            futs.add(compute.future());
+        }
+
+        info("Finished first loop.");
+
+        AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
+
+        idx.set(locId);
+
+        IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id())).withAsync();
+
+        for (int i = 0; i < 100; i++) {
+            compute1.call(new IgniteCallable<Object>() {
+                @JobContextResource
+                ComputeJobContext ctx;
+
+                boolean held;
+
+                @Override public Object call() throws Exception {
+                    if (!held) {
+                        ctx.holdcc(1000);
+
+                        held = true;
+                    }
+
+                    return null;
+                }
+            });
+
+            futs.add(compute1.future());
+        }
+
+        for (IgniteFuture<Object> fut : futs)
+            fut.get();
+    }
+}


[28/50] [abbrv] ignite git commit: IGNITE-3052 .NET: Deprecateв CacheEvent.LockId. This closes #671.

Posted by sh...@apache.org.
IGNITE-3052 .NET: Deprecate\u0432 CacheEvent.LockId. This closes #671.


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

Branch: refs/heads/ignite-2788
Commit: 90de28d1cef4e090ef94e12e526784cf1577da25
Parents: 73948df
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Apr 27 11:24:48 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../internal/processors/platform/PlatformContextImpl.java   | 1 -
 .../platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs | 4 ++--
 .../dotnet/Apache.Ignite.Core/Events/CacheEvent.cs          | 9 ++++-----
 3 files changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/90de28d1/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index f6e0079..d544fff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -514,7 +514,6 @@ public class PlatformContextImpl implements PlatformContext {
             writeNode(writer, event0.eventNode());
             writer.writeObject(event0.key());
             PlatformUtils.writeIgniteUuid(writer, event0.xid());
-            writer.writeObject(event0.lockId());
             writer.writeObject(event0.newValue());
             writer.writeObject(event0.oldValue());
             writer.writeBoolean(event0.hasOldValue());

http://git-wip-us.apache.org/repos/asf/ignite/blob/90de28d1/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
index a538cb4..6f51f4a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
@@ -238,7 +238,7 @@ namespace Apache.Ignite.Core.Tests
                     EventObjectType = typeof (CacheEvent),
                     GenerateEvent = g => g.GetCache<int, int>(null).Put(1, 1),
                     VerifyEvents = (e, g) => VerifyCacheEvents(e, g),
-                    EventCount = 1
+                    EventCount = 2
                 };
 
                 yield return new EventTestCase
@@ -484,7 +484,7 @@ namespace Apache.Ignite.Core.Tests
                 Assert.AreEqual(true, cacheEvent.IsNear);
                 Assert.AreEqual(2, cacheEvent.Key);
                 Assert.AreEqual(expectedGridGuid, cacheEvent.Xid);
-                Assert.AreEqual(3, cacheEvent.LockId);
+                Assert.AreEqual(null, cacheEvent.LockId);
                 Assert.AreEqual(4, cacheEvent.NewValue);
                 Assert.AreEqual(true, cacheEvent.HasNewValue);
                 Assert.AreEqual(5, cacheEvent.OldValue);

http://git-wip-us.apache.org/repos/asf/ignite/blob/90de28d1/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
index 4c75e0a..ec22fad 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
@@ -18,6 +18,7 @@
 namespace Apache.Ignite.Core.Events
 {
     using System;
+    using System.Diagnostics.CodeAnalysis;
     using System.Globalization;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cluster;
@@ -47,9 +48,6 @@ namespace Apache.Ignite.Core.Events
         private readonly IgniteGuid? _xid;
 
         /** */
-        private readonly object _lockId;
-
-        /** */
         private readonly object _newValue;
 
         /** */
@@ -82,7 +80,6 @@ namespace Apache.Ignite.Core.Events
             _eventNode = ReadNode(r);
             _key = r.ReadObject<object>();
             _xid = IgniteGuid.Read(r);
-            _lockId = r.ReadObject<object>();
             _newValue = r.ReadObject<object>();
             _oldValue = r.ReadObject<object>();
             _hasOldValue = r.ReadBoolean();
@@ -125,7 +122,9 @@ namespace Apache.Ignite.Core.Events
         /// <summary>
         /// ID of the lock if held or null if no lock held. 
         /// </summary>
-        public object LockId { get { return _lockId; } }
+        [Obsolete("LockId is no longer provided. This property is always null.")]
+        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Compatibility")]
+        public object LockId { get { return null; } }
 
         /// <summary>
         /// Gets new value for this event. 


[29/50] [abbrv] ignite git commit: IGNITE-2944: .NET: Implemented operations with near cache on IIgnite interface. This closes #625.

Posted by sh...@apache.org.
IGNITE-2944: .NET: Implemented operations with near cache on IIgnite interface. This closes #625.


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

Branch: refs/heads/ignite-2788
Commit: fdb2f6499856dd0144eb25d2ab8b6450024413a4
Parents: 90de28d
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Apr 27 11:30:17 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       |   2 +
 .../platform/PlatformNoopProcessor.java         |  10 +
 .../processors/platform/PlatformProcessor.java  |  19 ++
 .../platform/PlatformProcessorImpl.java         |  41 +++-
 .../utils/PlatformConfigurationUtils.java       |  93 ++++++++-
 .../cpp/common/include/ignite/common/exports.h  |   2 +
 .../cpp/common/include/ignite/common/java.h     |   5 +
 .../platforms/cpp/common/project/vs/module.def  |   2 +
 modules/platforms/cpp/common/src/exports.cpp    |   8 +
 modules/platforms/cpp/common/src/java.cpp       |  30 +++
 .../Apache.Ignite.Core.Tests.csproj             |   1 +
 .../Cache/CacheConfigurationTest.cs             |  49 +++++
 .../Cache/CacheNearTest.cs                      | 188 +++++++++++++++++++
 .../dotnet/Apache.Ignite.Core.Tests/app.config  |   4 +
 .../Apache.Ignite.Core.csproj                   |   5 +
 .../Cache/Configuration/CacheConfiguration.cs   |  15 ++
 .../Configuration/NearCacheConfiguration.cs     |  75 ++++++++
 .../Cache/Eviction/EvictionPolicyBase.cs        | 126 +++++++++++++
 .../Cache/Eviction/FifoEvictionPolicy.cs        |  39 ++++
 .../Cache/Eviction/IEvictionPolicy.cs           |  32 ++++
 .../Cache/Eviction/LruEvictionPolicy.cs         |  39 ++++
 .../dotnet/Apache.Ignite.Core/IIgnite.cs        |  42 +++++
 .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs    |  62 ++++++
 .../Apache.Ignite.Core/Impl/IgniteProxy.cs      |  25 +++
 .../Impl/Unmanaged/IgniteJniNativeMethods.cs    |   6 +
 .../Impl/Unmanaged/UnmanagedUtils.cs            |  32 ++++
 26 files changed, 948 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 07542de..ed392c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -544,6 +544,8 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
     }
 
     /**
+     * Sets the near cache configuration to use on all cache nodes.
+     *
      * @param nearCfg Near cache configuration.
      * @return {@code this} for chaining.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 06988ee..155981c 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
@@ -160,4 +160,14 @@ public class PlatformNoopProcessor extends GridProcessorAdapter implements Platf
     @Override public PlatformTarget atomicReference(String name, long memPtr, boolean create) throws IgniteException {
         return null;
     }
+
+    /** {@inheritDoc} */
+    @Override public PlatformTarget createNearCache(@Nullable String cacheName, long memPtr) {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public PlatformTarget getOrCreateNearCache(@Nullable String cacheName, long memPtr) {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 2d51c69..cca29d8 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
@@ -233,4 +233,23 @@ public interface PlatformProcessor extends GridProcessor {
      * @param memPtr Stream to write data to.
      */
     public void getIgniteConfiguration(long memPtr);
+
+    /**
+     * Starts a near cache on local node if cache was previously started.
+     *
+     * @param cacheName Cache name.
+     * @param memPtr Pointer to a stream with near cache config. 0 for default config.
+     * @return Cache.
+     */
+    public PlatformTarget createNearCache(@Nullable String cacheName, long memPtr);
+
+    /**
+     * Gets existing near cache with the given name or creates a new one.
+     *
+     * @param cacheName Cache name.
+     * @param memPtr Pointer to a stream with near cache config. 0 for default config.
+     * @return Cache.
+     */
+    public PlatformTarget getOrCreateNearCache(@Nullable String cacheName, long memPtr);
+
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 bcdd91d..e294735 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
@@ -24,6 +24,7 @@ import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.configuration.PlatformConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
@@ -263,7 +264,9 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
         BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
         CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
 
-        IgniteCacheProxy cache = (IgniteCacheProxy)ctx.grid().createCache(cfg);
+        IgniteCacheProxy cache = reader.readBoolean()
+            ? (IgniteCacheProxy)ctx.grid().createCache(cfg, PlatformConfigurationUtils.readNearConfiguration(reader))
+            : (IgniteCacheProxy)ctx.grid().createCache(cfg);
 
         return new PlatformCache(platformCtx, cache.keepBinary(), false);
     }
@@ -273,7 +276,10 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
         BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
         CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
 
-        IgniteCacheProxy cache = (IgniteCacheProxy)ctx.grid().getOrCreateCache(cfg);
+        IgniteCacheProxy cache = reader.readBoolean()
+            ? (IgniteCacheProxy)ctx.grid().getOrCreateCache(cfg,
+                    PlatformConfigurationUtils.readNearConfiguration(reader))
+            : (IgniteCacheProxy)ctx.grid().getOrCreateCache(cfg);
 
         return new PlatformCache(platformCtx, cache.keepBinary(), false);
     }
@@ -408,6 +414,37 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
         stream.synchronize();
     }
 
+    /** {@inheritDoc} */
+    @Override public PlatformTarget createNearCache(@Nullable String cacheName, long memPtr) {
+        NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
+
+        IgniteCacheProxy cache = (IgniteCacheProxy)ctx.grid().createNearCache(cacheName, cfg);
+
+        return new PlatformCache(platformCtx, cache.keepBinary(), false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public PlatformTarget getOrCreateNearCache(@Nullable String cacheName, long memPtr) {
+        NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
+
+        IgniteCacheProxy cache = (IgniteCacheProxy)ctx.grid().getOrCreateNearCache(cacheName, cfg);
+
+        return new PlatformCache(platformCtx, cache.keepBinary(), false);
+    }
+
+    /**
+     * Gets the near cache config.
+     *
+     * @param memPtr Memory pointer.
+     * @return Near config.
+     */
+    private NearCacheConfiguration getNearCacheConfiguration(long memPtr) {
+        assert memPtr != 0;
+
+        BinaryRawReaderEx reader = platformCtx.reader(platformCtx.memory().get(memPtr));
+        return PlatformConfigurationUtils.readNearConfiguration(reader);
+    }
+
     /**
      * Internal store initialization routine.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 51c7c6c..9d7f957 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -28,10 +28,14 @@ import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.eviction.EvictionPolicy;
+import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
+import org.apache.ignite.cache.eviction.lru.LruEvictionPolicy;
 import org.apache.ignite.configuration.AtomicConfiguration;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.binary.*;
 import org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration;
@@ -163,10 +167,86 @@ import java.util.Map;
             ccfg.setQueryEntities(entities);
         }
 
+        if (in.readBoolean())
+            ccfg.setNearConfiguration(readNearConfiguration(in));
+
         return ccfg;
     }
 
     /**
+     * Reads the near config.
+     *
+     * @param in Stream.
+     * @return NearCacheConfiguration.
+     */
+    public static NearCacheConfiguration readNearConfiguration(BinaryRawReader in) {
+        NearCacheConfiguration cfg = new NearCacheConfiguration();
+        cfg.setNearStartSize(in.readInt());
+
+        byte plcTyp = in.readByte();
+
+        switch (plcTyp) {
+            case 0:
+                break;
+            case 1: {
+                FifoEvictionPolicy p = new FifoEvictionPolicy();
+                p.setBatchSize(in.readInt());
+                p.setMaxSize(in.readInt());
+                p.setMaxMemorySize(in.readLong());
+                cfg.setNearEvictionPolicy(p);
+                break;
+            }
+            case 2: {
+                LruEvictionPolicy p = new LruEvictionPolicy();
+                p.setBatchSize(in.readInt());
+                p.setMaxSize(in.readInt());
+                p.setMaxMemorySize(in.readLong());
+                cfg.setNearEvictionPolicy(p);
+                break;
+            }
+            default:
+                assert false;
+        }
+
+        return cfg;
+    }
+
+    /**
+     * Reads the near config.
+     *
+     * @param out Stream.
+     * @param cfg NearCacheConfiguration.
+     */
+    @SuppressWarnings("TypeMayBeWeakened")
+    public static void writeNearConfiguration(BinaryRawWriter out, NearCacheConfiguration cfg) {
+        assert cfg != null;
+
+        out.writeInt(cfg.getNearStartSize());
+
+        EvictionPolicy p = cfg.getNearEvictionPolicy();
+
+        if (p instanceof FifoEvictionPolicy) {
+            out.writeByte((byte)1);
+
+            FifoEvictionPolicy p0 = (FifoEvictionPolicy)p;
+            out.writeInt(p0.getBatchSize());
+            out.writeInt(p0.getMaxSize());
+            out.writeLong(p0.getMaxMemorySize());
+        }
+        else if (p instanceof LruEvictionPolicy) {
+            out.writeByte((byte)2);
+
+            LruEvictionPolicy p0 = (LruEvictionPolicy)p;
+            out.writeInt(p0.getBatchSize());
+            out.writeInt(p0.getMaxSize());
+            out.writeLong(p0.getMaxMemorySize());
+        }
+        else {
+            out.writeByte((byte)0);
+        }
+    }
+
+    /**
      * Reads the query entity.
      *
      * @param in Stream.
@@ -469,8 +549,7 @@ import java.util.Map;
 
         Collection<QueryEntity> qryEntities = ccfg.getQueryEntities();
 
-        if (qryEntities != null)
-        {
+        if (qryEntities != null) {
             writer.writeInt(qryEntities.size());
 
             for (QueryEntity e : qryEntities)
@@ -478,6 +557,16 @@ import java.util.Map;
         }
         else
             writer.writeInt(0);
+
+        NearCacheConfiguration nearCfg = ccfg.getNearConfiguration();
+
+        if (nearCfg != null) {
+            writer.writeBoolean(true);
+
+            writeNearConfiguration(writer, nearCfg);
+        }
+        else
+            writer.writeBoolean(false);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 6f2049d..c62b365 100644
--- a/modules/platforms/cpp/common/include/ignite/common/exports.h
+++ b/modules/platforms/cpp/common/include/ignite/common/exports.h
@@ -38,6 +38,8 @@ extern "C" {
     void* IGNITE_CALL IgniteProcessorGetOrCreateCache(gcj::JniContext* ctx, void* obj, char* name);
     void* IGNITE_CALL IgniteProcessorCreateCacheFromConfig(gcj::JniContext* ctx, void* obj, long long memPtr);
     void* IGNITE_CALL IgniteProcessorGetOrCreateCacheFromConfig(gcj::JniContext* ctx, void* obj, long long memPtr);
+    void* IGNITE_CALL IgniteProcessorCreateNearCache(gcj::JniContext* ctx, void* obj, char* name, long long memPtr);
+    void* IGNITE_CALL IgniteProcessorGetOrCreateNearCache(gcj::JniContext* ctx, void* obj, char* name, long long memPtr);
     void IGNITE_CALL IgniteProcessorDestroyCache(gcj::JniContext* ctx, void* obj, char* name);
     void* IGNITE_CALL IgniteProcessorAffinity(gcj::JniContext* ctx, void* obj, char* name);
     void* IGNITE_CALL IgniteProcessorDataStreamer(gcj::JniContext* ctx, void* obj, char* name, bool keepPortable);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 4b79665..f2007cb 100644
--- a/modules/platforms/cpp/common/include/ignite/common/java.h
+++ b/modules/platforms/cpp/common/include/ignite/common/java.h
@@ -305,6 +305,8 @@ namespace ignite
                 jmethodID m_PlatformProcessor_getOrCreateCache;
                 jmethodID m_PlatformProcessor_createCacheFromConfig;
                 jmethodID m_PlatformProcessor_getOrCreateCacheFromConfig;
+                jmethodID m_PlatformProcessor_createNearCache;
+                jmethodID m_PlatformProcessor_getOrCreateNearCache;
                 jmethodID m_PlatformProcessor_destroyCache;
                 jmethodID m_PlatformProcessor_affinity;
                 jmethodID m_PlatformProcessor_dataStreamer;
@@ -519,6 +521,8 @@ namespace ignite
                 jobject ProcessorCreateCacheFromConfig(jobject obj, long long memPtr, JniErrorInfo* errInfo);
                 jobject ProcessorGetOrCreateCacheFromConfig(jobject obj, long long memPtr);
                 jobject ProcessorGetOrCreateCacheFromConfig(jobject obj, long long memPtr, JniErrorInfo* errInfo);
+                jobject ProcessorCreateNearCache(jobject obj, const char* name, long long memPtr);
+                jobject ProcessorGetOrCreateNearCache(jobject obj, const char* name, long long memPtr);
                 void ProcessorDestroyCache(jobject obj, const char* name);
                 void ProcessorDestroyCache(jobject obj, const char* name, JniErrorInfo* errInfo);
                 jobject ProcessorAffinity(jobject obj, const char* name);
@@ -665,6 +669,7 @@ namespace ignite
                 jobject LocalToGlobal(JNIEnv* env, jobject obj);
                 jobject ProcessorCache0(jobject proc, const char* name, jmethodID mthd, JniErrorInfo* errInfo);
                 jobject ProcessorCacheFromConfig0(jobject proc, long long memPtr, jmethodID mthd, JniErrorInfo* errInfo);
+                jobject ProcessorGetOrCreateNearCache0(jobject obj, const char* name, long long memPtr, jmethodID methodID);
             };
 
             JNIEXPORT jlong JNICALL JniCacheStoreCreate(JNIEnv *env, jclass cls, jlong envPtr, jlong memPtr);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 21a4994..57e58f3 100644
--- a/modules/platforms/cpp/common/project/vs/module.def
+++ b/modules/platforms/cpp/common/project/vs/module.def
@@ -130,3 +130,5 @@ IgniteAtomicSequenceClose @127
 IgniteProcessorAtomicReference @128
 IgniteAtomicReferenceIsClosed @129
 IgniteAtomicReferenceClose @130
+IgniteProcessorCreateNearCache @131
+IgniteProcessorGetOrCreateNearCache @132

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 93fd337..0d951b6 100644
--- a/modules/platforms/cpp/common/src/exports.cpp
+++ b/modules/platforms/cpp/common/src/exports.cpp
@@ -74,6 +74,14 @@ extern "C" {
         return ctx->ProcessorGetOrCreateCacheFromConfig(static_cast<jobject>(obj), memPtr);
     }
 
+    void* IGNITE_CALL IgniteProcessorCreateNearCache(gcj::JniContext* ctx, void* obj, char* name, long long memPtr) {
+        return ctx->ProcessorCreateNearCache(static_cast<jobject>(obj), name, memPtr);
+    }
+
+    void* IGNITE_CALL IgniteProcessorGetOrCreateNearCache(gcj::JniContext* ctx, void* obj, char* name, long long memPtr) {
+        return ctx->ProcessorGetOrCreateNearCache(static_cast<jobject>(obj), name, memPtr);
+    }
+
     void IGNITE_CALL IgniteProcessorDestroyCache(gcj::JniContext* ctx, void* obj, char* name) {
         ctx->ProcessorDestroyCache(static_cast<jobject>(obj), name);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 c029038..081a606 100644
--- a/modules/platforms/cpp/common/src/java.cpp
+++ b/modules/platforms/cpp/common/src/java.cpp
@@ -193,6 +193,8 @@ namespace ignite
             JniMethod M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE = JniMethod("getOrCreateCache", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
             JniMethod M_PLATFORM_PROCESSOR_CREATE_CACHE_FROM_CONFIG = JniMethod("createCacheFromConfig", "(J)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
             JniMethod M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE_FROM_CONFIG = JniMethod("getOrCreateCacheFromConfig", "(J)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
+            JniMethod M_PLATFORM_PROCESSOR_CREATE_NEAR_CACHE = JniMethod("createNearCache", "(Ljava/lang/String;J)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
+            JniMethod M_PLATFORM_PROCESSOR_GET_OR_CREATE_NEAR_CACHE = JniMethod("getOrCreateNearCache", "(Ljava/lang/String;J)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
             JniMethod M_PLATFORM_PROCESSOR_DESTROY_CACHE = JniMethod("destroyCache", "(Ljava/lang/String;)V", false);
             JniMethod M_PLATFORM_PROCESSOR_AFFINITY = JniMethod("affinity", "(Ljava/lang/String;)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
             JniMethod M_PLATFORM_PROCESSOR_DATA_STREAMER = JniMethod("dataStreamer", "(Ljava/lang/String;Z)Lorg/apache/ignite/internal/processors/platform/PlatformTarget;", false);
@@ -661,6 +663,8 @@ namespace ignite
                 m_PlatformProcessor_getOrCreateCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE);
                 m_PlatformProcessor_createCacheFromConfig = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_CREATE_CACHE_FROM_CONFIG);
                 m_PlatformProcessor_getOrCreateCacheFromConfig = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_OR_CREATE_CACHE_FROM_CONFIG);
+                m_PlatformProcessor_createNearCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_CREATE_NEAR_CACHE);
+                m_PlatformProcessor_getOrCreateNearCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_GET_OR_CREATE_NEAR_CACHE);
                 m_PlatformProcessor_destroyCache = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_DESTROY_CACHE);
                 m_PlatformProcessor_affinity = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_AFFINITY);
                 m_PlatformProcessor_dataStreamer = FindMethod(env, c_PlatformProcessor, M_PLATFORM_PROCESSOR_DATA_STREAMER);
@@ -1283,6 +1287,32 @@ namespace ignite
                 return ProcessorCacheFromConfig0(obj, memPtr, jvm->GetMembers().m_PlatformProcessor_getOrCreateCacheFromConfig, errInfo);
             }
 
+            jobject JniContext::ProcessorCreateNearCache(jobject obj, const char* name, long long memPtr)
+            {
+                return ProcessorGetOrCreateNearCache0(obj, name, memPtr, jvm->GetMembers().m_PlatformProcessor_createNearCache);
+            }
+
+            jobject JniContext::ProcessorGetOrCreateNearCache(jobject obj, const char* name, long long memPtr)
+            {
+                return ProcessorGetOrCreateNearCache0(obj, name, memPtr, jvm->GetMembers().m_PlatformProcessor_getOrCreateNearCache);
+            }
+
+            jobject JniContext::ProcessorGetOrCreateNearCache0(jobject obj, const char* name, long long memPtr, jmethodID methodID)
+            {
+                JNIEnv* env = Attach();
+
+                jstring name0 = name != NULL ? env->NewStringUTF(name) : NULL;
+
+                jobject cache = env->CallObjectMethod(obj, methodID, name0, memPtr);
+
+                if (name0)
+                    env->DeleteLocalRef(name0);
+
+                ExceptionCheck(env);
+
+                return LocalToGlobal(env, cache);
+            }
+
             jobject JniContext::ProcessorAffinity(jobject obj, const char* name) {
                 JNIEnv* env = Attach();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 de21765..002fa26 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
@@ -58,6 +58,7 @@
     <Compile Include="Cache\CacheAffinityFieldTest.cs" />
     <Compile Include="Cache\CacheConfigurationTest.cs" />
     <Compile Include="Cache\CacheDynamicStartTest.cs" />
+    <Compile Include="Cache\CacheNearTest.cs" />
     <Compile Include="Cache\CacheTestAsyncWrapper.cs" />
     <Compile Include="Cache\CacheAbstractTest.cs" />
     <Compile Include="Cache\CacheAffinityTest.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index bc259e5..d474f38 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -22,6 +22,7 @@ namespace Apache.Ignite.Core.Tests.Cache
     using System.Linq;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Eviction;
     using Apache.Ignite.Core.Cache.Store;
     using Apache.Ignite.Core.Common;
     using NUnit.Framework;
@@ -237,6 +238,44 @@ namespace Apache.Ignite.Core.Tests.Cache
             Assert.AreEqual(x.WriteBehindFlushSize, y.WriteBehindFlushSize);
 
             AssertConfigsAreEqual(x.QueryEntities, y.QueryEntities);
+            AssertConfigsAreEqual(x.NearConfiguration, y.NearConfiguration);
+        }
+
+        /// <summary>
+        /// Asserts that two configurations have the same properties.
+        /// </summary>
+        private static void AssertConfigsAreEqual(NearCacheConfiguration x, NearCacheConfiguration y)
+        {
+            if (x == null)
+            {
+                Assert.IsNull(y);
+                return;
+            }
+
+            Assert.AreEqual(x.NearStartSize, y.NearStartSize);
+
+            AssertConfigsAreEqual(x.EvictionPolicy, y.EvictionPolicy);
+        }
+
+        /// <summary>
+        /// Asserts that two configurations have the same properties.
+        /// </summary>
+        private static void AssertConfigsAreEqual(IEvictionPolicy x, IEvictionPolicy y)
+        {
+            if (x == null)
+            {
+                Assert.IsNull(y);
+                return;
+            }
+
+            Assert.AreEqual(x.GetType(), y.GetType());
+
+            var px = (EvictionPolicyBase) x;
+            var py = (EvictionPolicyBase) y;
+
+            Assert.AreEqual(px.BatchSize, py.BatchSize);
+            Assert.AreEqual(px.MaxSize, py.MaxSize);
+            Assert.AreEqual(px.MaxMemorySize, py.MaxMemorySize);
         }
 
         /// <summary>
@@ -460,6 +499,16 @@ namespace Apache.Ignite.Core.Tests.Cache
                             }
                         }
                     }
+                },
+                NearConfiguration = new NearCacheConfiguration
+                {
+                    NearStartSize = 456,
+                    EvictionPolicy = new LruEvictionPolicy
+                    {
+                        MaxSize = 25,
+                        MaxMemorySize = 2500,
+                        BatchSize = 3
+                    }
                 }
             };
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheNearTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheNearTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheNearTest.cs
new file mode 100644
index 0000000..f5a1337
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheNearTest.cs
@@ -0,0 +1,188 @@
+\ufeff/*
+ * 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.Cache
+{
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Eviction;
+    using Apache.Ignite.Core.Events;
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Near cache test.
+    /// </summary>
+    public class CacheNearTest : IEventListener<CacheEvent>
+    {
+        /** */
+        private IIgnite _grid;
+
+        /** */
+        private volatile CacheEvent _lastEvent;
+
+        /// <summary>
+        /// Fixture set up.
+        /// </summary>
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                CacheConfiguration = new[]
+                {
+                    new CacheConfiguration
+                    {
+                        NearConfiguration = new NearCacheConfiguration
+                        {
+                            EvictionPolicy = new FifoEvictionPolicy {MaxSize = 5}
+                        }
+                    }
+                },
+                IncludedEventTypes = new[] { EventType.CacheEntryCreated }
+            };
+
+            _grid = Ignition.Start(cfg);
+        }
+
+        /// <summary>
+        /// Fixture tear down.
+        /// </summary>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary>
+        /// Tests the existing near cache.
+        /// </summary>
+        [Test]
+        public void TestExistingNearCache()
+        {
+            var cache = _grid.GetCache<int, string>(null);
+
+            cache[1] = "1";
+
+            var nearCache = _grid.GetOrCreateNearCache<int, string>(null, new NearCacheConfiguration());
+            Assert.AreEqual("1", nearCache[1]);
+
+            // GetOrCreate when exists
+            nearCache = _grid.GetOrCreateNearCache<int, string>(null, new NearCacheConfiguration());
+            Assert.AreEqual("1", nearCache[1]);
+        }
+
+        /// <summary>
+        /// Tests the created near cache.
+        /// </summary>
+        [Test]
+        public void TestCreateNearCache()
+        {
+            const string cacheName = "dyn_cache";
+
+            var cache = _grid.CreateCache<int, string>(cacheName);
+            cache[1] = "1";
+
+            var nearCache = _grid.CreateNearCache<int, string>(cacheName, new NearCacheConfiguration());
+            Assert.AreEqual("1", nearCache[1]);
+
+            // Create when exists
+            nearCache = _grid.CreateNearCache<int, string>(cacheName, new NearCacheConfiguration());
+            Assert.AreEqual("1", nearCache[1]);
+        }
+
+        /// <summary>
+        /// Tests near cache on the client node.
+        /// </summary>
+        [Test]
+        public void TestCreateNearCacheOnClientNode()
+        {
+            const string cacheName = "client_cache";
+
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                ClientMode = true,
+                GridName = "clientGrid"
+            };
+
+            using (var clientGrid = Ignition.Start(cfg))
+            {
+                clientGrid.CreateCache<int, string>(cacheName);
+
+                // Near cache can't be started on client node
+                Assert.Throws<CacheException>(
+                    () => clientGrid.CreateNearCache<int, string>(cacheName, new NearCacheConfiguration()));
+            }
+        }
+
+        /// <summary>
+        /// Tests near cache on the client node.
+        /// </summary>
+        [Test]
+        public void TestCreateCacheWithNearConfigOnClientNode()
+        {
+            const string cacheName = "client_with_near_cache";
+
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                ClientMode = true,
+                GridName = "clientGrid",
+                IncludedEventTypes = new[] {EventType.CacheEntryCreated}
+            };
+
+            using (var clientGrid = Ignition.Start(cfg))
+            {
+                var cache = clientGrid.CreateCache<int, string>(new CacheConfiguration(cacheName), 
+                    new NearCacheConfiguration());
+
+                AssertCacheIsNear(cache);
+
+                cache[1] = "1";
+                Assert.AreEqual("1", cache[1]);
+
+                var cache2 = clientGrid.GetOrCreateCache<int, string>(new CacheConfiguration(cacheName),
+                    new NearCacheConfiguration());
+
+                Assert.AreEqual("1", cache2[1]);
+            }
+        }
+
+        /// <summary>
+        /// Asserts the cache is near.
+        /// </summary>
+        private void AssertCacheIsNear(ICache<int, string> cache)
+        {
+            var events = cache.Ignite.GetEvents();
+            events.LocalListen(this, EventType.CacheEntryCreated);
+
+            _lastEvent = null;
+            cache[-1] = "test";
+
+            TestUtils.WaitForCondition(() => _lastEvent != null, 500);
+            Assert.IsNotNull(_lastEvent);
+            Assert.IsTrue(_lastEvent.IsNear);
+
+            events.StopLocalListen(this, EventType.CacheEntryCreated);
+        }
+
+        /** <inheritdoc /> */
+        public bool Invoke(CacheEvent evt)
+        {
+            _lastEvent = evt;
+            return true;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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
index 2e72ce4..1df48bf 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/app.config
@@ -23,6 +23,10 @@
         <section name="igniteConfiguration2" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" />
     </configSections>
 
+    <runtime>
+        <gcServer enabled="true"/>
+    </runtime>
+
     <igniteConfiguration xmlns="http://ignite.apache.org/schema/dotnet/IgniteConfigurationSection" gridName="myGrid1">
         <discoverySpi type="TcpDiscoverySpi">
             <ipFinder type="TcpDiscoveryStaticIpFinder">

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 19d370a..8d56227 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -92,6 +92,7 @@
     <Compile Include="Cache\CacheException.cs" />
     <Compile Include="Cache\CachePartialUpdateException.cs" />
     <Compile Include="Cache\CachePeekMode.cs" />
+    <Compile Include="Cache\Configuration\NearCacheConfiguration.cs" />
     <Compile Include="DataStructures\Configuration\AtomicConfiguration.cs" />
     <Compile Include="Cache\Configuration\QueryAlias.cs" />
     <Compile Include="Cache\Configuration\QueryTextFieldAttribute.cs" />
@@ -100,6 +101,10 @@
     <Compile Include="Cache\Event\ICacheEntryEventFilter.cs" />
     <Compile Include="Cache\Event\ICacheEntryEventListener.cs" />
     <Compile Include="Cache\Event\Package-Info.cs" />
+    <Compile Include="Cache\Eviction\EvictionPolicyBase.cs" />
+    <Compile Include="Cache\Eviction\FifoEvictionPolicy.cs" />
+    <Compile Include="Cache\Eviction\IEvictionPolicy.cs" />
+    <Compile Include="Cache\Eviction\LruEvictionPolicy.cs" />
     <Compile Include="Cache\Expiry\ExpiryPolicy.cs" />
     <Compile Include="Cache\Expiry\IExpiryPolicy.cs" />
     <Compile Include="Cache\Expiry\Package-Info.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
index ba509fc..e5fcdb1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
@@ -267,6 +267,8 @@ namespace Apache.Ignite.Core.Cache.Configuration
 
             var count = reader.ReadInt();
             QueryEntities = count == 0 ? null : Enumerable.Range(0, count).Select(x => new QueryEntity(reader)).ToList();
+
+            NearConfiguration = reader.ReadBoolean() ? new NearCacheConfiguration(reader) : null;
         }
 
         /// <summary>
@@ -329,6 +331,14 @@ namespace Apache.Ignite.Core.Cache.Configuration
             }
             else
                 writer.WriteInt(0);
+
+            if (NearConfiguration != null)
+            {
+                writer.WriteBoolean(true);
+                NearConfiguration.Write(writer);
+            }
+            else
+                writer.WriteBoolean(false);
         }
 
         /// <summary>
@@ -633,5 +643,10 @@ namespace Apache.Ignite.Core.Cache.Configuration
         /// </summary>
         [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public ICollection<QueryEntity> QueryEntities { get; set; }
+
+        /// <summary>
+        /// Gets or sets the near cache configuration.
+        /// </summary>
+        public NearCacheConfiguration NearConfiguration { get; set; }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/NearCacheConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/NearCacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/NearCacheConfiguration.cs
new file mode 100644
index 0000000..dc9219f
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/NearCacheConfiguration.cs
@@ -0,0 +1,75 @@
+\ufeff/*
+ * 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.Cache.Configuration
+{
+    using System.ComponentModel;
+    using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Cache.Eviction;
+
+    /// <summary>
+    /// Defines near cache configuration.
+    /// <para />
+    /// Distributed cache can also be fronted by a Near cache, which is a smaller local cache that stores most 
+    /// recently or most frequently accessed data. 
+    /// Just like with a partitioned cache, the user can control the size of the near cache and its eviction policies. 
+    /// </summary>
+    public class NearCacheConfiguration
+    {
+        /// <summary> Initial default near cache size. </summary>
+        public const int DefaultNearStartSize = CacheConfiguration.DefaultStartSize / 4;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="NearCacheConfiguration"/> class.
+        /// </summary>
+        public NearCacheConfiguration()
+        {
+            NearStartSize = DefaultNearStartSize;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="NearCacheConfiguration"/> class.
+        /// </summary>
+        internal NearCacheConfiguration(IBinaryRawReader reader)
+        {
+            NearStartSize = reader.ReadInt();
+            EvictionPolicy = EvictionPolicyBase.Read(reader);
+        }
+
+        /// <summary>
+        /// Writes to the specified writer.
+        /// </summary>
+        internal void Write(IBinaryRawWriter writer)
+        {
+            writer.WriteInt(NearStartSize);
+            EvictionPolicyBase.Write(writer, EvictionPolicy);
+        }
+
+        /// <summary>
+        /// Gets or sets the eviction policy.
+        /// Null value means disabled evictions.
+        /// </summary>
+        public IEvictionPolicy EvictionPolicy { get; set; }
+
+        /// <summary>
+        /// Gets or sets the initial cache size for near cache which will be used 
+        /// to pre-create internal hash table after start.
+        /// </summary>
+        [DefaultValue(DefaultNearStartSize)]
+        public int NearStartSize { get; set; }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/EvictionPolicyBase.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/EvictionPolicyBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/EvictionPolicyBase.cs
new file mode 100644
index 0000000..ee533b1
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/EvictionPolicyBase.cs
@@ -0,0 +1,126 @@
+\ufeff/*
+ * 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.Cache.Eviction
+{
+    using System;
+    using System.ComponentModel;
+    using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Cache.Configuration;
+
+    /// <summary>
+    /// Base class for predefined eviction policies.
+    /// </summary>
+    public abstract class EvictionPolicyBase : IEvictionPolicy
+    {
+        /// <summary> Default batch cache size. </summary>
+        public const int DefaultBatchSize = 1;
+        
+        /// <summary> Default max cache size. </summary>
+        public const int DefaultMaxSize = CacheConfiguration.DefaultCacheSize;
+
+        /// <summary> Default max cache size in bytes. </summary>
+        public const long DefaultMaxMemorySize = 0;
+
+        /// <summary>
+        /// Gets or sets the size of the eviction batch.
+        /// Batch eviction is enabled only if maximum memory limit isn't set (<see cref="MaxMemorySize"/> == 0).
+        /// </summary>
+        [DefaultValue(DefaultBatchSize)]
+        public int BatchSize { get; set; }
+
+        /// <summary>
+        /// Gets or sets the maximum allowed cache size (entry count).
+        /// 0 for unlimited.
+        /// </summary>
+        [DefaultValue(DefaultMaxSize)]
+        public int MaxSize { get; set; }
+
+        /// <summary>
+        /// Gets or sets the maximum allowed cache size in bytes.
+        /// 0 for unlimited.
+        /// </summary>
+        [DefaultValue(DefaultMaxMemorySize)]
+        public long MaxMemorySize { get; set; }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="EvictionPolicyBase"/> class.
+        /// </summary>
+        internal EvictionPolicyBase()
+        {
+            BatchSize = DefaultBatchSize;
+            MaxSize = DefaultMaxSize;
+            MaxMemorySize = DefaultMaxMemorySize;
+        }
+        
+        /// <summary>
+        /// Writes to the specified writer.
+        /// </summary>
+        internal static void Write(IBinaryRawWriter writer, IEvictionPolicy policy)
+        {
+            if (policy == null)
+            {
+                writer.WriteByte(0);
+                return;
+            }
+
+            var p = policy as EvictionPolicyBase;
+
+            if (p == null)
+            {
+                throw new NotSupportedException(
+                    string.Format("Unsupported Eviction Policy: {0}. Only predefined eviction policy types " +
+                                  "are supported: {1}, {2}", policy.GetType(), typeof (LruEvictionPolicy),
+                        typeof (FifoEvictionPolicy)));
+            }
+
+            writer.WriteByte(p is FifoEvictionPolicy ? (byte) 1 : (byte) 2);
+
+            writer.WriteInt(p.BatchSize);
+            writer.WriteInt(p.MaxSize);
+            writer.WriteLong(p.MaxMemorySize);
+        }
+
+        /// <summary>
+        /// Reads an instance.
+        /// </summary>
+        internal static EvictionPolicyBase Read(IBinaryRawReader reader)
+        {
+            EvictionPolicyBase p;
+
+            switch (reader.ReadByte())
+            {
+                case 0:
+                    return null;
+                case 1:
+                    p = new FifoEvictionPolicy();
+                    break;
+                case 2:
+                    p = new LruEvictionPolicy();
+                    break;
+                default:
+                    throw new InvalidOperationException("Unsupported eviction policy.");
+            }
+
+            p.BatchSize = reader.ReadInt();
+            p.MaxSize = reader.ReadInt();
+            p.MaxMemorySize = reader.ReadLong();
+
+            return p;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/FifoEvictionPolicy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/FifoEvictionPolicy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/FifoEvictionPolicy.cs
new file mode 100644
index 0000000..9c8dc2a
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/FifoEvictionPolicy.cs
@@ -0,0 +1,39 @@
+\ufeff/*
+ * 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.Cache.Eviction
+{
+    /// <summary>
+    /// Eviction policy based on First In First Out (FIFO) algorithm with batch eviction support.
+    /// <para />
+    /// The eviction starts in the following cases: 
+    /// The cache size becomes { @code batchSize }
+    /// elements greater than the maximum size;
+    /// The size of cache entries in bytes becomes greater than the maximum memory size;
+    /// The size of cache entry calculates as sum of key size and value size.
+    /// <para />
+    /// Note: Batch eviction is enabled only if maximum memory limit isn't set.
+    /// <para />
+    /// This implementation is very efficient since it does not create any additional
+    /// table-like data structures. The FIFO ordering information is
+    /// maintained by attaching ordering metadata to cache entries.
+    /// </summary>
+    public class FifoEvictionPolicy : EvictionPolicyBase
+    {
+        // No-op.
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/IEvictionPolicy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/IEvictionPolicy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/IEvictionPolicy.cs
new file mode 100644
index 0000000..44d8d79
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/IEvictionPolicy.cs
@@ -0,0 +1,32 @@
+\ufeff/*
+ * 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.Cache.Eviction
+{
+    using System.Diagnostics.CodeAnalysis;
+
+    /// <summary>
+    /// Represents a cache eviction policy.
+    /// Only predefined implementations are supported now: 
+    /// <see cref="LruEvictionPolicy"/>, <see cref="FifoEvictionPolicy"/>.
+    /// </summary>
+    [SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")]
+    public interface IEvictionPolicy
+    {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/LruEvictionPolicy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/LruEvictionPolicy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/LruEvictionPolicy.cs
new file mode 100644
index 0000000..b3b9566
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Eviction/LruEvictionPolicy.cs
@@ -0,0 +1,39 @@
+\ufeff/*
+ * 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.Cache.Eviction
+{
+    /// <summary>
+    /// Eviction policy based on Least Recently Used (LRU) algorithm with batch eviction support.
+    /// <para />
+    /// The eviction starts in the following cases: 
+    /// The cache size becomes { @code batchSize }
+    /// elements greater than the maximum size;
+    /// The size of cache entries in bytes becomes greater than the maximum memory size;
+    /// The size of cache entry calculates as sum of key size and value size.
+    /// <para />
+    /// Note: Batch eviction is enabled only if maximum memory limit isn't set.
+    /// <para />
+    /// This implementation is very efficient since it does not create any additional
+    /// table-like data structures. The LRU ordering information is
+    /// maintained by attaching ordering metadata to cache entries.
+    /// </summary>
+    public class LruEvictionPolicy : EvictionPolicyBase
+    {
+        // No-op.
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 12ea09e..428c1a8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
@@ -103,6 +103,17 @@ namespace Apache.Ignite.Core
         ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration);
 
         /// <summary>
+        /// Gets existing cache with the given name or creates new one using provided configuration.
+        /// </summary>
+        /// <typeparam name="TK">Cache key type.</typeparam>
+        /// <typeparam name="TV">Cache value type.</typeparam>
+        /// <param name="configuration">Cache configuration.</param>
+        /// /// <param name="nearConfiguration">Near cache configuration for client.</param>
+        /// <returns>Existing or newly created cache.</returns>
+        ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration, 
+            NearCacheConfiguration nearConfiguration);
+
+        /// <summary>
         /// Dynamically starts new cache using template configuration.
         /// </summary>
         /// <typeparam name="TK">Cache key type.</typeparam>
@@ -121,6 +132,17 @@ namespace Apache.Ignite.Core
         ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration);
 
         /// <summary>
+        /// Dynamically starts new cache using provided configuration.
+        /// </summary>
+        /// <typeparam name="TK">Cache key type.</typeparam>
+        /// <typeparam name="TV">Cache value type.</typeparam>
+        /// <param name="configuration">Cache configuration.</param>
+        /// <param name="nearConfiguration">Near cache configuration for client.</param>
+        /// <returns>Existing or newly created cache.</returns>
+        ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration, 
+            NearCacheConfiguration nearConfiguration);
+
+        /// <summary>
         /// Destroys dynamically created (with <see cref="CreateCache{TK,TV}(string)"/> or 
         /// <see cref="GetOrCreateCache{TK,TV}(string)"/>) cache.
         /// </summary>
@@ -224,5 +246,25 @@ namespace Apache.Ignite.Core
         /// </summary>
         [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Semantics.")]
         IgniteConfiguration GetConfiguration();
+
+        /// <summary>
+        /// Starts a near cache on local node if cache with specified was previously started.
+        /// </summary>
+        /// <param name="name">The name.</param>
+        /// <param name="configuration">The configuration.</param>
+        /// <typeparam name="TK">Cache key type.</typeparam>
+        /// <typeparam name="TV">Cache value type.</typeparam>
+        /// <returns>Near cache instance.</returns>
+        ICache<TK, TV> CreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration);
+
+        /// <summary>
+        /// Gets existing near cache with the given name or creates a new one.
+        /// </summary>
+        /// <param name="name">The name.</param>
+        /// <param name="configuration">The configuration.</param>
+        /// <typeparam name="TK">Cache key type.</typeparam>
+        /// <typeparam name="TV">Cache value type.</typeparam>
+        /// <returns>Near cache instance.</returns>
+        ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 1735fb8..b84ff29 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -368,6 +368,13 @@ namespace Apache.Ignite.Core.Impl
         /** <inheritdoc /> */
         public ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration)
         {
+            return GetOrCreateCache<TK, TV>(configuration, null);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration, 
+            NearCacheConfiguration nearConfiguration)
+        {
             IgniteArgumentCheck.NotNull(configuration, "configuration");
 
             using (var stream = IgniteManager.Memory.Allocate().GetStream())
@@ -376,6 +383,14 @@ namespace Apache.Ignite.Core.Impl
 
                 configuration.Write(writer);
 
+                if (nearConfiguration != null)
+                {
+                    writer.WriteBoolean(true);
+                    nearConfiguration.Write(writer);
+                }
+                else
+                    writer.WriteBoolean(false);
+
                 stream.SynchronizeOutput();
 
                 return Cache<TK, TV>(UU.ProcessorGetOrCreateCache(_proc, stream.MemoryPointer));
@@ -391,6 +406,13 @@ namespace Apache.Ignite.Core.Impl
         /** <inheritdoc /> */
         public ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration)
         {
+            return CreateCache<TK, TV>(configuration, null);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration, 
+            NearCacheConfiguration nearConfiguration)
+        {
             IgniteArgumentCheck.NotNull(configuration, "configuration");
 
             using (var stream = IgniteManager.Memory.Allocate().GetStream())
@@ -399,6 +421,14 @@ namespace Apache.Ignite.Core.Impl
 
                 configuration.Write(writer);
 
+                if (nearConfiguration != null)
+                {
+                    writer.WriteBoolean(true);
+                    nearConfiguration.Write(writer);
+                }
+                else
+                    writer.WriteBoolean(false);
+
                 stream.SynchronizeOutput();
 
                 return Cache<TK, TV>(UU.ProcessorCreateCache(_proc, stream.MemoryPointer));
@@ -580,6 +610,38 @@ namespace Apache.Ignite.Core.Impl
             }
         }
 
+        /** <inheritdoc /> */
+        public ICache<TK, TV> CreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
+        {
+            return GetOrCreateNearCache0<TK, TV>(name, configuration, UU.ProcessorCreateNearCache);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
+        {
+            return GetOrCreateNearCache0<TK, TV>(name, configuration, UU.ProcessorGetOrCreateNearCache);
+        }
+
+        /// <summary>
+        /// Gets or creates near cache.
+        /// </summary>
+        private ICache<TK, TV> GetOrCreateNearCache0<TK, TV>(string name, NearCacheConfiguration configuration,
+            Func<IUnmanagedTarget, string, long, IUnmanagedTarget> func)
+        {
+            IgniteArgumentCheck.NotNull(configuration, "configuration");
+
+            using (var stream = IgniteManager.Memory.Allocate().GetStream())
+            {
+                var writer = Marshaller.StartMarshal(stream);
+
+                configuration.Write(writer);
+
+                stream.SynchronizeOutput();
+
+                return Cache<TK, TV>(func(_proc, name, stream.MemoryPointer));
+            }
+        }
+
         /// <summary>
         /// Gets internal projection.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 0aa55fb..a767077 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -240,6 +240,12 @@ namespace Apache.Ignite.Core.Impl
         }
 
         /** <inheritdoc /> */
+        public ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration, NearCacheConfiguration nearConfiguration)
+        {
+            return _ignite.GetOrCreateCache<TK, TV>(configuration, nearConfiguration);
+        }
+
+        /** <inheritdoc /> */
         public ICache<TK, TV> CreateCache<TK, TV>(string name)
         {
             return _ignite.CreateCache<TK, TV>(name);
@@ -250,6 +256,14 @@ namespace Apache.Ignite.Core.Impl
         {
             return _ignite.CreateCache<TK, TV>(configuration);
         }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration, NearCacheConfiguration nearConfiguration)
+        {
+            return _ignite.CreateCache<TK, TV>(configuration, nearConfiguration);
+        }
+
+        /** <inheritdoc /> */
         public void DestroyCache(string name)
         {
             _ignite.DestroyCache(name);
@@ -347,6 +361,17 @@ namespace Apache.Ignite.Core.Impl
         }
 
         /** <inheritdoc /> */
+        public ICache<TK, TV> CreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
+        {
+            return _ignite.CreateNearCache<TK, TV>(name, configuration);
+        }
+
+        public ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration)
+        {
+            return _ignite.GetOrCreateNearCache<TK, TV>(name, configuration);
+        }
+
+        /** <inheritdoc /> */
         public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create)
         {
             return _ignite.GetAtomicSequence(name, initialValue, create);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 28eb208..2603841 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/IgniteJniNativeMethods.cs
@@ -61,6 +61,12 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
         [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetOrCreateCacheFromConfig")]
         public static extern void* ProcessorGetOrCreateCacheFromConfig(void* ctx, void* obj, long memPtr);
 
+        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorCreateNearCache")]
+        public static extern void* ProcessorCreateNearCache(void* ctx, void* obj, sbyte* name, long memPtr);
+
+        [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorGetOrCreateNearCache")]
+        public static extern void* ProcessorGetOrCreateNearCache(void* ctx, void* obj, sbyte* name, long memPtr);
+
         [DllImport(IgniteUtils.FileIgniteJniDll, EntryPoint = "IgniteProcessorDestroyCache")]
         public static extern void ProcessorDestroyCache(void* ctx, void* obj, sbyte* name);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdb2f649/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 afe46a8..f8b5256 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -180,6 +180,38 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
             return target.ChangeTarget(res);
         }
 
+        internal static IUnmanagedTarget ProcessorCreateNearCache(IUnmanagedTarget target, string name, long memPtr)
+        {
+            sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name);
+
+            try
+            {
+                void* res = JNI.ProcessorCreateNearCache(target.Context, target.Target, name0, memPtr);
+
+                return target.ChangeTarget(res);
+            }
+            finally
+            {
+                Marshal.FreeHGlobal(new IntPtr(name0));
+            }
+        }
+
+        internal static IUnmanagedTarget ProcessorGetOrCreateNearCache(IUnmanagedTarget target, string name, long memPtr)
+        {
+            sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name);
+
+            try
+            {
+                void* res = JNI.ProcessorGetOrCreateNearCache(target.Context, target.Target, name0, memPtr);
+
+                return target.ChangeTarget(res);
+            }
+            finally
+            {
+                Marshal.FreeHGlobal(new IntPtr(name0));
+            }
+        }
+
         internal static void ProcessorDestroyCache(IUnmanagedTarget target, string name)
         {
             sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name);


[14/50] [abbrv] ignite git commit: IGNITE-2941: Add getOrStart method to ignition IGNITE-2942: Use getOrStart in IgniteContext instead of current try-catch structure This closes #631 Reviewed by Denis Magda, Alexey Goncharuk.

Posted by sh...@apache.org.
IGNITE-2941: Add getOrStart method to ignition
IGNITE-2942: Use getOrStart in IgniteContext instead of current try-catch structure
This closes #631
Reviewed by Denis Magda, Alexey Goncharuk.


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

Branch: refs/heads/ignite-2788
Commit: efe76f18db8f30492046e47994b1a96208df68f8
Parents: 50171eb
Author: Alexei Scherbakov <al...@gmail.com>
Authored: Tue Apr 19 07:11:54 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../main/java/org/apache/ignite/Ignition.java   |  19 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |  60 +++-
 .../ignite/internal/GridGetOrStartSelfTest.java | 129 +++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |  16 +-
 .../org/apache/ignite/spark/IgniteContext.scala |  73 ++--
 .../apache/ignite/spark/JavaIgniteContext.scala |  14 +-
 .../spark/JavaEmbeddedIgniteRDDSelfTest.java    | 343 +++++++++++++++++++
 .../ignite/spark/JavaIgniteRDDSelfTest.java     | 302 ----------------
 .../spark/JavaStandaloneIgniteRDDSelfTest.java  | 302 ++++++++++++++++
 .../ignite/testsuites/IgniteRDDTestSuite.java   |  40 +++
 10 files changed, 935 insertions(+), 363 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/core/src/main/java/org/apache/ignite/Ignition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignition.java b/modules/core/src/main/java/org/apache/ignite/Ignition.java
index 99ee1d9..b4c01f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignition.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignition.java
@@ -309,7 +309,7 @@ public class Ignition {
     }
 
     /**
-     * Starts grid with given configuration. Note that this method is no-op if grid with the name
+     * Starts grid with given configuration. Note that this method will throw an exception if grid with the name
      * provided in given configuration is already started.
      *
      * @param cfg Grid configuration. This cannot be {@code null}.
@@ -401,6 +401,23 @@ public class Ignition {
         }
     }
 
+
+    /**
+     * Gets or starts new grid instance if it hasn't been started yet.
+     *
+     * @param cfg Grid configuration. This cannot be {@code null}.
+     * @return Grid instance.
+     * @throws IgniteException If grid could not be started.
+     */
+    public static Ignite getOrStart(IgniteConfiguration cfg) throws IgniteException {
+        try {
+            return IgnitionEx.start(cfg, false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
     /**
      * Loads Spring bean by its name from given Spring XML configuration file. If bean
      * with such name doesn't exist, exception is thrown.

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 227e5c2..c46a05c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -499,7 +499,7 @@ public class IgnitionEx {
 
         U.warn(null, "Default Spring XML file not found (is IGNITE_HOME set?): " + DFLT_CFG);
 
-        return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx)).grid();
+        return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx), true).grid();
     }
 
     /**
@@ -512,11 +512,25 @@ public class IgnitionEx {
      *      also if named grid has already been started.
      */
     public static Ignite start(IgniteConfiguration cfg) throws IgniteCheckedException {
-        return start(cfg, null);
+        return start(cfg, null, true);
     }
 
     /**
-     * Starts grid with given configuration. Note that this method is no-op if grid with the name
+     * Starts a grid with given configuration. If the grid is already started and failIfStarted set to TRUE
+     * an exception will be thrown.
+     *
+     * @param cfg Grid configuration. This cannot be {@code null}.
+     * failIfStarted Throw or not an exception if grid is already started.
+     * @return Started grid.
+     * @throws IgniteCheckedException If grid could not be started. This exception will be thrown
+     *      also if named grid has already been started.
+     */
+    public static Ignite start(IgniteConfiguration cfg, boolean failIfStarted) throws IgniteCheckedException {
+        return start(cfg, null, failIfStarted);
+    }
+
+    /**
+     * Starts grid with given configuration. Note that this method will throw and exception if grid with the name
      * provided in given configuration is already started.
      *
      * @param cfg Grid configuration. This cannot be {@code null}.
@@ -531,7 +545,27 @@ public class IgnitionEx {
     public static Ignite start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException {
         A.notNull(cfg, "cfg");
 
-        return start0(new GridStartContext(cfg, null, springCtx)).grid();
+        return start0(new GridStartContext(cfg, null, springCtx), true).grid();
+    }
+
+    /**
+     * Starts grid with given configuration. If the grid is already started and failIfStarted set to TRUE
+     * an exception will be thrown.
+     *
+     * @param cfg Grid configuration. This cannot be {@code null}.
+     * @param springCtx Optional Spring application context, possibly {@code null}.
+     *      Spring bean definitions for bean injection are taken from this context.
+     *      If provided, this context can be injected into grid tasks and grid jobs using
+     *      {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation.
+     * @param failIfStarted Throw or not an exception if grid is already started.
+     * @return Started grid.
+     * @throws IgniteCheckedException If grid could not be started. This exception will be thrown
+     *      also if named grid has already been started.
+     */
+    public static Ignite start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx, boolean failIfStarted) throws IgniteCheckedException {
+        A.notNull(cfg, "cfg");
+
+        return start0(new GridStartContext(cfg, null, springCtx), failIfStarted).grid();
     }
 
     /**
@@ -927,7 +961,7 @@ public class IgnitionEx {
 
                 // Use either user defined context or our one.
                 IgniteNamedInstance grid = start0(
-                    new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx));
+                    new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx), true);
 
                 // Add it if it was not stopped during startup.
                 if (grid != null)
@@ -958,10 +992,11 @@ public class IgnitionEx {
      * Starts grid with given configuration.
      *
      * @param startCtx Start context.
+     * @param failIfStarted Throw or not an exception if grid is already started.
      * @return Started grid.
      * @throws IgniteCheckedException If grid could not be started.
      */
-    private static IgniteNamedInstance start0(GridStartContext startCtx) throws IgniteCheckedException {
+    private static IgniteNamedInstance start0(GridStartContext startCtx, boolean failIfStarted ) throws IgniteCheckedException {
         assert startCtx != null;
 
         String name = startCtx.config().getGridName();
@@ -984,12 +1019,15 @@ public class IgnitionEx {
             }
         }
 
-        if (old != null) {
-            if (name == null)
-                throw new IgniteCheckedException("Default Ignite instance has already been started.");
+        if (old != null)
+            if (failIfStarted) {
+                if (name == null)
+                    throw new IgniteCheckedException("Default Ignite instance has already been started.");
+                else
+                    throw new IgniteCheckedException("Ignite instance with this name has already been started: " + name);
+            }
             else
-                throw new IgniteCheckedException("Ignite instance with this name has already been started: " + name);
-        }
+                return old;
 
         if (startCtx.config().getWarmupClosure() != null)
             startCtx.config().getWarmupClosure().apply(startCtx.config());

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
new file mode 100644
index 0000000..9b3985e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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;
+
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.*;
+
+/**
+ * The GridGetOrStartSelfTest tests get or start semantics.
+ */
+
+@GridCommonTest(group = "Kernal Self")
+public class GridGetOrStartSelfTest extends GridCommonAbstractTest {
+    /** Concurrency. */
+    public static final int CONCURRENCY = 10;
+
+    /**
+     * Default constructor.
+     */
+    public GridGetOrStartSelfTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Tests default grid
+     */
+    public void testDefaultGridGetOrStart() throws Exception {
+        IgniteConfiguration cfg = getConfiguration(null);
+
+        try (Ignite ignite = Ignition.getOrStart(cfg)) {
+            try {
+                Ignition.start(cfg);
+
+                fail("Expected exception after grid started");
+            }
+            catch (IgniteException ignored) {
+            }
+
+            Ignite ignite2 = Ignition.getOrStart(cfg);
+
+            assertEquals("Must return same instance", ignite, ignite2);
+        }
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+
+    /**
+     * Tests named grid
+     */
+    public void testNamedGridGetOrStart() throws Exception {
+        IgniteConfiguration cfg = getConfiguration("test");
+        try (Ignite ignite = Ignition.getOrStart(cfg)) {
+            try {
+                Ignition.start(cfg);
+
+                fail("Expected exception after grid started");
+            }
+            catch (IgniteException ignored) {
+                // No-op.
+            }
+
+            Ignite ignite2 = Ignition.getOrStart(cfg);
+
+            assertEquals("Must return same instance", ignite, ignite2);
+        }
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+
+    /**
+     * Tests concurrent grid initialization
+     */
+    public void testConcurrentGridGetOrStartCon() throws Exception {
+        final IgniteConfiguration cfg = getConfiguration(null);
+
+        final AtomicReference<Ignite> ref = new AtomicReference<>();
+
+        try {
+            GridTestUtils.runMultiThreaded(new Runnable() {
+                @Override public void run() {
+                    // must return same instance in each thread
+
+                    try {
+                        Ignite ignite = Ignition.getOrStart(cfg);
+
+                        boolean set = ref.compareAndSet(null, ignite);
+
+                        if (!set)
+                            assertEquals(ref.get(), ignite);
+                    }
+                    catch (IgniteException e) {
+                        throw new RuntimeException("Ignite error", e);
+                    }
+                }
+            }, CONCURRENCY, "GridCreatorThread");
+        }
+        catch (Exception ignored) {
+            fail("Exception is not expected");
+        }
+
+        G.stopAll(true);
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 9e2324c..bb4b0f0 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -20,19 +20,7 @@ package org.apache.ignite.testsuites;
 import java.util.Set;
 import junit.framework.TestSuite;
 import org.apache.ignite.GridSuppressedExceptionSelfTest;
-import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
-import org.apache.ignite.internal.ClusterGroupSelfTest;
-import org.apache.ignite.internal.GridFailFastNodeFailureDetectionSelfTest;
-import org.apache.ignite.internal.GridLifecycleAwareSelfTest;
-import org.apache.ignite.internal.GridLifecycleBeanSelfTest;
-import org.apache.ignite.internal.GridNodeMetricsLogSelfTest;
-import org.apache.ignite.internal.GridProjectionForCachesSelfTest;
-import org.apache.ignite.internal.GridReduceSelfTest;
-import org.apache.ignite.internal.GridReleaseTypeSelfTest;
-import org.apache.ignite.internal.GridSelfTest;
-import org.apache.ignite.internal.GridStartStopSelfTest;
-import org.apache.ignite.internal.GridStopWithCancelSelfTest;
-import org.apache.ignite.internal.IgniteSlowClientDetectionSelfTest;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorRendezvousSelfTest;
 import org.apache.ignite.internal.processors.cache.GridProjectionForCachesOnDaemonNodeSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteDaemonNodeMarshallerCacheTest;
@@ -129,6 +117,8 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(VariationsIteratorTest.class);
         suite.addTestSuite(ConfigVariationsTestSuiteBuilderTest.class);
 
+        GridTestUtils.addTestIfNeeded(suite, GridGetOrStartSelfTest.class, ignoredTests);
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
index 57fe84f..182605c 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/IgniteContext.scala
@@ -17,13 +17,12 @@
 
 package org.apache.ignite.spark
 
-
-import org.apache.ignite.internal.IgnitionEx
-import org.apache.ignite.internal.util.IgniteUtils
 import org.apache.ignite._
 import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
-import org.apache.spark.{Logging, SparkContext}
+import org.apache.ignite.internal.IgnitionEx
+import org.apache.ignite.internal.util.IgniteUtils
 import org.apache.spark.sql.SQLContext
+import org.apache.spark.{Logging, SparkContext}
 
 /**
  * Ignite context.
@@ -36,15 +35,13 @@ import org.apache.spark.sql.SQLContext
 class IgniteContext[K, V](
     @transient val sparkContext: SparkContext,
     cfgF: () \u21d2 IgniteConfiguration,
-    client: Boolean = true
-) extends Serializable with Logging {
-    @transient private val driver = true
-
+    standalone: Boolean = true
+    ) extends Serializable with Logging {
     private val cfgClo = new Once(cfgF)
 
     private val igniteHome = IgniteUtils.getIgniteHome
 
-    if (!client) {
+    if (!standalone) {
         // Get required number of executors with default equals to number of available executors.
         val workers = sparkContext.getConf.getInt("spark.executor.instances",
             sparkContext.getExecutorStorageStatus.length)
@@ -55,7 +52,7 @@ class IgniteContext[K, V](
         logInfo("Will start Ignite nodes on " + workers + " workers")
 
         // Start ignite server node on each worker in server mode.
-        sparkContext.parallelize(1 to workers, workers).foreach(it \u21d2 ignite())
+        sparkContext.parallelize(1 to workers, workers).foreachPartition(it \u21d2 ignite())
     }
 
     // Make sure to start Ignite on context creation.
@@ -71,7 +68,7 @@ class IgniteContext[K, V](
         sc: SparkContext,
         springUrl: String,
         client: Boolean
-    ) {
+        ) {
         this(sc, () \u21d2 IgnitionEx.loadConfiguration(springUrl).get1(), client)
     }
 
@@ -84,7 +81,7 @@ class IgniteContext[K, V](
     def this(
         sc: SparkContext,
         springUrl: String
-    ) {
+        ) {
         this(sc, () \u21d2 IgnitionEx.loadConfiguration(springUrl).get1())
     }
 
@@ -124,10 +121,8 @@ class IgniteContext[K, V](
     }
 
     /**
-     * Gets an Ignite instance supporting this context. Ignite instance will be started
-     * if it has not been started yet.
-     *
-     * @return Ignite instance.
+     * Get or start Ignite instance it it's not started yet.
+     * @return
      */
     def ignite(): Ignite = {
         val home = IgniteUtils.getIgniteHome
@@ -142,24 +137,17 @@ class IgniteContext[K, V](
 
         val igniteCfg = cfgClo()
 
+        // check if called from driver
+        if (sparkContext != null) igniteCfg.setClientMode(true)
+
         try {
-            Ignition.ignite(igniteCfg.getGridName)
+            Ignition.getOrStart(igniteCfg)
         }
         catch {
-            case e: IgniteIllegalStateException \u21d2
-                try {
-                    igniteCfg.setClientMode(client || driver)
-
-                    Ignition.start(igniteCfg)
-                }
-                catch {
-                    case e: IgniteException \u21d2 {
-                        logError("Failed to start Ignite client. Will try to use an existing instance with name: "
-                            + igniteCfg.getGridName, e)
-
-                        Ignition.ignite(igniteCfg.getGridName)
-                    }
-                }
+            case e: IgniteException \u21d2
+                logError("Failed to start Ignite.", e)
+
+                throw e
         }
     }
 
@@ -167,7 +155,25 @@ class IgniteContext[K, V](
      * Stops supporting ignite instance. If ignite instance has been already stopped, this operation will be
      * a no-op.
      */
-    def close() = {
+    def close(shutdownIgniteOnWorkers: Boolean = false) = {
+        // additional check if called from driver
+        if (sparkContext != null && shutdownIgniteOnWorkers) {
+            // Get required number of executors with default equals to number of available executors.
+            val workers = sparkContext.getConf.getInt("spark.executor.instances",
+                sparkContext.getExecutorStorageStatus.length)
+
+            if (workers > 0) {
+                logInfo("Will stop Ignite nodes on " + workers + " workers")
+
+                // Start ignite server node on each worker in server mode.
+                sparkContext.parallelize(1 to workers, workers).foreachPartition(it \u21d2 doClose())
+            }
+        }
+
+        doClose()
+    }
+
+    private def doClose() = {
         val igniteCfg = cfgClo()
 
         Ignition.stop(igniteCfg.getGridName, false)
@@ -184,8 +190,11 @@ private class Once(clo: () \u21d2 IgniteConfiguration) extends Serializable {
 
     def apply(): IgniteConfiguration = {
         if (res == null) {
+
             this.synchronized {
+
                 if (res == null)
+
                     res = clo()
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala b/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
index e2d57bf..44b1cd9 100644
--- a/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
+++ b/modules/spark/src/main/scala/org/apache/ignite/spark/JavaIgniteContext.scala
@@ -34,10 +34,16 @@ import scala.reflect.ClassTag
  * @tparam V Value type.
  */
 class JavaIgniteContext[K, V](
-    @scala.transient val sc: JavaSparkContext,
-    val cfgF: IgniteOutClosure[IgniteConfiguration]) extends Serializable {
+    @transient val sc: JavaSparkContext,
+    val cfgF: IgniteOutClosure[IgniteConfiguration],
+    standalone: Boolean = true
+    ) extends Serializable {
 
-    @transient val ic: IgniteContext[K, V] = new IgniteContext[K, V](sc.sc, () => cfgF.apply())
+    @transient val ic: IgniteContext[K, V] = new IgniteContext[K, V](sc.sc, () => cfgF.apply(), standalone)
+
+    def this(sc: JavaSparkContext, cfgF: IgniteOutClosure[IgniteConfiguration]) {
+        this(sc, cfgF, true)
+    }
 
     def this(sc: JavaSparkContext, springUrl: String) {
         this(sc, new IgniteOutClosure[IgniteConfiguration] {
@@ -53,7 +59,7 @@ class JavaIgniteContext[K, V](
 
     def ignite(): Ignite = ic.ignite()
 
-    def close() = ic.close()
+    def close(shutdownIgniteOnWorkers:Boolean = false) = ic.close(shutdownIgniteOnWorkers)
 
     private[spark] def fakeClassTag[T]: ClassTag[T] = ClassTag.AnyRef.asInstanceOf[ClassTag[T]]
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
new file mode 100644
index 0000000..5ceaca7
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/spark/JavaEmbeddedIgniteRDDSelfTest.java
@@ -0,0 +1,343 @@
+/*
+ * 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.spark;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteOutClosure;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.spark.SparkConf;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.api.java.function.PairFunction;
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.DataFrame;
+import org.apache.spark.sql.Row;
+import scala.Tuple2;
+
+/**
+ * Tests for {@link JavaIgniteRDD} (embedded mode).
+ */
+public class JavaEmbeddedIgniteRDDSelfTest extends GridCommonAbstractTest {
+    /** For grid names generation */
+    private static AtomicInteger cntr = new AtomicInteger(1);
+
+    /** Grid names. */
+    private static ThreadLocal<Integer> gridNames = new ThreadLocal<Integer>() {
+        @Override protected Integer initialValue() {
+            return cntr.getAndIncrement();
+        }
+    };
+
+    /** Grid count. */
+    private static final int GRID_CNT = 3;
+
+    /** Keys count. */
+    private static final int KEYS_CNT = 10000;
+
+    /** Cache name. */
+    private static final String PARTITIONED_CACHE_NAME = "partitioned";
+
+    /** Sum function. */
+    private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
+        public Integer call(Integer x, Integer y) {
+            return x + y;
+        }
+    };
+
+    /** To pair function. */
+    private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
+        /** {@inheritDoc} */
+        @Override public Tuple2<String, String> call(Integer i) {
+            return new Tuple2<>(String.valueOf(i), "val" + i);
+        }
+    };
+
+    /** (String, Integer); pair to Integer value function. */
+    private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
+
+    /** (String, Entity) pair to Entity value function. */
+    private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
+        new PairToValueFunction<>();
+
+    /** Integer to entity function. */
+    private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
+        new PairFunction<Integer, String, Entity>() {
+            @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
+                return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
+            }
+        };
+
+    /**
+     * Default constructor.
+     */
+    public JavaEmbeddedIgniteRDDSelfTest() {
+        super(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Creates default spark context
+     */
+    private JavaSparkContext createContext() {
+        SparkConf conf = new SparkConf();
+
+        conf.set("spark.executor.instances", String.valueOf(GRID_CNT));
+
+        return new JavaSparkContext("local[" + GRID_CNT + "]", "test", conf);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStoreDataToIgnite() throws Exception {
+        JavaSparkContext sc = createContext();
+
+        JavaIgniteContext<String, String> ic = null;
+
+        try {
+            ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+            ic.fromCache(PARTITIONED_CACHE_NAME)
+                .savePairs(sc.parallelize(F.range(0, KEYS_CNT), GRID_CNT).mapToPair(TO_PAIR_F));
+
+            Ignite ignite = ic.ignite();
+
+            IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+            for (int i = 0; i < KEYS_CNT; i++) {
+                String val = cache.get(String.valueOf(i));
+
+                assertNotNull("Value was not put to cache for key: " + i, val);
+                assertEquals("Invalid value stored for key: " + i, "val" + i, val);
+            }
+        }
+        finally {
+            if (ic != null)
+                ic.close(true);
+
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReadDataFromIgnite() throws Exception {
+        JavaSparkContext sc = createContext();
+
+        JavaIgniteContext<String, Integer> ic = null;
+
+        try {
+            ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+            Ignite ignite = ic.ignite();
+
+            IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+            for (int i = 0; i < KEYS_CNT; i++)
+                cache.put(String.valueOf(i), i);
+
+            JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
+
+            int sum = values.fold(0, SUM_F);
+
+            int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
+
+            assertEquals(expSum, sum);
+        }
+        finally {
+            if (ic != null)
+                ic.close(true);
+
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryObjectsFromIgnite() throws Exception {
+        fail("IGNITE-3009");
+
+        JavaSparkContext sc = createContext();
+
+        JavaIgniteContext<String, Entity> ic = null;
+
+        try {
+            ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+            int cnt = 1001;
+
+            List<Integer> numbers = F.range(0, cnt);
+
+            cache.savePairs(sc.parallelize(numbers, GRID_CNT).mapToPair(INT_TO_ENTITY_F));
+
+            List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
+                .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
+
+            assertEquals("Invalid result length", 1, res.size());
+            assertEquals("Invalid result", 50, res.get(0).id());
+            assertEquals("Invalid result", "name50", res.get(0).name());
+            assertEquals("Invalid result", 5000, res.get(0).salary());
+
+//            Ignite ignite = ic.ignite();
+//            IgniteCache<Object, Object> underCache = ignite.cache(PARTITIONED_CACHE_NAME);
+//            assertEquals("Invalid total count", cnt, underCache.size());
+
+            assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
+        }
+        finally {
+            if (ic != null)
+                ic.close(true);
+
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryFieldsFromIgnite() throws Exception {
+        JavaSparkContext sc = createContext();
+
+        JavaIgniteContext<String, Entity> ic = null;
+
+        try {
+            ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider(), false);
+
+            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+            cache.savePairs(sc.parallelize(F.range(0, 1001), GRID_CNT).mapToPair(INT_TO_ENTITY_F));
+
+            DataFrame df =
+                cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
+
+            df.printSchema();
+
+            Row[] res = df.collect();
+
+            assertEquals("Invalid result length", 1, res.length);
+            assertEquals("Invalid result", 50, res[0].get(0));
+            assertEquals("Invalid result", "name50", res[0].get(1));
+            assertEquals("Invalid result", 5000, res[0].get(2));
+
+            Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
+
+            DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
+
+            df.printSchema();
+
+            Row[] res0 = df0.collect();
+
+            assertEquals("Invalid result length", 1, res0.length);
+            assertEquals("Invalid result", 50, res0[0].get(0));
+            assertEquals("Invalid result", "name50", res0[0].get(1));
+            assertEquals("Invalid result", 5000, res0[0].get(2));
+
+            assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
+        }
+        finally {
+            if (ic != null)
+                ic.close(true);
+
+            sc.stop();
+        }
+    }
+
+    /** Finder. */
+    private static TcpDiscoveryVmIpFinder FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /**
+     * @param gridName Grid name.
+     * @param client Client.
+     */
+    private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        cfg.setClientMode(client);
+
+        cfg.setGridName(gridName);
+
+        return cfg;
+    }
+
+    /**
+     * Creates cache configuration.
+     */
+    private static CacheConfiguration<Object, Object> cacheConfiguration() {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setBackups(1);
+
+        ccfg.setName(PARTITIONED_CACHE_NAME);
+
+        ccfg.setIndexedTypes(String.class, Entity.class);
+
+        return ccfg;
+    }
+
+    /**
+     * Ignite configiration provider.
+     */
+    static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
+        /** {@inheritDoc} */
+        @Override public IgniteConfiguration apply() {
+            try {
+                return getConfiguration("worker-" + gridNames.get(), false);
+            }
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * @param <K>
+     * @param <V>
+     */
+    static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
+        /** {@inheritDoc} */
+        @Override public V call(Tuple2<K, V> t) throws Exception {
+            return t._2();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
deleted file mode 100644
index becd90a..0000000
--- a/modules/spark/src/test/java/org/apache/ignite/spark/JavaIgniteRDDSelfTest.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.spark;
-
-import java.util.List;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgniteOutClosure;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.spark.api.java.JavaRDD;
-import org.apache.spark.api.java.JavaSparkContext;
-import org.apache.spark.api.java.function.Function;
-import org.apache.spark.api.java.function.Function2;
-import org.apache.spark.api.java.function.PairFunction;
-import org.apache.spark.sql.Column;
-import org.apache.spark.sql.DataFrame;
-import org.apache.spark.sql.Row;
-import scala.Tuple2;
-
-/**
- * Tests for {@link JavaIgniteRDD}.
- */
-public class JavaIgniteRDDSelfTest extends GridCommonAbstractTest {
-    /** Grid count. */
-    private static final int GRID_CNT = 3;
-
-    /** Keys count. */
-    private static final int KEYS_CNT = 10000;
-
-    /** Cache name. */
-    private static final String PARTITIONED_CACHE_NAME = "partitioned";
-
-    /** Ip finder. */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** Sum function. */
-    private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
-        public Integer call(Integer x, Integer y) {
-            return x + y;
-        }
-    };
-
-    /** To pair function. */
-    private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
-        /** {@inheritDoc} */
-        @Override public Tuple2<String, String> call(Integer i) {
-            return new Tuple2<>(String.valueOf(i), "val" + i);
-        }
-    };
-
-    /** (String, Integer); pair to Integer value function. */
-    private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
-
-    /** (String, Entity) pair to Entity value function. */
-    private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
-        new PairToValueFunction<>();
-
-    /** Integer to entity function. */
-    private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
-        new PairFunction<Integer, String, Entity>() {
-            @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
-                return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
-            }
-        };
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        Ignition.ignite("grid-0").cache(PARTITIONED_CACHE_NAME).removeAll();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        Ignition.stop("client", false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        for (int i = 0; i < GRID_CNT; i++)
-            Ignition.start(getConfiguration("grid-" + i, false));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        for (int i = 0; i < GRID_CNT; i++)
-            Ignition.stop("grid-" + i, false);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testStoreDataToIgnite() throws Exception {
-        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
-        try {
-            JavaIgniteContext<String, String> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
-            ic.fromCache(PARTITIONED_CACHE_NAME)
-                .savePairs(sc.parallelize(F.range(0, KEYS_CNT), 2).mapToPair(TO_PAIR_F));
-
-            Ignite ignite = Ignition.ignite("grid-0");
-
-            IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
-
-            for (int i = 0; i < KEYS_CNT; i++) {
-                String val = cache.get(String.valueOf(i));
-
-                assertNotNull("Value was not put to cache for key: " + i, val);
-                assertEquals("Invalid value stored for key: " + i, "val" + i, val);
-            }
-        }
-        finally {
-            sc.stop();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testReadDataFromIgnite() throws Exception {
-        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
-        try {
-            JavaIgniteContext<String, Integer> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
-            Ignite ignite = Ignition.ignite("grid-0");
-
-            IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
-
-            for (int i = 0; i < KEYS_CNT; i++)
-                cache.put(String.valueOf(i), i);
-
-            JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
-
-            int sum = values.fold(0, SUM_F);
-
-            int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
-
-            assertEquals(expSum, sum);
-        }
-        finally {
-            sc.stop();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testQueryObjectsFromIgnite() throws Exception {
-        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
-        try {
-            JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
-            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
-
-            cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
-
-            List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
-                .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
-
-            assertEquals("Invalid result length", 1, res.size());
-            assertEquals("Invalid result", 50, res.get(0).id());
-            assertEquals("Invalid result", "name50", res.get(0).name());
-            assertEquals("Invalid result", 5000, res.get(0).salary());
-            assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
-        }
-        finally {
-            sc.stop();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testQueryFieldsFromIgnite() throws Exception {
-        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
-
-        try {
-            JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
-
-            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
-
-            cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
-
-            DataFrame df =
-                cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
-
-            df.printSchema();
-
-            Row[] res = df.collect();
-
-            assertEquals("Invalid result length", 1, res.length);
-            assertEquals("Invalid result", 50, res[0].get(0));
-            assertEquals("Invalid result", "name50", res[0].get(1));
-            assertEquals("Invalid result", 5000, res[0].get(2));
-
-            Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
-
-            DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
-
-            df.printSchema();
-
-            Row[] res0 = df0.collect();
-
-            assertEquals("Invalid result length", 1, res0.length);
-            assertEquals("Invalid result", 50, res0[0].get(0));
-            assertEquals("Invalid result", "name50", res0[0].get(1));
-            assertEquals("Invalid result", 5000, res0[0].get(2));
-
-            assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
-        }
-        finally {
-            sc.stop();
-        }
-
-    }
-
-    /**
-     * @param gridName Grid name.
-     * @param client Client.
-     */
-    private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
-        IgniteConfiguration cfg = new IgniteConfiguration();
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        cfg.setCacheConfiguration(cacheConfiguration());
-
-        cfg.setClientMode(client);
-
-        cfg.setGridName(gridName);
-
-        return cfg;
-    }
-
-    /**
-     * Creates cache configuration.
-     */
-    private static CacheConfiguration<Object, Object> cacheConfiguration() {
-        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
-
-        ccfg.setBackups(1);
-
-        ccfg.setName(PARTITIONED_CACHE_NAME);
-
-        ccfg.setIndexedTypes(String.class, Entity.class);
-
-        return ccfg;
-    }
-
-    /**
-     * Ignite configiration provider.
-     */
-    static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
-        /** {@inheritDoc} */
-        @Override public IgniteConfiguration apply() {
-            try {
-                return getConfiguration("client", true);
-            }
-            catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        }
-    }
-
-    /**
-     * @param <K>
-     * @param <V>
-     */
-    static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
-        /** {@inheritDoc} */
-        @Override public V call(Tuple2<K, V> t) throws Exception {
-            return t._2();
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java b/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
new file mode 100644
index 0000000..faa8fda
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/spark/JavaStandaloneIgniteRDDSelfTest.java
@@ -0,0 +1,302 @@
+/*
+ * 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.spark;
+
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgniteOutClosure;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.api.java.function.Function;
+import org.apache.spark.api.java.function.Function2;
+import org.apache.spark.api.java.function.PairFunction;
+import org.apache.spark.sql.Column;
+import org.apache.spark.sql.DataFrame;
+import org.apache.spark.sql.Row;
+import scala.Tuple2;
+
+/**
+ * Tests for {@link JavaIgniteRDD} (standalone mode).
+ */
+public class JavaStandaloneIgniteRDDSelfTest extends GridCommonAbstractTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 3;
+
+    /** Keys count. */
+    private static final int KEYS_CNT = 10000;
+
+    /** Cache name. */
+    private static final String PARTITIONED_CACHE_NAME = "partitioned";
+
+    /** Ip finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Sum function. */
+    private static final Function2<Integer, Integer, Integer> SUM_F = new Function2<Integer, Integer, Integer>() {
+        public Integer call(Integer x, Integer y) {
+            return x + y;
+        }
+    };
+
+    /** To pair function. */
+    private static final PairFunction<Integer, String, String> TO_PAIR_F = new PairFunction<Integer, String, String>() {
+        /** {@inheritDoc} */
+        @Override public Tuple2<String, String> call(Integer i) {
+            return new Tuple2<>(String.valueOf(i), "val" + i);
+        }
+    };
+
+    /** (String, Integer); pair to Integer value function. */
+    private static final Function<Tuple2<String, Integer>, Integer> STR_INT_PAIR_TO_INT_F = new PairToValueFunction<>();
+
+    /** (String, Entity) pair to Entity value function. */
+    private static final Function<Tuple2<String, Entity>, Entity> STR_ENTITY_PAIR_TO_ENTITY_F =
+        new PairToValueFunction<>();
+
+    /** Integer to entity function. */
+    private static final PairFunction<Integer, String, Entity> INT_TO_ENTITY_F =
+        new PairFunction<Integer, String, Entity>() {
+            @Override public Tuple2<String, Entity> call(Integer i) throws Exception {
+                return new Tuple2<>(String.valueOf(i), new Entity(i, "name" + i, i * 100));
+            }
+        };
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        Ignition.ignite("grid-0").cache(PARTITIONED_CACHE_NAME).removeAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        Ignition.stop("client", false);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        for (int i = 0; i < GRID_CNT; i++)
+            Ignition.start(getConfiguration("grid-" + i, false));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        for (int i = 0; i < GRID_CNT; i++)
+            Ignition.stop("grid-" + i, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStoreDataToIgnite() throws Exception {
+        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+        try {
+            JavaIgniteContext<String, String> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+            ic.fromCache(PARTITIONED_CACHE_NAME)
+                .savePairs(sc.parallelize(F.range(0, KEYS_CNT), 2).mapToPair(TO_PAIR_F));
+
+            Ignite ignite = Ignition.ignite("grid-0");
+
+            IgniteCache<String, String> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+            for (int i = 0; i < KEYS_CNT; i++) {
+                String val = cache.get(String.valueOf(i));
+
+                assertNotNull("Value was not put to cache for key: " + i, val);
+                assertEquals("Invalid value stored for key: " + i, "val" + i, val);
+            }
+        }
+        finally {
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReadDataFromIgnite() throws Exception {
+        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+        try {
+            JavaIgniteContext<String, Integer> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+            Ignite ignite = Ignition.ignite("grid-0");
+
+            IgniteCache<String, Integer> cache = ignite.cache(PARTITIONED_CACHE_NAME);
+
+            for (int i = 0; i < KEYS_CNT; i++)
+                cache.put(String.valueOf(i), i);
+
+            JavaRDD<Integer> values = ic.fromCache(PARTITIONED_CACHE_NAME).map(STR_INT_PAIR_TO_INT_F);
+
+            int sum = values.fold(0, SUM_F);
+
+            int expSum = (KEYS_CNT * KEYS_CNT + KEYS_CNT) / 2 - KEYS_CNT;
+
+            assertEquals(expSum, sum);
+        }
+        finally {
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryObjectsFromIgnite() throws Exception {
+        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+        try {
+            JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+            cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
+
+            List<Entity> res = cache.objectSql("Entity", "name = ? and salary = ?", "name50", 5000)
+                .map(STR_ENTITY_PAIR_TO_ENTITY_F).collect();
+
+            assertEquals("Invalid result length", 1, res.size());
+            assertEquals("Invalid result", 50, res.get(0).id());
+            assertEquals("Invalid result", "name50", res.get(0).name());
+            assertEquals("Invalid result", 5000, res.get(0).salary());
+            assertEquals("Invalid count", 500, cache.objectSql("Entity", "id > 500").count());
+        }
+        finally {
+            sc.stop();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryFieldsFromIgnite() throws Exception {
+        JavaSparkContext sc = new JavaSparkContext("local[*]", "test");
+
+        try {
+            JavaIgniteContext<String, Entity> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider());
+
+            JavaIgniteRDD<String, Entity> cache = ic.fromCache(PARTITIONED_CACHE_NAME);
+
+            cache.savePairs(sc.parallelize(F.range(0, 1001), 2).mapToPair(INT_TO_ENTITY_F));
+
+            DataFrame df =
+                cache.sql("select id, name, salary from Entity where name = ? and salary = ?", "name50", 5000);
+
+            df.printSchema();
+
+            Row[] res = df.collect();
+
+            assertEquals("Invalid result length", 1, res.length);
+            assertEquals("Invalid result", 50, res[0].get(0));
+            assertEquals("Invalid result", "name50", res[0].get(1));
+            assertEquals("Invalid result", 5000, res[0].get(2));
+
+            Column exp = new Column("NAME").equalTo("name50").and(new Column("SALARY").equalTo(5000));
+
+            DataFrame df0 = cache.sql("select id, name, salary from Entity").where(exp);
+
+            df.printSchema();
+
+            Row[] res0 = df0.collect();
+
+            assertEquals("Invalid result length", 1, res0.length);
+            assertEquals("Invalid result", 50, res0[0].get(0));
+            assertEquals("Invalid result", "name50", res0[0].get(1));
+            assertEquals("Invalid result", 5000, res0[0].get(2));
+
+            assertEquals("Invalid count", 500, cache.sql("select id from Entity where id > 500").count());
+        }
+        finally {
+            sc.stop();
+        }
+
+    }
+
+    /**
+     * @param gridName Grid name.
+     * @param client Client.
+     */
+    private static IgniteConfiguration getConfiguration(String gridName, boolean client) throws Exception {
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        cfg.setClientMode(client);
+
+        cfg.setGridName(gridName);
+
+        return cfg;
+    }
+
+    /**
+     * Creates cache configuration.
+     */
+    private static CacheConfiguration<Object, Object> cacheConfiguration() {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setBackups(1);
+
+        ccfg.setName(PARTITIONED_CACHE_NAME);
+
+        ccfg.setIndexedTypes(String.class, Entity.class);
+
+        return ccfg;
+    }
+
+    /**
+     * Ignite configiration provider.
+     */
+    static class IgniteConfigProvider implements IgniteOutClosure<IgniteConfiguration> {
+        /** {@inheritDoc} */
+        @Override public IgniteConfiguration apply() {
+            try {
+                return getConfiguration("client", true);
+            }
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * @param <K>
+     * @param <V>
+     */
+    static class PairToValueFunction<K, V> implements Function<Tuple2<K, V>, V> {
+        /** {@inheritDoc} */
+        @Override public V call(Tuple2<K, V> t) throws Exception {
+            return t._2();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/efe76f18/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java b/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
new file mode 100644
index 0000000..a4177f0
--- /dev/null
+++ b/modules/spark/src/test/java/org/apache/ignite/testsuites/IgniteRDDTestSuite.java
@@ -0,0 +1,40 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.spark.JavaEmbeddedIgniteRDDSelfTest;
+import org.apache.ignite.spark.JavaStandaloneIgniteRDDSelfTest;
+
+/**
+ * Test suit for Ignite RDD
+ */
+public class IgniteRDDTestSuite extends TestSuite {
+    /**
+     * @return Java Ignite RDD test suit.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Java Ignite RDD tests (standalone and embedded modes");
+
+        suite.addTest(new TestSuite(JavaEmbeddedIgniteRDDSelfTest.class));
+        suite.addTest(new TestSuite(JavaStandaloneIgniteRDDSelfTest.class));
+
+        return suite;
+    }
+}
\ No newline at end of file


[30/50] [abbrv] ignite git commit: IGNITE-3028 XML and code generation: do not generate not selected fields. Generate aliases as simple map.

Posted by sh...@apache.org.
IGNITE-3028 XML and code generation: do not generate not selected fields. Generate aliases as simple map.


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

Branch: refs/heads/ignite-2788
Commit: 3ab39af4322b48d8ae6b44c5ca298ca1ded1df05
Parents: bb5cd16
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Wed Apr 27 16:21:29 2016 +0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 30 +++++++++-----------
 .../ignite/schema/generator/XmlGenerator.java   |  2 +-
 2 files changed, 14 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3ab39af4/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
index 3ab0f4e..01fcfa6 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -194,11 +194,11 @@ public class CodeGenerator {
      *
      * @param src Source code.
      * @param pkg Package name.
-     * @param imports Optional imports.
      * @param desc Class description.
      * @param cls Class declaration.
+     * @param imports Optional imports.
      */
-    private static void header(Collection<String> src, String pkg, String imports, String desc, String cls) {
+    private static void header(Collection<String> src, String pkg, String desc, String cls, String... imports) {
         // License.
         add0(src, "/*");
         add0(src, " * Licensed to the Apache Software Foundation (ASF) under one or more");
@@ -223,12 +223,9 @@ public class CodeGenerator {
         add0(src, "");
 
         // Imports.
-        if (!imports.isEmpty()) {
-            for (String imp : imports.split(";"))
-                if (imp.isEmpty())
-                    add0(src, "");
-                else
-                    add0(src, "import " + imp + ";");
+        if (imports != null && imports.length > 0) {
+            for (String imp : imports)
+                add0(src, imp.isEmpty() ? "" : "import " + imp + ";");
 
             add0(src, "");
         }
@@ -295,7 +292,7 @@ public class CodeGenerator {
 
         Collection<String> src = new ArrayList<>(256);
 
-        header(src, pkg, "java.io.*", type, type + " implements Serializable");
+        header(src, pkg, type, type + " implements Serializable", "java.io.*");
 
         add1(src, "/** */");
         add1(src, "private static final long serialVersionUID = 0L;");
@@ -584,15 +581,14 @@ public class CodeGenerator {
 
         Collection<String> src = new ArrayList<>(256);
 
-        header(src, pkg, "java.sql.*;java.util.*;" +
-            "org.apache.ignite.cache.*;org.apache.ignite.cache.store.jdbc.*;" +
-            "org.apache.ignite.configuration.*",
-            "CacheConfig", "CacheConfig");
+        header(src, pkg, "CacheConfig", "CacheConfig", "java.sql.*", "java.util.*", "", "org.apache.ignite.cache.*",
+            "org.apache.ignite.cache.store.jdbc.*", "org.apache.ignite.configuration.*");
 
         // Generate methods for each type in order to avoid compiler error "java: code too large".
         for (PojoDescriptor pojo : pojos) {
             String tbl = pojo.table();
             String valClsName = pojo.valueClassName();
+            Collection<PojoField> fields = pojo.valueFields(true);
 
             add1(src, "/**");
             add1(src, " * Create JDBC type for " + tbl + ".");
@@ -656,7 +652,7 @@ public class CodeGenerator {
             add2(src, "LinkedHashMap<String, String> fields = new LinkedHashMap<>();");
             add0(src, "");
 
-            for (PojoField field : pojo.fields())
+            for (PojoField field : fields)
                 add2(src, "fields.put(\"" + field.javaName() + "\", \"" +
                     GeneratorUtils.boxPrimitiveType(field.javaTypeName()) + "\");");
 
@@ -668,14 +664,14 @@ public class CodeGenerator {
             if (generateAliases) {
                 Collection<PojoField> aliases = new ArrayList<>();
 
-                for (PojoField field : pojo.fields()) {
+                for (PojoField field : fields) {
                     if (!field.javaName().equalsIgnoreCase(field.dbName()))
                         aliases.add(field);
                 }
 
                 if (!aliases.isEmpty()) {
                     add2(src, "// Aliases for fields.");
-                    add2(src, "LinkedHashMap<String, String> aliases = new LinkedHashMap<>();");
+                    add2(src, "Map<String, String> aliases = new HashMap<>();");
                     add0(src, "");
 
                     for (PojoField alias : aliases)
@@ -702,7 +698,7 @@ public class CodeGenerator {
                     List<T2<String, Boolean>> idxFlds = new ArrayList<>(sz);
 
                     for (Map.Entry<String, Boolean> idxFld : dbIdxFlds) {
-                        PojoField field = GeneratorUtils.findFieldByName(pojo.valueFields(true), idxFld.getKey());
+                        PojoField field = GeneratorUtils.findFieldByName(fields, idxFld.getKey());
 
                         if (field != null)
                             idxFlds.add(new T2<>(field.javaName(), idxFld.getValue()));

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ab39af4/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
index bb5a0cb..df54e04 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
@@ -226,7 +226,7 @@ public class XmlGenerator {
         if (!aliases.isEmpty()) {
             Element prop = addProperty(doc, parent, "aliases", null);
 
-            Element map = addElement(doc, prop, "util:map", "map-class", "java.util.LinkedHashMap");
+            Element map = addElement(doc, prop, "map");
 
             for (PojoField alias : aliases)
                 addElement(doc, map, "entry", "key", alias.javaName(), "value", alias.dbName());


[25/50] [abbrv] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
index 05ff71a..e733114 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
@@ -17,367 +17,14 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
-import java.lang.reflect.Array;
-import java.util.AbstractCollection;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Random;
 import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
-import javax.cache.Cache;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.util.F0;
-import org.apache.ignite.internal.util.lang.GridTriple;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.P1;
-import org.apache.ignite.internal.util.typedef.X;
-import org.apache.ignite.internal.util.typedef.internal.A;
-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.IgnitePredicate;
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.LongAdder8;
 
 /**
- * Concurrent implementation of cache map.
+ * Concurrent cache map.
  */
-public class GridCacheConcurrentMap {
-    /** Debug flag. */
-    private static final boolean DEBUG = false;
-
-    /** Random. */
-    private static final Random RAND = new Random();
-
-    /** The default load factor for this map. */
-    private static final float DFLT_LOAD_FACTOR = 0.75f;
-
-    /** The default concurrency level for this map. */
-    private static final int DFLT_CONCUR_LEVEL = Runtime.getRuntime().availableProcessors() * 2;
-
-    /**
-     * The maximum capacity, used if a higher value is implicitly specified by either
-     * of the constructors with arguments. Must be a power of two <= 1<<30 to ensure
-     * that entries are indexable using integers.
-     */
-    private static final int MAX_CAP = 1 << 30;
-
-    /** The maximum number of segments to allow. */
-    private static final int MAX_SEGS = 1 << 16; // slightly conservative
-
-    /**
-     * Mask value for indexing into segments. The upper bits of a
-     * key's hash code are used to choose the segment.
-     */
-    private final int segMask;
-
-    /** Shift value for indexing within segments. */
-    private final int segShift;
-
-    /** The segments, each of which is a specialized hash table. */
-    private final Segment[] segs;
-
-    /** */
-    private GridCacheMapEntryFactory factory;
-
-    /** Cache context. */
-    protected final GridCacheContext ctx;
-
-    /** */
-    private final LongAdder8 mapPubSize = new LongAdder8();
-
-    /** */
-    private final LongAdder8 mapSize = new LongAdder8();
-
-    /** Filters cache internal entry. */
-    private static final CacheEntryPredicate NON_INTERNAL =
-        new CacheEntrySerializablePredicate(new CacheEntryPredicateAdapter() {
-            @Override public boolean apply(GridCacheEntryEx entry) {
-                return !entry.isInternal();
-            }
-        });
-
-    /** Non-internal predicate array. */
-    public static final CacheEntryPredicate[] NON_INTERNAL_ARR = new CacheEntryPredicate[] {NON_INTERNAL};
-
-    /** Filters obsolete cache map entry. */
-    private final IgnitePredicate<GridCacheMapEntry> obsolete =
-        new P1<GridCacheMapEntry>() {
-            @Override public boolean apply(GridCacheMapEntry entry) {
-                return entry.obsolete();
-            }
-        };
-
-    /**
-     * Applies a supplemental hash function to a given hashCode, which
-     * defends against poor quality hash functions.  This is critical
-     * because ConcurrentHashMap uses power-of-two length hash tables,
-     * that otherwise encounter collisions for hashCodes that do not
-     * differ in lower or upper bits.
-     * <p>
-     * This function has been taken from Java 8 ConcurrentHashMap with
-     * slightly modifications.
-     *
-     * @param h Value to hash.
-     * @return Hash value.
-     */
-    protected static int hash(int h) {
-        return U.hash(h);
-    }
-
-    /**
-     * Returns the segment that should be used for key with given hash
-     *
-     * @param hash The hash code for the key.
-     * @return The segment.
-     */
-    private Segment segmentFor(int hash) {
-        return segs[(hash >>> segShift) & segMask];
-    }
-
-    /**
-     * Creates a new, empty map with the specified initial
-     * capacity, load factor and concurrency level.
-     *
-     * @param ctx Cache context.
-     * @param initCap the initial capacity. The implementation
-     *      performs internal sizing to accommodate this many elements.
-     * @param factory Entry factory.
-     * @param loadFactor  the load factor threshold, used to control resizing.
-     *      Resizing may be performed when the average number of elements per
-     *      bin exceeds this threshold.
-     * @param concurrencyLevel the estimated number of concurrently
-     *      updating threads. The implementation performs internal sizing
-     *      to try to accommodate this many threads.
-     * @throws IllegalArgumentException if the initial capacity is
-     *      negative or the load factor or concurrencyLevel are
-     *      non-positive.
-     */
-    @SuppressWarnings({"unchecked"})
-    protected GridCacheConcurrentMap(
-        GridCacheContext ctx,
-        int initCap,
-        GridCacheMapEntryFactory factory,
-        float loadFactor,
-        int concurrencyLevel
-    ) {
-        this.ctx = ctx;
-
-        if (!(loadFactor > 0) || initCap < 0 || concurrencyLevel <= 0)
-            throw new IllegalArgumentException();
-
-        if (concurrencyLevel > MAX_SEGS)
-            concurrencyLevel = MAX_SEGS;
-
-        // Find power-of-two sizes best matching arguments
-        int sshift = 0;
-        int ssize = 1;
-
-        while (ssize < concurrencyLevel) {
-            ++sshift;
-            ssize <<= 1;
-        }
-
-        segShift = 32 - sshift;
-        segMask = ssize - 1;
-        segs = (Segment[])Array.newInstance(Segment.class, ssize);
-
-        if (initCap > MAX_CAP)
-            initCap = MAX_CAP;
-
-        int c = initCap / ssize;
-
-        if (c * ssize < initCap)
-            ++c;
-
-        int cap = 1;
-
-        while (cap < c)
-            cap <<= 1;
-
-        if (cap < 16)
-            cap = 16;
-
-        for (int i = 0; i < segs.length; ++i)
-            segs[i] = new Segment(cap, loadFactor);
-
-        this.factory = factory;
-    }
-
-    /**
-     * Creates a new, empty map with the specified initial capacity
-     * and load factor and with the default concurrencyLevel (16).
-     *
-     * @param ctx Cache context.
-     * @param initCap The implementation performs internal
-     *      sizing to accommodate this many elements.
-     * @param factory Entries factory.
-     * @throws IllegalArgumentException if the initial capacity of
-     *      elements is negative or the load factor is non-positive.
-     */
-    public GridCacheConcurrentMap(
-        GridCacheContext ctx,
-        int initCap,
-        @Nullable GridCacheMapEntryFactory factory
-    ) {
-        this(ctx, initCap, factory, DFLT_LOAD_FACTOR, DFLT_CONCUR_LEVEL);
-    }
-
-    /**
-     * Sets factory for entries.
-     *
-     * @param factory Entry factory.
-     */
-    public void setEntryFactory(GridCacheMapEntryFactory factory) {
-        assert factory != null;
-
-        this.factory = factory;
-    }
-
-    /**
-     * @return Entries factory.
-     */
-    public GridCacheMapEntryFactory getEntryFactory() {
-        return factory;
-    }
-
-    /**
-     * @return Non-internal predicate.
-     */
-    private static CacheEntryPredicate[] nonInternal() {
-        return NON_INTERNAL_ARR;
-    }
-
-    /**
-     * @param filter Filter to add to non-internal-key filter.
-     * @return Non-internal predicate.
-     */
-    private static CacheEntryPredicate[] nonInternal(
-        CacheEntryPredicate[] filter) {
-        return F.asArray(F0.and0(NON_INTERNAL_ARR, filter));
-    }
-
-    /**
-     * @return {@code True} if this map is empty.
-     */
-    public boolean isEmpty() {
-        return mapSize.sum() == 0;
-    }
-
-    /**
-     * Returns the number of key-value mappings in this map.
-     *
-     * @return the number of key-value mappings in this map.
-     */
-    public int size() {
-        return mapSize.intValue();
-    }
-
-    /**
-     * @return Public size.
-     */
-    public int publicSize() {
-        return mapPubSize.intValue();
-    }
-
-    /**
-     * @param e Cache map entry.
-     */
-    public void decrementSize(GridCacheMapEntry e) {
-        assert !e.isInternal();
-        assert Thread.holdsLock(e);
-        assert e.deletedUnlocked();
-        assert ctx.deferredDelete();
-
-        mapPubSize.decrement();
-
-        segmentFor(e.hash()).decrementPublicSize();
-    }
-
-    /**
-     * @param e Cache map entry.
-     */
-    public void incrementSize(GridCacheMapEntry e) {
-        assert !e.isInternal();
-        assert Thread.holdsLock(e);
-        assert !e.deletedUnlocked();
-        assert ctx.deferredDelete();
-
-        mapPubSize.increment();
-
-        segmentFor(e.hash()).incrementPublicSize();
-    }
-
-    /**
-     * @param key Key.
-     * @return {@code True} if map contains mapping for provided key.
-     */
-    public boolean containsKey(Object key) {
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).containsKey(key, hash);
-    }
-
-    /**
-     * Collection of all (possibly {@code null}) values.
-     *
-     * @param filter Filter.
-     * @return a collection view of the values contained in this map.
-     */
-    public <K, V> Collection<V> allValues(CacheEntryPredicate[] filter) {
-        return new Values<>(this, filter);
-    }
-
-    /**
-     * @return Random entry out of hash map.
-     */
-    @Nullable public GridCacheMapEntry randomEntry() {
-        while (true) {
-            if (mapPubSize.sum() == 0)
-                return null;
-
-            // Desired and current indexes.
-            int segIdx = RAND.nextInt(segs.length);
-
-            Segment seg = null;
-
-            for (int i = segIdx; i < segs.length + segIdx; i++) {
-                Segment s = segs[i % segs.length];
-
-                if (s.publicSize() > 0)
-                    seg = s;
-            }
-
-            if (seg == null)
-                // It happened so that all public values had been removed from segments.
-                return null;
-
-            GridCacheMapEntry entry = seg.randomEntry();
-
-            if (entry == null)
-                continue;
-
-            assert !(entry.key() instanceof GridCacheInternal);
-
-            return entry;
-        }
-    }
-
+public interface GridCacheConcurrentMap {
     /**
      * Returns the entry associated with the specified key in the
      * HashMap.  Returns null if the HashMap contains no mapping
@@ -386,27 +33,7 @@ public class GridCacheConcurrentMap {
      * @param key Key.
      * @return Entry.
      */
-    @Nullable public GridCacheMapEntry getEntry(Object key) {
-        assert key != null;
-
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).get(key, hash);
-    }
-
-    /**
-     * @param topVer Topology version.
-     * @param key Key.
-     * @param val Value.
-     * @return Cache entry for corresponding key-value pair.
-     */
-    public GridCacheMapEntry putEntry(AffinityTopologyVersion topVer, KeyCacheObject key, @Nullable CacheObject val) {
-        assert key != null;
-
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).put(key, hash, val, topVer);
-    }
+    @Nullable public GridCacheMapEntry getEntry(KeyCacheObject key);
 
     /**
      * @param topVer Topology version.
@@ -416,1633 +43,72 @@ public class GridCacheConcurrentMap {
      * @return Triple where the first element is current entry associated with the key,
      *      the second is created entry and the third is doomed (all may be null).
      */
-    public GridTriple<GridCacheMapEntry> putEntryIfObsoleteOrAbsent(
+    @Nullable public GridCacheMapEntry putEntryIfObsoleteOrAbsent(
         AffinityTopologyVersion topVer,
         KeyCacheObject key,
         @Nullable CacheObject val,
-        boolean create)
-    {
-        assert key != null;
-
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).putIfObsolete(key, hash, val, topVer, create);
-    }
-
-    /**
-     * Copies all of the mappings from the specified map to this map
-     * These mappings will replace any mappings that
-     * this map had for any of the keys currently in the specified map.
-     *
-     * @param m mappings to be stored in this map.
-     * @throws NullPointerException If the specified map is null.
-     */
-    public void putAll(Map<KeyCacheObject, CacheObject> m) {
-        for (Map.Entry<KeyCacheObject, CacheObject> e : m.entrySet())
-            putEntry(AffinityTopologyVersion.NONE, e.getKey(), e.getValue());
-    }
+        boolean create,
+        boolean touch);
 
     /**
      * Removes passed in entry if it presents in the map.
      *
-     * @param e Entry to remove.
+     * @param entry Entry to remove.
      * @return {@code True} if remove happened.
      */
-    public boolean removeEntry(GridCacheEntryEx e) {
-        assert e != null;
-
-        KeyCacheObject key = e.key();
-
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).remove(key, hash, same(e)) != null;
-    }
+    public boolean removeEntry(GridCacheEntryEx entry);
 
     /**
-     * @param p Entry to check equality.
-     * @return Predicate to filter the same (equal by ==) entry.
-     */
-    private IgnitePredicate<GridCacheMapEntry> same(final GridCacheEntryEx p) {
-        return new P1<GridCacheMapEntry>() {
-            @Override public boolean apply(GridCacheMapEntry e) {
-                return e == p;
-            }
-        };
-    }
-
-    /**
-     * Removes and returns the entry associated with the specified key
-     * in the HashMap if entry is obsolete. Returns null if the HashMap
-     * contains no mapping for this key.
+     * Returns the number of key-value mappings in this map.
      *
-     * @param key Key.
-     * @return Removed entry, possibly {@code null}.
-     */
-    @SuppressWarnings( {"unchecked"})
-    @Nullable public GridCacheMapEntry removeEntryIfObsolete(KeyCacheObject key) {
-        assert key != null;
-
-        int hash = hash(key.hashCode());
-
-        return segmentFor(hash).remove(key, hash, obsolete);
-    }
-
-    /**
-     * @param filter Filter.
-     * @return Set of the mappings contained in this map.
+     * @return the number of key-value mappings in this map.
      */
-    @SuppressWarnings({"unchecked"})
-    public <K, V> Set<Cache.Entry<K, V>> entries(CacheEntryPredicate... filter) {
-        return new EntrySet<>(this, filter);
-    }
+    public int size();
 
     /**
-     * Returns entry set containing internal entries.
+     * Returns the number of publicly available key-value mappings in this map.
+     * It excludes entries that are marked as deleted.
      *
-     * @param filter Filter.
-     * @return Set of the mappings contained in this map.
+     * @return the number of publicly available key-value mappings in this map.
      */
-    @SuppressWarnings({"unchecked"})
-    public <K, V> Set<Cache.Entry<K, V>> entriesx(CacheEntryPredicate... filter) {
-        return new EntrySet<>(this, filter, true);
-    }
+    public int publicSize();
 
     /**
-     * Internal entry set, excluding {@link GridCacheInternal} entries.
+     * Increments public size.
      *
-     * @return Set of the mappings contained in this map.
+     * @param e Entry that caused public size change.
      */
-    public Set<GridCacheEntryEx> entries0() {
-        return new Set0<>(this, GridCacheConcurrentMap.nonInternal());
-    }
+    public void incrementPublicSize(GridCacheEntryEx e);
 
     /**
-     * Get striped entry iterator.
+     * Decrements public size.
      *
-     * @param id Expected modulo.
-     * @param totalCnt Maximum modulo.
-     * @return Striped entry iterator.
+     * @param e Entry that caused public size change.
      */
-    public Iterator<GridCacheEntryEx> stripedEntryIterator(int id, int totalCnt) {
-        return new Iterator0<>(this, false, GridCacheConcurrentMap.nonInternal(), id, totalCnt);
-    }
+    public void decrementPublicSize(GridCacheEntryEx e);
 
-    /**
-     * Gets all internal entry set, including {@link GridCacheInternal} entries.
-     *
-     * @return All internal entry set, including {@link GridCacheInternal} entries.
-     */
-    public Set<GridCacheEntryEx> allEntries0() {
-        return new Set0<>(this, CU.empty0());
-    }
+    @Nullable public GridCacheMapEntry randomEntry();
 
     /**
-     * Key set.
-     *
-     * @param filter Filter.
-     * @return Set of the keys contained in this map.
+     * @return Random entry out of hash map.
      */
-    public <K, V> Set<K> keySet(CacheEntryPredicate... filter) {
-        return new KeySet<>(this, filter, false);
-    }
+    public Set<KeyCacheObject> keySet(CacheEntryPredicate... filter);
 
     /**
-     * Key set including internal keys.
-     *
      * @param filter Filter.
-     * @return Set of the keys contained in this map.
+     * @return Iterable of the mappings contained in this map, excluding entries in unvisitable state.
      */
-    public <K, V> Set<K> keySetx(CacheEntryPredicate... filter) {
-        return new KeySet<>(this, filter, true);
-    }
+    public Iterable<GridCacheMapEntry> entries(CacheEntryPredicate... filter);
 
     /**
-     * Collection of non-{@code null} values.
-     *
      * @param filter Filter.
-     * @return Collection view of the values contained in this map.
-     */
-    public <K, V> Collection<V> values(CacheEntryPredicate... filter) {
-        return allValues(filter);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridCacheConcurrentMap.class, this, "size", mapSize, "pubSize", mapPubSize);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
-    void printDebugInfo() {
-        for (Segment s : segs)
-            s.lock();
-
-        try {
-            X.println(">>> Cache map debug info: " + ctx.namexx());
-
-            for (int i = 0; i < segs.length; i++) {
-                Segment seg = segs[i];
-
-                X.println("    Segment [idx=" + i + ", size=" + seg.size() + ']');
-
-                HashEntry[] tab = seg.tbl;
-
-                for (int j = 0; j < tab.length; j++)
-                    X.println("        Bucket [idx=" + j + ", bucket=" + tab[j] + ']');
-            }
-
-            checkConsistency();
-        }
-        finally {
-            for (Segment s : segs)
-                s.unlock();
-        }
-    }
-
-    /**
-     *
-     */
-    public void checkConsistency() {
-        int size = 0;
-        int pubSize = 0;
-
-        IgniteLogger log = ctx.logger(GridCacheConcurrentMap.class);
-
-        for (Segment s : segs) {
-            assert s.isHeldByCurrentThread();
-
-            HashEntry[] tab = s.tbl;
-
-            for (HashEntry b : tab) {
-                if (b != null) {
-                    HashEntry e = b;
-
-                    assert e != null;
-
-                    int cnt = 0;
-                    int pubCnt = 0;
-
-                    while (e != null) {
-                        cnt++;
-
-                        log.info("Cache map entry: " + e);
-
-                        if (!e.mapEntry.deleted()) {
-                            if (!(e.mapEntry.key instanceof GridCacheInternal))
-                                pubCnt++;
-                        }
-
-                        e = e.next;
-                    }
-
-                    size += cnt;
-                    pubSize += pubCnt;
-                }
-            }
-        }
-
-        assert size() == size : "Invalid size [expected=" + size() + ", actual=" + size + ']';
-        assert publicSize() == pubSize : "Invalid public size [expected=" + publicSize() + ", actual=" + pubSize + ']';
-    }
-
-    /**
-     * Segments are specialized versions of hash tables.  This
-     * subclasses from ReentrantLock opportunistically,
-     * just to simplify some locking and avoid separate construction.
-     */
-    private class Segment extends ReentrantLock {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /*
-         * Segments maintain a table of entry lists that are ALWAYS
-         * kept in a consistent state, so can be read without locking.
-         * Next fields of nodes are immutable (final).  All list
-         * additions are performed at the front of each bin. This
-         * makes it easy to check changes, and also fast to traverse.
-         * When nodes would otherwise be changed, new nodes are
-         * created to replace them. This works well for hash tables
-         * since the bin lists tend to be short. (The average length
-         * is less than two for the default load factor threshold.)
-         *
-         * Read operations can thus proceed without locking, but rely
-         * on selected uses of volatiles to ensure that completed
-         * write operations performed by other threads are
-         * noticed. For most purposes, the "count" field, tracking the
-         * number of elements, serves as that volatile variable
-         * ensuring visibility.  This is convenient because this field
-         * needs to be read in many read operations anyway:
-         *
-         *   - All (unsynchronized) read operations must first read the
-         *     "count" field, and should not look at table entries if
-         *     it is 0.
-         *
-         *   - All (synchronized) write operations should write to
-         *     the "count" field after structurally changing any bin.
-         *     The operations must not take any action that could even
-         *     momentarily cause a concurrent read operation to see
-         *     inconsistent data. This is made easier by the nature of
-         *     the read operations in Map. For example, no operation
-         *     can reveal that the table has grown but the threshold
-         *     has not yet been updated, so there are no atomicity
-         *     requirements for this with respect to reads.
-         *
-         * As a guide, all critical volatile reads and writes to the
-         * count field are marked in code comments.
-         */
-
-        /**
-         * The table is rehashed when its size exceeds this threshold.
-         * (The value of this field is always <tt>(int)(capacity * loadFactor)</tt>.)
-         */
-        private int threshold;
-
-        /** The number of public elements in this segment's region. */
-        private final LongAdder8 pubSize = new LongAdder8();
-
-        /**
-         * The load factor for the hash table. Even though this value
-         * is same for all segments, it is replicated to avoid needing
-         * links to outer object.
-         * @serial
-         */
-        private final float loadFactor;
-
-        /** Entry table. */
-        private volatile HashEntry[] tbl;
-
-        /** The number of elements in this segment's region. */
-        private volatile int size;
-
-        /**
-         * @param initCap Initial capacity.
-         * @param lf Load factor.
-         */
-        @SuppressWarnings("unchecked")
-        Segment(int initCap, float lf) {
-            loadFactor = lf;
-
-            tbl = new HashEntry[initCap];
-
-            threshold = (int)(initCap * loadFactor);
-        }
-
-        /**
-         * Returns properly casted first entry for given hash.
-         *
-         * @param hash Hash.
-         * @return Entry for hash.
-         */
-        @Nullable HashEntry getFirst(HashEntry[] tbl, int hash) {
-            return tbl[hash & (tbl.length - 1)];
-        }
-
-        /**
-         * @param key Key.
-         * @param hash Hash.
-         * @return Value.
-         */
-        @Nullable GridCacheMapEntry get(Object key, int hash) {
-            if (size != 0) {
-                HashEntry e = getFirst(tbl, hash);
-
-                while (e != null) {
-                    if (e.mapEntry.hash() == hash && key.equals(e.mapEntry.key()))
-                        return e.mapEntry;
-
-                    e = e.next;
-                }
-            }
-
-            return null;
-        }
-
-        /**
-         * @param key Key.
-         * @param hash Hash.
-         * @return {@code True} if segment contains value.
-         */
-        boolean containsKey(Object key, int hash) {
-            if (size != 0) {
-                HashEntry e = getFirst(tbl, hash);
-
-                while (e != null) {
-                    if (e.mapEntry.hash() == hash && key.equals(e.mapEntry.key()))
-                        return true;
-
-                    e = e.next;
-                }
-            }
-
-            return false;
-        }
-
-        /**
-         * @param key Key.
-         * @param hash Hash.
-         * @param val Value.
-         * @param topVer Topology version.
-         * @return Associated value.
-         */
-        @SuppressWarnings({"unchecked"})
-        GridCacheMapEntry put(KeyCacheObject key, int hash, @Nullable CacheObject val, AffinityTopologyVersion topVer) {
-            lock();
-
-            try {
-                return put0(key, hash, val, topVer);
-            }
-            finally {
-                unlock();
-            }
-        }
-
-        /**
-         * @param key Key.
-         * @param hash Hash.
-         * @param val Value.
-         * @param topVer Topology version.
-         * @return Associated value.
-         */
-        @SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
-        private GridCacheMapEntry put0(KeyCacheObject key, int hash, CacheObject val, AffinityTopologyVersion topVer) {
-            try {
-                int c = size;
-
-                if (c++ > threshold) // Ensure capacity.
-                    rehash();
-
-                HashEntry[] tab = tbl;
-
-                int idx = hash & (tab.length - 1);
-
-                HashEntry bin = tab[idx];
-
-                HashEntry e = bin;
-
-                while (e != null && (e.mapEntry.hash() != hash || !key.equals(e.mapEntry.key())))
-                    e = e.next;
-
-                GridCacheMapEntry retVal;
-
-                if (e != null) {
-                    retVal = e.mapEntry;
-
-                    retVal.rawPut(val, 0);
-                }
-                else {
-                    HashEntry next = bin != null ? bin : null;
-
-                    GridCacheMapEntry newEntry = factory.create(ctx, topVer, key, hash, val);
-
-                    tab[idx] = new HashEntry(newEntry, next);
-
-                    retVal = newEntry;
-
-                    // Modify counters.
-                    if (!retVal.isInternal()) {
-                        mapPubSize.increment();
-
-                        pubSize.increment();
-                    }
-
-                    mapSize.increment();
-
-                    size = c;
-                }
-
-                return retVal;
-            }
-            finally {
-                if (DEBUG)
-                    checkSegmentConsistency();
-            }
-        }
-
-        /**
-         * @param key Key.
-         * @param hash Hash.
-         * @param val Value.
-         * @param topVer Topology version.
-         * @param create Create flag.
-         * @return Triple where the first element is current entry associated with the key,
-         *      the second is created entry and the third is doomed (all may be null).
-         */
-        @SuppressWarnings( {"unchecked"})
-        GridTriple<GridCacheMapEntry> putIfObsolete(KeyCacheObject key,
-            int hash,
-            @Nullable CacheObject val,
-            AffinityTopologyVersion topVer,
-            boolean create
-        ) {
-            lock();
-
-            try {
-                HashEntry[] tab = tbl;
-
-                int idx = hash & (tab.length - 1);
-
-                HashEntry bin = tab[idx];
-
-                GridCacheMapEntry cur = null;
-                GridCacheMapEntry created = null;
-                GridCacheMapEntry doomed = null;
-
-                if (bin == null) {
-                    if (create)
-                        cur = created = put0(key, hash, val, topVer);
-
-                    return new GridTriple<>(cur, created, doomed);
-                }
-
-                HashEntry e = bin;
-
-                while (e != null && (e.mapEntry.hash() != hash || !key.equals(e.mapEntry.key())))
-                    e = e.next;
-
-                if (e != null) {
-                    if (e.mapEntry.obsolete()) {
-                        doomed = remove(key, hash, null);
-
-                        if (create)
-                            cur = created = put0(key, hash, val, topVer);
-                    }
-                    else
-                        cur = e.mapEntry;
-                }
-                else if (create)
-                    cur = created = put0(key, hash, val, topVer);
-
-                return new GridTriple<>(cur, created, doomed);
-            }
-            finally {
-                unlock();
-            }
-        }
-
-        /**
-         *
-         */
-        @SuppressWarnings("unchecked")
-        void rehash() {
-            HashEntry[] oldTbl = tbl;
-
-            int oldCap = oldTbl.length;
-
-            if (oldCap >= MAX_CAP)
-                return;
-
-            /*
-             * Reclassify nodes in each list to new Map.  Because we are
-             * using power-of-two expansion, the elements from each bin
-             * must either stay at same index, or move with a power of two
-             * offset. We eliminate unnecessary node creation by catching
-             * cases where old nodes can be reused because their next
-             * fields won't change. Statistically, at the default
-             * threshold, only about one-sixth of them need cloning when
-             * a table doubles. The nodes they replace will be eligible for GC
-             * as soon as they are no longer referenced by any
-             * reader thread that may be in the midst of traversing table
-             * right now.
-             */
-            HashEntry[] newTbl = new HashEntry[oldCap << 1];
-
-            threshold = (int)(newTbl.length * loadFactor);
-
-            int sizeMask = newTbl.length - 1;
-
-            for (int i = 0; i < oldCap ; i++) {
-                HashEntry e = oldTbl[i];
-
-                if (e != null) {
-                    HashEntry next = e.next;
-
-                    int idx = e.mapEntry.hash() & sizeMask;
-
-                    if (next == null)   //  Single node on list
-                        newTbl[idx] = e;
-                    else { // Reuse consecutive sequence at same slot
-                        HashEntry lastRun = e;
-
-                        int lastIdx = idx;
-
-                        for (HashEntry last = next; last != null; last = last.next) {
-                            int k = last.mapEntry.hash() & sizeMask;
-
-                            if (k != lastIdx) {
-                                lastIdx = k;
-                                lastRun = last;
-                            }
-                        }
-
-                        newTbl[lastIdx] = lastRun;
-
-                        // Clone remaining nodes
-                        for (HashEntry p = e; p != lastRun; p = p.next) {
-                            int k = p.mapEntry.hash() & sizeMask;
-
-                            HashEntry n = newTbl[k];
-
-                            newTbl[k] = new HashEntry(p.mapEntry, n);
-                        }
-                    }
-                }
-            }
-
-            tbl = newTbl;
-
-            if (DEBUG)
-                checkSegmentConsistency();
-        }
-
-        /**
-         * Remove; match on key only if value null, else match both.
-         *
-         * @param key Key.
-         * @param hash Hash.
-         * @param filter Optional predicate.
-         * @return Removed value.
-         */
-        @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
-        @Nullable GridCacheMapEntry remove(Object key, int hash,
-            @Nullable IgnitePredicate<GridCacheMapEntry> filter) {
-            lock();
-
-            try {
-                int idx = hash & (tbl.length - 1);
-
-                HashEntry bin = tbl[idx];
-
-                if (bin == null)
-                    return null;
-
-                HashEntry prev = null;
-                HashEntry e = bin;
-
-                while (e != null && (e.mapEntry.hash() != hash || !key.equals(e.mapEntry.key))) {
-                    prev = e;
-
-                    e = e.next;
-                }
-
-                if (e != null) {
-                    if (filter != null && !filter.apply(e.mapEntry))
-                        return null;
-
-                    if (prev == null)
-                        tbl[idx] = e.next;
-                    else
-                        prev.next = e.next;
-
-                    // Modify counters.
-                    synchronized (e) {
-                        if (!e.mapEntry.isInternal() && !e.mapEntry.deleted()) {
-                            mapPubSize.decrement();
-
-                            pubSize.decrement();
-                        }
-                    }
-
-                    mapSize.decrement();
-
-                    --size;
-
-                    return e.mapEntry;
-                }
-
-                return null;
-            }
-            finally {
-                if (DEBUG)
-                    checkSegmentConsistency();
-
-                unlock();
-            }
-        }
-
-        /**
-         * @return Entries count within segment.
-         */
-        int size() {
-            return size;
-        }
-
-        /**
-         * @return Public entries count within segment.
-         */
-        int publicSize() {
-            return pubSize.intValue();
-        }
-
-        /**
-         * Decrements segment public size.
-         */
-        void decrementPublicSize() {
-            pubSize.decrement();
-        }
-
-        /**
-         * Decrements segment public size.
-         */
-        void incrementPublicSize() {
-            pubSize.increment();
-        }
-
-        /**
-         * @return Random cache map entry from this segment.
-         */
-        @Nullable GridCacheMapEntry randomEntry() {
-            if (size == 0)
-                return null;
-
-            HashEntry[] tbl = this.tbl;
-
-            Collection<GridCacheMapEntry> entries = new ArrayList<>(3);
-
-            int pubCnt = 0;
-
-            int start = RAND.nextInt(tbl.length);
-
-            outerLoop:
-            {
-                for (int i = start; i < start + tbl.length; i++) {
-                    HashEntry first = tbl[i & (tbl.length - 1)];
-
-                    if (first == null)
-                        continue;
-
-                    for (HashEntry e = first; e != null; e = e.next) {
-                        if (!e.mapEntry.isInternal())
-                            pubCnt++;
-
-                        entries.add(e.mapEntry);
-
-                        if (entries.size() == 3)
-                            break outerLoop;
-
-                    }
-                }
-            }
-
-            if (entries.isEmpty())
-                return null;
-
-            if (pubCnt == 0)
-                return null;
-
-            // Desired and current indexes.
-            int idx = RAND.nextInt(pubCnt);
-
-            int i = 0;
-
-            GridCacheMapEntry retVal = null;
-
-            for (GridCacheMapEntry e : entries) {
-                if (!(e.key instanceof GridCacheInternal)) {
-                    // In case desired entry was deleted, we return the closest one from left.
-                    retVal = e;
-
-                    if (idx == i++)
-                        break;
-                }
-            }
-
-            return retVal;
-        }
-
-        /**
-         *
-         */
-        void checkSegmentConsistency() {
-            HashEntry[] tbl = this.tbl;
-
-            int cnt = 0;
-            int pubCnt = 0;
-
-            for (HashEntry b : tbl) {
-                if (b != null) {
-                    HashEntry e = b;
-
-                    assert e != null;
-
-                    while (e != null) {
-                        cnt++;
-
-                        if (!(e.mapEntry.key instanceof GridCacheInternal))
-                            pubCnt++;
-
-                        e = e.next;
-                    }
-                }
-            }
-
-            assert cnt == size : "Entry count and header size mismatch [cnt=" + cnt + ", hdrSize=" +
-                size + ", segment=" + this + ']';
-            assert pubCnt == pubSize.intValue();
-        }
-    }
-
-    /**
-     * Iterator over {@link GridCacheEntryEx} elements.
-     *
-     * @param <K> Key type.
-     * @param <V> Value type.
+     * @return Iterable of the mappings contained in this map, including entries in unvisitable state.
      */
-    private static class Iterator0<K, V> implements Iterator<GridCacheEntryEx>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** */
-        private int nextSegIdx;
-
-        /** */
-        private int nextTblIdx;
-
-        /** */
-        private HashEntry[] curTbl;
-
-        /** */
-        private HashEntry nextEntry;
-
-        /** Next entry to return. */
-        private HashEntry next;
-
-        /** Next value. */
-        private V nextVal;
-
-        /** Current value. */
-        private V curVal;
-
-        /** */
-        private boolean isVal;
-
-        /** Current entry. */
-        private HashEntry cur;
-
-        /** Iterator filter. */
-        private CacheEntryPredicate[] filter;
-
-        /** Outer cache map. */
-        private GridCacheConcurrentMap map;
-
-        /** Cache context. */
-        private GridCacheContext<K, V> ctx;
-
-        /** Mod. */
-        private int id;
-
-        /** Mod count. */
-        private int totalCnt;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public Iterator0() {
-            // No-op.
-        }
-
-        /**
-         * @param map Cache map.
-         * @param isVal {@code True} if value iterator.
-         * @param filter Entry filter.
-         * @param id ID of the iterator.
-         * @param totalCnt Total count of iterators.
-         */
-        @SuppressWarnings({"unchecked"})
-        Iterator0(GridCacheConcurrentMap map, boolean isVal,
-            CacheEntryPredicate[] filter, int id, int totalCnt) {
-            this.filter = filter;
-            this.isVal = isVal;
-            this.id = id;
-            this.totalCnt = totalCnt;
-
-            this.map = map;
-
-            ctx = map.ctx;
-
-            nextSegIdx = map.segs.length - 1;
-            nextTblIdx = -1;
-
-            advance();
-        }
-
-        /**
-         *
-         */
-        @SuppressWarnings({"unchecked"})
-        private void advance() {
-            if (nextEntry != null && advanceInBucket(nextEntry, true))
-                return;
-
-            while (nextTblIdx >= 0) {
-                HashEntry bucket = curTbl[nextTblIdx--];
-
-                if (bucket != null && advanceInBucket(bucket, false))
-                    return;
-            }
-
-            while (nextSegIdx >= 0) {
-                int nextSegIdx0 = nextSegIdx--;
-
-                GridCacheConcurrentMap.Segment seg = map.segs[nextSegIdx0];
-
-                if (seg.size != 0 && (id == -1 || nextSegIdx0 % totalCnt == id)) {
-                    curTbl = seg.tbl;
-
-                    for (int j = curTbl.length - 1; j >= 0; --j) {
-                        HashEntry bucket = curTbl[j];
-
-                        if (bucket != null && advanceInBucket(bucket, false)) {
-                            nextTblIdx = j - 1;
-
-                            return;
-                        }
-                    }
-                }
-            }
-        }
-
-        /**
-         * @param e Current next.
-         * @param skipFirst {@code True} to skip check on first iteration.
-         * @return {@code True} if advance succeeded.
-         */
-        @SuppressWarnings( {"unchecked"})
-        private boolean advanceInBucket(@Nullable HashEntry e, boolean skipFirst) {
-            if (e == null)
-                return false;
-
-            nextEntry = e;
-
-            do {
-                if (!skipFirst) {
-                    next = nextEntry;
-
-                    // Check if entry is visitable first before doing projection-aware peek.
-                    if (!next.mapEntry.visitable(filter))
-                        continue;
-
-                    if (isVal) {
-                        nextVal = next.mapEntry.<K, V>wrap().getValue();
-
-                        if (nextVal == null)
-                            continue;
-                    }
-
-                    return true;
-                }
-
-                // Perform checks in any case.
-                skipFirst = false;
-            }
-            while ((nextEntry = nextEntry.next) != null);
-
-            next = null;
-            nextVal = null;
-
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return next != null && (!isVal || nextVal != null);
-        }
-
-        /**
-         * @return Next value.
-         */
-        public V currentValue() {
-            return curVal;
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public GridCacheEntryEx next() {
-            HashEntry e = next;
-            V v = nextVal;
-
-            if (e == null)
-                throw new NoSuchElementException();
-
-            advance();
-
-            cur = e;
-            curVal = v;
-
-            return cur.mapEntry;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void remove() {
-            if (cur == null)
-                throw new IllegalStateException();
-
-            HashEntry e = cur;
-
-            cur = null;
-            curVal = null;
-
-            try {
-                ((IgniteKernal)ctx.grid()).getCache(ctx.name()).getAndRemove(e.mapEntry.key);
-            }
-            catch (IgniteCheckedException ex) {
-                throw new IgniteException(ex);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(ctx);
-            out.writeObject(filter);
-            out.writeBoolean(isVal);
-            out.writeInt(id);
-            out.writeInt(totalCnt);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            ctx = (GridCacheContext<K, V>)in.readObject();
-            filter = (CacheEntryPredicate[])in.readObject();
-            isVal = in.readBoolean();
-            id = in.readInt();
-            totalCnt = in.readInt();
-        }
-
-        /**
-         * Reconstructs object on unmarshalling.
-         *
-         * @return Reconstructed object.
-         * @throws ObjectStreamException Thrown in case of unmarshalling error.
-         */
-        protected Object readResolve() throws ObjectStreamException {
-            return new Iterator0<>(ctx.cache().map(), isVal, filter, id, totalCnt);
-        }
-    }
+    public Iterable<GridCacheMapEntry> allEntries(CacheEntryPredicate... filter);
 
     /**
-     * Entry set.
-     */
-    @SuppressWarnings("unchecked")
-    private static class Set0<K, V> extends AbstractSet<GridCacheEntryEx> implements Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Filter. */
-        private CacheEntryPredicate[] filter;
-
-        /** Base map. */
-        private GridCacheConcurrentMap map;
-
-        /** Context. */
-        private GridCacheContext<K, V> ctx;
-
-        /** */
-        private CacheOperationContext opCtxPerCall;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public Set0() {
-            // No-op.
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Filter.
-         */
-        private Set0(GridCacheConcurrentMap map, CacheEntryPredicate[] filter) {
-            assert map != null;
-
-            this.map = map;
-            this.filter = filter;
-
-            ctx = map.ctx;
-
-            opCtxPerCall = ctx.operationContextPerCall();
-        }
-
-        /** {@inheritDoc} */
-        @NotNull @Override public Iterator<GridCacheEntryEx> iterator() {
-            return new Iterator0<>(map, false, filter, -1, -1);
-        }
-
-        /**
-         * @return Entry iterator.
-         */
-        Iterator<Cache.Entry<K, V>> entryIterator() {
-            return new EntryIterator<>(map, filter, ctx, opCtxPerCall);
-        }
-
-        /**
-         * @return Key iterator.
-         */
-        Iterator<K> keyIterator() {
-            return new KeyIterator<>(map, opCtxPerCall != null && opCtxPerCall.isKeepBinary(), filter);
-        }
-
-        /**
-         * @return Value iterator.
-         */
-        Iterator<V> valueIterator() {
-            return new ValueIterator<>(map, filter, ctx);
-        }
-
-        /**
-         * Checks for key containment.
-         *
-         * @param k Key to check.
-         * @return {@code True} if key is in the map.
-         */
-        boolean containsKey(K k) {
-            KeyCacheObject cacheKey = ctx.toCacheKeyObject(k);
-
-            GridCacheEntryEx e = ctx.cache().peekEx(cacheKey);
-
-            try {
-                return e != null && !e.obsolete() &&
-                    (!e.deleted() || e.lockedByThread()) &&
-                    F.isAll(e, filter);
-            }
-            catch (GridCacheEntryRemovedException ignore) {
-                return false;
-            }
-        }
-
-        /**
-         * @param v Checks if value is contained in
-         * @return {@code True} if value is in the set.
-         */
-        boolean containsValue(V v) {
-            A.notNull(v, "value");
-
-            for (Iterator<V> it = valueIterator(); it.hasNext(); ) {
-                V v0 = it.next();
-
-                if (F.eq(v0, v))
-                    return true;
-            }
-
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean contains(Object o) {
-            if (!(o instanceof GridCacheEntryEx))
-                return false;
-
-            GridCacheEntryEx e = (GridCacheEntryEx)o;
-
-            GridCacheEntryEx cur = ctx.cache().peekEx(e.key());
-
-            return cur != null && cur.equals(e);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean remove(Object o) {
-            return o instanceof Cache.Entry && removeKey(((Map.Entry<K, V>)o).getKey());
-        }
-
-        /**
-         * @param k Key to remove.
-         * @return If key has been removed.
-         */
-        boolean removeKey(K k) {
-            try {
-                return ((IgniteKernal)ctx.grid()).getCache(ctx.name()).remove(k, CU.<K, V>empty());
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException("Failed to remove cache entry for key: " + k, e);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public int size() {
-            return F.isEmpty(filter) ? map.publicSize() : F.size(iterator());
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isEmpty() {
-            return F.isEmpty(filter) ? map.publicSize() == 0 : !iterator().hasNext();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void clear() {
-            ctx.cache().clearLocallyAll(new KeySet<K, V>(map, filter, false), true, true, false);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(ctx);
-            out.writeObject(filter);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            ctx = (GridCacheContext<K, V>)in.readObject();
-            filter = (CacheEntryPredicate[])in.readObject();
-        }
-
-        /**
-         * Reconstructs object on unmarshalling.
-         *
-         * @return Reconstructed object.
-         * @throws ObjectStreamException Thrown in case of unmarshalling error.
-         */
-        protected Object readResolve() throws ObjectStreamException {
-            return new Set0<>(ctx.cache().map(), filter);
-        }
-    }
-
-    /**
-     * Iterator over hash table.
-     * <p>
-     * Note, class is static for {@link Externalizable}.
-     */
-    private static class EntryIterator<K, V> implements Iterator<Cache.Entry<K, V>>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Base iterator. */
-        private Iterator0<K, V> it;
-
-        /** */
-        private GridCacheContext<K, V> ctx;
-
-        /** */
-        private CacheOperationContext opCtxPerCall;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public EntryIterator() {
-            // No-op.
-        }
-
-        /**
-         * @param map Cache map.
-         * @param filter Entry filter.
-         * @param ctx Cache context.
-         * @param opCtxPerCall Operation context per call.
-         */
-        EntryIterator(
-            GridCacheConcurrentMap map,
-            CacheEntryPredicate[] filter,
-            GridCacheContext<K, V> ctx,
-            CacheOperationContext opCtxPerCall) {
-            it = new Iterator0<>(map, false, filter, -1, -1);
-
-            this.ctx = ctx;
-            this.opCtxPerCall = opCtxPerCall;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return it.hasNext();
-        }
-
-        /** {@inheritDoc} */
-        @Override public Cache.Entry<K, V> next() {
-            CacheOperationContext old = ctx.operationContextPerCall();
-
-            ctx.operationContextPerCall(opCtxPerCall);
-
-            try {
-                return it.next().wrapLazyValue();
-            }
-            finally {
-                ctx.operationContextPerCall(old);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void remove() {
-            it.remove();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(it);
-            out.writeObject(ctx);
-            out.writeObject(opCtxPerCall);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            it = (Iterator0<K, V>)in.readObject();
-            ctx = (GridCacheContext<K, V>)in.readObject();
-            opCtxPerCall = (CacheOperationContext)in.readObject();
-        }
-    }
-
-    /**
-     * Value iterator.
-     * <p>
-     * Note that class is static for {@link Externalizable}.
-     */
-    private static class ValueIterator<K, V> implements Iterator<V>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Hash table iterator. */
-        private Iterator0<K, V> it;
-
-        /** Context. */
-        private GridCacheContext<K, V> ctx;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public ValueIterator() {
-            // No-op.
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Value filter.
-         * @param ctx Cache context.
-         */
-        private ValueIterator(
-            GridCacheConcurrentMap map,
-            CacheEntryPredicate[] filter,
-            GridCacheContext ctx) {
-            it = new Iterator0<>(map, true, filter, -1, -1);
-
-            this.ctx = ctx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return it.hasNext();
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public V next() {
-            it.next();
-
-            // Cached value.
-            return it.currentValue();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void remove() {
-            it.remove();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(it);
-            out.writeObject(ctx);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            it = (Iterator0)in.readObject();
-            ctx = (GridCacheContext<K, V>)in.readObject();
-        }
-    }
-
-    /**
-     * Key iterator.
-     */
-    private static class KeyIterator<K, V> implements Iterator<K>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Hash table iterator. */
-        private Iterator0<K, V> it;
-
-        /** Keep binary flag. */
-        private boolean keepBinary;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public KeyIterator() {
-            // No-op.
-        }
-
-        /**
-         * @param map Cache map.
-         * @param filter Filter.
-         */
-        private KeyIterator(GridCacheConcurrentMap map, boolean keepBinary, CacheEntryPredicate[] filter) {
-            it = new Iterator0<>(map, false, filter, -1, -1);
-            this.keepBinary = keepBinary;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean hasNext() {
-            return it.hasNext();
-        }
-
-        /** {@inheritDoc} */
-        @Override public K next() {
-            return (K)it.ctx.cacheObjectContext().unwrapBinaryIfNeeded(it.next().key(), keepBinary, true);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void remove() {
-            it.remove();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(it);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            it = (Iterator0)in.readObject();
-        }
-    }
-
-    /**
-     * Key set.
-     */
-    private static class KeySet<K, V> extends AbstractSet<K> implements Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Base entry set. */
-        private Set0<K, V> set;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public KeySet() {
-            // No-op.
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Key filter.
-         * @param internal Whether to allow internal keys.
-         */
-        private KeySet(GridCacheConcurrentMap map, CacheEntryPredicate[] filter, boolean internal) {
-            assert map != null;
-
-            set = new Set0<>(map, internal ? filter : nonInternal(filter));
-        }
-
-        /** {@inheritDoc} */
-        @NotNull @Override public Iterator<K> iterator() {
-            return set.keyIterator();
-        }
-
-        /** {@inheritDoc} */
-        @Override public int size() {
-            return set.size();
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean contains(Object o) {
-            return set.containsKey((K)o);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean remove(Object o) {
-            return set.removeKey((K)o);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void clear() {
-            set.clear();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(set);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            set = (Set0<K, V>)in.readObject();
-        }
-    }
-
-    /**
-     * Value set.
-     * <p>
-     * Note that the set is static for {@link Externalizable} support.
-     */
-    private static class Values<K, V> extends AbstractCollection<V> implements Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Base entry set. */
-        private Set0<K, V> set;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public Values() {
-            // No-op.
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Value filter.
-         */
-        private Values(GridCacheConcurrentMap map, CacheEntryPredicate[] filter) {
-            assert map != null;
-
-            set = new Set0<>(map, nonInternal(filter));
-        }
-
-        /** {@inheritDoc} */
-        @NotNull @Override public Iterator<V> iterator() {
-            return set.valueIterator();
-        }
-
-        /** {@inheritDoc} */
-        @Override public int size() {
-            return set.size();
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean contains(Object o) {
-            return set.containsValue((V)o);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void clear() {
-            set.clear();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(set);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            set = (Set0<K, V>)in.readObject();
-        }
-    }
-
-    /**
-     * Entry set.
-     */
-    private static class EntrySet<K, V> extends AbstractSet<Cache.Entry<K, V>> implements Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** Base entry set. */
-        private Set0<K, V> set;
-
-        /**
-         * Empty constructor required for {@link Externalizable}.
-         */
-        public EntrySet() {
-            // No-op.
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Key filter.
-         */
-        private EntrySet(GridCacheConcurrentMap map, CacheEntryPredicate[] filter) {
-            this(map, filter, false);
-        }
-
-        /**
-         * @param map Base map.
-         * @param filter Key filter.
-         * @param internal Whether to allow internal entries.
-         */
-        private EntrySet(GridCacheConcurrentMap map, CacheEntryPredicate[] filter,
-            boolean internal) {
-            assert map != null;
-
-            set = new Set0<>(map, internal ? filter : nonInternal(filter));
-        }
-
-        /** {@inheritDoc} */
-        @NotNull @Override public Iterator<Cache.Entry<K, V>> iterator() {
-            return set.entryIterator();
-        }
-
-        /** {@inheritDoc} */
-        @Override public int size() {
-            return set.size();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isEmpty() {
-            return set.isEmpty();
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean contains(Object o) {
-            if (o instanceof CacheEntryImpl) {
-                GridCacheEntryEx unwrapped = set.map.getEntry(((CacheEntryImpl)o).getKey());
-
-                return unwrapped != null && set.contains(unwrapped);
-            }
-
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public boolean remove(Object o) {
-            return set.removeKey((K)o);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void clear() {
-            set.clear();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(set);
-        }
-
-        /** {@inheritDoc} */
-        @SuppressWarnings({"unchecked"})
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            set = (Set0<K, V>)in.readObject();
-        }
-    }
-
-    /**
-     *
+     * @param filter Filter.
+     * @return Set of the mappings contained in this map.
      */
-    private static class HashEntry {
-        /** */
-        private final GridCacheMapEntry mapEntry;
-
-        /** */
-        @GridToStringExclude
-        private volatile HashEntry next;
-
-        /**
-         * @param mapEntry Entry.
-         * @param next Next.
-         */
-        private HashEntry(
-            GridCacheMapEntry mapEntry,
-            HashEntry next
-        ) {
-            this.mapEntry = mapEntry;
-            this.next = next;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(HashEntry.class, this, super.toString());
-        }
-    }
+    public Set<GridCacheMapEntry> entrySet(CacheEntryPredicate... filter);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java
new file mode 100644
index 0000000..48dae76
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_CREATED;
+import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_DESTROYED;
+
+/**
+ * Implementation of concurrent cache map.
+ */
+public class GridCacheConcurrentMapImpl implements GridCacheConcurrentMap {
+    /** Default load factor. */
+    private static final float DFLT_LOAD_FACTOR = 0.75f;
+
+    /** Default concurrency level. */
+    private static final int DFLT_CONCUR_LEVEL = Runtime.getRuntime().availableProcessors() * 2;
+
+    /** Internal map. */
+    private final ConcurrentMap<KeyCacheObject, GridCacheMapEntry> map;
+
+    /** Map entry factory. */
+    private final GridCacheMapEntryFactory factory;
+
+    /** Cache context. */
+    private final GridCacheContext ctx;
+
+    /** Public size counter. */
+    private final AtomicInteger pubSize = new AtomicInteger();
+
+    /**
+     * Creates a new, empty map with the specified initial
+     * capacity.
+     *
+     * @param ctx Cache context.
+     * @param factory Entry factory.
+     * @param initialCapacity the initial capacity. The implementation
+     *      performs internal sizing to accommodate this many elements.
+
+     * @throws IllegalArgumentException if the initial capacity is
+     *      negative.
+     */
+    public GridCacheConcurrentMapImpl(GridCacheContext ctx, GridCacheMapEntryFactory factory, int initialCapacity) {
+        this(ctx, factory, initialCapacity, DFLT_LOAD_FACTOR, DFLT_CONCUR_LEVEL);
+    }
+
+    /**
+     * Creates a new, empty map with the specified initial
+     * capacity, load factor and concurrency level.
+     *
+     * @param ctx Cache context.
+     * @param factory Entry factory.
+     * @param initialCapacity the initial capacity. The implementation
+     *      performs internal sizing to accommodate this many elements.
+     * @param loadFactor  the load factor threshold, used to control resizing.
+     *      Resizing may be performed when the average number of elements per
+     *      bin exceeds this threshold.
+     * @param concurrencyLevel the estimated number of concurrently
+     *      updating threads. The implementation performs internal sizing
+     *      to try to accommodate this many threads.
+     * @throws IllegalArgumentException if the initial capacity is
+     *      negative or the load factor or concurrencyLevel are
+     *      non-positive.
+     */
+    public GridCacheConcurrentMapImpl(
+        GridCacheContext ctx,
+        GridCacheMapEntryFactory factory,
+        int initialCapacity,
+        float loadFactor,
+        int concurrencyLevel
+    ) {
+        this.ctx = ctx;
+        this.factory = factory;
+
+        map = new ConcurrentHashMap8<>(initialCapacity, loadFactor, concurrencyLevel);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) {
+        return map.get(key);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(final AffinityTopologyVersion topVer,
+        KeyCacheObject key, @Nullable final CacheObject val, final boolean create, final boolean touch) {
+
+        GridCacheMapEntry cur = null;
+        GridCacheMapEntry created = null;
+        GridCacheMapEntry created0 = null;
+        GridCacheMapEntry doomed = null;
+
+        boolean done = false;
+
+        while (!done) {
+            GridCacheMapEntry entry = map.get(key);
+            created = null;
+            doomed = null;
+
+            if (entry == null) {
+                if (create) {
+                    if (created0 == null)
+                        created0 = factory.create(ctx, topVer, key, key.hashCode(), val);
+
+                    cur = created = created0;
+
+                    done = map.putIfAbsent(created.key(), created) == null;
+                }
+                else
+                    done = true;
+            }
+            else {
+                if (entry.obsolete()) {
+                    doomed = entry;
+
+                    if (create) {
+                        if (created0 == null)
+                            created0 = factory.create(ctx, topVer, key, key.hashCode(), val);
+
+                        cur = created = created0;
+
+                        done = map.replace(entry.key(), doomed, created);
+                    }
+                    else
+                        done = map.remove(entry.key(), doomed);
+                }
+                else {
+                    cur = entry;
+
+                    done = true;
+                }
+            }
+        }
+
+        int sizeChange = 0;
+
+        if (doomed != null) {
+            synchronized (doomed) {
+                if (!doomed.deleted())
+                    sizeChange--;
+            }
+
+            if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
+                ctx.events().addEvent(doomed.partition(),
+                    doomed.key(),
+                    ctx.localNodeId(),
+                    (IgniteUuid)null,
+                    null,
+                    EVT_CACHE_ENTRY_DESTROYED,
+                    null,
+                    false,
+                    null,
+                    false,
+                    null,
+                    null,
+                    null,
+                    true);
+        }
+
+        if (created != null) {
+            sizeChange++;
+
+            if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED))
+                ctx.events().addEvent(created.partition(),
+                    created.key(),
+                    ctx.localNodeId(),
+                    (IgniteUuid)null,
+                    null,
+                    EVT_CACHE_ENTRY_CREATED,
+                    null,
+                    false,
+                    null,
+                    false,
+                    null,
+                    null,
+                    null,
+                    true);
+
+            if (touch)
+                ctx.evicts().touch(
+                    cur,
+                    topVer);
+        }
+
+        if (sizeChange != 0)
+            pubSize.addAndGet(sizeChange);
+
+        return cur;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removeEntry(final GridCacheEntryEx entry) {
+        boolean removed = map.remove(entry.key(), entry);
+
+        if (removed) {
+            if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
+                // Event notification.
+                ctx.events().addEvent(entry.partition(), entry.key(), ctx.localNodeId(), (IgniteUuid)null, null,
+                    EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, false);
+
+            synchronized (entry) {
+                if (!entry.deleted())
+                    decrementPublicSize(entry);
+            }
+        }
+
+        return removed;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return map.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int publicSize() {
+        return pubSize.get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void incrementPublicSize(GridCacheEntryEx e) {
+        pubSize.incrementAndGet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void decrementPublicSize(GridCacheEntryEx e) {
+        pubSize.decrementAndGet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<KeyCacheObject> keySet(final CacheEntryPredicate... filter) {
+        final IgnitePredicate<KeyCacheObject> p = new IgnitePredicate<KeyCacheObject>() {
+            @Override public boolean apply(KeyCacheObject key) {
+                GridCacheMapEntry entry = map.get(key);
+
+                return entry != null && entry.visitable(filter);
+            }
+        };
+
+        return new AbstractSet<KeyCacheObject>() {
+            @Override public Iterator<KeyCacheObject> iterator() {
+                return F.iterator0(map.keySet(), true, p);
+            }
+
+            @Override public int size() {
+                return F.size(iterator());
+            }
+
+            @Override public boolean contains(Object o) {
+                if (!(o instanceof KeyCacheObject))
+                    return false;
+
+                return map.keySet().contains(o) && p.apply((KeyCacheObject)o);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridCacheMapEntry> entries(final CacheEntryPredicate... filter) {
+        final IgnitePredicate<GridCacheMapEntry> p = new IgnitePredicate<GridCacheMapEntry>() {
+            @Override public boolean apply(GridCacheMapEntry entry) {
+                return entry.visitable(filter);
+            }
+        };
+
+        return F.viewReadOnly(map.values(), F.<GridCacheMapEntry>identity(), p);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridCacheMapEntry> allEntries(final CacheEntryPredicate... filter) {
+        final IgnitePredicate<GridCacheMapEntry> p = new IgnitePredicate<GridCacheMapEntry>() {
+            @Override public boolean apply(GridCacheMapEntry entry) {
+                return F.isAll(entry, filter);
+            }
+        };
+
+        return F.viewReadOnly(map.values(), F.<GridCacheMapEntry>identity(), p);
+    }
+
+    /** {@inheritDoc} */
+    @Deprecated @Nullable @Override public GridCacheMapEntry randomEntry() {
+        Iterator<GridCacheMapEntry> iterator = map.values().iterator();
+
+        if (iterator.hasNext())
+            return iterator.next();
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<GridCacheMapEntry> entrySet(final CacheEntryPredicate... filter) {
+        final IgnitePredicate<GridCacheMapEntry> p = new IgnitePredicate<GridCacheMapEntry>() {
+            @Override public boolean apply(GridCacheMapEntry entry) {
+                return entry.visitable(filter);
+            }
+        };
+
+        return new AbstractSet<GridCacheMapEntry>() {
+            @Override public Iterator<GridCacheMapEntry> iterator() {
+                return F.iterator0(map.values(), true, p);
+            }
+
+            @Override public int size() {
+                return F.size(iterator());
+            }
+
+            @Override public boolean contains(Object o) {
+                if (!(o instanceof GridCacheMapEntry))
+                    return false;
+
+                GridCacheMapEntry entry = (GridCacheMapEntry)o;
+
+                return entry.equals(map.get(entry.key())) && p.apply(entry);
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 88d6e04..7ad6c77 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -59,7 +59,6 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter;
@@ -589,14 +588,7 @@ public class GridCacheContext<K, V> implements Externalizable {
         assert e != null;
         assert !e.isInternal() : e;
 
-        cache.map().incrementSize(e);
-
-        if (isDht() || isColocated() || isDhtAtomic()) {
-            GridDhtLocalPartition part = topology().localPartition(e.partition(), AffinityTopologyVersion.NONE, false);
-
-            if (part != null)
-                part.incrementPublicSize();
-        }
+        cache.incrementSize(e);
     }
 
     /**
@@ -607,14 +599,7 @@ public class GridCacheContext<K, V> implements Externalizable {
         assert e != null;
         assert !e.isInternal() : e;
 
-        cache.map().decrementSize(e);
-
-        if (isDht() || isColocated() || isDhtAtomic()) {
-            GridDhtLocalPartition part = topology().localPartition(e.partition(), AffinityTopologyVersion.NONE, false);
-
-            if (part != null)
-                part.decrementPublicSize();
-        }
+        cache.decrementSize(e);
     }
 
     /**
@@ -1097,8 +1082,8 @@ public class GridCacheContext<K, V> implements Externalizable {
 
         for (CacheEntryPredicate p0 : p) {
             if ((p0 instanceof CacheEntrySerializablePredicate) &&
-               ((CacheEntrySerializablePredicate)p0).predicate() instanceof CacheEntryPredicateNoValue)
-            return true;
+                ((CacheEntrySerializablePredicate)p0).predicate() instanceof CacheEntryPredicateNoValue)
+                return true;
         }
 
         return false;
@@ -1155,7 +1140,7 @@ public class GridCacheContext<K, V> implements Externalizable {
      */
     @SuppressWarnings({"unchecked"})
     public IgnitePredicate<Cache.Entry<K, V>>[] vararg(IgnitePredicate<Cache.Entry<K, V>> p) {
-        return p == null ? CU.<K, V>empty() : new IgnitePredicate[]{p};
+        return p == null ? CU.<K, V>empty() : new IgnitePredicate[] {p};
     }
 
     /**
@@ -1320,8 +1305,6 @@ public class GridCacheContext<K, V> implements Externalizable {
         return (opCtx != null && opCtx.skipStore());
     }
 
-
-
     /**
      * @return {@code True} if need check near cache context.
      */
@@ -1804,9 +1787,20 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @return Cache key object.
      */
     public KeyCacheObject toCacheKeyObject(Object obj) {
+        return toCacheKeyObject(obj, false);
+    }
+
+    /**
+     * @param obj Object.
+     * @return Cache key object.
+     */
+    public KeyCacheObject toCacheKeyObject(Object obj, boolean includePartition) {
         assert validObjectForCache(obj) : obj;
 
-        return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, true);
+        if (includePartition)
+            return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, true, affinity().partition(obj));
+        else
+            return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, true);
     }
 
     /**
@@ -1838,8 +1832,7 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @throws IgniteCheckedException If failed.
      */
     @Nullable public CacheObject unswapCacheObject(byte type, byte[] bytes, @Nullable IgniteUuid clsLdrId)
-        throws IgniteCheckedException
-    {
+        throws IgniteCheckedException {
         if (ctx.config().isPeerClassLoadingEnabled() && type != CacheObject.TYPE_BYTE_ARR) {
             ClassLoader ldr = clsLdrId != null ? deploy().getClassLoader(clsLdrId) : deploy().localLoader();
 
@@ -1973,15 +1966,24 @@ public class GridCacheContext<K, V> implements Externalizable {
 
     /**
      * @param keys Keys.
-     * @return Co
+     * @return Read-only collection of KeyCacheObject instances.
      */
     public Collection<KeyCacheObject> cacheKeysView(Collection<?> keys) {
+        return cacheKeysView(keys, false);
+    }
+
+    /**
+     * @param keys Keys.
+     * @param includePartition Include partition.
+     * @return Read-only collection of KeyCacheObject instances.
+     */
+    public Collection<KeyCacheObject> cacheKeysView(Collection<?> keys, final boolean includePartition) {
         return F.viewReadOnly(keys, new C1<Object, KeyCacheObject>() {
             @Override public KeyCacheObject apply(Object key) {
                 if (key == null)
                     throw new NullPointerException("Null key.");
 
-                return toCacheKeyObject(key);
+                return toCacheKeyObject(key, includePartition);
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
index d54ecd6..8e66233 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
@@ -304,7 +304,7 @@ public class GridCacheDeploymentManager<K, V> extends GridCacheSharedManagerAdap
     private void addEntries(ClassLoader ldr, Collection<KeyCacheObject> keys, GridCacheAdapter cache) {
         GridCacheContext cacheCtx = cache.context();
 
-        for (GridCacheEntryEx e : (Collection<GridCacheEntryEx>)cache.entries()) {
+        for (GridCacheEntryEx e : (Iterable<GridCacheEntryEx>)cache.entries()) {
             boolean undeploy = cacheCtx.isNear() ?
                 undeploy(ldr, e, cacheCtx.near()) || undeploy(ldr, e, cacheCtx.near().dht()) :
                 undeploy(ldr, e, cacheCtx.cache());

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntrySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntrySet.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntrySet.java
deleted file mode 100644
index 1dbc564..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntrySet.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.cache;
-
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import javax.cache.Cache;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.lang.IgnitePredicate;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Entry set backed by cache itself.
- */
-public class GridCacheEntrySet<K, V> extends AbstractSet<Cache.Entry<K, V>> {
-    /** Cache context. */
-    private final GridCacheContext<K, V> ctx;
-
-    /** Filter. */
-    private final IgnitePredicate<Cache.Entry<K, V>>[] filter;
-
-    /** Base set. */
-    private final Set<Cache.Entry<K, V>> set;
-
-    /**
-     * @param ctx Cache context.
-     * @param c Entry collection.
-     * @param filter Filter.
-     */
-    public GridCacheEntrySet(GridCacheContext<K, V> ctx, Collection<? extends Cache.Entry<K, V>> c,
-        @Nullable IgnitePredicate<Cache.Entry<K, V>>... filter) {
-        set = new HashSet<>(c.size(), 1.0f);
-
-        assert ctx != null;
-
-        this.ctx = ctx;
-        this.filter = filter;
-
-        for (Cache.Entry<K, V> e : c) {
-            if (e != null)
-                set.add(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Cache.Entry<K, V>> iterator() {
-        return new GridCacheIterator<>(ctx, set, F.<Cache.Entry<K, V>>identity(), filter);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        throw new UnsupportedOperationException("clear");
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked"})
-    @Override public boolean remove(Object o) {
-        if (!(o instanceof CacheEntryImpl))
-            return false;
-
-        Cache.Entry<K, V> e = (Cache.Entry<K,V>)o;
-
-        if (F.isAll(e, filter) && set.remove(e)) {
-            try {
-                ((IgniteKernal)ctx.grid()).getCache(ctx.name()).remove(e.getKey(), e.getValue());
-            }
-            catch (IgniteCheckedException ex) {
-                throw new IgniteException(ex);
-            }
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return F.size(set, filter);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked"})
-    @Override public boolean contains(Object o) {
-        if (!(o instanceof CacheEntryImpl))
-            return false;
-
-        Cache.Entry<K,V> e = (Cache.Entry<K, V>)o;
-
-        return F.isAll(e, filter) && set.contains(e);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
index a21e18b..c102c58 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
@@ -1514,7 +1514,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
                             if (log.isDebugEnabled())
                                 log.debug("Touching partition entries: " + part);
 
-                            touchOnTopologyChange(part.entries());
+                            touchOnTopologyChange(part.allEntries());
                         }
                     }
                 }


[17/50] [abbrv] ignite git commit: IGNITE-2926: Implemented special version of single-update future for ATOMIC cache. Used for PRIMARY mode and only in case of a single key-value pair update. Gives 3% garbage reduction. Not much, though, the main goal fo

Posted by sh...@apache.org.
IGNITE-2926: Implemented special version of single-update future for ATOMIC cache. Used for PRIMARY mode and only in case of a single key-value pair update. Gives 3% garbage reduction. Not much, though, the main goal for this change is not perofmance, but rather infrastructure for further improvements. Namely, for single-update request which will be initiated only form this future.


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

Branch: refs/heads/ignite-2788
Commit: 0d077613451bd8e667ae7116c34b81258fa8c356
Parents: f6232b3
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Apr 20 10:06:55 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../processors/cache/CacheOperationFilter.java  |  61 ++
 .../processors/cache/GridCacheAtomicFuture.java |   5 -
 .../dht/atomic/GridDhtAtomicCache.java          | 107 ++-
 .../dht/atomic/GridDhtAtomicUpdateFuture.java   |   5 -
 .../GridNearAtomicAbstractUpdateFuture.java     | 244 +++++++
 .../GridNearAtomicSingleUpdateFuture.java       | 645 +++++++++++++++++++
 .../dht/atomic/GridNearAtomicUpdateFuture.java  | 319 ++-------
 7 files changed, 1085 insertions(+), 301 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationFilter.java
new file mode 100644
index 0000000..7fdfaac
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationFilter.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Cache operation filter.
+ */
+public enum CacheOperationFilter {
+    /** Always pass. */
+    ALWAYS,
+
+    /** No value. */
+    NO_VAL,
+
+    /** Has value. */
+    HAS_VAL,
+
+    /** Equals to value. */
+    EQUALS_VAL;
+
+    /**
+     * Creare predicate from operation filter.
+     *
+     * @param val Optional value.
+     * @return Predicate.
+     */
+    @Nullable public CacheEntryPredicate createPredicate(@Nullable CacheObject val) {
+        switch (this) {
+            case ALWAYS:
+                return null;
+
+            case NO_VAL:
+                return new CacheEntryPredicateNoValue();
+
+            case HAS_VAL:
+                return new CacheEntryPredicateHasValue();
+
+            default:
+                assert this == EQUALS_VAL;
+
+                return new CacheEntryPredicateContainsValue(val);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicFuture.java
index 359909e..c96d00f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAtomicFuture.java
@@ -38,9 +38,4 @@ public interface GridCacheAtomicFuture<R> extends GridCacheFuture<R> {
      * @return Future or {@code null} if no need to wait.
      */
     public IgniteInternalFuture<Void> completeFuture(AffinityTopologyVersion topVer);
-
-    /**
-     * @return Future keys.
-     */
-    public Collection<?> keys();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 4f8b32c..013184b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -984,7 +984,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         ctx.checkSecurity(SecurityPermission.CACHE_PUT);
 
-        final GridNearAtomicUpdateFuture updateFut =
+        final GridNearAtomicAbstractUpdateFuture updateFut =
             createSingleUpdateFuture(key, val, proc, invokeArgs, retval, filter, waitTopFut);
 
         return asyncOp(new CO<IgniteInternalFuture<Object>>() {
@@ -1016,7 +1016,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         ctx.checkSecurity(SecurityPermission.CACHE_REMOVE);
 
-        final GridNearAtomicUpdateFuture updateFut =
+        final GridNearAtomicAbstractUpdateFuture updateFut =
             createSingleUpdateFuture(key, null, null, null, retval, filter, true);
 
         if (statsEnabled)
@@ -1043,7 +1043,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
      * @param waitTopFut Whether to wait for topology future.
      * @return Future.
      */
-    private GridNearAtomicUpdateFuture createSingleUpdateFuture(
+    private GridNearAtomicAbstractUpdateFuture createSingleUpdateFuture(
         K key,
         @Nullable V val,
         @Nullable EntryProcessor proc,
@@ -1055,19 +1055,19 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
         CacheOperationContext opCtx = ctx.operationContextPerCall();
 
         GridCacheOperation op;
-        Collection vals;
+        Object val0;
 
         if (val != null) {
             op = UPDATE;
-            vals = Collections.singletonList(val);
+            val0 = val;
         }
         else if (proc != null) {
             op = TRANSFORM;
-            vals = Collections.singletonList(proc);
+            val0 = proc;
         }
         else {
             op = DELETE;
-            vals = null;
+            val0 = null;
         }
 
         GridCacheDrInfo conflictPutVal = null;
@@ -1081,37 +1081,75 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
             if (op == UPDATE) {
                 conflictPutVal = new GridCacheDrInfo(ctx.toCacheObject(val), ctx.versions().next(dcId));
 
-                vals = null;
+                val0 = null;
             }
             else if (op == GridCacheOperation.TRANSFORM) {
                 conflictPutVal = new GridCacheDrInfo(proc, ctx.versions().next(dcId));
 
-                vals = null;
+                val0 = null;
             }
             else
                 conflictRmvVer = ctx.versions().next(dcId);
         }
 
-        return new GridNearAtomicUpdateFuture(
-            ctx,
-            this,
-            ctx.config().getWriteSynchronizationMode(),
-            op,
-            Collections.singletonList(key),
-            vals,
-            invokeArgs,
-            conflictPutVal != null ? Collections.singleton(conflictPutVal) : null,
-            conflictRmvVer != null ? Collections.singleton(conflictRmvVer) : null,
-            retval,
-            false,
-            opCtx != null ? opCtx.expiry() : null,
-            CU.filterArray(filter),
-            ctx.subjectIdPerCall(null, opCtx),
-            ctx.kernalContext().job().currentTaskNameHash(),
-            opCtx != null && opCtx.skipStore(),
-            opCtx != null && opCtx.isKeepBinary(),
-            opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
-            waitTopFut);
+        CacheEntryPredicate[] filters = CU.filterArray(filter);
+
+        if (conflictPutVal == null && conflictRmvVer == null && !isFastMap(filters, op)) {
+            return new GridNearAtomicSingleUpdateFuture(
+                ctx,
+                this,
+                ctx.config().getWriteSynchronizationMode(),
+                op,
+                key,
+                val0,
+                invokeArgs,
+                retval,
+                false,
+                opCtx != null ? opCtx.expiry() : null,
+                filters,
+                ctx.subjectIdPerCall(null, opCtx),
+                ctx.kernalContext().job().currentTaskNameHash(),
+                opCtx != null && opCtx.skipStore(),
+                opCtx != null && opCtx.isKeepBinary(),
+                opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
+                waitTopFut
+            );
+        }
+        else {
+            return new GridNearAtomicUpdateFuture(
+                ctx,
+                this,
+                ctx.config().getWriteSynchronizationMode(),
+                op,
+                Collections.singletonList(key),
+                val0 != null ? Collections.singletonList(val0) : null,
+                invokeArgs,
+                conflictPutVal != null ? Collections.singleton(conflictPutVal) : null,
+                conflictRmvVer != null ? Collections.singleton(conflictRmvVer) : null,
+                retval,
+                false,
+                opCtx != null ? opCtx.expiry() : null,
+                filters,
+                ctx.subjectIdPerCall(null, opCtx),
+                ctx.kernalContext().job().currentTaskNameHash(),
+                opCtx != null && opCtx.skipStore(),
+                opCtx != null && opCtx.isKeepBinary(),
+                opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
+                waitTopFut);
+        }
+    }
+
+    /**
+     * Whether this is fast-map operation.
+     *
+     * @param filters Filters.
+     * @param op Operation.
+     * @return {@code True} if fast-map.
+     */
+    public boolean isFastMap(CacheEntryPredicate[] filters, GridCacheOperation op) {
+        return F.isEmpty(filters) && op != TRANSFORM && ctx.config().getWriteSynchronizationMode() == FULL_SYNC &&
+            ctx.config().getAtomicWriteOrderMode() == CLOCK &&
+            !(ctx.writeThrough() && ctx.config().getInterceptor() != null);
     }
 
     /**
@@ -2893,10 +2931,15 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         res.nodeId(ctx.localNodeId());
 
-        GridNearAtomicUpdateFuture fut = (GridNearAtomicUpdateFuture)ctx.mvcc().atomicFuture(res.futureVersion());
+        GridNearAtomicAbstractUpdateFuture fut =
+            (GridNearAtomicAbstractUpdateFuture)ctx.mvcc().atomicFuture(res.futureVersion());
 
-        if (fut != null)
-            fut.onResult(nodeId, res, false);
+        if (fut != null) {
+            if (fut instanceof GridNearAtomicSingleUpdateFuture)
+                ((GridNearAtomicSingleUpdateFuture)fut).onResult(nodeId, res, false);
+            else
+                ((GridNearAtomicUpdateFuture)fut).onResult(nodeId, res, false);
+        }
         else
             U.warn(log, "Failed to find near update future for update response (will ignore) " +
                 "[nodeId=" + nodeId + ", res=" + res + ']');

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
index 9f52658..4721d6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
@@ -212,11 +212,6 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
         return null;
     }
 
-    /** {@inheritDoc} */
-    @Override public Collection<KeyCacheObject> keys() {
-        return keys;
-    }
-
     /**
      * @param entry Entry to map.
      * @param val Value to write.

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
new file mode 100644
index 0000000..7f52299
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht.atomic;
+
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
+import org.apache.ignite.internal.processors.cache.GridCacheAtomicFuture;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheMvccManager;
+import org.apache.ignite.internal.processors.cache.GridCacheOperation;
+import org.apache.ignite.internal.processors.cache.GridCacheReturn;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.expiry.ExpiryPolicy;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_ASYNC;
+
+/**
+ * Base for near atomic update futures.
+ */
+public abstract class GridNearAtomicAbstractUpdateFuture extends GridFutureAdapter<Object>
+    implements GridCacheAtomicFuture<Object> {
+    /** Logger reference. */
+    private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
+
+    /** Logger. */
+    protected static IgniteLogger log;
+
+    /** Cache context. */
+    protected final GridCacheContext cctx;
+
+    /** Cache. */
+    protected final GridDhtAtomicCache cache;
+
+    /** Write synchronization mode. */
+    protected final CacheWriteSynchronizationMode syncMode;
+
+    /** Update operation. */
+    protected final GridCacheOperation op;
+
+    /** Optional arguments for entry processor. */
+    protected final Object[] invokeArgs;
+
+    /** Return value require flag. */
+    protected final boolean retval;
+
+    /** Raw return value flag. */
+    protected final boolean rawRetval;
+
+    /** Expiry policy. */
+    protected final ExpiryPolicy expiryPlc;
+
+    /** Optional filter. */
+    protected final CacheEntryPredicate[] filter;
+
+    /** Subject ID. */
+    protected final UUID subjId;
+
+    /** Task name hash. */
+    protected final int taskNameHash;
+
+    /** Skip store flag. */
+    protected final boolean skipStore;
+
+    /** Keep binary flag. */
+    protected final boolean keepBinary;
+
+    /** Wait for topology future flag. */
+    protected final boolean waitTopFut;
+
+    /** Near cache flag. */
+    protected final boolean nearEnabled;
+
+    /** Mutex to synchronize state updates. */
+    protected final Object mux = new Object();
+
+    /** Topology locked flag. Set if atomic update is performed inside a TX or explicit lock. */
+    protected boolean topLocked;
+
+    /** Remap count. */
+    protected int remapCnt;
+
+    /** Current topology version. */
+    protected AffinityTopologyVersion topVer = AffinityTopologyVersion.ZERO;
+
+    /** */
+    protected GridCacheVersion updVer;
+
+    /** Topology version when got mapping error. */
+    protected AffinityTopologyVersion mapErrTopVer;
+
+    /** */
+    protected int resCnt;
+
+    /** Error. */
+    protected CachePartialUpdateCheckedException err;
+
+    /** Future ID. */
+    protected GridCacheVersion futVer;
+
+    /** Completion future for a particular topology version. */
+    protected GridFutureAdapter<Void> topCompleteFut;
+
+    /** Operation result. */
+    protected GridCacheReturn opRes;
+
+    /**
+     * Constructor.
+     *
+     * @param cctx Cache context.
+     * @param cache Cache.
+     * @param syncMode Synchronization mode.
+     * @param op Operation.
+     * @param invokeArgs Invoke arguments.
+     * @param retval Return value flag.
+     * @param rawRetval Raw return value flag.
+     * @param expiryPlc Expiry policy.
+     * @param filter Filter.
+     * @param subjId Subject ID.
+     * @param taskNameHash Task name hash.
+     * @param skipStore Skip store flag.
+     * @param keepBinary Keep binary flag.
+     * @param remapCnt Remap count.
+     * @param waitTopFut Wait topology future flag.
+     */
+    protected GridNearAtomicAbstractUpdateFuture(
+        GridCacheContext cctx,
+        GridDhtAtomicCache cache,
+        CacheWriteSynchronizationMode syncMode,
+        GridCacheOperation op,
+        @Nullable Object[] invokeArgs,
+        boolean retval,
+        boolean rawRetval,
+        @Nullable ExpiryPolicy expiryPlc,
+        CacheEntryPredicate[] filter,
+        UUID subjId,
+        int taskNameHash,
+        boolean skipStore,
+        boolean keepBinary,
+        int remapCnt,
+        boolean waitTopFut
+    ) {
+        if (log == null)
+            log = U.logger(cctx.kernalContext(), logRef, GridFutureAdapter.class);
+
+        this.cctx = cctx;
+        this.cache = cache;
+        this.syncMode = syncMode;
+        this.op = op;
+        this.invokeArgs = invokeArgs;
+        this.retval = retval;
+        this.rawRetval = rawRetval;
+        this.expiryPlc = expiryPlc;
+        this.filter = filter;
+        this.subjId = subjId;
+        this.taskNameHash = taskNameHash;
+        this.skipStore = skipStore;
+        this.keepBinary = keepBinary;
+        this.waitTopFut = waitTopFut;
+
+        nearEnabled = CU.isNearEnabled(cctx);
+
+        if (!waitTopFut)
+            remapCnt = 1;
+
+        this.remapCnt = remapCnt;
+    }
+
+    /**
+     * Performs future mapping.
+     */
+    public void map() {
+        AffinityTopologyVersion topVer = cctx.shared().lockedTopologyVersion(null);
+
+        if (topVer == null)
+            mapOnTopology();
+        else {
+            topLocked = true;
+
+            // Cannot remap.
+            remapCnt = 1;
+
+            map(topVer);
+        }
+    }
+
+    /**
+     * @param topVer Topology version.
+     */
+    protected abstract void map(AffinityTopologyVersion topVer);
+
+    /**
+     * Maps future on ready topology.
+     */
+    protected abstract void mapOnTopology();
+
+    /** {@inheritDoc} */
+    @Override public IgniteUuid futureId() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean trackable() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void markNotTrackable() {
+        // No-op.
+    }
+
+    /**
+     * @return {@code True} future is stored by {@link GridCacheMvccManager#addAtomicFuture}.
+     */
+    protected boolean storeFuture() {
+        return cctx.config().getAtomicWriteOrderMode() == CLOCK || syncMode != FULL_ASYNC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
new file mode 100644
index 0000000..abfc5c9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFuture.java
@@ -0,0 +1,645 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht.atomic;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheOperation;
+import org.apache.ignite.internal.processors.cache.GridCacheReturn;
+import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache;
+import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.CI1;
+import org.apache.ignite.internal.util.typedef.CI2;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import javax.cache.expiry.ExpiryPolicy;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_ASYNC;
+import static org.apache.ignite.internal.processors.cache.GridCacheOperation.TRANSFORM;
+
+/**
+ * DHT atomic cache near update future.
+ */
+public class GridNearAtomicSingleUpdateFuture extends GridNearAtomicAbstractUpdateFuture {
+    /** Keys */
+    private Object key;
+
+    /** Values. */
+    @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
+    private Object val;
+
+    /** Not null is operation is mapped to single node. */
+    private GridNearAtomicUpdateRequest req;
+
+    /**
+     * @param cctx Cache context.
+     * @param cache Cache instance.
+     * @param syncMode Write synchronization mode.
+     * @param op Update operation.
+     * @param key Keys to update.
+     * @param val Values or transform closure.
+     * @param invokeArgs Optional arguments for entry processor.
+     * @param retval Return value require flag.
+     * @param rawRetval {@code True} if should return {@code GridCacheReturn} as future result.
+     * @param expiryPlc Expiry policy explicitly specified for cache operation.
+     * @param filter Entry filter.
+     * @param subjId Subject ID.
+     * @param taskNameHash Task name hash code.
+     * @param skipStore Skip store flag.
+     * @param keepBinary Keep binary flag.
+     * @param remapCnt Maximum number of retries.
+     * @param waitTopFut If {@code false} does not wait for affinity change future.
+     */
+    public GridNearAtomicSingleUpdateFuture(
+        GridCacheContext cctx,
+        GridDhtAtomicCache cache,
+        CacheWriteSynchronizationMode syncMode,
+        GridCacheOperation op,
+        Object key,
+        @Nullable Object val,
+        @Nullable Object[] invokeArgs,
+        final boolean retval,
+        final boolean rawRetval,
+        @Nullable ExpiryPolicy expiryPlc,
+        final CacheEntryPredicate[] filter,
+        UUID subjId,
+        int taskNameHash,
+        boolean skipStore,
+        boolean keepBinary,
+        int remapCnt,
+        boolean waitTopFut
+    ) {
+        super(cctx, cache, syncMode, op, invokeArgs, retval, rawRetval, expiryPlc, filter, subjId, taskNameHash,
+            skipStore, keepBinary, remapCnt, waitTopFut);
+
+        assert subjId != null;
+
+        this.key = key;
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheVersion version() {
+        synchronized (mux) {
+            return futVer;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onNodeLeft(UUID nodeId) {
+        GridNearAtomicUpdateResponse res = null;
+
+        synchronized (mux) {
+            GridNearAtomicUpdateRequest req = this.req != null && this.req.nodeId().equals(nodeId) ?
+                this.req : null;
+
+            if (req != null && req.response() == null) {
+                res = new GridNearAtomicUpdateResponse(cctx.cacheId(),
+                    nodeId,
+                    req.futureVersion(),
+                    cctx.deploymentEnabled());
+
+                ClusterTopologyCheckedException e = new ClusterTopologyCheckedException("Primary node left grid " +
+                    "before response is received: " + nodeId);
+
+                e.retryReadyFuture(cctx.shared().nextAffinityReadyFuture(req.topologyVersion()));
+
+                res.addFailedKeys(req.keys(), e);
+            }
+        }
+
+        if (res != null)
+            onResult(nodeId, res, true);
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Void> completeFuture(AffinityTopologyVersion topVer) {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("ConstantConditions")
+    @Override public boolean onDone(@Nullable Object res, @Nullable Throwable err) {
+        assert res == null || res instanceof GridCacheReturn;
+
+        GridCacheReturn ret = (GridCacheReturn)res;
+
+        Object retval =
+            res == null ? null : rawRetval ? ret : (this.retval || op == TRANSFORM) ?
+                cctx.unwrapBinaryIfNeeded(ret.value(), keepBinary) : ret.success();
+
+        if (op == TRANSFORM && retval == null)
+            retval = Collections.emptyMap();
+
+        if (super.onDone(retval, err)) {
+            GridCacheVersion futVer = onFutureDone();
+
+            if (futVer != null)
+                cctx.mvcc().removeAtomicFuture(futVer);
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Response callback.
+     *
+     * @param nodeId Node ID.
+     * @param res Update response.
+     * @param nodeErr {@code True} if response was created on node failure.
+     */
+    @SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"})
+    public void onResult(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
+        GridNearAtomicUpdateRequest req;
+
+        AffinityTopologyVersion remapTopVer = null;
+
+        GridCacheReturn opRes0 = null;
+        CachePartialUpdateCheckedException err0 = null;
+
+        GridFutureAdapter<?> fut0 = null;
+
+        synchronized (mux) {
+            if (!res.futureVersion().equals(futVer))
+                return;
+
+            if (!this.req.nodeId().equals(nodeId))
+                return;
+
+            req = this.req;
+
+            this.req = null;
+
+            boolean remapKey = !F.isEmpty(res.remapKeys());
+
+            if (remapKey) {
+                if (mapErrTopVer == null || mapErrTopVer.compareTo(req.topologyVersion()) < 0)
+                    mapErrTopVer = req.topologyVersion();
+            }
+            else if (res.error() != null) {
+                if (res.failedKeys() != null) {
+                    if (err == null)
+                        err = new CachePartialUpdateCheckedException(
+                            "Failed to update keys (retry update if possible).");
+
+                    Collection<Object> keys = new ArrayList<>(res.failedKeys().size());
+
+                    for (KeyCacheObject key : res.failedKeys())
+                        keys.add(cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary, false));
+
+                    err.add(keys, res.error(), req.topologyVersion());
+                }
+            }
+            else {
+                if (!req.fastMap() || req.hasPrimary()) {
+                    GridCacheReturn ret = res.returnValue();
+
+                    if (op == TRANSFORM) {
+                        if (ret != null) {
+                            assert ret.value() == null || ret.value() instanceof Map : ret.value();
+
+                            if (ret.value() != null) {
+                                if (opRes != null)
+                                    opRes.mergeEntryProcessResults(ret);
+                                else
+                                    opRes = ret;
+                            }
+                        }
+                    }
+                    else
+                        opRes = ret;
+                }
+            }
+
+            if (remapKey) {
+                assert mapErrTopVer != null;
+
+                remapTopVer = cctx.shared().exchange().topologyVersion();
+            }
+            else {
+                if (err != null &&
+                    X.hasCause(err, CachePartialUpdateCheckedException.class) &&
+                    X.hasCause(err, ClusterTopologyCheckedException.class) &&
+                    storeFuture() &&
+                    --remapCnt > 0) {
+                    ClusterTopologyCheckedException topErr =
+                        X.cause(err, ClusterTopologyCheckedException.class);
+
+                    if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
+                        CachePartialUpdateCheckedException cause =
+                            X.cause(err, CachePartialUpdateCheckedException.class);
+
+                        assert cause != null && cause.topologyVersion() != null : err;
+
+                        remapTopVer =
+                            new AffinityTopologyVersion(cause.topologyVersion().topologyVersion() + 1);
+
+                        err = null;
+                        updVer = null;
+                    }
+                }
+            }
+
+            if (remapTopVer == null) {
+                err0 = err;
+                opRes0 = opRes;
+            }
+            else {
+                fut0 = topCompleteFut;
+
+                topCompleteFut = null;
+
+                cctx.mvcc().removeAtomicFuture(futVer);
+
+                futVer = null;
+                topVer = AffinityTopologyVersion.ZERO;
+            }
+        }
+
+        if (res.error() != null && res.failedKeys() == null) {
+            onDone(res.error());
+
+            return;
+        }
+
+        if (nearEnabled && !nodeErr)
+            updateNear(req, res);
+
+        if (remapTopVer != null) {
+            if (fut0 != null)
+                fut0.onDone();
+
+            if (!waitTopFut) {
+                onDone(new GridCacheTryPutFailedException());
+
+                return;
+            }
+
+            if (topLocked) {
+                CachePartialUpdateCheckedException e =
+                    new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
+
+                ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException(
+                    "Failed to update keys, topology changed while execute atomic update inside transaction.");
+
+                cause.retryReadyFuture(cctx.affinity().affinityReadyFuture(remapTopVer));
+
+                e.add(Collections.singleton(cctx.toCacheKeyObject(key)), cause);
+
+                onDone(e);
+
+                return;
+            }
+
+            IgniteInternalFuture<AffinityTopologyVersion> fut =
+                cctx.shared().exchange().affinityReadyFuture(remapTopVer);
+
+            if (fut == null)
+                fut = new GridFinishedFuture<>(remapTopVer);
+
+            fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
+                @Override public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
+                    cctx.kernalContext().closure().runLocalSafe(new Runnable() {
+                        @Override public void run() {
+                            try {
+                                AffinityTopologyVersion topVer = fut.get();
+
+                                map(topVer);
+                            }
+                            catch (IgniteCheckedException e) {
+                                onDone(e);
+                            }
+                        }
+                    });
+                }
+            });
+
+            return;
+        }
+
+        onDone(opRes0, err0);
+    }
+
+    /**
+     * Updates near cache.
+     *
+     * @param req Update request.
+     * @param res Update response.
+     */
+    private void updateNear(GridNearAtomicUpdateRequest req, GridNearAtomicUpdateResponse res) {
+        assert nearEnabled;
+
+        if (res.remapKeys() != null || !req.hasPrimary())
+            return;
+
+        GridNearAtomicCache near = (GridNearAtomicCache)cctx.dht().near();
+
+        near.processNearAtomicUpdateResponse(req, res);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void mapOnTopology() {
+        cache.topology().readLock();
+
+        AffinityTopologyVersion topVer = null;
+
+        try {
+            if (cache.topology().stopping()) {
+                onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " +
+                    cache.name()));
+
+                return;
+            }
+
+            GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
+
+            if (fut.isDone()) {
+                Throwable err = fut.validateCache(cctx);
+
+                if (err != null) {
+                    onDone(err);
+
+                    return;
+                }
+
+                topVer = fut.topologyVersion();
+            }
+            else {
+                if (waitTopFut) {
+                    assert !topLocked : this;
+
+                    fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
+                        @Override public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
+                            cctx.kernalContext().closure().runLocalSafe(new Runnable() {
+                                @Override public void run() {
+                                    mapOnTopology();
+                                }
+                            });
+                        }
+                    });
+                }
+                else
+                    onDone(new GridCacheTryPutFailedException());
+
+                return;
+            }
+        }
+        finally {
+            cache.topology().readUnlock();
+        }
+
+        map(topVer);
+    }
+
+    /**
+     * Maps future to single node.
+     *
+     * @param nodeId Node ID.
+     * @param req Request.
+     */
+    private void mapSingle(UUID nodeId, GridNearAtomicUpdateRequest req) {
+        if (cctx.localNodeId().equals(nodeId)) {
+            cache.updateAllAsyncInternal(nodeId, req,
+                new CI2<GridNearAtomicUpdateRequest, GridNearAtomicUpdateResponse>() {
+                    @Override public void apply(GridNearAtomicUpdateRequest req, GridNearAtomicUpdateResponse res) {
+                        onResult(res.nodeId(), res, false);
+                    }
+                });
+        }
+        else {
+            try {
+                if (log.isDebugEnabled())
+                    log.debug("Sending near atomic update request [nodeId=" + req.nodeId() + ", req=" + req + ']');
+
+                cctx.io().send(req.nodeId(), req, cctx.ioPolicy());
+
+                if (syncMode == FULL_ASYNC)
+                    onDone(new GridCacheReturn(cctx, true, true, null, true));
+            }
+            catch (IgniteCheckedException e) {
+                onSendError(req, e);
+            }
+        }
+    }
+
+    /**
+     * @param req Request.
+     * @param e Error.
+     */
+    void onSendError(GridNearAtomicUpdateRequest req, IgniteCheckedException e) {
+        synchronized (mux) {
+            GridNearAtomicUpdateResponse res = new GridNearAtomicUpdateResponse(cctx.cacheId(),
+                req.nodeId(),
+                req.futureVersion(),
+                cctx.deploymentEnabled());
+
+            res.addFailedKeys(req.keys(), e);
+
+            onResult(req.nodeId(), res, true);
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void map(AffinityTopologyVersion topVer) {
+        Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
+
+        if (F.isEmpty(topNodes)) {
+            onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes " +
+                "left the grid)."));
+
+            return;
+        }
+
+        Exception err = null;
+        GridNearAtomicUpdateRequest singleReq0 = null;
+
+        GridCacheVersion futVer = cctx.versions().next(topVer);
+
+        GridCacheVersion updVer;
+
+        // Assign version on near node in CLOCK ordering mode even if fastMap is false.
+        if (cctx.config().getAtomicWriteOrderMode() == CLOCK) {
+            updVer = this.updVer;
+
+            if (updVer == null) {
+                updVer = cctx.versions().next(topVer);
+
+                if (log.isDebugEnabled())
+                    log.debug("Assigned fast-map version for update on near node: " + updVer);
+            }
+        }
+        else
+            updVer = null;
+
+        try {
+            singleReq0 = mapSingleUpdate(topVer, futVer, updVer);
+
+            synchronized (mux) {
+                assert this.futVer == null : this;
+                assert this.topVer == AffinityTopologyVersion.ZERO : this;
+
+                this.topVer = topVer;
+                this.updVer = updVer;
+                this.futVer = futVer;
+
+                resCnt = 0;
+
+                req = singleReq0;
+            }
+        }
+        catch (Exception e) {
+            err = e;
+        }
+
+        if (err != null) {
+            onDone(err);
+
+            return;
+        }
+
+        if (storeFuture()) {
+            if (!cctx.mvcc().addAtomicFuture(futVer, this)) {
+                assert isDone() : this;
+
+                return;
+            }
+        }
+
+        // Optimize mapping for single key.
+        mapSingle(singleReq0.nodeId(), singleReq0);
+    }
+
+    /**
+     * @return Future version.
+     */
+    GridCacheVersion onFutureDone() {
+        GridCacheVersion ver0;
+
+        GridFutureAdapter<Void> fut0;
+
+        synchronized (mux) {
+            fut0 = topCompleteFut;
+
+            topCompleteFut = null;
+
+            ver0 = futVer;
+
+            futVer = null;
+        }
+
+        if (fut0 != null)
+            fut0.onDone();
+
+        return ver0;
+    }
+
+    /**
+     * @param topVer Topology version.
+     * @param futVer Future version.
+     * @param updVer Update version.
+     * @return Request.
+     * @throws Exception If failed.
+     */
+    private GridNearAtomicUpdateRequest mapSingleUpdate(AffinityTopologyVersion topVer,
+        GridCacheVersion futVer,
+        @Nullable GridCacheVersion updVer) throws Exception {
+        if (key == null)
+            throw new NullPointerException("Null key.");
+
+        Object val = this.val;
+
+        if (val == null && op != GridCacheOperation.DELETE)
+            throw new NullPointerException("Null value.");
+
+        KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
+
+        if (op != TRANSFORM)
+            val = cctx.toCacheObject(val);
+
+        ClusterNode primary = cctx.affinity().primary(cacheKey, topVer);
+
+        if (primary == null)
+            throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes " +
+                "left the grid).");
+
+        GridNearAtomicUpdateRequest req = new GridNearAtomicUpdateRequest(
+            cctx.cacheId(),
+            primary.id(),
+            futVer,
+            false,
+            updVer,
+            topVer,
+            topLocked,
+            syncMode,
+            op,
+            retval,
+            expiryPlc,
+            invokeArgs,
+            filter,
+            subjId,
+            taskNameHash,
+            skipStore,
+            keepBinary,
+            cctx.kernalContext().clientNode(),
+            cctx.deploymentEnabled(),
+            1);
+
+        req.addUpdateEntry(cacheKey,
+            val,
+            CU.TTL_NOT_CHANGED,
+            CU.EXPIRE_TIME_CALCULATE,
+            null,
+            true);
+
+        return req;
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        synchronized (mux) {
+            return S.toString(GridNearAtomicSingleUpdateFuture.class, this, super.toString());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0d077613/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index 9955df7..edebd8c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -23,10 +23,8 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.atomic.AtomicReference;
 import javax.cache.expiry.ExpiryPolicy;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
@@ -36,9 +34,7 @@ import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
-import org.apache.ignite.internal.processors.cache.GridCacheAtomicFuture;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheMvccManager;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.GridCacheReturn;
 import org.apache.ignite.internal.processors.cache.GridCacheTryPutFailedException;
@@ -57,34 +53,19 @@ import org.apache.ignite.internal.util.typedef.X;
 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.IgniteUuid;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_ASYNC;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
 import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
 import static org.apache.ignite.internal.processors.cache.GridCacheOperation.TRANSFORM;
 
 /**
  * DHT atomic cache near update future.
  */
-public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
-    implements GridCacheAtomicFuture<Object>{
-    /** Logger reference. */
-    private static final AtomicReference<IgniteLogger> logRef = new AtomicReference<>();
-
-    /** Logger. */
-    protected static IgniteLogger log;
-
-    /** Cache context. */
-    private final GridCacheContext cctx;
-
-    /** Cache. */
-    private GridDhtAtomicCache cache;
-
-    /** Update operation. */
-    private final GridCacheOperation op;
+public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFuture {
+    /** Fast map flag. */
+    private final boolean fastMap;
 
     /** Keys */
     private Collection<?> keys;
@@ -93,9 +74,6 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
     private Collection<?> vals;
 
-    /** Optional arguments for entry processor. */
-    private Object[] invokeArgs;
-
     /** Conflict put values. */
     @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
     private Collection<GridCacheDrInfo> conflictPutVals;
@@ -104,85 +82,16 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
     private Collection<GridCacheVersion> conflictRmvVals;
 
-    /** Return value require flag. */
-    private final boolean retval;
-
-    /** Expiry policy. */
-    private final ExpiryPolicy expiryPlc;
-
-    /** Optional filter. */
-    private final CacheEntryPredicate[] filter;
-
-    /** Write synchronization mode. */
-    private final CacheWriteSynchronizationMode syncMode;
-
-    /** Raw return value flag. */
-    private final boolean rawRetval;
-
-    /** Fast map flag. */
-    private final boolean fastMap;
-
-    /** Near cache flag. */
-    private final boolean nearEnabled;
-
-    /** Subject ID. */
-    private final UUID subjId;
-
-    /** Task name hash. */
-    private final int taskNameHash;
-
-    /** Topology locked flag. Set if atomic update is performed inside a TX or explicit lock. */
-    private boolean topLocked;
-
-    /** Skip store flag. */
-    private final boolean skipStore;
-
-    /** */
-    private final boolean keepBinary;
-
-    /** Wait for topology future flag. */
-    private final boolean waitTopFut;
-
-    /** Remap count. */
-    private int remapCnt;
-
-    /** Mutex to synchronize state updates. */
-    private final Object mux = new Object();
-
-    /** Current topology version. */
-    private AffinityTopologyVersion topVer = AffinityTopologyVersion.ZERO;
-
-    /** */
-    private GridCacheVersion updVer;
-
-    /** Topology version when got mapping error. */
-    private AffinityTopologyVersion mapErrTopVer;
-
     /** Mappings if operations is mapped to more than one node. */
     @GridToStringInclude
     private Map<UUID, GridNearAtomicUpdateRequest> mappings;
 
-    /** */
-    private int resCnt;
-
-    /** Error. */
-    private CachePartialUpdateCheckedException err;
-
-    /** Future ID. */
-    private GridCacheVersion futVer;
-
-    /** Completion future for a particular topology version. */
-    private GridFutureAdapter<Void> topCompleteFut;
-
     /** Keys to remap. */
     private Collection<KeyCacheObject> remapKeys;
 
     /** Not null is operation is mapped to single node. */
     private GridNearAtomicUpdateRequest singleReq;
 
-    /** Operation result. */
-    private GridCacheReturn opRes;
-
     /**
      * @param cctx Cache context.
      * @param cache Cache instance.
@@ -225,49 +134,20 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
         int remapCnt,
         boolean waitTopFut
     ) {
-        this.rawRetval = rawRetval;
+        super(cctx, cache, syncMode, op, invokeArgs, retval, rawRetval, expiryPlc, filter, subjId, taskNameHash,
+            skipStore, keepBinary, remapCnt, waitTopFut);
 
         assert vals == null || vals.size() == keys.size();
         assert conflictPutVals == null || conflictPutVals.size() == keys.size();
         assert conflictRmvVals == null || conflictRmvVals.size() == keys.size();
         assert subjId != null;
 
-        this.cctx = cctx;
-        this.cache = cache;
-        this.syncMode = syncMode;
-        this.op = op;
         this.keys = keys;
         this.vals = vals;
-        this.invokeArgs = invokeArgs;
         this.conflictPutVals = conflictPutVals;
         this.conflictRmvVals = conflictRmvVals;
-        this.retval = retval;
-        this.expiryPlc = expiryPlc;
-        this.filter = filter;
-        this.subjId = subjId;
-        this.taskNameHash = taskNameHash;
-        this.skipStore = skipStore;
-        this.keepBinary = keepBinary;
-        this.waitTopFut = waitTopFut;
-
-        if (log == null)
-            log = U.logger(cctx.kernalContext(), logRef, GridFutureAdapter.class);
 
-        fastMap = F.isEmpty(filter) && op != TRANSFORM && cctx.config().getWriteSynchronizationMode() == FULL_SYNC &&
-            cctx.config().getAtomicWriteOrderMode() == CLOCK &&
-            !(cctx.writeThrough() && cctx.config().getInterceptor() != null);
-
-        nearEnabled = CU.isNearEnabled(cctx);
-
-        if (!waitTopFut)
-            remapCnt = 1;
-
-        this.remapCnt = remapCnt;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteUuid futureId() {
-        throw new UnsupportedOperationException();
+        fastMap = cache.isFastMap(filter, op);
     }
 
     /** {@inheritDoc} */
@@ -277,19 +157,6 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
         }
     }
 
-    /**
-     * @return {@code True} if this future should block partition map exchange.
-     */
-    private boolean waitForPartitionExchange() {
-        // Wait fast-map near atomic update futures in CLOCK mode.
-        return fastMap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<?> keys() {
-        return keys;
-    }
-
     /** {@inheritDoc} */
     @Override public boolean onNodeLeft(UUID nodeId) {
         GridNearAtomicUpdateResponse res = null;
@@ -324,37 +191,21 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     }
 
     /** {@inheritDoc} */
-    @Override public boolean trackable() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void markNotTrackable() {
-        // No-op.
-    }
-
-    /**
-     * Performs future mapping.
-     */
-    public void map() {
-        AffinityTopologyVersion topVer = cctx.shared().lockedTopologyVersion(null);
-
-        if (topVer == null)
-            mapOnTopology();
-        else {
-            topLocked = true;
-
-            // Cannot remap.
-            remapCnt = 1;
+    @Override public IgniteInternalFuture<Void> completeFuture(AffinityTopologyVersion topVer) {
+        // Wait fast-map near atomic update futures in CLOCK mode.
+        if (fastMap) {
+            GridFutureAdapter<Void> fut;
 
-            map(topVer, null);
-        }
-    }
+            synchronized (mux) {
+                if (this.topVer != AffinityTopologyVersion.ZERO && this.topVer.compareTo(topVer) < 0) {
+                    if (topCompleteFut == null)
+                        topCompleteFut = new GridFutureAdapter<>();
 
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Void> completeFuture(AffinityTopologyVersion topVer) {
-        if (waitForPartitionExchange()) {
-            GridFutureAdapter<Void> fut = completeFuture0(topVer);
+                    fut = topCompleteFut;
+                }
+                else
+                    fut = null;
+            }
 
             if (fut != null && isDone()) {
                 fut.onDone();
@@ -454,16 +305,34 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
                     mapErrTopVer = req.topologyVersion();
             }
             else if (res.error() != null) {
-                if (res.failedKeys() != null)
-                    addFailedKeys(res.failedKeys(), req.topologyVersion(), res.error());
+                if (res.failedKeys() != null) {
+                    if (err == null)
+                        err = new CachePartialUpdateCheckedException(
+                            "Failed to update keys (retry update if possible).");
+
+                    Collection<Object> keys = new ArrayList<>(res.failedKeys().size());
+
+                    for (KeyCacheObject key : res.failedKeys())
+                        keys.add(cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary, false));
+
+                    err.add(keys, res.error(), req.topologyVersion());
+                }
             }
             else {
                 if (!req.fastMap() || req.hasPrimary()) {
                     GridCacheReturn ret = res.returnValue();
 
                     if (op == TRANSFORM) {
-                        if (ret != null)
-                            addInvokeResults(ret);
+                        if (ret != null) {
+                            assert ret.value() == null || ret.value() instanceof Map : ret.value();
+
+                            if (ret.value() != null) {
+                                if (opRes != null)
+                                    opRes.mergeEntryProcessResults(ret);
+                                else
+                                    opRes = ret;
+                            }
+                        }
                     }
                     else
                         opRes = ret;
@@ -620,10 +489,8 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
         near.processNearAtomicUpdateResponse(req, res);
     }
 
-    /**
-     * Maps future on ready topology.
-     */
-    private void mapOnTopology() {
+    /** {@inheritDoc} */
+    @Override protected void mapOnTopology() {
         cache.topology().readLock();
 
         AffinityTopologyVersion topVer = null;
@@ -677,35 +544,6 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     }
 
     /**
-     * @return {@code True} future is stored by {@link GridCacheMvccManager#addAtomicFuture}.
-     */
-    private boolean storeFuture() {
-        return cctx.config().getAtomicWriteOrderMode() == CLOCK || syncMode != FULL_ASYNC;
-    }
-
-    /**
-     * Maps key to nodes. If filters are absent and operation is not TRANSFORM, then we can assign version on near
-     * node and send updates in parallel to all participating nodes.
-     *
-     * @param key Key to map.
-     * @param topVer Topology version to map.
-     * @param fastMap Flag indicating whether mapping is performed for fast-circuit update.
-     * @return Collection of nodes to which key is mapped.
-     */
-    private Collection<ClusterNode> mapKey(
-        KeyCacheObject key,
-        AffinityTopologyVersion topVer,
-        boolean fastMap
-    ) {
-        GridCacheAffinityManager affMgr = cctx.affinity();
-
-        // If we can send updates in parallel - do it.
-        return fastMap ?
-            cctx.topology().nodes(affMgr.partition(key), topVer) :
-            Collections.singletonList(affMgr.primary(key, topVer));
-    }
-
-    /**
      * Maps future to single node.
      *
      * @param nodeId Node ID.
@@ -797,6 +635,11 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
         }
     }
 
+    /** {@inheritDoc} */
+    protected void map(AffinityTopologyVersion topVer) {
+        map(topVer, null);
+    }
+
     /**
      * @param topVer Topology version.
      * @param remapKeys Keys to remap.
@@ -914,26 +757,6 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     }
 
     /**
-     * @param topVer Topology version.
-     * @return Future.
-     */
-    @Nullable GridFutureAdapter<Void> completeFuture0(AffinityTopologyVersion topVer) {
-        synchronized (mux) {
-            if (this.topVer == AffinityTopologyVersion.ZERO)
-                return null;
-
-            if (this.topVer.compareTo(topVer) < 0) {
-                if (topCompleteFut == null)
-                    topCompleteFut = new GridFutureAdapter<>();
-
-                return topCompleteFut;
-            }
-
-            return null;
-        }
-    }
-
-    /**
      * @return Future version.
      */
     GridCacheVersion onFutureDone() {
@@ -1039,7 +862,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
             if (op != TRANSFORM)
                 val = cctx.toCacheObject(val);
 
-            Collection<ClusterNode> affNodes = mapKey(cacheKey, topVer, fastMap);
+            Collection<ClusterNode> affNodes = mapKey(cacheKey, topVer);
 
             if (affNodes.isEmpty())
                 throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
@@ -1190,41 +1013,19 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
     }
 
     /**
-     * @param ret Result from single node.
-     */
-    @SuppressWarnings("unchecked")
-    private void addInvokeResults(GridCacheReturn ret) {
-        assert op == TRANSFORM : op;
-        assert ret.value() == null || ret.value() instanceof Map : ret.value();
-
-        if (ret.value() != null) {
-            if (opRes != null)
-                opRes.mergeEntryProcessResults(ret);
-            else
-                opRes = ret;
-        }
-    }
-
-    /**
-     * @param failedKeys Failed keys.
-     * @param topVer Topology version for failed update.
-     * @param err Error cause.
+     * Maps key to nodes. If filters are absent and operation is not TRANSFORM, then we can assign version on near
+     * node and send updates in parallel to all participating nodes.
+     *
+     * @param key Key to map.
+     * @param topVer Topology version to map.
+     * @return Collection of nodes to which key is mapped.
      */
-    private void addFailedKeys(Collection<KeyCacheObject> failedKeys,
-        AffinityTopologyVersion topVer,
-        Throwable err) {
-        CachePartialUpdateCheckedException err0 = this.err;
-
-        if (err0 == null)
-            err0 = this.err =
-                new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
-
-        Collection<Object> keys = new ArrayList<>(failedKeys.size());
-
-        for (KeyCacheObject key : failedKeys)
-            keys.add(cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary, false));
+    private Collection<ClusterNode> mapKey(KeyCacheObject key, AffinityTopologyVersion topVer) {
+        GridCacheAffinityManager affMgr = cctx.affinity();
 
-        err0.add(keys, err, topVer);
+        // If we can send updates in parallel - do it.
+        return fastMap ? cctx.topology().nodes(affMgr.partition(key), topVer) :
+            Collections.singletonList(affMgr.primary(key, topVer));
     }
 
     /** {@inheritDoc} */


[36/50] [abbrv] ignite git commit: IGNITE-2948 Optimize usage of GridCacheConcurrentMap: fixed compatibility (broken in commit 3be3d16)

Posted by sh...@apache.org.
IGNITE-2948 Optimize usage of GridCacheConcurrentMap: fixed compatibility (broken in commit 3be3d16)


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

Branch: refs/heads/ignite-2788
Commit: 8873d43487626f9e58d52139d719378556ae226e
Parents: 03b776f
Author: sboikov <sb...@gridgain.com>
Authored: Thu Apr 28 10:58:59 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../apache/ignite/internal/direct/DirectMessageReader.java  | 5 +++++
 .../cache/distributed/near/GridNearSingleGetRequest.java    | 4 +++-
 .../processors/cache/transactions/IgniteTxEntry.java        | 4 ++--
 .../plugin/extensions/communication/MessageReader.java      | 9 +++++++++
 4 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8873d434/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
index 10bc7e2..7d3644f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
@@ -113,6 +113,11 @@ public class DirectMessageReader implements MessageReader {
     }
 
     /** {@inheritDoc} */
+    @Override public int readInt(String name, int dflt) {
+        return readInt(name);
+    }
+
+    /** {@inheritDoc} */
     @Override public long readLong(String name) {
         DirectByteBufferStream stream = state.item().stream;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/8873d434/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
index 62d37af..7fc2b1e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.distributed.near;
 import java.nio.ByteBuffer;
 import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.IgniteCodeGeneratingFail;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDeployable;
@@ -37,6 +38,7 @@ import static org.apache.ignite.internal.processors.cache.GridCacheUtils.SKIP_ST
 /**
  *
  */
+@IgniteCodeGeneratingFail // partId read should not be generated by MessageCodeGenerator.
 public class GridNearSingleGetRequest extends GridCacheMessage implements GridCacheDeployable {
     /** */
     private static final long serialVersionUID = 0L;
@@ -312,7 +314,7 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
                 reader.incrementState();
 
             case 10:
-                partId = reader.readInt("partId");
+                partId = reader.readInt("partId", -1);
 
                 if (!reader.isLastRead())
                     return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/8873d434/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
index 4d8139f..45a3fff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
@@ -65,7 +65,7 @@ import static org.apache.ignite.internal.processors.cache.GridCacheUtils.SKIP_ST
  * {@link #equals(Object)} method, as transaction entries should use referential
  * equality.
  */
-@IgniteCodeGeneratingFail // Field filters should not be generated by MessageCodeGenerator.
+@IgniteCodeGeneratingFail // Field filters, partId should not be generated by MessageCodeGenerator.
 public class IgniteTxEntry implements GridPeerDeployAware, Message {
     /** */
     private static final long serialVersionUID = 0L;
@@ -1162,7 +1162,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
                 reader.incrementState();
 
             case 12:
-                partId = reader.readInt("partId");
+                partId = reader.readInt("partId", -1);
 
                 if (!reader.isLastRead())
                     return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/8873d434/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
index 502c69f..0502042 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
@@ -85,6 +85,15 @@ public interface MessageReader {
     public int readInt(String name);
 
     /**
+     * Reads {@code int} value.
+     *
+     * @param name Field name.
+     * @param dflt Default value if field not found.
+     * @return {@code int} value.
+     */
+    public int readInt(String name, int dflt);
+
+    /**
      * Reads {@code long} value.
      *
      * @param name Field name.


[06/50] [abbrv] ignite git commit: IGNITE-3019 Implement config variations test for IgniteCompute

Posted by sh...@apache.org.
IGNITE-3019 Implement config variations test for IgniteCompute


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

Branch: refs/heads/ignite-2788
Commit: 24b24bf8a8fedac55d41f69ebf75e08975ff1bea
Parents: b674865
Author: sboikov <sb...@gridgain.com>
Authored: Fri Apr 22 16:44:39 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 ...gniteComputeConfigVariationsFullApiTest.java | 2009 ++++++++++++++++++
 .../configvariations/ConfigVariations.java      |    2 +-
 .../IgniteConfigVariationsAbstractTest.java     |   43 +-
 ...teBasicConfigVariationsFullApiTestSuite.java |   72 +
 4 files changed, 2124 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/24b24bf8/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeConfigVariationsFullApiTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeConfigVariationsFullApiTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeConfigVariationsFullApiTest.java
new file mode 100644
index 0000000..81cdb15
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/compute/IgniteComputeConfigVariationsFullApiTest.java
@@ -0,0 +1,2009 @@
+/*
+ * 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.compute;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskFuture;
+import org.apache.ignite.compute.ComputeTaskSplitAdapter;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteReducer;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.testframework.junits.IgniteConfigVariationsAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Assert;
+
+/**
+ * Full API compute test.
+ */
+@SuppressWarnings("unchecked")
+public class IgniteComputeConfigVariationsFullApiTest extends IgniteConfigVariationsAbstractTest {
+    /** Max job count. */
+    private static final int MAX_JOB_COUNT = 10;
+
+    /** Test cache name. */
+    private static final String CACHE_NAME = "test";
+
+    /** */
+    private static final String STR_VAL = "string value";
+
+    /** */
+    private static final Object[] ARRAY_VAL = {"str0", "str1", "str2"};
+
+    /** Job factories. */
+    private static final JobFactory[] jobFactories = new JobFactory[] {
+        new JobFactory(EchoJob.class),
+        new JobFactory(EchoJobExternalizable.class),
+        new JobFactory(EchoJobBinarylizable.class)
+    };
+
+    /** Closure factories. */
+    private static final Factory[] closureFactories = new Factory[] {
+        new JobFactory(EchoClosure.class),
+        new JobFactory(EchoClosureExternalizable.class),
+        new JobFactory(EchoClosureBinarylizable.class)
+    };
+
+    /** Callable factories. */
+    private static final Factory[] callableFactories = new Factory[] {
+        new JobFactory(EchoCallable.class),
+        new JobFactory(EchoCallableExternalizable.class),
+        new JobFactory(EchoCallableBinarylizable.class)
+    };
+
+    /** Runnable factories. */
+    private static final Factory[] runnableFactories = new Factory[] {
+        new JobFactory(ComputeTestRunnable.class),
+        new JobFactory(ComputeTestRunnableExternalizable.class),
+        new JobFactory(ComputeTestRunnableBinarylizable.class)
+    };
+
+    /**
+     * @param expCnt Expected count.
+     * @param results Results.
+     * @param dataCls Data class.
+     */
+    private static void checkResultsClassCount(final int expCnt, final Collection<Object> results,
+        final Class dataCls) {
+        int cnt = 0;
+
+        for (Object o : results) {
+            if ((o != null) && dataCls.equals(o.getClass()))
+                ++cnt;
+        }
+
+        assertEquals("Count of the result objects' type mismatch (null values are filtered)", expCnt, cnt);
+    }
+
+    /**
+     * @return Expected valid result.
+     */
+    private Collection<Object> createGoldenResults() {
+        Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+        for (int i = 0; i < MAX_JOB_COUNT; ++i)
+            results.add(value(i - 1));
+
+        return results;
+    }
+
+    /**
+     * @param msg Message.
+     * @param exp Expected.
+     * @param act Action.
+     */
+    private <E> void assertCollectionsEquals(String msg, Collection<E> exp, Collection<E> act) {
+        assertEquals(msg + "; Size are different", exp.size(), act.size());
+
+        for (Object o : exp) {
+            if (!act.contains(o)) {
+                error("Expected: " + exp.toString());
+                error("Actual: " + act.toString());
+
+                assertTrue(msg + String.format("; actual collection doesn't contain the object [%s]", o), false);
+            }
+        }
+    }
+
+    /**
+     * The test's wrapper provides variations of the argument data model and user factories. The test is launched {@code
+     * factories.length * DataMode.values().length} times with each datamodel and each factory.
+     *
+     * @param test Test.
+     * @param factories various factories
+     * @throws Exception If failed.
+     */
+    protected void runTest(final Factory[] factories, final ComputeTest test) throws Exception {
+        runInAllDataModes(new TestRunnable() {
+            @Override public void run() throws Exception {
+                for (int i = 0; i < factories.length; i++) {
+                    Factory factory = factories[i];
+
+                    info("Running test with jobs model: " + factory.create().getClass().getSimpleName());
+
+                    if (i != 0)
+                        beforeTest();
+
+                    try {
+                        test.test(factory, grid(testedNodeIdx));
+                    }
+                    finally {
+                        if (i + 1 != factories.length)
+                            afterTest();
+                    }
+                }
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testExecuteTaskClass() throws Exception {
+        runTest(jobFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                // Begin with negative to check 'null' value in the test.
+                final int[] i = {-1};
+
+                List<Object> results = ignite.compute().execute(
+                    TestTask.class,
+                    new T2<>((Factory<ComputeJobAdapter>)factory,
+                        (Factory<Object>)new Factory<Object>() {
+                            @Override public Object create() {
+                                return value(i[0]++);
+                            }
+                        }));
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testExecuteTask() throws Exception {
+        runTest(jobFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                // Begin with negative to check 'null' value in the test.
+                final int[] i = {-1};
+
+                List<Object> results = ignite.compute().execute(new TestTask(),
+                    new T2<>((Factory<ComputeJobAdapter>)factory,
+                        (Factory<Object>)new Factory<Object>() {
+                            @Override public Object create() {
+                                return value(i[0]++);
+                            }
+                        }));
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBroadcastClosure() throws Exception {
+        runTest(closureFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                final Collection<Object> resultsAllNull = ignite.compute()
+                    .broadcast((IgniteClosure<Object, Object>)factory.create(), null);
+
+                assertEquals("Result's size mismatch: job must be run on all server nodes",
+                    gridCount() - clientsCount(), resultsAllNull.size());
+
+                for (Object o : resultsAllNull)
+                    assertNull("All results must be null", o);
+
+                Collection<Object> resultsNotNull = ignite.compute()
+                    .broadcast((IgniteClosure<Object, Object>)factory.create(), value(0));
+
+                checkResultsClassCount(gridCount() - clientsCount(), resultsNotNull, value(0).getClass());
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBroadcastCallable() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                EchoCallable job = (EchoCallable)factory.create();
+                job.setArg(null);
+
+                final Collection<Object> resultsAllNull = ignite.compute()
+                    .broadcast(job);
+
+                assertEquals("Result's size mismatch: job must be run on all server nodes",
+                    gridCount() - clientsCount(), resultsAllNull.size());
+
+                for (Object o : resultsAllNull)
+                    assertNull("All results must be null", o);
+
+                job.setArg(value(0));
+                Collection<Object> resultsNotNull = ignite.compute()
+                    .broadcast(job);
+
+                checkResultsClassCount(gridCount() - clientsCount(), resultsNotNull, value(0).getClass());
+                for (Object o : resultsNotNull)
+                    assertEquals("Invalid broadcast results", value(0), o);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBroadcastRunnable() throws Exception {
+        runTest(runnableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                IgniteRunnable job = (IgniteRunnable)factory.create();
+
+                ignite.compute().broadcast(job);
+                // All checks are inside the run() method of the job.
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRun() throws Exception {
+        runTest(runnableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                IgniteRunnable job = (IgniteRunnable)factory.create();
+
+                ignite.compute().run(job);
+                // All checks are inside the run() method of the job.
+
+                Collection<IgniteRunnable> jobs = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i)
+                    jobs.add((IgniteRunnable)factory.create());
+
+                ignite.compute().run(jobs);
+                // All checks are inside the run() method of the job.
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testApplyAsync() throws Exception {
+        runTest(closureFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                final IgniteCompute comp = ignite.compute().withAsync();
+
+                Collection<ComputeTaskFuture<Object>> futures = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    // value(i - 1): use negative argument of the value method to generate nullong value.
+                    comp.apply((IgniteClosure<Object, Object>)factory.create(), value(i - 1));
+
+                    futures.add(comp.future());
+                }
+
+                // Wait for results.
+                Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (ComputeTaskFuture<Object> future : futures)
+                    results.add(future.get());
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testApplySync() throws Exception {
+        runTest(closureFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    // value(i - 1): use negative argument of the value method to generate nullong value.
+                    results.add(ignite.compute().apply((IgniteClosure<Object, Object>)factory.create(), value(i - 1)));
+                }
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testApplyForCollection() throws Exception {
+        runTest(closureFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<TestObject> params = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    // value(i - 1): use negative argument of the value method to generate nullong value.
+                    // Use type casting to avoid ambiguous for apply(Callable, Object) vs apply(Callable, Collection<Object>).
+                    params.add((TestObject)value(i - 1));
+                }
+
+                Collection<Object> results = ignite.compute()
+                    .apply((IgniteClosure<TestObject, Object>)factory.create(), params);
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testApplyForCollectionWithReducer() throws Exception {
+        runTest(closureFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<Object> params = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    // value(i - 1): use negative argument of the value method to generate nullong value.
+                    params.add(value(i - 1));
+                }
+
+                boolean res = ignite.compute()
+                    .apply((IgniteClosure<Object, Object>)factory.create(), params, new IgniteReducer<Object, Boolean>() {
+
+                        private Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                        @Override public boolean collect(@Nullable Object o) {
+                            results.add(o);
+                            return true;
+                        }
+
+                        @Override public Boolean reduce() {
+                            checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                            assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+                            return true;
+                        }
+                    });
+                assertTrue(res);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCallAsync() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                final IgniteCompute comp = ignite.compute().withAsync();
+
+                Collection<ComputeTaskFuture<Object>> futures = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    EchoCallable job = (EchoCallable)factory.create();
+                    job.setArg(value(i - 1));
+
+                    comp.call(job);
+                    futures.add(comp.future());
+                }
+
+                // Wait for results.
+                Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+                for (ComputeTaskFuture<Object> future : futures)
+                    results.add(future.get());
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCallSync() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    EchoCallable job = (EchoCallable)factory.create();
+                    job.setArg(value(i - 1));
+                    results.add(ignite.compute().call(job));
+                }
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCallCollection() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    EchoCallable job = (EchoCallable)factory.create();
+                    job.setArg(value(i - 1));
+                    jobs.add(job);
+                }
+
+                Collection<Object> results = ignite.compute().call(jobs);
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCallCollectionWithReducer() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    EchoCallable job = (EchoCallable)factory.create();
+                    job.setArg(value(i - 1));
+                    jobs.add(job);
+                }
+
+                boolean res = ignite.compute().call(jobs, new IgniteReducer<Object, Boolean>() {
+                    private Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                    @Override public boolean collect(@Nullable Object o) {
+                        results.add(o);
+                        return true;
+                    }
+
+                    @Override public Boolean reduce() {
+                        checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                        assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+                        return true;
+                    }
+                });
+
+                assertTrue(res);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDummyAffinityCall() throws Exception {
+        runTest(callableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                ignite.getOrCreateCache(CACHE_NAME);
+
+                final IgniteCompute comp = ignite.compute();
+
+                Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    EchoCallable job = (EchoCallable)factory.create();
+
+                    job.setArg(value(i - 1));
+
+                    results.add(comp.affinityCall("test", key(0), job));
+                }
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDummyAffinityRun() throws Exception {
+        runTest(runnableFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                ignite.getOrCreateCache(CACHE_NAME);
+
+                final IgniteCompute comp = ignite.compute();
+
+                for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                    IgniteRunnable job = (IgniteRunnable)factory.create();
+
+                    comp.affinityRun("test", key(0), job);
+                }
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeployExecuteByName() throws Exception {
+        runTest(jobFactories, new ComputeTest() {
+            @Override public void test(Factory factory, Ignite ignite) throws Exception {
+                final int[] i = {-1};
+
+                final IgniteCompute comp = ignite.compute();
+
+                comp.localDeployTask(TestTask.class, TestTask.class.getClassLoader());
+
+                List<Object> results = ignite.compute().execute(
+                    TestTask.class.getName(),
+                    new T2<>((Factory<ComputeJobAdapter>)factory,
+                        (Factory<Object>)new Factory<Object>() {
+                            @Override public Object create() {
+                                return value(i[0]++);
+                            }
+                        }));
+
+                checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
+                assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
+
+                comp.undeployTask(TestTask.class.getName());
+            }
+        });
+    }
+
+    /**
+     * Override the base method to return {@code null} value in case the valId is negative.
+     */
+    @Nullable @Override public Object value(int valId) {
+        if (valId < 0)
+            return null;
+
+        return super.value(valId);
+    }
+
+    /**
+     *
+     */
+    enum TestJobEnum {
+        /** */
+        VALUE_0,
+        /** */
+        VALUE_1,
+        /** */
+        VALUE_2
+    }
+
+    /**
+     *
+     */
+    public interface ComputeTest {
+        /**
+         * @param factory Factory.
+         * @param ignite Ignite instance to use.
+         * @throws Exception If failed.
+         */
+        public void test(Factory factory, Ignite ignite) throws Exception;
+    }
+
+    /**
+     * Creates set of jobs.
+     */
+    static class TestTask
+        extends ComputeTaskSplitAdapter<T2<Factory<ComputeJobAdapter>, Factory<Object>>, List<Object>> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int gridSize,
+            T2<Factory<ComputeJobAdapter>, Factory<Object>> factoriesJobAndArg) throws IgniteException {
+            Collection<ComputeJob> jobs = new HashSet<>();
+
+            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
+                ComputeJobAdapter job = factoriesJobAndArg.get1().create();
+
+                job.setArguments(factoriesJobAndArg.get2().create());
+                jobs.add(job);
+            }
+
+            return jobs;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public List<Object> reduce(List<ComputeJobResult> results) throws IgniteException {
+            List<Object> ret = new ArrayList<>(results.size());
+
+            for (ComputeJobResult result : results)
+                ret.add(result.getData());
+
+            return ret;
+        }
+    }
+
+    /**
+     * Echo job, serializable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoJob extends ComputeJobAdapter {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor (required by ReflectionFactory).
+         */
+        public EchoJob() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoJob(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal, float fltVal,
+            double dblVal,
+            String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object execute() {
+            checkState();
+
+            return argument(0);
+        }
+
+        /**
+         * Check the object state after serialization / deserialization
+         */
+        protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo job, externalizable. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoJobExternalizable extends EchoJob implements Externalizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor (required by {@link Externalizable}).
+         */
+        public EchoJobExternalizable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoJobExternalizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(argument(0));
+
+            JobUtils.writeJobState(out, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            setArguments(in.readObject());
+
+            isVal = in.readBoolean();
+            bVal = in.readByte();
+            cVal = in.readChar();
+            sVal = in.readShort();
+            intVal = in.readInt();
+            lVal = in.readLong();
+            fltVal = in.readFloat();
+            dblVal = in.readDouble();
+            strVal = (String)in.readObject();
+            arrVal = (Object[])in.readObject();
+            eVal = (TestJobEnum)in.readObject();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo job, externalizable. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoJobBinarylizable extends EchoJob implements Binarylizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor (required by ReflectionFactory).
+         */
+        public EchoJobBinarylizable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoJobBinarylizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeObject("arg", argument(0));
+
+            JobUtils.writeJobState(writer, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            Object arg = reader.readObject("arg");
+
+            setArguments(arg);
+
+            isVal = reader.readBoolean("isVal");
+            bVal = reader.readByte("bVal");
+            cVal = reader.readChar("cVal");
+            sVal = reader.readShort("sVal");
+            intVal = reader.readInt("intVal");
+            lVal = reader.readLong("lVal");
+            fltVal = reader.readFloat("fltVal");
+            dblVal = reader.readDouble("dblVal");
+            strVal = reader.readString("strVal");
+            arrVal = reader.readObjectArray("arrVal");
+            eVal = reader.readEnum("eVal");
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo job, serializable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoClosure implements IgniteClosure<Object, Object> {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public EchoClosure() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoClosure(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal, float fltVal,
+            double dblVal,
+            String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object apply(Object arg) {
+            checkState();
+
+            return arg;
+        }
+
+        /**
+         * Check the object state after serialization / deserialization
+         */
+        protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo closure, externalizable. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoClosureExternalizable extends EchoClosure implements Externalizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor (required by Externalizable).
+         */
+        public EchoClosureExternalizable() {
+            // No-op
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoClosureExternalizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            JobUtils.writeJobState(out, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            isVal = in.readBoolean();
+            bVal = in.readByte();
+            cVal = in.readChar();
+            sVal = in.readShort();
+            intVal = in.readInt();
+            lVal = in.readLong();
+            fltVal = in.readFloat();
+            dblVal = in.readDouble();
+            strVal = (String)in.readObject();
+            arrVal = (Object[])in.readObject();
+            eVal = (TestJobEnum)in.readObject();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo closure, externalizable. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoClosureBinarylizable extends EchoClosure implements Binarylizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoClosureBinarylizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            JobUtils.writeJobState(writer, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            isVal = reader.readBoolean("isVal");
+            bVal = reader.readByte("bVal");
+            cVal = reader.readChar("cVal");
+            sVal = reader.readShort("sVal");
+            intVal = reader.readInt("intVal");
+            lVal = reader.readLong("lVal");
+            fltVal = reader.readFloat("fltVal");
+            dblVal = reader.readDouble("dblVal");
+            strVal = reader.readString("strVal");
+            arrVal = reader.readObjectArray("arrVal");
+            eVal = reader.readEnum("eVal");
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Test callable, serializable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoCallable implements IgniteCallable<Object> {
+        /** */
+        protected Object arg;
+
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public EchoCallable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoCallable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal, float fltVal,
+            double dblVal,
+            String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * @param arg Argument.
+         */
+        void setArg(@Nullable Object arg) {
+            this.arg = arg;
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object call() throws Exception {
+            checkState();
+
+            return arg;
+        }
+
+        /**
+         * Check the object state after serialization / deserialization
+         */
+        protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo callable, externalizable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoCallableExternalizable extends EchoCallable implements Externalizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public EchoCallableExternalizable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoCallableExternalizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(arg);
+
+            JobUtils.writeJobState(out, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            arg = in.readObject();
+
+            isVal = in.readBoolean();
+            bVal = in.readByte();
+            cVal = in.readChar();
+            sVal = in.readShort();
+            intVal = in.readInt();
+            lVal = in.readLong();
+            fltVal = in.readFloat();
+            dblVal = in.readDouble();
+            strVal = (String)in.readObject();
+            arrVal = (Object[])in.readObject();
+            eVal = (TestJobEnum)in.readObject();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Echo callable, binarylizable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class EchoCallableBinarylizable extends EchoCallable implements Binarylizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public EchoCallableBinarylizable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public EchoCallableBinarylizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeObject("arg", arg);
+
+            JobUtils.writeJobState(writer, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            arg = reader.readObject("arg");
+
+            isVal = reader.readBoolean("isVal");
+            bVal = reader.readByte("bVal");
+            cVal = reader.readChar("cVal");
+            sVal = reader.readShort("sVal");
+            intVal = reader.readInt("intVal");
+            lVal = reader.readLong("lVal");
+            fltVal = reader.readFloat("fltVal");
+            dblVal = reader.readDouble("dblVal");
+            strVal = reader.readString("strVal");
+            arrVal = reader.readObjectArray("arrVal");
+            eVal = reader.readEnum("eVal");
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Test runnable, serializable object. All fields are used only for serialization check.
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class ComputeTestRunnable implements IgniteRunnable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public ComputeTestRunnable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public ComputeTestRunnable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal, float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void run() {
+            checkState();
+        }
+
+        /**
+         * Check the object state after serialization / deserialization
+         */
+        protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Test runnable, externalizable object. All fields are used only for serialization check.
+     */
+    public static class ComputeTestRunnableExternalizable extends ComputeTestRunnable implements Externalizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor (required by Externalizable).
+         */
+        public ComputeTestRunnableExternalizable() {
+            // No-op
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public ComputeTestRunnableExternalizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal, double dblVal, String strVal, Object[] arrVal,
+            TestJobEnum val) {
+            this.intVal = intVal;
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            JobUtils.writeJobState(out, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            isVal = in.readBoolean();
+            bVal = in.readByte();
+            cVal = in.readChar();
+            sVal = in.readShort();
+            intVal = in.readInt();
+            lVal = in.readLong();
+            fltVal = in.readFloat();
+            dblVal = in.readDouble();
+            strVal = (String)in.readObject();
+            arrVal = (Object[])in.readObject();
+            eVal = (TestJobEnum)in.readObject();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Test runnable, binarylizable object. All fields are used only for serialization check.
+     */
+    public static class ComputeTestRunnableBinarylizable extends ComputeTestRunnable implements Binarylizable {
+        /** */
+        private boolean isVal;
+
+        /** */
+        private byte bVal;
+
+        /** */
+        private char cVal;
+
+        /** */
+        private short sVal;
+
+        /** */
+        private int intVal;
+
+        /** */
+        private long lVal;
+
+        /** */
+        private float fltVal;
+
+        /** */
+        private double dblVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private Object[] arrVal;
+
+        /** */
+        private TestJobEnum eVal;
+
+        /**
+         * Default constructor.
+         */
+        public ComputeTestRunnableBinarylizable() {
+            // No-op.
+        }
+
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param val Enum value.
+         */
+        public ComputeTestRunnableBinarylizable(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal, double dblVal, String strVal, Object[] arrVal,
+            TestJobEnum val) {
+            this.isVal = isVal;
+            this.bVal = bVal;
+            this.cVal = cVal;
+            this.sVal = sVal;
+            this.intVal = intVal;
+            this.lVal = lVal;
+            this.fltVal = fltVal;
+            this.dblVal = dblVal;
+            this.strVal = strVal;
+            this.arrVal = arrVal;
+            eVal = val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            JobUtils.writeJobState(writer, isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            isVal = reader.readBoolean("isVal");
+            bVal = reader.readByte("bVal");
+            cVal = reader.readChar("cVal");
+            sVal = reader.readShort("sVal");
+            intVal = reader.readInt("intVal");
+            lVal = reader.readLong("lVal");
+            fltVal = reader.readFloat("fltVal");
+            dblVal = reader.readDouble("dblVal");
+            strVal = reader.readString("strVal");
+            arrVal = reader.readObjectArray("arrVal");
+            eVal = reader.readEnum("eVal");
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override protected void checkState() {
+            JobUtils.checkJobState(isVal, bVal, cVal, sVal, intVal, lVal, fltVal, dblVal, strVal, arrVal, eVal);
+        }
+    }
+
+    /**
+     * Creates test jobs with tested parameters
+     */
+    private static class JobFactory<T> implements Factory<T> {
+        /** */
+        private static final long serialVersionUID = 0;
+
+        /** */
+        private Class<?> cls;
+
+        /**
+         * @param cls Class.
+         */
+        JobFactory(Class<?> cls) {
+            this.cls = cls;
+        }
+
+        /** {@inheritDoc} */
+        @Override public T create() {
+            try {
+                Constructor<?> constructor = cls.getConstructor(Boolean.TYPE, Byte.TYPE, Character.TYPE,
+                    Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, String.class, Object[].class, TestJobEnum.class);
+
+                return (T)constructor.newInstance(true,
+                    Byte.MAX_VALUE,
+                    Character.MAX_VALUE,
+                    Short.MAX_VALUE,
+                    Integer.MAX_VALUE,
+                    Long.MAX_VALUE,
+                    Float.MAX_VALUE,
+                    Double.MAX_VALUE,
+                    STR_VAL, ARRAY_VAL,
+                    TestJobEnum.VALUE_2);
+            }
+            catch (NoSuchMethodException | InstantiationException | InvocationTargetException |
+                IllegalAccessException e) {
+                throw new IgniteException("Failed to create object using default constructor: " + cls, e);
+            }
+        }
+    }
+
+    /**
+     * Collection of utility methods to simplify EchoJob*, EchoCLosure*, EchoCallable* and ComputeTestRunnable* classes
+     */
+    private static class JobUtils {
+        /**
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param eVal Enum value.
+         */
+        private static void checkJobState(boolean isVal, byte bVal, char cVal, short sVal, int intVal, long lVal,
+            float fltVal,
+            double dblVal, String strVal, Object[] arrVal, TestJobEnum eVal) {
+            assertEquals(true, isVal);
+            assertEquals(Byte.MAX_VALUE, bVal);
+            assertEquals(Character.MAX_VALUE, cVal);
+            assertEquals(Short.MAX_VALUE, sVal);
+            assertEquals(Integer.MAX_VALUE, intVal);
+            assertEquals(Long.MAX_VALUE, lVal);
+            assertEquals(Float.MAX_VALUE, fltVal);
+            assertEquals(Double.MAX_VALUE, dblVal);
+            assertEquals(STR_VAL, strVal);
+            Assert.assertArrayEquals(ARRAY_VAL, arrVal);
+            assertEquals(TestJobEnum.VALUE_2, eVal);
+        }
+
+        /**
+         * @param writer Writer.
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param eVal Enum value.
+         * @throws BinaryObjectException If failed.
+         */
+        private static void writeJobState(BinaryWriter writer, boolean isVal, byte bVal, char cVal, short sVal,
+            int intVal, long lVal, float fltVal, double dblVal, String strVal,
+            Object[] arrVal, TestJobEnum eVal) throws BinaryObjectException {
+            writer.writeBoolean("isVal", isVal);
+            writer.writeByte("bVal", bVal);
+            writer.writeChar("cVal", cVal);
+            writer.writeShort("sVal", sVal);
+            writer.writeInt("intVal", intVal);
+            writer.writeLong("lVal", lVal);
+            writer.writeFloat("fltVal", fltVal);
+            writer.writeDouble("dblVal", dblVal);
+            writer.writeString("strVal", strVal);
+            writer.writeObjectArray("arrVal", arrVal);
+            writer.writeEnum("eVal", eVal);
+        }
+
+        /**
+         * @param out Out.
+         * @param isVal boolean value.
+         * @param bVal byte value.
+         * @param cVal char value.
+         * @param sVal short value.
+         * @param intVal int value.
+         * @param lVal long value.
+         * @param fltVal float value.
+         * @param dblVal double value.
+         * @param strVal String value.
+         * @param arrVal Array value.
+         * @param eVal Enum value.
+         * @throws IOException If failed.
+         */
+        private static void writeJobState(ObjectOutput out, boolean isVal, byte bVal, char cVal, short sVal,
+            int intVal, long lVal, float fltVal, double dblVal, String strVal, Object[] arrVal,
+            TestJobEnum eVal) throws IOException {
+            out.writeBoolean(isVal);
+            out.writeByte(bVal);
+            out.writeChar(cVal);
+            out.writeShort(sVal);
+            out.writeInt(intVal);
+            out.writeLong(lVal);
+            out.writeFloat(fltVal);
+            out.writeDouble(dblVal);
+            out.writeObject(strVal);
+            out.writeObject(arrVal);
+            out.writeObject(eVal);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/24b24bf8/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
index e5856f0..0be6d50 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/ConfigVariations.java
@@ -215,7 +215,7 @@ public class ConfigVariations {
     /**
      * @return Marshaller.
      */
-    private static Factory<OptimizedMarshaller> optimizedMarshallerFactory() {
+    public static Factory<OptimizedMarshaller> optimizedMarshallerFactory() {
         return new Factory<OptimizedMarshaller>() {
             @Override public OptimizedMarshaller create() {
                 OptimizedMarshaller marsh = new OptimizedMarshaller(true);

http://git-wip-us.apache.org/repos/asf/ignite/blob/24b24bf8/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
index b22f289..258eba8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
@@ -21,13 +21,16 @@ import java.io.Externalizable;
 import java.io.File;
 import java.io.IOException;
 import java.io.ObjectInput;
+import java.io.ObjectInputStream;
 import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import org.apache.commons.io.FileUtils;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.testframework.configvariations.VariationsTestsConfig;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 
@@ -197,6 +200,12 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         for (int i = 0; i < DataMode.values().length; i++) {
             dataMode = DataMode.values()[i];
 
+            if ((getConfiguration().getMarshaller() instanceof JdkMarshaller)
+                && (dataMode == DataMode.PLANE_OBJECT)) {
+                info("Skip test for JdkMarshaller & PLANE_OBJECT data mode");
+                continue;
+            }
+
             info("Running test in data mode: " + dataMode);
 
             if (i != 0)
@@ -289,6 +298,13 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         protected TestEnum enumVal;
 
         /**
+         * Default constructor must be accessible for deserialize subclasses by JDK serialization API.
+         */
+        TestObject() {
+            // No-op.
+        }
+
+        /**
          * @param val Value.
          */
         TestObject(int val) {
@@ -345,6 +361,31 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         public SerializableObject(int val) {
             super(val);
         }
+
+        /**
+         * Custom serialization of superclass because {@link TestObject} is non-serializable.
+         *
+         * @param out output stream.
+         * @throws IOException if de-serialization failed.
+         */
+        private void writeObject(ObjectOutputStream out) throws IOException {
+            out.writeInt(val);
+            out.writeObject(strVal);
+            out.writeObject(enumVal);
+        }
+
+        /**
+         * Custom deserialization of superclass because {@link TestObject} is non-serializable.
+         *
+         * @param in input stream
+         * @throws IOException if de-serialization failed.
+         * @throws ClassNotFoundException if de-serialization failed.
+         */
+        private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+            val = in.readInt();
+            strVal = (String)in.readObject();
+            enumVal = (TestEnum)in.readObject();
+        }
     }
 
     /**
@@ -354,7 +395,7 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         /**
          * Default constructor.
          */
-        ExternalizableObject() {
+        public ExternalizableObject() {
             super(-1);
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/24b24bf8/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeBasicConfigVariationsFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeBasicConfigVariationsFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeBasicConfigVariationsFullApiTestSuite.java
new file mode 100644
index 0000000..1be932a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteComputeBasicConfigVariationsFullApiTestSuite.java
@@ -0,0 +1,72 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.compute.IgniteComputeConfigVariationsFullApiTest;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+import org.apache.ignite.testframework.configvariations.ConfigParameter;
+import org.apache.ignite.testframework.configvariations.ConfigVariations;
+import org.apache.ignite.testframework.configvariations.ConfigVariationsTestSuiteBuilder;
+import org.apache.ignite.testframework.configvariations.Parameters;
+
+/**
+ * Full API compute test.
+ */
+public class IgniteComputeBasicConfigVariationsFullApiTestSuite extends TestSuite {
+    /** */
+    @SuppressWarnings("unchecked")
+    private static final ConfigParameter<IgniteConfiguration>[][] BASIC_COMPUTE_SET = new ConfigParameter[][] {
+        Parameters.objectParameters("setMarshaller",
+            Parameters.factory(JdkMarshaller.class),
+            Parameters.factory(BinaryMarshaller.class),
+            ConfigVariations.optimizedMarshallerFactory()
+        ),
+        Parameters.booleanParameters("setPeerClassLoadingEnabled"),
+        Parameters.booleanParameters("setMarshalLocalJobs"),
+    };
+
+    /**
+     * @return Compute API test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Compute New Full API Test Suite");
+
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "Single server",
+            IgniteComputeConfigVariationsFullApiTest.class)
+            .igniteParams(BASIC_COMPUTE_SET)
+            .gridsCount(1)
+            .build());
+
+        // Tests run on server (node#0) & client(node#1).
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "3 servers, 1 client",
+            IgniteComputeConfigVariationsFullApiTest.class)
+            .igniteParams(BASIC_COMPUTE_SET)
+            .gridsCount(4)
+            .testedNodesCount(2)
+            .withClients()
+            .build());
+
+        return suite;
+    }
+}


[42/50] [abbrv] ignite git commit: IGNITE-3027 - TcpDiscoveryImpl.registerLocalNodeAddress() has an infinite loop (cherry picked from commit 1f8b394)

Posted by sh...@apache.org.
IGNITE-3027 - TcpDiscoveryImpl.registerLocalNodeAddress() has an infinite loop
(cherry picked from commit 1f8b394)


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

Branch: refs/heads/ignite-2788
Commit: 90df322d534c086230f9baa1608853ed7db25750
Parents: 8873d43
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Thu Apr 28 14:32:30 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../ignite/spi/discovery/tcp/ServerImpl.java    |  5 ++-
 .../spi/discovery/tcp/TcpDiscoveryImpl.java     | 10 ++++++
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java | 34 ++++++++++++++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/90df322d/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index d7dd8c8..05bb1e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -160,7 +160,6 @@ import static org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryStatusChe
 /**
  *
  */
-@SuppressWarnings("All")
 class ServerImpl extends TcpDiscoveryImpl {
     /** */
     private static final int ENSURED_MSG_HIST_SIZE = getInteger(IGNITE_DISCOVERY_HISTORY_SIZE, 1024 * 10);
@@ -1643,7 +1642,7 @@ class ServerImpl extends TcpDiscoveryImpl {
      * @return {@code True} if given parameters contain the same permissions, {@code False} otherwise.
      */
     private boolean permissionsEqual(SecurityPermissionSet locPerms, SecurityPermissionSet rmtPerms) {
-        boolean dfltAllowMatch = !(locPerms.defaultAllowAll() ^ rmtPerms.defaultAllowAll());
+        boolean dfltAllowMatch = locPerms.defaultAllowAll() == rmtPerms.defaultAllowAll();
 
         boolean bothHaveSamePerms = F.eqNotOrdered(rmtPerms.systemPermissions(), locPerms.systemPermissions()) &&
             F.eqNotOrdered(rmtPerms.cachePermissions(), locPerms.cachePermissions()) &&
@@ -1964,7 +1963,7 @@ class ServerImpl extends TcpDiscoveryImpl {
         private final Queue<TcpDiscoveryAbstractMessage> msgs = new ArrayDeque<>(MAX * 2);
 
         /** Processed custom message IDs. */
-        private Set<IgniteUuid> procCustomMsgs = new GridBoundedLinkedHashSet<IgniteUuid>(MAX * 2);
+        private Set<IgniteUuid> procCustomMsgs = new GridBoundedLinkedHashSet<>(MAX * 2);
 
         /** Discarded message ID. */
         private IgniteUuid discardId;

http://git-wip-us.apache.org/repos/asf/ignite/blob/90df322d/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
index 1aef728..41086d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryImpl.java
@@ -260,6 +260,9 @@ abstract class TcpDiscoveryImpl {
     @SuppressWarnings("BusyWait")
     protected final void registerLocalNodeAddress() throws IgniteSpiException {
         // Make sure address registration succeeded.
+        // ... but limit it if join timeout is configured.
+        long start = spi.getJoinTimeout() > 0 ? U.currentTimeMillis() : 0;
+
         while (true) {
             try {
                 spi.ipFinder.initializeLocalAddresses(locNode.socketAddresses());
@@ -276,6 +279,13 @@ abstract class TcpDiscoveryImpl {
                     "(retrying every 2000 ms).");
             }
 
+            if (start > 0 && (U.currentTimeMillis() - start) > spi.getJoinTimeout())
+                throw new IgniteSpiException(
+                    "Failed to register local addresses with IP finder within join timeout " +
+                        "(make sure IP finder configuration is correct, and operating system firewalls are disabled " +
+                        "on all host machines, or consider increasing 'joinTimeout' configuration property) " +
+                        "[joinTimeout=" + spi.getJoinTimeout() + ']');
+
             try {
                 U.sleep(2000);
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/90df322d/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 45cd276..96c0e66 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -1058,6 +1058,40 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If any error occurs.
+     */
+    public void testJoinTimeoutForIpFinder() throws Exception {
+        try {
+            // This start will fail as expected.
+            Throwable t = GridTestUtils.assertThrows(log, new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    IgniteConfiguration c = getConfiguration("test-grid");
+
+                    TcpDiscoverySpi disco = (TcpDiscoverySpi)c.getDiscoverySpi();
+
+                    disco.setJoinTimeout(3000);
+                    disco.setIpFinder(
+                        new TcpDiscoveryVmIpFinder(true) {
+                            @Override public void initializeLocalAddresses(Collection<InetSocketAddress> addrs)
+                                throws IgniteSpiException {
+                                throw new IgniteSpiException("Test exception.");
+                            }
+                        });
+
+                    startGrid("test-grid", c);
+
+                    return null;
+                }
+            }, IgniteException.class, null);
+
+            assert X.hasCause(t, IgniteSpiException.class) : "Unexpected exception: " + t;
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testDirtyIpFinder() throws Exception {


[16/50] [abbrv] ignite git commit: Moved tests from GridGetOrStartSelfTest to GridFactorySelfTest and removed the first suite.

Posted by sh...@apache.org.
Moved tests from GridGetOrStartSelfTest to GridFactorySelfTest and removed the first suite.


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

Branch: refs/heads/ignite-2788
Commit: 9aab9e1b46ad21a20a0b422763976e1d060a804b
Parents: 0d07761
Author: Denis Magda <dm...@gridgain.com>
Authored: Wed Apr 20 17:03:57 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../ignite/internal/GridGetOrStartSelfTest.java | 132 -------------------
 .../ignite/testsuites/IgniteBasicTestSuite.java |   3 -
 .../ignite/internal/GridFactorySelfTest.java    |  85 ++++++++++++
 3 files changed, 85 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9aab9e1b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
deleted file mode 100644
index 211d413..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal;
-
-import java.util.concurrent.atomic.AtomicReference;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.typedef.G;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * The GridGetOrStartSelfTest tests get or start semantics.
- */
-
-@GridCommonTest(group = "Kernal Self")
-public class GridGetOrStartSelfTest extends GridCommonAbstractTest {
-    /** Concurrency. */
-    public static final int CONCURRENCY = 10;
-
-    /**
-     * Default constructor.
-     */
-    public GridGetOrStartSelfTest() {
-        super(false);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * Tests default grid
-     */
-    public void testDefaultGridGetOrStart() throws Exception {
-        IgniteConfiguration cfg = getConfiguration(null);
-
-        try (Ignite ignite = Ignition.getOrStart(cfg)) {
-            try {
-                Ignition.start(cfg);
-
-                fail("Expected exception after grid started");
-            }
-            catch (IgniteException ignored) {
-            }
-
-            Ignite ignite2 = Ignition.getOrStart(cfg);
-
-            assertEquals("Must return same instance", ignite, ignite2);
-        }
-
-        assertTrue(G.allGrids().isEmpty());
-    }
-
-    /**
-     * Tests named grid
-     */
-    public void testNamedGridGetOrStart() throws Exception {
-        IgniteConfiguration cfg = getConfiguration("test");
-        try (Ignite ignite = Ignition.getOrStart(cfg)) {
-            try {
-                Ignition.start(cfg);
-
-                fail("Expected exception after grid started");
-            }
-            catch (IgniteException ignored) {
-                // No-op.
-            }
-
-            Ignite ignite2 = Ignition.getOrStart(cfg);
-
-            assertEquals("Must return same instance", ignite, ignite2);
-        }
-
-        assertTrue(G.allGrids().isEmpty());
-    }
-
-    /**
-     * Tests concurrent grid initialization
-     */
-    public void testConcurrentGridGetOrStartCon() throws Exception {
-        final IgniteConfiguration cfg = getConfiguration(null);
-
-        final AtomicReference<Ignite> ref = new AtomicReference<>();
-
-        try {
-            GridTestUtils.runMultiThreaded(new Runnable() {
-                @Override public void run() {
-                    // must return same instance in each thread
-
-                    try {
-                        Ignite ignite = Ignition.getOrStart(cfg);
-
-                        boolean set = ref.compareAndSet(null, ignite);
-
-                        if (!set)
-                            assertEquals(ref.get(), ignite);
-                    }
-                    catch (IgniteException e) {
-                        throw new RuntimeException("Ignite error", e);
-                    }
-                }
-            }, CONCURRENCY, "GridCreatorThread");
-        }
-        catch (Exception ignored) {
-            fail("Exception is not expected");
-        }
-
-        G.stopAll(true);
-
-        assertTrue(G.allGrids().isEmpty());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/9aab9e1b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index a4be2de..9e2324c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -23,7 +23,6 @@ import org.apache.ignite.GridSuppressedExceptionSelfTest;
 import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
 import org.apache.ignite.internal.ClusterGroupSelfTest;
 import org.apache.ignite.internal.GridFailFastNodeFailureDetectionSelfTest;
-import org.apache.ignite.internal.GridGetOrStartSelfTest;
 import org.apache.ignite.internal.GridLifecycleAwareSelfTest;
 import org.apache.ignite.internal.GridLifecycleBeanSelfTest;
 import org.apache.ignite.internal.GridNodeMetricsLogSelfTest;
@@ -130,8 +129,6 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(VariationsIteratorTest.class);
         suite.addTestSuite(ConfigVariationsTestSuiteBuilderTest.class);
 
-        GridTestUtils.addTestIfNeeded(suite, GridGetOrStartSelfTest.class, ignoredTests);
-
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9aab9e1b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index cca3e8b..0868dff 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -91,6 +91,9 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     /** */
     private static final AtomicInteger cnt = new AtomicInteger();
 
+    /** Concurrency. */
+    private static final int CONCURRENCY = 10;
+
     /** */
     private static final String CUSTOM_CFG_PATH =
         "modules/core/src/test/config/factory/custom-grid-name-spring-test.xml";
@@ -206,6 +209,88 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Tests default grid
+     */
+    public void testDefaultGridGetOrStart() throws Exception {
+        IgniteConfiguration cfg = getConfiguration(null);
+
+        try (Ignite ignite = Ignition.getOrStart(cfg)) {
+            try {
+                Ignition.start(cfg);
+
+                fail("Expected exception after grid started");
+            }
+            catch (IgniteException ignored) {
+            }
+
+            Ignite ignite2 = Ignition.getOrStart(cfg);
+
+            assertEquals("Must return same instance", ignite, ignite2);
+        }
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+
+    /**
+     * Tests named grid
+     */
+    public void testNamedGridGetOrStart() throws Exception {
+        IgniteConfiguration cfg = getConfiguration("test");
+        try (Ignite ignite = Ignition.getOrStart(cfg)) {
+            try {
+                Ignition.start(cfg);
+
+                fail("Expected exception after grid started");
+            }
+            catch (IgniteException ignored) {
+                // No-op.
+            }
+
+            Ignite ignite2 = Ignition.getOrStart(cfg);
+
+            assertEquals("Must return same instance", ignite, ignite2);
+        }
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+
+    /**
+     * Tests concurrent grid initialization
+     */
+    public void testConcurrentGridGetOrStartCon() throws Exception {
+        final IgniteConfiguration cfg = getConfiguration(null);
+
+        final AtomicReference<Ignite> ref = new AtomicReference<>();
+
+        try {
+            GridTestUtils.runMultiThreaded(new Runnable() {
+                @Override public void run() {
+                    // must return same instance in each thread
+
+                    try {
+                        Ignite ignite = Ignition.getOrStart(cfg);
+
+                        boolean set = ref.compareAndSet(null, ignite);
+
+                        if (!set)
+                            assertEquals(ref.get(), ignite);
+                    }
+                    catch (IgniteException e) {
+                        throw new RuntimeException("Ignite error", e);
+                    }
+                }
+            }, CONCURRENCY, "GridCreatorThread");
+        }
+        catch (Exception ignored) {
+            fail("Exception is not expected");
+        }
+
+        G.stopAll(true);
+
+        assertTrue(G.allGrids().isEmpty());
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testLifecycleBeansNullGridName() throws Exception {


[35/50] [abbrv] ignite git commit: IGNITE-642 Implement IgniteReentrantLock data structure

Posted by sh...@apache.org.
IGNITE-642 Implement IgniteReentrantLock data structure


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

Branch: refs/heads/ignite-2788
Commit: f8bf93a79d74231f720972ba7fbaf113d0060e2d
Parents: 0f6c97e
Author: Vladisav Jelisavcic <vl...@gmail.com>
Authored: Wed Apr 27 18:31:26 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../datastructures/IgniteLockExample.java       |  293 ++++
 .../ignite/examples/CacheExamplesSelfTest.java  |    8 +
 .../src/main/java/org/apache/ignite/Ignite.java |   17 +
 .../java/org/apache/ignite/IgniteCondition.java |  338 ++++
 .../main/java/org/apache/ignite/IgniteLock.java |  489 ++++++
 .../ignite/internal/GridKernalContextImpl.java  |    4 +-
 .../apache/ignite/internal/IgniteKernal.java    |   21 +
 .../datastructures/DataStructuresProcessor.java |  158 +-
 .../datastructures/GridCacheLockEx.java         |   52 +
 .../datastructures/GridCacheLockImpl.java       | 1538 +++++++++++++++++
 .../datastructures/GridCacheLockState.java      |  353 ++++
 .../datastructures/GridCacheSemaphoreImpl.java  |   33 +
 .../resources/META-INF/classnames.properties    |    2 +
 .../IgniteClientReconnectAtomicsTest.java       |   58 +
 ...eAbstractDataStructuresFailoverSelfTest.java |  208 ++-
 .../IgniteClientDataStructuresAbstractTest.java |   70 +
 .../IgniteDataStructureUniqueNameTest.java      |   13 +-
 .../IgniteLockAbstractSelfTest.java             | 1629 ++++++++++++++++++
 .../IgniteSemaphoreAbstractSelfTest.java        |   31 +
 .../local/IgniteLocalLockSelfTest.java          |  110 ++
 .../IgnitePartitionedLockSelfTest.java          |   33 +
 .../IgniteReplicatedLockSelfTest.java           |   33 +
 .../distributed/GridCacheLockAbstractTest.java  |    2 +-
 .../cache/GridCacheDataStructuresLoadTest.java  |   53 +
 .../ignite/testframework/junits/IgniteMock.java |   10 +
 .../junits/multijvm/IgniteProcessProxy.java     |    7 +
 .../IgniteCacheDataStructuresSelfTestSuite.java |    6 +
 .../org/apache/ignite/IgniteSpringBean.java     |   11 +
 28 files changed, 5570 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteLockExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteLockExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteLockExample.java
new file mode 100644
index 0000000..1f84787
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteLockExample.java
@@ -0,0 +1,293 @@
+/*
+ * 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.examples.datastructures;
+
+import java.util.UUID;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCondition;
+import org.apache.ignite.IgniteLock;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.lang.IgniteRunnable;
+
+/**
+ * This example demonstrates cache based reentrant lock.
+ * <p>
+ * Remote nodes should always be started with special configuration
+ * file which enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
+ * <p>
+ * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node with {@code
+ * examples/config/example-ignite.xml} configuration.
+ */
+public class IgniteLockExample {
+    /** Number of items for each producer/consumer to produce/consume. */
+    private static final int OPS_COUNT = 100;
+
+    /** Number of producers. */
+    private static final int NUM_PRODUCERS = 5;
+
+    /** Number of consumers. */
+    private static final int NUM_CONSUMERS = 5;
+
+    /** Cache name. */
+    private static final String CACHE_NAME = "cache";
+
+    /** Name of the global resource. */
+    private static final String QUEUE_ID = "queue";
+
+    /** Name of the synchronization variable. */
+    private static final String SYNC_NAME = "done";
+
+    /** Name of the condition object. */
+    private static final String NOT_FULL = "notFull";
+
+    /** Name of the condition object. */
+    private static final String NOT_EMPTY = "notEmpty";
+
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     */
+    public static void main(String[] args) {
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            System.out.println();
+            System.out.println(">>> Cache atomic reentrant lock example started.");
+
+            // Make name of reentrant lock.
+            final String reentrantLockName = UUID.randomUUID().toString();
+
+            // Initialize lock.
+            IgniteLock lock = ignite.reentrantLock(reentrantLockName, true, false, true);
+
+            // Init distributed cache.
+            IgniteCache<String, Integer> cache = ignite.getOrCreateCache(CACHE_NAME);
+
+            // Init shared variable.
+            cache.put(QUEUE_ID, 0);
+
+            // Shared variable indicating number of jobs left to be completed.
+            cache.put(SYNC_NAME, NUM_PRODUCERS + NUM_CONSUMERS);
+
+            // Start consumers on all cluster nodes.
+            for (int i = 0; i < NUM_CONSUMERS; i++)
+                ignite.compute().withAsync().run(new Consumer(reentrantLockName));
+
+            // Start producers on all cluster nodes.
+            for (int i = 0; i < NUM_PRODUCERS; i++)
+                ignite.compute().withAsync().run(new Producer(reentrantLockName));
+
+            System.out.println("Master node is waiting for all other nodes to finish...");
+
+            // Wait for everyone to finish.
+            try {
+                lock.lock();
+
+                IgniteCondition notDone = lock.getOrCreateCondition(SYNC_NAME);
+
+                int count = cache.get(SYNC_NAME);
+
+                while(count > 0) {
+                    notDone.await();
+
+                    count = cache.get(SYNC_NAME);
+                }
+            }
+            finally {
+                lock.unlock();
+            }
+        }
+
+        System.out.flush();
+        System.out.println();
+        System.out.println("Finished reentrant lock example...");
+        System.out.println("Check all nodes for output (this node is also part of the cluster).");
+    }
+
+    /**
+     * Closure which simply acquires reentrant lock.
+     */
+    private abstract static class ReentrantLockExampleClosure implements IgniteRunnable {
+        /** Semaphore name. */
+        protected final String reentrantLockName;
+
+        /**
+         * @param reentrantLockName Reentrant lock name.
+         */
+        ReentrantLockExampleClosure(String reentrantLockName) {
+            this.reentrantLockName = reentrantLockName;
+        }
+    }
+
+    /**
+     * Closure which simulates producer.
+     */
+    private static class Producer extends ReentrantLockExampleClosure {
+        /**
+         * @param reentrantLockName Reentrant lock name.
+         */
+        public Producer(String reentrantLockName) {
+            super(reentrantLockName);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            System.out.println("Producer started. ");
+
+            IgniteLock lock = Ignition.ignite().reentrantLock(reentrantLockName, true, false, true);
+
+            // Condition to wait on when queue is full.
+            IgniteCondition notFull = lock.getOrCreateCondition(NOT_FULL);
+
+            // Signaled to wait on when queue is empty.
+            IgniteCondition notEmpty = lock.getOrCreateCondition(NOT_EMPTY);
+
+            // Signaled when job is done.
+            IgniteCondition done = lock.getOrCreateCondition(SYNC_NAME);
+
+            IgniteCache<String, Integer> cache = Ignition.ignite().cache(CACHE_NAME);
+
+            for (int i = 0; i < OPS_COUNT; i++) {
+                try {
+                    lock.lock();
+
+                    int val = cache.get(QUEUE_ID);
+
+                    while(val >= 100){
+                        System.out.println("Queue is full. Producer [nodeId=" + Ignition.ignite().cluster().localNode().id() +
+                            " paused.");
+
+                        notFull.await();
+
+                        val = cache.get(QUEUE_ID);
+                    }
+
+                    val++;
+
+                    System.out.println("Producer [nodeId=" + Ignition.ignite().cluster().localNode().id() +
+                        ", available=" + val + ']');
+
+                    cache.put(QUEUE_ID, val);
+
+                    notEmpty.signalAll();
+                }
+                finally {
+                    lock.unlock();
+                }
+            }
+
+            System.out.println("Producer finished [nodeId=" + Ignition.ignite().cluster().localNode().id() + ']');
+
+            try {
+                lock.lock();
+
+                int count = cache.get(SYNC_NAME);
+
+                count--;
+
+                cache.put(SYNC_NAME, count);
+
+                // Signals the master thread.
+                done.signal();
+            }
+            finally {
+                lock.unlock();
+            }
+        }
+    }
+
+    /**
+     * Closure which simulates consumer.
+     */
+    private static class Consumer extends ReentrantLockExampleClosure {
+        /**
+         * @param reentrantLockName ReentrantLock name.
+         */
+        public Consumer(String reentrantLockName) {
+            super(reentrantLockName);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            System.out.println("Consumer started. ");
+
+            Ignite g = Ignition.ignite();
+
+            IgniteLock lock = g.reentrantLock(reentrantLockName, true, false, true);
+
+            // Condition to wait on when queue is full.
+            IgniteCondition notFull = lock.getOrCreateCondition(NOT_FULL);
+
+            // Signaled to wait on when queue is empty.
+            IgniteCondition notEmpty = lock.getOrCreateCondition(NOT_EMPTY);
+
+            // Signaled when job is done.
+            IgniteCondition done = lock.getOrCreateCondition(SYNC_NAME);
+
+            IgniteCache<String, Integer> cache = g.cache(CACHE_NAME);
+
+            for (int i = 0; i < OPS_COUNT; i++) {
+                try {
+                    lock.lock();
+
+                    int val = cache.get(QUEUE_ID);
+
+                    while (val <= 0) {
+                        System.out.println("Queue is empty. Consumer [nodeId=" +
+                            Ignition.ignite().cluster().localNode().id() + " paused.");
+
+                        notEmpty.await();
+
+                        val = cache.get(QUEUE_ID);
+                    }
+
+                    val--;
+
+                    System.out.println("Consumer [nodeId=" + Ignition.ignite().cluster().localNode().id() +
+                        ", available=" + val + ']');
+
+                    cache.put(QUEUE_ID, val);
+
+                    notFull.signalAll();
+                }
+                finally {
+                    lock.unlock();
+                }
+            }
+
+            System.out.println("Consumer finished [nodeId=" + Ignition.ignite().cluster().localNode().id() + ']');
+
+            try {
+                lock.lock();
+
+                int count = cache.get(SYNC_NAME);
+
+                count--;
+
+                cache.put(SYNC_NAME, count);
+
+                // Signals the master thread.
+                done.signal();
+            }
+            finally {
+                lock.unlock();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
index 541291b..43b05b5 100644
--- a/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
+++ b/examples/src/test/java/org/apache/ignite/examples/CacheExamplesSelfTest.java
@@ -33,6 +33,7 @@ import org.apache.ignite.examples.datastructures.IgniteAtomicSequenceExample;
 import org.apache.ignite.examples.datastructures.IgniteAtomicStampedExample;
 import org.apache.ignite.examples.datastructures.IgniteCountDownLatchExample;
 import org.apache.ignite.examples.datastructures.IgniteQueueExample;
+import org.apache.ignite.examples.datastructures.IgniteLockExample;
 import org.apache.ignite.examples.datastructures.IgniteSemaphoreExample;
 import org.apache.ignite.examples.datastructures.IgniteSetExample;
 import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
@@ -100,6 +101,13 @@ public class CacheExamplesSelfTest extends GridAbstractExamplesTest {
     /**
      * @throws Exception If failed.
      */
+    public void testCacheLockExample() throws Exception {
+        IgniteLockExample.main(EMPTY_ARGS);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testCacheQueueExample() throws Exception {
         IgniteQueueExample.main(EMPTY_ARGS);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 5703744..b62672e 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -466,6 +466,23 @@ public interface Ignite extends AutoCloseable {
         throws IgniteException;
 
     /**
+     * Gets or creates reentrant lock. If reentrant lock is not found in cache and {@code create} flag
+     * is {@code true}, it is created using provided name.
+     *
+     * @param name Name of the lock.
+     * @param failoverSafe {@code True} to create failover safe lock which means that
+     *      if any node leaves topology, all locks already acquired by that node are silently released
+     *      and become available for other nodes to acquire. If flag is {@code false} then
+     *      all threads on other nodes waiting to acquire lock are interrupted.
+     * @param fair If {@code True}, fair lock will be created.
+     * @param create Boolean flag indicating whether data structure should be created if does not exist.
+     * @return ReentrantLock for the given name.
+     * @throws IgniteException If reentrant lock could not be fetched or created.
+     */
+    public IgniteLock reentrantLock(String name, boolean failoverSafe, boolean fair, boolean create)
+        throws IgniteException;
+
+    /**
      * Will get a named queue from cache and create one if it has not been created yet and {@code cfg} is not
      * {@code null}.
      * If queue is present already, queue properties will not be changed. Use

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/IgniteCondition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCondition.java b/modules/core/src/main/java/org/apache/ignite/IgniteCondition.java
new file mode 100644
index 0000000..020f23a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCondition.java
@@ -0,0 +1,338 @@
+/*
+ * 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;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+
+/**
+ * This interface provides a rich API for working with condition objects
+ * associated with distributed reentrant locks.
+ * <p>
+ * <h1 class="header">Functionality</h1>
+ * IgniteCondition provides functionality similar to {@code java.util.concurrent.locks.Condition}.
+ */
+public interface IgniteCondition extends Condition {
+    /**
+     * Name of ignite condition.
+     *
+     * @return Name of ignite condition.
+     */
+    public String name();
+
+    /**
+     * Causes the current thread to wait until it is signalled or
+     * {@linkplain Thread#interrupt interrupted}.
+     *
+     * <p>The lock associated with this {@code IgniteCondition} is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of six things happens:
+     * <ul>
+     * <li>Some other thread (on any node) invokes the {@link #signal} method for this
+     * {@code Condition} and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread (on any node) invokes the {@link #signalAll} method for this
+     * {@code Condition}; or
+     * <li>Some other thread {@linkplain Thread#interrupt interrupts} the
+     * current thread, and interruption of thread suspension is supported; or
+     * <li>Some other node in grid fails, and lock is created in non-failoverSafe mode; or
+     * <li>Local node is stopped; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+     * </ul>
+     *
+     * <p>If lock is not broken (because of failure of lock owner node)
+     * in non-failoverSafe mode and local node is alive,
+     * before this method can return the current thread must
+     * re-acquire the lock associated with this condition. In all other cases
+     * when the thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread:
+     * <ul>
+     * <li>has its interrupted status set on entry to this method; or
+     * <li>is {@linkplain Thread#interrupt interrupted} while waiting
+     * and interruption of thread suspension is supported,
+     * </ul>
+     * then {@link IgniteInterruptedException} is thrown and the current thread's
+     * interrupted status is cleared. It is not specified, in the first
+     * case, whether or not the test for interruption occurs before the lock
+     * is released.
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     * @throws IgniteException if the node stopped, or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override void await() throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Causes the current thread to wait until it is signalled.
+     *
+     * <p>The lock associated with this condition is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of five things happens:
+     * <ul>
+     * <li>Some other thread invokes the {@link #signal} method for this
+     * {@code Condition} and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the {@link #signalAll} method for this
+     * {@code Condition}; or
+     * <li>Some other node in grid fails, and lock is created in non-failoverSafe mode; or
+     * <li>Local node is stopped; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+     * </ul>
+     *
+     * <p>If lock is not broken (because of failure of lock owner node)
+     * in non-failoverSafe mode and local node is alive,
+     * before this method can return the current thread must
+     * re-acquire the lock associated with this condition. In all other cases,
+     * when the thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread's interrupted status is set when it enters
+     * this method, or it is {@linkplain Thread#interrupt interrupted}
+     * while waiting, it will continue to wait until signalled. When it finally
+     * returns from this method its interrupted status will still
+     * be set.
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @throws IgniteException if the node stopped, or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override void awaitUninterruptibly() throws IgniteException;
+
+    /**
+     * Causes the current thread to wait until it is signalled or interrupted,
+     * or the specified waiting time elapses.
+     *
+     * <p>The lock associated with this condition is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of seven things happens:
+     * <ul>
+     * <li>Some other thread invokes the {@link #signal} method for this
+     * {@code Condition} and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the {@link #signalAll} method for this
+     * {@code Condition}; or
+     * <li>Some other thread {@linkplain Thread#interrupt interrupts} the
+     * current thread, and interruption of thread suspension is supported; or
+     * <li>The specified waiting time elapses; or
+     * <li>Some other node in grid fails, and lock is created in non-failoverSafe mode; or
+     * <li>Local node is stopped; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+     * </ul>
+     *
+     * <p>If lock is not broken (because of failure of lock owner node)
+     * in non-failoverSafe mode and local node is alive,
+     * before this method can return the current thread must
+     * re-acquire the lock associated with this condition. When the
+     * thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread:
+     * <ul>
+     * <li>has its interrupted status set on entry to this method; or
+     * <li>is {@linkplain Thread#interrupt interrupted} while waiting
+     * and interruption of thread suspension is supported,
+     * </ul>
+     * then {@link IgniteInterruptedException} is thrown and the current thread's
+     * interrupted status is cleared. It is not specified, in the first
+     * case, whether or not the test for interruption occurs before the lock
+     * is released.
+     *
+     * <p>The method returns an estimate of the number of nanoseconds
+     * remaining to wait given the supplied {@code nanosTimeout}
+     * value upon return, or a value less than or equal to zero if it
+     * timed out. This value can be used to determine whether and how
+     * long to re-wait in cases where the wait returns but an awaited
+     * condition still does not hold. Typical uses of this method take
+     * the following form:
+     *
+     *  <pre> {@code
+     * boolean aMethod(long timeout, TimeUnit unit) {
+     *   long nanos = unit.toNanos(timeout);
+     *   lock.lock();
+     *   try {
+     *     while (!conditionBeingWaitedFor()) {
+     *       if (nanos <= 0L)
+     *         return false;
+     *       nanos = theCondition.awaitNanos(nanos);
+     *     }
+     *     // ...
+     *   } finally {
+     *     lock.unlock();
+     *   }
+     * }}</pre>
+     *
+     * <p>Design note: This method requires a nanosecond argument so
+     * as to avoid truncation errors in reporting remaining times.
+     * Such precision loss would make it difficult for programmers to
+     * ensure that total waiting times are not systematically shorter
+     * than specified when re-waits occur.
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @param nanosTimeout the maximum time to wait, in nanoseconds
+     * @return an estimate of the {@code nanosTimeout} value minus
+     *         the time spent waiting upon return from this method.
+     *         A positive value may be used as the argument to a
+     *         subsequent call to this method to finish waiting out
+     *         the desired time.  A value less than or equal to zero
+     *         indicates that no time remains.
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     * @throws IgniteException if the node stopped, or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override long awaitNanos(long nanosTimeout) throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Causes the current thread to wait until it is signalled or interrupted,
+     * or the specified waiting time elapses. This method is behaviorally
+     * equivalent to:
+     *  <pre> {@code awaitNanos(unit.toNanos(time)) > 0}</pre>
+     *
+     * @param time the maximum time to wait
+     * @param unit the time unit of the {@code time} argument
+     * @return {@code false} if the waiting time detectably elapsed
+     *         before return from the method, else {@code true}
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     * @throws IgniteException if the node stopped, or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override boolean await(long time, TimeUnit unit) throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Causes the current thread to wait until it is signalled or interrupted,
+     * or the specified deadline elapses.
+     *
+     * <p>The lock associated with this condition is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of seven things happens:
+     * <ul>
+     * <li>Some other thread invokes the {@link #signal} method for this
+     * {@code Condition} and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the {@link #signalAll} method for this
+     * {@code Condition}; or
+     * <li>Some other thread {@linkplain Thread#interrupt interrupts} the
+     * current thread, and interruption of thread suspension is supported; or
+     * <li>Some other node in grid fails, and lock is created in non-failoverSafe mode; or
+     * <li>Local node is stopped; or
+     * <li>The specified deadline elapses; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+     * </ul>
+     *
+     * <p>If lock is not broken (because of failure of lock owner node)
+     * in non-failoverSafe mode and local node is alive,
+     * before this method can return the current thread must
+     * re-acquire the lock associated with this condition. When the
+     * thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread:
+     * <ul>
+     * <li>has its interrupted status set on entry to this method; or
+     * <li>is {@linkplain Thread#interrupt interrupted} while waiting
+     * and interruption of thread suspension is supported,
+     * </ul>
+     * then {@link IgniteInterruptedException} is thrown and the current thread's
+     * interrupted status is cleared. It is not specified, in the first
+     * case, whether or not the test for interruption occurs before the lock
+     * is released.
+     *
+     * <p>The return value indicates whether the deadline has elapsed,
+     * which can be used as follows:
+     *  <pre> {@code
+     * boolean aMethod(Date deadline) {
+     *   boolean stillWaiting = true;
+     *   lock.lock();
+     *   try {
+     *     while (!conditionBeingWaitedFor()) {
+     *       if (!stillWaiting)
+     *         return false;
+     *       stillWaiting = theCondition.awaitUntil(deadline);
+     *     }
+     *     // ...
+     *   } finally {
+     *     lock.unlock();
+     *   }
+     * }}</pre>
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @param deadline the absolute time to wait until
+     * @return {@code false} if the deadline has elapsed upon return, else
+     *         {@code true}
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     *         (and interruption of thread suspension is supported)
+     * @throws IgniteException if the node stopped, or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override boolean awaitUntil(Date deadline) throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Wakes up one waiting thread.
+     *
+     * <p>If any threads are waiting on this condition then one
+     * is selected for waking up. That thread must then re-acquire the
+     * lock before returning from {@code await}.
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @throws IgniteException if node is stopped or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override void signal() throws IgniteException;
+
+    /**
+     * Wakes up all waiting threads.
+     *
+     * <p>If any threads are waiting on this condition then they are
+     * all woken up. Each thread must re-acquire the lock before it can
+     * return from {@code await}.
+     *
+     * <p><b>Implementation Considerations</b>
+     *
+     * <p>The current thread is assumed to hold the lock associated with this
+     * {@code Condition} when this method is called. If not, an {@link IllegalMonitorStateException}
+     * will be thrown.
+     *
+     * @throws IgniteException if node is stopped or
+     *         node owning the lock failed in non-failoversafe mode
+     */
+    @Override void signalAll() throws IgniteException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/IgniteLock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteLock.java b/modules/core/src/main/java/org/apache/ignite/IgniteLock.java
new file mode 100644
index 0000000..2b3ad3d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteLock.java
@@ -0,0 +1,489 @@
+/*
+ * 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;
+
+import java.io.Closeable;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+
+/**
+ * This interface provides a rich API for working with distributed reentrant locks.
+ * <p>
+ * <h1 class="header">Functionality</h1>
+ * Distributed reentrant lock provides functionality similar to {@code java.util.concurrent.ReentrantLock}.
+ * <h1 class="header">Creating Distributed ReentrantLock</h1>
+ * Instance of cache reentrant lock can be created by calling the following method:
+ * {@link Ignite#reentrantLock(String, boolean, boolean, boolean)}.
+ * <h1 class="header">Protection from failover</h1>
+ * Ignite lock can automatically recover from node failure.
+ * <ul>
+ * <li>If failoverSafe flag is set to true upon creation,
+ * in case a node owning the lock fails, lock will be automatically released and become available for threads on other
+ * nodes to acquire. No exception will be thrown.
+ * <li>If failoverSafe flag is set to false upon creation,
+ * in case a node owning the lock fails, {@code IgniteException} will be thrown on every other node attempting to
+ * perform any operation on this lock. No automatic recovery will be attempted,
+ * and lock will be marked as broken (i.e. unusable), which can be checked using the method #isBroken().
+ * Broken lock cannot be reused again.
+ * </ul>
+ *
+ * <h1 class="header">Implementation issues</h1>
+ * Ignite lock comes in two flavours: fair and non-fair. Non-fair lock assumes no ordering should be imposed
+ * on acquiring threads; in case of contention, threads from all nodes compete for the lock once the lock is released.
+ * In most cases this is the desired behaviour. However, in some cases, using the non-fair lock can lead to uneven load
+ * distribution among nodes.
+ * Fair lock solves this issue by imposing strict FIFO ordering policy at a cost of an additional transaction.
+ * This ordering does not guarantee fairness of thread scheduling (similar to {@code java.util.concurrent.ReentrantLock}).
+ * Thus, one of many threads on any node using a fair lock may obtain it multiple times in succession while other
+ * active threads are not progressing and not currently holding the lock. Also note that the untimed tryLock method
+ * does not honor the fairness setting. It will succeed if the lock is available even if other threads are waiting.
+ *
+ * </p>
+ * As a rule of thumb, whenever there is a reasonable time window between successive calls to release and acquire
+ * the lock, non-fair lock should be preferred:
+ *
+ * <pre> {@code
+ *      while(someCondition){
+ *          // do anything
+ *          lock.lock();
+ *          try{
+ *              // ...
+ *          }
+ *          finally {
+ *              lock.unlock();
+ *          }
+ *      }
+ * }</pre>
+ *
+ * If successive calls to release/acquire are following immediately,
+ * e.g.
+ *
+ * <pre> {@code
+ *      while(someCondition){
+ *          lock.lock();
+ *          try {
+ *              // do something
+ *          }
+ *          finally {
+ *              lock.unlock();
+ *          }
+ *      }
+ * }</pre>
+ *
+ * using the fair lock is reasonable in order to allow even distribution of load among nodes
+ * (although overall throughput may be lower due to increased overhead).
+ *
+ */
+public interface IgniteLock extends Lock, Closeable {
+    /**
+     * Name of atomic reentrant lock.
+     *
+     * @return Name of atomic reentrant lock.
+     */
+    public String name();
+
+    /**
+     * Acquires the distributed reentrant lock.
+     *
+     * <p>Acquires the lock if it is not held by another thread and returns
+     * immediately, setting the lock hold count to one.
+     *
+     * <p>If the current thread already holds this lock then the hold count
+     * is incremented by one and the method returns immediately.
+     *
+     * <p>If the lock is held by another thread then the
+     * current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until one of four things happens:
+     *
+     * <ul>
+     *
+     * <li>The lock is acquired by the current thread; or
+     *
+     * <li>Lock is broken (any node failed while owning this lock), and lock is created in
+     * non-failoverSafe mode.
+     *
+     * <li>Local node is stopped.
+     *
+     * @throws IgniteException if the node is stopped or broken in non-failoverSafe mode
+     */
+    void lock() throws IgniteException;
+
+    /**
+     * Acquires the lock unless the current thread is
+     * {@linkplain Thread#interrupt interrupted}.
+     *
+     * <p>Acquires the lock if it is not held by another thread and returns
+     * immediately, setting the lock hold count to one.
+     *
+     * <p>If the current thread already holds this lock then the hold count
+     * is incremented by one and the method returns immediately.
+     *
+     * <p>If the lock is held by another thread then the
+     * current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until one of four things happens:
+     *
+     * <ul>
+     *
+     * <li>The lock is acquired by the current thread; or
+     *
+     * <li>Some other thread {@linkplain Thread#interrupt interrupts} the
+     * current thread.
+     *
+     * <li>Lock is broken (any node failed while owning this lock), and lock is created in
+     * non-failoverSafe mode.
+     *
+     * <li>Local node is stopped.
+     *
+     * </ul>
+     *
+     * <p>If the lock is acquired by the current thread then the lock hold
+     * count is set to one.
+     *
+     * <p>If the current thread:
+     *
+     * <ul>
+     *
+     * <li>has its interrupted status set on entry to this method; or
+     *
+     * <li>is {@linkplain Thread#interrupt interrupted} while acquiring
+     * the lock; or
+     *
+     * then {@link IgniteInterruptedException} is thrown and the current thread's
+     * interrupted status is cleared.
+     *
+     * </ul>
+     *
+     * <p>{@link IgniteException} is thrown in case:
+     *
+     * <ul>
+     *
+     * <li>the lock is broken before or during the attempt to acquire this lock; or
+     *
+     * <li>local node is stopped,
+     *
+     * </ul>
+     *
+     * <p>In this implementation, as this method is an explicit
+     * interruption point, preference is given to responding to the
+     * interrupt over normal or reentrant acquisition of the lock.
+     *
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     * @throws IgniteException if the lock is broken in non-failoverSafe mode (any node failed while owning this lock),
+     *         or local node is stopped
+     */
+    @Override public void lockInterruptibly() throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Acquires the lock only if it is free at the time of invocation.
+     *
+     * <p>Acquires the lock if it is available and returns immediately
+     * with the value {@code true}.
+     * If the lock is not available then this method will return
+     * immediately with the value {@code false}.
+     *
+     * <p>A typical usage idiom for this method would be:
+     *  <pre> {@code
+     * Lock lock = ...;
+     * if (lock.tryLock()) {
+     *   try {
+     *     // manipulate protected state
+     *   } finally {
+     *     lock.unlock();
+     *   }
+     * } else {
+     *   // perform alternative actions
+     * }}</pre>
+     *
+     * This usage ensures that the lock is unlocked if it was acquired, and
+     * doesn't try to unlock if the lock was not acquired.
+     *
+     * If node is stopped, or any node failed while owning the lock in non-failoverSafe mode,
+     * then {@link IgniteException} is thrown.
+     *
+     * @return {@code true} if the lock was acquired and
+     *         {@code false} otherwise
+     *
+     * @throws IgniteException if node is stopped, or lock is already broken in non-failover safe mode
+     */
+    @Override public boolean tryLock() throws IgniteException;
+
+    /**
+     * Acquires the lock if it is not held by another thread within the given
+     * waiting time and the current thread has not been
+     * {@linkplain Thread#interrupt interrupted}.
+     *
+     * <p>Acquires the lock if it is not held by another thread and returns
+     * immediately with the value {@code true}, setting the lock hold count
+     * to one.
+     *
+     * <p>If the current thread
+     * already holds this lock then the hold count is incremented by one and
+     * the method returns {@code true}.
+     *
+     * <p>If the lock is held by another thread then the
+     * current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until one of five things happens:
+     *
+     * <ul>
+     *
+     * <li>The lock is acquired by the current thread; or
+     *
+     * <li>Some other thread {@linkplain Thread#interrupt interrupts}
+     * the current thread; or
+     *
+     * <li>Lock is broken (any node failed while owning this lock), and lock is created in
+     * non-failoverSafe mode.
+     *
+     * <li>Local node is stopped.
+     *
+     * <li>The specified waiting time elapses
+     *
+     * </ul>
+     *
+     * <p>If the lock is acquired then the value {@code true} is returned and
+     * the lock hold count is set to one.
+     *
+     * <p>If the current thread:
+     *
+     * <ul>
+     *
+     * <li>has its interrupted status set on entry to this method; or
+     *
+     * <li>is {@linkplain Thread#interrupt interrupted} while
+     * acquiring the lock; or
+     *
+     * </ul>
+     * then {@link IgniteInterruptedException} is thrown and the current thread's
+     * interrupted status is cleared.
+     *
+     * <p>{@link IgniteException} is thrown in case:
+     *
+     * <ul>
+     *
+     * <li>the lock is broken before or during the attempt to acquire this lock; or
+     *
+     * <li>local node is stopped,
+     *
+     * </ul>
+     *
+     * <p>If the specified waiting time elapses then the value {@code false}
+     * is returned.  If the time is less than or equal to zero, the method
+     * will not wait at all.
+     *
+     * <p>In this implementation, as this method is an explicit
+     * interruption point, preference is given to responding to the
+     * interrupt over normal or reentrant acquisition of the lock, and
+     * over reporting the elapse of the waiting time.
+     *
+     * @param timeout the time to wait for the lock
+     * @param unit the time unit of the timeout argument
+     * @return {@code true} if the lock was free and was acquired by the
+     *         current thread, or the lock was already held by the current
+     *         thread; and {@code false} if the waiting time elapsed before
+     *         the lock could be acquired
+     * @throws IgniteInterruptedException if the current thread is interrupted
+     * @throws IgniteException if node is stopped, or lock is already broken in non-failover safe mode
+     * @throws NullPointerException if the time unit is null
+     */
+    @Override public boolean tryLock(long timeout, TimeUnit unit) throws IgniteInterruptedException, IgniteException;
+
+    /**
+     * Releases the lock.
+     *
+     * If lock is not owned by current thread, then an {@link
+     * IllegalMonitorStateException} is thrown.
+     * If lock is already broken prior to invocation of this method, and
+     * lock is created in non-failover safe mode, then {@link IgniteException} is thrown.
+     *
+     * @throws IllegalMonitorStateException if not owned by current thread
+     * @throws IgniteException if node is stopped, or lock is already broken in non-failover safe mode
+     */
+    void unlock() throws IgniteInterruptedException;
+
+    /**
+     * Returns a {@link Condition} instance for use with this
+     * {@link IgniteLock} instance.
+     *
+     * <ul>
+     *
+     * <li>If this lock is not held when any of the {@link Condition}
+     * {@linkplain Condition#await() waiting} or {@linkplain
+     * Condition#signal signalling} methods are called, then an {@link
+     * IllegalMonitorStateException} is thrown.
+     *
+     * <li>When the condition {@linkplain Condition#await() waiting}
+     * methods are called the lock is released and, before they
+     * return, the lock is reacquired and the lock hold count restored
+     * to what it was when the method was called.
+     *
+     * <li>If a thread is {@linkplain Thread#interrupt interrupted}
+     * while waiting then the wait will terminate, an {@link
+     * IgniteInterruptedException} will be thrown, and the thread's
+     * interrupted status will be cleared.
+     *
+     * <li> Waiting threads are signalled in FIFO order.
+     *
+     * </ul>
+     *
+     * @param name Name of the distributed condition object
+     *
+     * @return the Condition object
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public IgniteCondition getOrCreateCondition(String name) throws IgniteException;
+
+    /**
+     * This method is not supported in IgniteLock,
+     * Any invocation of this method will result in {@linkplain UnsupportedOperationException}.
+     * Correct way to obtain Condition object is through method {@linkplain IgniteLock#getOrCreateCondition(String)}
+     *
+     */
+    @Override public Condition newCondition();
+
+    /**
+     * Queries the number of holds on this lock by the current thread.
+     *
+     * @return the number of holds on this lock by the current thread,
+     *         or zero if this lock is not held by the current thread
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public int getHoldCount() throws IgniteException;
+
+    /**
+     * Queries if this lock is held by the current thread.
+     *
+     * @return {@code true} if current thread holds this lock and
+     *         {@code false} otherwise
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean isHeldByCurrentThread() throws IgniteException;
+
+    /**
+     * Queries if this lock is held by any thread on any node. This method is
+     * designed for use in monitoring of the system state,
+     * not for synchronization control.
+     *
+     * @return {@code true} if any thread on this or any other node holds this lock and
+     *         {@code false} otherwise
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean isLocked() throws IgniteException;
+
+    /**
+     * Queries whether any threads on this node are waiting to acquire this lock. Note that
+     * because cancellations may occur at any time, a {@code true}
+     * return does not guarantee that any other thread will ever
+     * acquire this lock.  This method is designed primarily for use in
+     * monitoring of the system state.
+     *
+     * @return {@code true} if there may be other threads on this node waiting to
+     *         acquire the lock
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean hasQueuedThreads() throws IgniteException;
+
+    /**
+     * Queries whether the given thread is waiting to acquire this
+     * lock. Note that because cancellations may occur at any time, a
+     * {@code true} return does not guarantee that this thread
+     * will ever acquire this lock.  This method is designed primarily for use
+     * in monitoring of the system state.
+     *
+     * @param thread the thread
+     * @return {@code true} if the given thread is queued waiting for this lock
+     * @throws NullPointerException if the thread is null
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean hasQueuedThread(Thread thread) throws IgniteException;
+
+    /**
+     * Queries whether any threads on this node are waiting on the given condition
+     * associated with this lock. Note that because timeouts and
+     * interrupts may occur at any time, a {@code true} return does
+     * not guarantee that a future {@code signal} will awaken any
+     * threads.  This method is designed primarily for use in
+     * monitoring of the system state.
+     *
+     * @param condition the condition
+     * @return {@code true} if there are any waiting threads on this node
+     * @throws IllegalMonitorStateException if this lock is not held
+     * @throws IllegalArgumentException if the given condition is
+     *         not associated with this lock
+     * @throws NullPointerException if the condition is null
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean hasWaiters(IgniteCondition condition) throws IgniteException;
+
+    /**
+     * Returns an estimate of the number of threads on this node that are waiting on the
+     * given condition associated with this lock. Note that because
+     * timeouts and interrupts may occur at any time, the estimate
+     * serves only as an upper bound on the actual number of waiters.
+     * This method is designed for use in monitoring of the system
+     * state, not for synchronization control.
+     *
+     * @param condition the condition
+     * @return the estimated number of waiting threads on this node
+     * @throws IllegalMonitorStateException if this lock is not held
+     * @throws IllegalArgumentException if the given condition is
+     *         not associated with this lock
+     * @throws NullPointerException if the condition is null
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public int getWaitQueueLength(IgniteCondition condition) throws IgniteException;
+
+    /**
+     * Returns {@code true} if this lock is safe to use after node failure.
+     * If not, IgniteInterruptedException is thrown on every other node after node failure.
+     *
+     * @return {@code true} if this reentrant lock has failoverSafe set true
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean isFailoverSafe();
+
+    /**
+     * Returns {@code true} if this lock is fair. Fairness flag can only be set on lock creation.
+     *
+     * @return {@code true} if this reentrant lock has fairness flag set true.
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean isFair();
+
+    /**
+     * Returns true if any node that owned the locked failed before releasing the lock.
+     *
+     * @return true if any node failed while owning the lock since the lock on this node was initialized.
+     * @throws IgniteException if the lock is not initialized or already removed
+     */
+    public boolean isBroken() throws IgniteException;
+
+    /**
+     * Gets status of reentrant lock.
+     *
+     * @return {@code true} if reentrant lock was removed from cache, {@code false} in other case.
+     */
+    public boolean removed();
+
+    /**
+     * Removes reentrant lock.
+     *
+     * @throws IgniteException If operation failed.
+     */
+    @Override public void close();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 79d67df..1ff4543 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -876,7 +876,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        stash.set(U.readString(in));
+        U.readString(in); // Read for compatibility only. See #readResolve().
     }
 
     /**
@@ -887,7 +887,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
      */
     protected Object readResolve() throws ObjectStreamException {
         try {
-            return IgnitionEx.gridx(stash.get()).context();
+            return IgnitionEx.localIgnite().context();
         }
         catch (IllegalStateException e) {
             throw U.withCause(new InvalidObjectException(e.getMessage()), e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 5094415..0f180b2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -64,6 +64,7 @@ import org.apache.ignite.IgniteFileSystem;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteMessaging;
 import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteScheduler;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteServices;
@@ -3036,6 +3037,26 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public IgniteLock reentrantLock(
+        String name,
+        boolean failoverSafe,
+        boolean fair,
+        boolean create
+    ) {
+        guard();
+
+        try {
+            return ctx.dataStructures().reentrantLock(name, failoverSafe, fair, create);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public <T> IgniteQueue<T> queue(String name,
         int cap,
         CollectionConfiguration cfg)

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
index 10aa71e..1cad22f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
@@ -43,6 +43,7 @@ import org.apache.ignite.IgniteAtomicStamped;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCountDownLatch;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteQueue;
 import org.apache.ignite.IgniteSemaphore;
@@ -95,6 +96,7 @@ import static org.apache.ignite.internal.processors.datastructures.DataStructure
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.COUNT_DOWN_LATCH;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.QUEUE;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SEMAPHORE;
+import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.REENTRANT_LOCK;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SET;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
@@ -135,6 +137,9 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
     /** Cache contains only {@code GridCacheSemaphoreState}. */
     private IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semView;
 
+    /** Cache contains only {@code GridCacheLockState}. */
+    private IgniteInternalCache<GridCacheInternalKey, GridCacheLockState> reentrantLockView;
+
     /** Cache contains only {@code GridCacheAtomicReferenceValue}. */
     private IgniteInternalCache<GridCacheInternalKey, GridCacheAtomicReferenceValue> atomicRefView;
 
@@ -177,7 +182,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         ctx.event().addLocalEventListener(
             new GridLocalEventListener() {
                 @Override public void onEvent(final Event evt) {
-                    // This may require cache operation to exectue,
+                    // This may require cache operation to execute,
                     // therefore cannot use event notification thread.
                     ctx.closure().callLocalSafe(
                         new Callable<Object>() {
@@ -189,6 +194,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
                                 for (GridCacheRemovable ds : dsMap.values()) {
                                     if (ds instanceof GridCacheSemaphoreEx)
                                         ((GridCacheSemaphoreEx)ds).onNodeRemoved(leftNodeId);
+                                    else if (ds instanceof GridCacheLockEx)
+                                        ((GridCacheLockEx)ds).onNodeRemoved(leftNodeId);
                                 }
 
                                 return null;
@@ -224,6 +231,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
 
             semView = atomicsCache;
 
+            reentrantLockView = atomicsCache;
+
             atomicLongView = atomicsCache;
 
             atomicRefView = atomicsCache;
@@ -262,6 +271,9 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         for (GridCacheRemovable ds : dsMap.values()) {
             if (ds instanceof GridCacheSemaphoreEx)
                 ((GridCacheSemaphoreEx)ds).stop();
+
+            if (ds instanceof GridCacheLockEx)
+                ((GridCacheLockEx)ds).onStop();
         }
 
         if (initLatch.getCount() > 0) {
@@ -1332,6 +1344,124 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets or creates reentrant lock. If reentrant lock is not found in cache,
+     * it is created using provided name, failover mode, and fairness mode parameters.
+     *
+     * @param name Name of the reentrant lock.
+     * @param failoverSafe Flag indicating behaviour in case of failure.
+     * @param fair Flag indicating fairness policy of this lock.
+     * @param create If {@code true} reentrant lock will be created in case it is not in cache.
+     * @return ReentrantLock for the given name or {@code null} if it is not found and
+     *      {@code create} is false.
+     * @throws IgniteCheckedException If operation failed.
+     */
+    public IgniteLock reentrantLock(final String name, final boolean failoverSafe, final boolean fair, final boolean create)
+        throws IgniteCheckedException {
+        A.notNull(name, "name");
+
+        awaitInitialization();
+
+        checkAtomicsConfiguration();
+
+        startQuery();
+
+        return getAtomic(new IgniteOutClosureX<IgniteLock>() {
+            @Override public IgniteLock applyx() throws IgniteCheckedException {
+                GridCacheInternalKey key = new GridCacheInternalKeyImpl(name);
+
+                dsCacheCtx.gate().enter();
+
+                try (IgniteInternalTx tx = CU.txStartInternal(dsCacheCtx, dsView, PESSIMISTIC, REPEATABLE_READ)) {
+                    GridCacheLockState val = cast(dsView.get(key), GridCacheLockState.class);
+
+                    // Check that reentrant lock hasn't been created in other thread yet.
+                    GridCacheLockEx reentrantLock = cast(dsMap.get(key), GridCacheLockEx.class);
+
+                    if (reentrantLock != null) {
+                        assert val != null;
+
+                        return reentrantLock;
+                    }
+
+                    if (val == null && !create)
+                        return null;
+
+                    if (val == null) {
+                        val = new GridCacheLockState(0, dsCacheCtx.nodeId(), 0, failoverSafe, fair);
+
+                        dsView.put(key, val);
+                    }
+
+                    GridCacheLockEx reentrantLock0 = new GridCacheLockImpl(
+                        name,
+                        key,
+                        reentrantLockView,
+                        dsCacheCtx);
+
+                    dsMap.put(key, reentrantLock0);
+
+                    tx.commit();
+
+                    return reentrantLock0;
+                }
+                catch (Error | Exception e) {
+                    dsMap.remove(key);
+
+                    U.error(log, "Failed to create reentrant lock: " + name, e);
+
+                    throw e;
+                }
+                finally {
+                    dsCacheCtx.gate().leave();
+                }
+            }
+        }, new DataStructureInfo(name, REENTRANT_LOCK, null), create, GridCacheLockEx.class);
+    }
+
+    /**
+     * Removes reentrant lock from cache.
+     *
+     * @param name Name of the reentrant lock.
+     * @param broken Flag indicating the reentrant lock is broken and should be removed unconditionally.
+     * @throws IgniteCheckedException If operation failed.
+     */
+    public void removeReentrantLock(final String name, final boolean broken) throws IgniteCheckedException {
+        assert name != null;
+        assert dsCacheCtx != null;
+
+        awaitInitialization();
+
+        removeDataStructure(new IgniteOutClosureX<Void>() {
+            @Override public Void applyx() throws IgniteCheckedException {
+                GridCacheInternal key = new GridCacheInternalKeyImpl(name);
+
+                dsCacheCtx.gate().enter();
+
+                try (IgniteInternalTx tx = CU.txStartInternal(dsCacheCtx, dsView, PESSIMISTIC, REPEATABLE_READ)) {
+                    // Check correctness type of removable object.
+                    GridCacheLockState val = cast(dsView.get(key), GridCacheLockState.class);
+
+                    if (val != null) {
+                        if (val.get() > 0 && !broken)
+                            throw new IgniteCheckedException("Failed to remove reentrant lock with blocked threads. ");
+
+                        dsView.remove(key);
+
+                        tx.commit();
+                    }
+                    else
+                        tx.setRollbackOnly();
+
+                    return null;
+                }
+                finally {
+                    dsCacheCtx.gate().leave();
+                }
+            }
+        }, name, REENTRANT_LOCK, null);
+    }
+
+    /**
      * Remove internal entry by key from cache.
      *
      * @param key Internal entry key.
@@ -1379,7 +1509,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
             if (evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED)
                 return evt.getValue() instanceof GridCacheCountDownLatchValue ||
-                    evt.getValue() instanceof GridCacheSemaphoreState;
+                    evt.getValue() instanceof GridCacheSemaphoreState ||
+                    evt.getValue() instanceof GridCacheLockState;
             else {
                 assert evt.getEventType() == EventType.REMOVED : evt;
 
@@ -1476,7 +1607,25 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
                                     ", actual=" + sem.getClass() + ", value=" + sem + ']');
                         }
                     }
+                    else if (val0 instanceof GridCacheLockState) {
+                        GridCacheInternalKey key = evt.getKey();
+
+                        // Notify reentrant lock on changes.
+                        final GridCacheRemovable reentrantLock = dsMap.get(key);
+
+                        GridCacheLockState val = (GridCacheLockState)val0;
+
+                        if (reentrantLock instanceof GridCacheLockEx) {
+                            final GridCacheLockEx lock0 = (GridCacheLockEx)reentrantLock;
 
+                            lock0.onUpdate(val);
+                        }
+                        else if (reentrantLock != null) {
+                            U.error(log, "Failed to cast object " +
+                                "[expected=" + IgniteLock.class.getSimpleName() +
+                                ", actual=" + reentrantLock.getClass() + ", value=" + reentrantLock + ']');
+                        }
+                    }
                 }
                 else {
                     assert evt.getEventType() == EventType.REMOVED : evt;
@@ -1694,7 +1843,10 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         SET(IgniteSet.class.getSimpleName()),
 
         /** */
-        SEMAPHORE(IgniteSemaphore.class.getSimpleName());
+        SEMAPHORE(IgniteSemaphore.class.getSimpleName()),
+
+        /** */
+        REENTRANT_LOCK(IgniteLock.class.getSimpleName());
 
         /** */
         private static final DataStructureType[] VALS = values();

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockEx.java
new file mode 100644
index 0000000..0887345
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockEx.java
@@ -0,0 +1,52 @@
+/*
+ * 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.datastructures;
+
+import java.util.UUID;
+import org.apache.ignite.IgniteLock;
+
+/**
+ * Grid cache reentrant lock ({@code 'Ex'} stands for external).
+ */
+public interface GridCacheLockEx extends IgniteLock, GridCacheRemovable {
+    /**
+     * Get current reentrant lock latch key.
+     *
+     * @return Lock key.
+     */
+    public GridCacheInternalKey key();
+
+    /**
+     * Callback to notify reentrant lock on changes.
+     *
+     * @param state New reentrant lock state.
+     */
+    public void onUpdate(GridCacheLockState state);
+
+    /**
+     * Callback to notify semaphore on topology changes.
+     *
+     * @param nodeId Id of the node that left the grid.
+     */
+    public void onNodeRemoved(UUID nodeId);
+
+    /**
+     * Callback to notify local reentrant lock instance on node stop.
+     */
+    public void onStop();
+}


[27/50] [abbrv] ignite git commit: IGNITE-3061: Platforms: now Spring context is propagated correctly for platform nodes.

Posted by sh...@apache.org.
IGNITE-3061: Platforms: now Spring context is propagated correctly for platform nodes.


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

Branch: refs/heads/ignite-2788
Commit: 0f6c97e61b465bd1a51280a3fb61a9bf2b12f985
Parents: 91fd8ff
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Apr 27 16:42:24 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../platform/PlatformAbstractBootstrap.java       | 17 ++++++++++++++---
 .../processors/platform/PlatformBootstrap.java    |  6 +++++-
 .../processors/platform/PlatformIgnition.java     | 18 +++++++++---------
 .../utils/PlatformConfigurationUtils.java         |  3 ++-
 4 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0f6c97e6/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
index 7e71e11..6fc46c4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractBootstrap.java
@@ -17,25 +17,36 @@
 
 package org.apache.ignite.internal.processors.platform;
 
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgnitionEx;
 import org.apache.ignite.internal.processors.platform.memory.PlatformExternalMemory;
+import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
+import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteClosure;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Base interop bootstrap implementation.
  */
 public abstract class PlatformAbstractBootstrap implements PlatformBootstrap {
     /** {@inheritDoc} */
-    @Override public PlatformProcessor start(IgniteConfiguration cfg, long envPtr, long dataPtr) {
+    @Override public PlatformProcessor start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx,
+        long envPtr, long dataPtr) {
         Ignition.setClientMode(new PlatformExternalMemory(null, dataPtr).input().readBoolean());
 
         IgniteConfiguration cfg0 = closure(envPtr).apply(cfg);
 
-        IgniteEx node = (IgniteEx) Ignition.start(cfg0);
+        try {
+            IgniteEx node = (IgniteEx)IgnitionEx.start(cfg0, springCtx);
 
-        return node.context().platform();
+            return node.context().platform();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0f6c97e6/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformBootstrap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformBootstrap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformBootstrap.java
index 9d64649..956a02d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformBootstrap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformBootstrap.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal.processors.platform;
 
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Platform bootstrap. Responsible for starting Ignite node with non-Java platform.
@@ -27,9 +29,11 @@ public interface PlatformBootstrap {
      * Start Ignite node.
      *
      * @param cfg Configuration.
+     * @param springCtx Optional Spring resource context.
      * @param envPtr Environment pointer.
      * @param dataPtr Optional pointer to additional data required for startup.
      * @return Platform processor.
      */
-    public PlatformProcessor start(IgniteConfiguration cfg, long envPtr, long dataPtr);
+    public PlatformProcessor start(IgniteConfiguration cfg, @Nullable GridSpringResourceContext springCtx,
+        long envPtr, long dataPtr);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0f6c97e6/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformIgnition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformIgnition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformIgnition.java
index d25acfc..928aa66 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformIgnition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformIgnition.java
@@ -28,6 +28,7 @@ import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgnitionEx;
 import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
+import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.jetbrains.annotations.Nullable;
@@ -60,16 +61,16 @@ public class PlatformIgnition {
         Thread.currentThread().setContextClassLoader(PlatformProcessor.class.getClassLoader());
 
         try {
-            IgniteConfiguration cfg = configuration(springCfgPath);
+            IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfg = configuration(springCfgPath);
 
             if (gridName != null)
-                cfg.setGridName(gridName);
+                cfg.get1().setGridName(gridName);
             else
-                gridName = cfg.getGridName();
+                gridName = cfg.get1().getGridName();
 
             PlatformBootstrap bootstrap = bootstrap(factoryId);
 
-            PlatformProcessor proc = bootstrap.start(cfg, envPtr, dataPtr);
+            PlatformProcessor proc = bootstrap.start(cfg.get1(), cfg.get2(), envPtr, dataPtr);
 
             PlatformProcessor old = instances.put(gridName, proc);
 
@@ -141,16 +142,15 @@ public class PlatformIgnition {
      * @param springCfgPath Path to Spring XML.
      * @return Configuration.
      */
-    private static IgniteConfiguration configuration(@Nullable String springCfgPath) {
+    private static IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> configuration(
+        @Nullable String springCfgPath) {
         if (springCfgPath == null)
-            return new IgniteConfiguration();
+            return new T2<>(new IgniteConfiguration(), null);
 
         try {
             URL url = U.resolveSpringUrl(springCfgPath);
 
-            IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> t = IgnitionEx.loadConfiguration(url);
-
-            return t.get1();
+            return IgnitionEx.loadConfiguration(url);
         }
         catch (IgniteCheckedException e) {
             throw new IgniteException("Failed to instantiate configuration from Spring XML: " + springCfgPath, e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/0f6c97e6/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 9d7f957..898bcf9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -62,7 +62,8 @@ import java.util.Map;
 /**
  * Configuration utils.
  */
-@SuppressWarnings("unchecked") public class PlatformConfigurationUtils {
+@SuppressWarnings("unchecked")
+public class PlatformConfigurationUtils {
     /**
      * Write .Net configuration to the stream.
      *


[10/50] [abbrv] ignite git commit: IGNITE-3015 - Clean up some GridGain references in Javadoc - Fixes #650.

Posted by sh...@apache.org.
IGNITE-3015 - Clean up some GridGain references in Javadoc - Fixes #650.

Signed-off-by: Alexey Kuznetsov <ak...@apache.org>


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

Branch: refs/heads/ignite-2788
Commit: bc98fa584fbc3e96cef0f4b96e5ea0ffa3938769
Parents: 7d4e22e
Author: Matt Hoffman <ma...@lucidworks.com>
Authored: Tue Apr 26 09:57:00 2016 +0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../org/apache/ignite/compute/ComputeJob.java   |  2 +-
 .../ignite/compute/ComputeJobAfterSend.java     |  2 +-
 .../compute/ComputeJobBeforeFailover.java       |  2 +-
 .../ignite/compute/ComputeJobContext.java       |  2 +-
 .../compute/ComputeJobContinuationAdapter.java  | 12 ++++-----
 .../ignite/compute/ComputeLoadBalancer.java     | 12 ++++-----
 .../org/apache/ignite/compute/ComputeTask.java  | 26 ++++++++++----------
 .../ignite/compute/ComputeTaskAdapter.java      |  8 +++---
 .../compute/ComputeTaskNoResultCache.java       |  6 ++---
 .../ignite/compute/ComputeTaskSession.java      |  4 +--
 .../ignite/compute/ComputeTaskSplitAdapter.java |  8 +++---
 .../apache/ignite/compute/gridify/Gridify.java  |  2 +-
 .../apache/ignite/igfs/mapreduce/IgfsTask.java  |  6 ++---
 .../ignite/internal/GridTaskSessionImpl.java    |  2 +-
 .../internal/processors/job/GridJobWorker.java  |  4 +--
 .../GridResourceJobContextInjector.java         |  4 +--
 .../processors/task/GridTaskProcessor.java      |  6 ++---
 .../processors/task/GridTaskWorker.java         | 10 ++++----
 .../org/apache/ignite/internal/util/F0.java     |  4 +--
 .../ignite/internal/util/IgniteUtils.java       |  2 +-
 .../ignite/internal/util/lang/GridFunc.java     |  4 +--
 .../apache/ignite/internal/util/typedef/PN.java |  2 +-
 .../jobstealing/JobStealingDisabled.java        |  2 +-
 .../communication/tcp/TcpCommunicationSpi.java  |  6 ++---
 .../spi/loadbalancing/LoadBalancingSpi.java     |  8 +++---
 .../adaptive/AdaptiveLoadBalancingSpi.java      | 20 +++++++--------
 .../adaptive/AdaptiveLoadProbe.java             |  2 +-
 .../roundrobin/RoundRobinLoadBalancingSpi.java  |  6 ++---
 .../WeightedRandomLoadBalancingSpi.java         | 14 +++++------
 .../GridEventStorageCheckAllEventsSelfTest.java |  2 +-
 .../GridTcpCommunicationBenchmark.java          | 26 ++++++++++----------
 .../GridP2PMissedResourceCacheSizeSelfTest.java |  6 ++---
 .../scalar/pimps/ScalarProjectionPimp.scala     |  4 +--
 .../scalar/pimps/ScalarTaskThreadContext.scala  |  4 +--
 .../uri/GridUriDeploymentFileProcessor.java     |  2 +-
 .../commands/top/VisorTopologyCommand.scala     |  2 +-
 .../scala/org/apache/ignite/visor/visor.scala   |  2 +-
 37 files changed, 118 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJob.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJob.java
index 9558255..dadc05d 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJob.java
@@ -102,7 +102,7 @@ import org.apache.ignite.IgniteException;
  * </ul>
  * Refer to corresponding resource documentation for more information.
  * <p>
- * <h1 class="header">GridComputeJobAdapter</h1>
+ * <h1 class="header">ComputeJobAdapter</h1>
  * Ignite comes with convenience {@link ComputeJobAdapter} adapter that provides
  * default empty implementation for {@link ComputeJob#cancel()} method and also
  * allows user to set and get job argument, if there is one.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAfterSend.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAfterSend.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAfterSend.java
index f81e969..4cc867f 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAfterSend.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobAfterSend.java
@@ -35,7 +35,7 @@ import java.lang.annotation.Target;
  * <pre name="code" class="java">
  * public class MyGridJob implements ComputeJob {
  *     ...
- *     &#64;GridComputeJobAfterSend
+ *     &#64;ComputeJobAfterSend
  *     public void onJobAfterSend() {
  *          ...
  *     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobBeforeFailover.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobBeforeFailover.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobBeforeFailover.java
index 7ae6455..7ad6350 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobBeforeFailover.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobBeforeFailover.java
@@ -36,7 +36,7 @@ import java.lang.annotation.Target;
  * <pre name="code" class="java">
  * public class MyGridJob implements ComputeJob {
  *     ...
- *     &#64;GridComputeJobBeforeFailover
+ *     &#64;ComputeJobBeforeFailover
  *     public void onJobBeforeFailover() {
  *          ...
  *     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContext.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContext.java
index 086356a..a0a22d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContext.java
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
  * all context attributes set on one node will be available on any other node
  * this job travels to.
  * <p>
- * You can also use {@code GridComputeJobContext} to communicate between SPI's and jobs.
+ * You can also use {@code ComputeJobContext} to communicate between SPI's and jobs.
  * For example, if you need to cancel an actively running job from {@link org.apache.ignite.spi.collision.CollisionSpi}
  * you may choose to set some context attribute on the job to mark the fact
  * that a job was cancelled by grid and not by a user. Context attributes can

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContinuationAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContinuationAdapter.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContinuationAdapter.java
index 936c9c7..8f92d98 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContinuationAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeJobContinuationAdapter.java
@@ -33,21 +33,21 @@ import org.jetbrains.annotations.Nullable;
  *      and {@link #argument(int)} methods.
  * </li>
  * </ul>
- * Here is an example of how {@code GridComputeJobAdapter} can be used from task logic
+ * Here is an example of how {@code ComputeJobAdapter} can be used from task logic
  * to create jobs. The example creates job adapter as anonymous class, but you
  * are free to create a separate class for it.
  * <pre name="code" class="java">
- * public class TestGridTask extends GridComputeTaskSplitAdapter&lt;String, Integer&gt; {
+ * public class TestGridTask extends ComputeTaskSplitAdapter&lt;String, Integer&gt; {
  *     // Used to imitate some logic for the
  *     // sake of this example
  *     private int multiplier = 3;
  *
  *     &#64;Override
  *     protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, final String arg) throws IgniteCheckedException {
- *         List&lt;GridComputeJobAdapter&lt;String&gt;&gt; jobs = new ArrayList&lt;GridComputeJobAdapter&lt;String&gt;&gt;(gridSize);
+ *         List&lt;ComputeJobAdapter&lt;String&gt;&gt; jobs = new ArrayList&lt;ComputeJobAdapter&lt;String&gt;&gt;(gridSize);
  *
  *         for (int i = 0; i < gridSize; i++) {
- *             jobs.add(new GridComputeJobAdapter() {
+ *             jobs.add(new ComputeJobAdapter() {
  *                 // Job execution logic.
  *                 public Object execute() throws IgniteCheckedException {
  *                     return multiplier * arg.length();
@@ -60,11 +60,11 @@ import org.jetbrains.annotations.Nullable;
  *
  *     // Aggregate multiple job results into
  *     // one task result.
- *     public Integer reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *     public Integer reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *         int sum = 0;
  *
  *         // For the sake of this example, let's sum all results.
- *         for (GridComputeJobResult res : results) {
+ *         for (ComputeJobResult res : results) {
  *             sum += (Integer)res.getData();
  *         }
  *

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeLoadBalancer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeLoadBalancer.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeLoadBalancer.java
index 356e5a6..7c4736c 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeLoadBalancer.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeLoadBalancer.java
@@ -39,7 +39,7 @@ import org.jetbrains.annotations.Nullable;
  * is transparent to your code and is handled automatically by the adapter.
  * Here is an example of how your task will look:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;String> {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;String> {
  *     &#64;Override
  *     protected Collection&lt;? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException {
  *         List&lt;MyFooBarJob> jobs = new ArrayList&lt;MyFooBarJob>(gridSize);
@@ -61,14 +61,14 @@ import org.jetbrains.annotations.Nullable;
  * case we manually inject load balancer and use it to pick the best node. Doing it in
  * such way would allow user to map some jobs manually and for others use load balancer.
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String, String> {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String, String> {
  *     // Inject load balancer.
  *     &#64;LoadBalancerResource
  *     ComputeLoadBalancer balancer;
  *
  *     // Map jobs to grid nodes.
- *     public Map&lt;? extends ComputeJob, GridNode> map(List&lt;GridNode> subgrid, String arg) throws IgniteCheckedException {
- *         Map&lt;MyFooBarJob, GridNode> jobs = new HashMap&lt;MyFooBarJob, GridNode>(subgrid.size());
+ *     public Map&lt;? extends ComputeJob, ClusterNode> map(List&lt;ClusterNode> subgrid, String arg) throws IgniteCheckedException {
+ *         Map&lt;MyFooBarJob, ClusterNode> jobs = new HashMap&lt;MyFooBarJob, ClusterNode>(subgrid.size());
  *
  *         // In more complex cases, you can actually do
  *         // more complicated assignments of jobs to nodes.
@@ -83,13 +83,13 @@ import org.jetbrains.annotations.Nullable;
  *     }
  *
  *     // Aggregate results into one compound result.
- *     public String reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *     public String reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *         // For the purpose of this example we simply
  *         // concatenate string representation of every
  *         // job result
  *         StringBuilder buf = new StringBuilder();
  *
- *         for (GridComputeJobResult res : results) {
+ *         for (ComputeJobResult res : results) {
  *             // Append string representation of result
  *             // returned by every job.
  *             buf.append(res.getData().toString());

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTask.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTask.java
index d24bf00..0c69fab 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTask.java
@@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
  *      Upon request to execute a grid task with given task name system will find
  *      deployed task with given name. Task needs to be deployed prior to execution
  *      (see {@link org.apache.ignite.IgniteCompute#localDeployTask(Class, ClassLoader)} method), however if task does not specify
- *      its name explicitly via {@link ComputeTaskName @GridComputeTaskName} annotation, it
+ *      its name explicitly via {@link ComputeTaskName @ComputeTaskName} annotation, it
  *      will be auto-deployed first time it gets executed.
  * </li>
  * <li>
@@ -62,7 +62,7 @@ import org.jetbrains.annotations.Nullable;
  *      on the remote node (immediately, buffered or canceled).
  * </li>
  * <li>
- *      Once job execution results become available method {@link #result(ComputeJobResult, List) result(GridComputeJobResult, List)}
+ *      Once job execution results become available method {@link #result(ComputeJobResult, List) result(ComputeJobResult, List)}
  *      will be called for each received job result. The policy returned by this method will
  *      determine the way task reacts to every job result:
  *      <ul>
@@ -80,7 +80,7 @@ import org.jetbrains.annotations.Nullable;
  *          If {@link ComputeJobResultPolicy#FAILOVER} policy is returned, then job will
  *          be failed over to another node for execution. The node to which job will get
  *          failed over is decided by {@link org.apache.ignite.spi.failover.FailoverSpi} SPI implementation.
- *          Note that if you use {@link ComputeTaskAdapter} adapter for {@code GridComputeTask}
+ *          Note that if you use {@link ComputeTaskAdapter} adapter for {@code ComputeTask}
  *          implementation, then it will automatically fail jobs to another node for 2
  *          known failure cases:
  *          <ul>
@@ -99,7 +99,7 @@ import org.jetbrains.annotations.Nullable;
  *      </ul>
  * </li>
  * <li>
- *      Once all results are received or {@link #result(ComputeJobResult, List) result(GridComputeJobResult, List)}
+ *      Once all results are received or {@link #result(ComputeJobResult, List) result(ComputeJobResult, List)}
  *      method returned {@link ComputeJobResultPolicy#REDUCE} policy, method {@link #reduce(List) reduce(List)}
  *      is called to aggregate received results into one final result. Once this method is finished the
  *      execution of the grid task is complete. This result will be returned to the user through
@@ -113,12 +113,12 @@ import org.jetbrains.annotations.Nullable;
  * use {@link ComputeTaskContinuousMapper} to continuously stream jobs from task even after {@code map(...)}
  * step is complete. Usually with continuous mapper the number of jobs within task
  * may grow too large - in this case it may make sense to use it in combination with
- * {@link ComputeTaskNoResultCache @GridComputeTaskNoResultCache} annotation.
+ * {@link ComputeTaskNoResultCache @ComputeTaskNoResultCache} annotation.
  * <p>
  * <h1 class="header">Task Result Caching</h1>
  * Sometimes job results are too large or task simply has too many jobs to keep track
  * of which may hinder performance. In such cases it may make sense to disable task
- * result caching by attaching {@link ComputeTaskNoResultCache @GridComputeTaskNoResultCache} annotation to task class, and
+ * result caching by attaching {@link ComputeTaskNoResultCache @ComputeTaskNoResultCache} annotation to task class, and
  * processing all results as they come in {@link #result(ComputeJobResult, List)} method.
  * When Ignite sees this annotation it will disable tracking of job results and
  * list of all job results passed into {@link #result(ComputeJobResult, List)} or
@@ -140,7 +140,7 @@ import org.jetbrains.annotations.Nullable;
  * Refer to corresponding resource documentation for more information.
  * <p>
  * <h1 class="header">Grid Task Adapters</h1>
- * {@code GridComputeTask} comes with several convenience adapters to make the usage easier:
+ * {@code ComputeTask} comes with several convenience adapters to make the usage easier:
  * <ul>
  * <li>
  * {@link ComputeTaskAdapter} provides default implementation for {@link ComputeTask#result(ComputeJobResult, List)}
@@ -149,14 +149,14 @@ import org.jetbrains.annotations.Nullable;
  * execution rejection (detected by {@link ComputeExecutionRejectedException} exception).
  * Here is an example of how a you would implement your task using {@link ComputeTaskAdapter}:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String, String&gt; {
  *     // Inject load balancer.
  *     &#64;LoadBalancerResource
  *     ComputeLoadBalancer balancer;
  *
  *     // Map jobs to grid nodes.
- *     public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *         Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *     public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *         Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *         // In more complex cases, you can actually do
  *         // more complicated assignments of jobs to nodes.
@@ -192,7 +192,7 @@ import org.jetbrains.annotations.Nullable;
  * method for splitting task into sub-jobs in homogeneous environments.
  * Here is an example of how you would implement your task using {@link ComputeTaskSplitAdapter}:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object, String&gt; {
  *     &#64;Override
  *     protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *         List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -207,13 +207,13 @@ import org.jetbrains.annotations.Nullable;
  *     }
  *
  *     // Aggregate results into one compound result.
- *     public String reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *     public String reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *         // For the purpose of this example we simply
  *         // concatenate string representation of every
  *         // job result
  *         StringBuilder buf = new StringBuilder();
  *
- *         for (GridComputeJobResult res : results) {
+ *         for (ComputeJobResult res : results) {
  *             // Append string representation of result
  *             // returned by every job.
  *             buf.append(res.getData().string());

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskAdapter.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskAdapter.java
index 2de0794..c5352aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskAdapter.java
@@ -23,16 +23,16 @@ import org.apache.ignite.cluster.ClusterTopologyException;
 
 /**
  * Convenience adapter for {@link ComputeTask} interface. Here is an example of
- * how {@code GridComputeTaskAdapter} can be used:
+ * how {@code ComputeTaskAdapter} can be used:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String, String&gt; {
  *     // Inject load balancer.
  *     &#64;LoadBalancerResource
  *     ComputeLoadBalancer balancer;
  *
  *     // Map jobs to grid nodes.
- *     public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *         Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *     public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *         Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *         // In more complex cases, you can actually do
  *         // more complicated assignments of jobs to nodes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskNoResultCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskNoResultCache.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskNoResultCache.java
index bbd0ff4..23f2082 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskNoResultCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskNoResultCache.java
@@ -28,8 +28,8 @@ import java.util.List;
  * This annotation disables caching of task results when attached to {@link ComputeTask} class
  * being executed. Use it when number of jobs within task grows too big, or jobs themselves
  * are too large to keep in memory throughout task execution. By default all results are cached and passed into
- * {@link ComputeTask#result(ComputeJobResult,List) GridComputeTask.result(GridComputeJobResult, List&lt;GridComputeJobResult&gt;)}
- * method or {@link ComputeTask#reduce(List) GridComputeTask.reduce(List&lt;GridComputeJobResult&gt;)} method.
+ * {@link ComputeTask#result(ComputeJobResult,List) ComputeTask.result(ComputeJobResult, List&lt;ComputeJobResult&gt;)}
+ * method or {@link ComputeTask#reduce(List) ComputeTask.reduce(List&lt;ComputeJobResult&gt;)} method.
  * When this annotation is attached to a task class, then this list of job results will always be empty.
  * <p>
  * Note that if this annotation is attached to a task class, then job siblings list is not maintained
@@ -44,7 +44,7 @@ import java.util.List;
  *
  * Use this annotation when job results are too large to hold in memory and can be discarded
  * after being processed in
- * {@link ComputeTask#result(ComputeJobResult, List) GridComputeTask.result(GridComputeJobResult, List&lt;GridComputeJobResult&gt;)}
+ * {@link ComputeTask#result(ComputeJobResult, List) ComputeTask.result(ComputeJobResult, List&lt;ComputeJobResult&gt;)}
  * method.
  */
 @Documented

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSession.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSession.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSession.java
index d6ebe15..66a72f7 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSession.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSession.java
@@ -86,7 +86,7 @@ import org.jetbrains.annotations.Nullable;
  * ...
  * // This field will be injected with distributed task session.
  * &#64TaskSessionResource
- * private GridComputeTaskSession ses;
+ * private ComputeTaskSession ses;
  * ...
  * </pre>
  * or from a setter method:
@@ -94,7 +94,7 @@ import org.jetbrains.annotations.Nullable;
  * // This setter method will be automatically called by the system
  * // to set grid task session.
  * &#64TaskSessionResource
- * void setSession(GridComputeTaskSession ses) {
+ * void setSession(ComputeTaskSession ses) {
  *     this.ses = ses;
  * }
  * </pre>

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSplitAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSplitAdapter.java b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSplitAdapter.java
index 0b62519..73ca7f7 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSplitAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/ComputeTaskSplitAdapter.java
@@ -32,9 +32,9 @@ import org.apache.ignite.resources.LoadBalancerResource;
  * in most homogeneous environments where all nodes are equally suitable for executing grid
  * job. See {@link #split(int, Object)} method for more details.
  * <p>
- * Below is a coding example of how you would use {@code GridComputeTaskSplitAdapter}:
+ * Below is a coding example of how you would use {@code ComputeTaskSplitAdapter}:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object, String&gt; {
  *     &#64;Override
  *     protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *         List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -49,13 +49,13 @@ import org.apache.ignite.resources.LoadBalancerResource;
  *     }
  *
  *     // Aggregate results into one compound result.
- *     public String reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *     public String reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *         // For the purpose of this example we simply
  *         // concatenate string representation of every
  *         // job result
  *         StringBuilder buf = new StringBuilder();
  *
- *         for (GridComputeJobResult res : results) {
+ *         for (ComputeJobResult res : results) {
  *             // Append string representation of result
  *             // returned by every job.
  *             buf.append(res.getData().string());

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/compute/gridify/Gridify.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/compute/gridify/Gridify.java b/modules/core/src/main/java/org/apache/ignite/compute/gridify/Gridify.java
index f7d96e0..3cf1b73 100644
--- a/modules/core/src/main/java/org/apache/ignite/compute/gridify/Gridify.java
+++ b/modules/core/src/main/java/org/apache/ignite/compute/gridify/Gridify.java
@@ -92,7 +92,7 @@ import org.apache.ignite.compute.gridify.aop.GridifyDefaultTask;
  *        }));
  *    }
  *
- *    public Integer reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *    public Integer reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *        return results.size() - 1 + F.sum(F.&lt;Integer&gt;jobResults(results));
  *    }
  * }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/igfs/mapreduce/IgfsTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/igfs/mapreduce/IgfsTask.java b/modules/core/src/main/java/org/apache/ignite/igfs/mapreduce/IgfsTask.java
index 34eb7da..fa0f137 100644
--- a/modules/core/src/main/java/org/apache/ignite/igfs/mapreduce/IgfsTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/igfs/mapreduce/IgfsTask.java
@@ -53,7 +53,7 @@ import org.jetbrains.annotations.Nullable;
  * <p>
  * Finally all generated jobs are sent to Grid nodes for execution.
  * <p>
- * As with regular {@code GridComputeTask} you can define your own logic for results handling and reduce step.
+ * As with regular {@code ComputeTask} you can define your own logic for results handling and reduce step.
  * <p>
  * Here is an example of such a task:
  * <pre name="code" class="java">
@@ -66,10 +66,10 @@ import org.jetbrains.annotations.Nullable;
  *     }
  *
  *     // Aggregate results into one compound result.
- *     public Integer reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *     public Integer reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *         Integer total = 0;
  *
- *         for (GridComputeJobResult res : results) {
+ *         for (ComputeJobResult res : results) {
  *             Integer cnt = res.getData();
  *
  *             // Null can be returned for non-existent file in case we decide to ignore such situations.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionImpl.java
index 677d464..bbe05b8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionImpl.java
@@ -188,7 +188,7 @@ public class GridTaskSessionImpl implements GridTaskSessionInternal {
         if (!fullSup)
             throw new IllegalStateException("Sessions attributes and checkpoints are disabled by default " +
                 "for better performance (to enable, annotate task class with " +
-                "@GridComputeTaskSessionFullSupport annotation).");
+                "@ComputeTaskSessionFullSupport annotation).");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java
index 164c9e7..5b04d6f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java
@@ -849,11 +849,11 @@ public class GridJobWorker extends GridWorker implements GridTimeoutObject {
                     ((ComputeJobMasterLeaveAware)job).onMasterNodeLeft(ses.session());
 
                     if (log.isDebugEnabled())
-                        log.debug("Successfully executed GridComputeJobMasterLeaveAware.onMasterNodeLeft() callback " +
+                        log.debug("Successfully executed ComputeJobMasterLeaveAware.onMasterNodeLeft() callback " +
                             "[nodeId=" + taskNode.id() + ", jobId=" + ses.getJobId() + ", job=" + job + ']');
                 }
                 catch (Exception e) {
-                    U.error(log, "Failed to execute GridComputeJobMasterLeaveAware.onMasterNodeLeft() callback " +
+                    U.error(log, "Failed to execute ComputeJobMasterLeaveAware.onMasterNodeLeft() callback " +
                         "[nodeId=" + taskNode.id() + ", jobId=" + ses.getJobId() + ", job=" + job + ']', e);
                 }
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceJobContextInjector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceJobContextInjector.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceJobContextInjector.java
index 3a6e779..69cab2e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceJobContextInjector.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/resource/GridResourceJobContextInjector.java
@@ -27,9 +27,9 @@ import org.apache.ignite.internal.managers.deployment.GridDeployment;
  */
 public class GridResourceJobContextInjector extends GridResourceBasicInjector<ComputeJobContext> {
     /**
-     * Creates GridComputeJobContext injector.
+     * Creates ComputeJobContext injector.
      *
-     * @param rsrc GridComputeJobContext resource to inject.
+     * @param rsrc ComputeJobContext resource to inject.
      */
     GridResourceJobContextInjector(ComputeJobContext rsrc) {
         super(rsrc);

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
index 75f3023..f54277c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
@@ -719,14 +719,14 @@ public class GridTaskProcessor extends GridProcessorAdapter {
 
     /**
      * Gets task name for a task class. It firstly checks
-     * {@link @GridComputeTaskName} annotation, then thread context
+     * {@link @ComputeTaskName} annotation, then thread context
      * map. If both are empty, class name is returned.
      *
      * @param dep Deployment.
      * @param cls Class.
      * @param map Thread context map.
      * @return Task name.
-     * @throws IgniteCheckedException If {@link @GridComputeTaskName} annotation is found, but has empty value.
+     * @throws IgniteCheckedException If {@link @ComputeTaskName} annotation is found, but has empty value.
      */
     private String taskName(GridDeployment dep, Class<?> cls,
         Map<GridTaskThreadContextKey, Object> map) throws IgniteCheckedException {
@@ -742,7 +742,7 @@ public class GridTaskProcessor extends GridProcessorAdapter {
             taskName = ann.value();
 
             if (F.isEmpty(taskName))
-                throw new IgniteCheckedException("Task name specified by @GridComputeTaskName annotation" +
+                throw new IgniteCheckedException("Task name specified by @ComputeTaskName annotation" +
                     " cannot be empty for class: " + cls);
         }
         else

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
index dc86343..659d5a6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
@@ -594,7 +594,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                 if (resCache && jobRes.size() > ctx.discovery().size() && jobRes.size() % SPLIT_WARN_THRESHOLD == 0)
                     LT.warn(log, null, "Number of jobs in task is too large for task: " + ses.getTaskName() +
                         ". Consider reducing number of jobs or disabling job result cache with " +
-                        "@GridComputeTaskNoResultCache annotation.");
+                        "@ComputeTaskNoResultCache annotation.");
             }
         }
 
@@ -801,7 +801,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                 ComputeJobResultPolicy plc = result(jobRes, results);
 
                 if (plc == null) {
-                    String errMsg = "Failed to obtain remote job result policy for result from GridComputeTask.result(..) " +
+                    String errMsg = "Failed to obtain remote job result policy for result from ComputeTask.result(..) " +
                         "method that returned null (will fail the whole task): " + jobRes;
 
                     finishTask(null, new IgniteCheckedException(errMsg));
@@ -814,7 +814,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                     // then there is no point to proceed.
                     if (state != State.WAITING) {
                         if (log.isDebugEnabled())
-                            log.debug("Ignoring GridComputeTask.result(..) value since task is already reducing or" +
+                            log.debug("Ignoring ComputeTask.result(..) value since task is already reducing or" +
                                 "finishing [res=" + res + ", job=" + ses + ", state=" + state + ']');
 
                         return;
@@ -941,7 +941,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                     else if (X.hasCause(e, ComputeJobFailoverException.class)) {
                         IgniteCheckedException e0 = new IgniteCheckedException(" Job was not failed over because " +
                             "ComputeJobResultPolicy.FAILOVER was not returned from " +
-                            "ComputeTask.result(...) method for job result with GridComputeJobFailoverException.", e);
+                            "ComputeTask.result(...) method for job result with ComputeJobFailoverException.", e);
 
                         finishTask(null, e0);
 
@@ -957,7 +957,7 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                 }
                 catch (Throwable e) {
                     String errMsg = "Failed to obtain remote job result policy for result from" +
-                        "GridComputeTask.result(..) method due to undeclared user exception " +
+                        "ComputeTask.result(..) method due to undeclared user exception " +
                         "(will fail the whole task): " + jobRes;
 
                     U.error(log, errMsg, e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java b/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
index 7e9e448..130987b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
@@ -318,7 +318,7 @@ public class F0 {
                     ids.addAll(((GridNodePredicate)p).nodeIds());
             }
 
-            // T must be <T extends GridNode>.
+            // T must be <T extends ClusterNode>.
             return (IgnitePredicate<T>)new GridNodePredicate(ids);
         }
         else {
@@ -394,7 +394,7 @@ public class F0 {
             else
                 ids.retainAll(list);
 
-            // T must be <T extends GridNode>.
+            // T must be <T extends ClusterNode>.
             return (IgnitePredicate<T>)new GridNodePredicate(ids);
         }
         else {

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index ad6f0e9..8a313cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -6523,7 +6523,7 @@ public abstract class IgniteUtils {
      * @return Short string representing the node.
      */
     public static String toShortString(ClusterNode n) {
-        return "GridNode [id=" + n.id() + ", order=" + n.order() + ", addr=" + n.addresses() +
+        return "ClusterNode [id=" + n.id() + ", order=" + n.order() + ", addr=" + n.addresses() +
             ", daemon=" + n.isDaemon() + ']';
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 7551b0e..8234dc4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -568,7 +568,7 @@ public class GridFunc {
      * Here's the typical example of how this method is used in {@code reduce()} method
      * implementation (this example sums up all the values of {@code Integer} type):
      * <pre name="code" class="java">
-     * public Integer reduce(List&lt;GridComputeJobResult&gt; res) throws IgniteCheckedException {
+     * public Integer reduce(List&lt;ComputeJobResult&gt; res) throws IgniteCheckedException {
      *     return F.sum(F.&lt;Integer&gt;jobResults(res));
      * }
      * </pre>
@@ -3014,7 +3014,7 @@ public class GridFunc {
                 }
             }
 
-            // T must be <T extends GridNode>.
+            // T must be <T extends ClusterNode>.
             return (IgnitePredicate<T>)new GridNodePredicate(ids);
         }
         else {

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/PN.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/PN.java b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/PN.java
index c706873..8623555 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/PN.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/PN.java
@@ -22,7 +22,7 @@ import org.apache.ignite.internal.util.lang.GridFunc;
 import org.apache.ignite.lang.IgnitePredicate;
 
 /**
- * Defines {@code alias} for <tt>GridPredicate&lt;GridNode&gt;</tt> by extending
+ * Defines {@code alias} for <tt>GridPredicate&lt;ClusterNode&gt;</tt> by extending
  * {@link org.apache.ignite.lang.IgnitePredicate}. Since Java doesn't provide type aliases (like Scala, for example) we resort
  * to these types of measures. This is intended to provide for more concise code without sacrificing
  * readability. For more information see {@link org.apache.ignite.lang.IgnitePredicate} and {@link org.apache.ignite.cluster.ClusterNode}.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingDisabled.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingDisabled.java b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingDisabled.java
index 9aad93d..bf16a68 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingDisabled.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/collision/jobstealing/JobStealingDisabled.java
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
  * Here is an example of how this annotation can be attached to a job class:
  * <pre name="code" class="java">
  * &#64;GridJobStealingDisabled
- * public class MyJob extends GridComputeJobAdapter&lt;Object&gt; {
+ * public class MyJob extends ComputeJobAdapter&lt;Object&gt; {
  *     public Serializable execute() throws IgniteCheckedException {
  *         // Job logic goes here.
  *         ...

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index 080437d..904047e 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -2422,7 +2422,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
 
                         if (errs == null)
                             errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " +
-                                "Make sure that each GridComputeTask and GridCacheTransaction has a timeout set " +
+                                "Make sure that each ComputeTask and GridCacheTransaction has a timeout set " +
                                 "in order to prevent parties from waiting forever in case of network issues " +
                                 "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
 
@@ -2450,7 +2450,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
 
                         if (errs == null)
                             errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " +
-                                "Make sure that each GridComputeTask and GridCacheTransaction has a timeout set " +
+                                "Make sure that each ComputeTask and GridCacheTransaction has a timeout set " +
                                 "in order to prevent parties from waiting forever in case of network issues " +
                                 "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
 
@@ -2490,7 +2490,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
 
                     if (errs == null)
                         errs = new IgniteCheckedException("Failed to connect to node (is node still alive?). " +
-                            "Make sure that each GridComputeTask and GridCacheTransaction has a timeout set " +
+                            "Make sure that each ComputeTask and GridCacheTransaction has a timeout set " +
                             "in order to prevent parties from waiting forever in case of network issues " +
                             "[nodeId=" + node.id() + ", addrs=" + addrs + ']');
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.java
index 6431fab..9d0c2b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/LoadBalancingSpi.java
@@ -34,7 +34,7 @@ import org.apache.ignite.spi.IgniteSpi;
  * is transparent to your code and is handled automatically by the adapter.
  * Here is an example of how your task could look:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object,Object&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object,Object&gt; {
  *    &#64;Override
  *    protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *        List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -56,14 +56,14 @@ import org.apache.ignite.spi.IgniteSpi;
  * case we manually inject load balancer and use it to pick the best node. Doing it in
  * such way would allow user to map some jobs manually and for others use load balancer.
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String,String&gt; {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String,String&gt; {
  *    // Inject load balancer.
  *    &#64;LoadBalancerResource
  *    ComputeLoadBalancer balancer;
  *
  *    // Map jobs to grid nodes.
- *    public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *        Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *    public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *        Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *        // In more complex cases, you can actually do
  *        // more complicated assignments of jobs to nodes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadBalancingSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadBalancingSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadBalancingSpi.java
index 3db9441..82bc015 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadBalancingSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadBalancingSpi.java
@@ -116,7 +116,7 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  *     }
  *
  *     // Calculate load based on number of active and waiting jobs.
- *     public double getLoad(GridNode node, int jobsSentSinceLastUpdate) {
+ *     public double getLoad(ClusterNode node, int jobsSentSinceLastUpdate) {
  *         GridNodeMetrics metrics = node.getMetrics();
  *
  *         if (useAvg) {
@@ -143,7 +143,7 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  * is transparent to your code and is handled automatically by the adapter.
  * Here is an example of how your task will look:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object, Object&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object, Object&gt; {
  *    &#64;Override
  *    protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *        List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -165,14 +165,14 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  * case we manually inject load balancer and use it to pick the best node. Doing it in
  * such way would allow user to map some jobs manually and for others use load balancer.
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String, String&gt; {
  *    // Inject load balancer.
  *    &#64;LoadBalancerResource
  *    ComputeLoadBalancer balancer;
  *
  *    // Map jobs to grid nodes.
- *    public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *        Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *    public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *        Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *        // In more complex cases, you can actually do
  *        // more complicated assignments of jobs to nodes.
@@ -185,13 +185,13 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  *    }
  *
  *    // Aggregate results into one compound result.
- *    public String reduce(List&lt;GridComputeJobResult&gt; results) throws IgniteCheckedException {
+ *    public String reduce(List&lt;ComputeJobResult&gt; results) throws IgniteCheckedException {
  *        // For the purpose of this example we simply
  *        // concatenate string representation of every
  *        // job result
  *        StringBuilder buf = new StringBuilder();
  *
- *        for (GridComputeJobResult res : results) {
+ *        for (ComputeJobResult res : results) {
  *            // Append string representation of result
  *            // returned by every job.
  *            buf.append(res.getData().string());
@@ -351,7 +351,7 @@ public class AdaptiveLoadBalancingSpi extends IgniteSpiAdapter implements LoadBa
                     }
 
                     case EVT_JOB_MAPPED: {
-                        // We should keep topology and use cache in GridComputeTask#map() method to
+                        // We should keep topology and use cache in ComputeTask#map() method to
                         // avoid O(n*n/2) complexity, after that we can drop caches.
                         // Here we set mapped property and later cache will be ignored
                         JobEvent jobEvt = (JobEvent)evt;
@@ -448,11 +448,11 @@ public class AdaptiveLoadBalancingSpi extends IgniteSpiAdapter implements LoadBa
         // Create new cached topology if there is no one. Do not
         // use cached topology after task has been mapped.
         if (weightedTop == null)
-            // Called from GridComputeTask#map(). Put new topology and false as not mapped yet.
+            // Called from ComputeTask#map(). Put new topology and false as not mapped yet.
             taskTops.put(ses.getId(), weightedTop = F.t(false, new WeightedTopology(top)));
         // We have topology - check if task has been mapped.
         else if (weightedTop.get1())
-            // Do not use cache after GridComputeTask#map().
+            // Do not use cache after ComputeTask#map().
             return new WeightedTopology(top).pickWeightedNode();
 
         return weightedTop.get2().pickWeightedNode();

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadProbe.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadProbe.java b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadProbe.java
index eb23d97..57fa4a9 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadProbe.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/adaptive/AdaptiveLoadProbe.java
@@ -46,7 +46,7 @@ import org.apache.ignite.cluster.ClusterNode;
  *     }
  *
  *     // Calculate load based on number of active and waiting jobs.
- *     public double getLoad(GridNode node, int jobsSentSinceLastUpdate) {
+ *     public double getLoad(ClusterNode node, int jobsSentSinceLastUpdate) {
  *         GridNodeMetrics metrics = node.getMetrics();
  *
  *         if (useAvg) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinLoadBalancingSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinLoadBalancingSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinLoadBalancingSpi.java
index 170e6be..069641b 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinLoadBalancingSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/roundrobin/RoundRobinLoadBalancingSpi.java
@@ -71,7 +71,7 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  * is transparent to your code and is handled automatically by the adapter.
  * Here is an example of how your task will look:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object, Object&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object, Object&gt; {
  *    &#64;Override
  *    protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *        List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -99,8 +99,8 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  *    ComputeLoadBalancer balancer;
  *
  *    // Map jobs to grid nodes.
- *    public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *        Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *    public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *        Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *        // In more complex cases, you can actually do
  *        // more complicated assignments of jobs to nodes.

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/weightedrandom/WeightedRandomLoadBalancingSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/weightedrandom/WeightedRandomLoadBalancingSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/weightedrandom/WeightedRandomLoadBalancingSpi.java
index 05dd3cb..1f69b52 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/weightedrandom/WeightedRandomLoadBalancingSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/loadbalancing/weightedrandom/WeightedRandomLoadBalancingSpi.java
@@ -64,7 +64,7 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  * is transparent to your code and is handled automatically by the adapter.
  * Here is an example of how your task could look:
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskSplitAdapter&lt;Object, Object&gt; {
+ * public class MyFooBarTask extends ComputeTaskSplitAdapter&lt;Object, Object&gt; {
  *    &#64;Override
  *    protected Collection&lt;? extends ComputeJob&gt; split(int gridSize, Object arg) throws IgniteCheckedException {
  *        List&lt;MyFooBarJob&gt; jobs = new ArrayList&lt;MyFooBarJob&gt;(gridSize);
@@ -86,14 +86,14 @@ import static org.apache.ignite.events.EventType.EVT_TASK_FINISHED;
  * case we manually inject load balancer and use it to pick the best node. Doing it in
  * such way would allow user to map some jobs manually and for others use load balancer.
  * <pre name="code" class="java">
- * public class MyFooBarTask extends GridComputeTaskAdapter&lt;String, String&gt; {
+ * public class MyFooBarTask extends ComputeTaskAdapter&lt;String, String&gt; {
  *    // Inject load balancer.
  *    &#64;LoadBalancerResource
  *    ComputeLoadBalancer balancer;
  *
  *    // Map jobs to grid nodes.
- *    public Map&lt;? extends ComputeJob, GridNode&gt; map(List&lt;GridNode&gt; subgrid, String arg) throws IgniteCheckedException {
- *        Map&lt;MyFooBarJob, GridNode&gt; jobs = new HashMap&lt;MyFooBarJob, GridNode&gt;(subgrid.size());
+ *    public Map&lt;? extends ComputeJob, ClusterNode&gt; map(List&lt;ClusterNode&gt; subgrid, String arg) throws IgniteCheckedException {
+ *        Map&lt;MyFooBarJob, ClusterNode&gt; jobs = new HashMap&lt;MyFooBarJob, ClusterNode&gt;(subgrid.size());
  *
  *        // In more complex cases, you can actually do
  *        // more complicated assignments of jobs to nodes.
@@ -291,7 +291,7 @@ public class WeightedRandomLoadBalancingSpi extends IgniteSpiAdapter implements
                     if (log.isDebugEnabled())
                         log.debug("Removed task topology from topology cache for session: " + sesId);
                 }
-                // We should keep topology and use cache in GridComputeTask#map() method to
+                // We should keep topology and use cache in ComputeTask#map() method to
                 // avoid O(n*n/2) complexity, after that we can drop caches.
                 // Here we set mapped property and later cache will be ignored
                 else if (evt.type() == EVT_JOB_MAPPED) {
@@ -338,12 +338,12 @@ public class WeightedRandomLoadBalancingSpi extends IgniteSpiAdapter implements
         // Create new cached topology if there is no one. Do not
         // use cached topology after task has been mapped.
         if (weightedTop == null) {
-            // Called from GridComputeTask#map(). Put new topology and false as not mapped yet.
+            // Called from ComputeTask#map(). Put new topology and false as not mapped yet.
             taskTops.put(ses.getId(), weightedTop = F.t(false, new WeightedTopology(top)));
         }
         // We have topology - check if task has been mapped.
         else if (weightedTop.get1()) {
-            // Do not use cache after GridComputeTask#map().
+            // Do not use cache after ComputeTask#map().
             return new WeightedTopology(top).pickWeightedNode();
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
index ad15894..c3f77c7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java
@@ -198,7 +198,7 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe
         try {
             fut.get();
 
-            assert false : "Grid with locally executed job with timeout should throw GridComputeTaskTimeoutException.";
+            assert false : "Grid with locally executed job with timeout should throw ComputeTaskTimeoutException.";
         }
         catch (IgniteException e) {
             info("Expected exception caught [taskFuture=" + fut + ", exception=" + e + ']');

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTcpCommunicationBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTcpCommunicationBenchmark.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTcpCommunicationBenchmark.java
index d732b14..b6c6797 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTcpCommunicationBenchmark.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTcpCommunicationBenchmark.java
@@ -52,7 +52,7 @@ package org.apache.ignite.loadtests.communication;
 //    private final Map<UUID, GridCommunicationSpi> spis = new HashMap<>();
 //
 //    /** */
-//    private final Collection<GridNode> nodes = new ArrayList<>();
+//    private final Collection<ClusterNode> nodes = new ArrayList<>();
 //
 //    /**
 //     * Disable automatic test SPI start.
@@ -63,7 +63,7 @@ package org.apache.ignite.loadtests.communication;
 //
 //    /** {@inheritDoc} */
 //    @Override protected void beforeTest() throws Exception {
-//        Map<GridNode, GridSpiTestContext> ctxs = new HashMap<>();
+//        Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
 //
 //        for (int i = 0; i < 2; i++) {
 //            GridCommunicationSpi spi = getCommunication();
@@ -94,8 +94,8 @@ package org.apache.ignite.loadtests.communication;
 //        }
 //
 //        // For each context set remote nodes.
-//        for (Map.Entry<GridNode, GridSpiTestContext> e : ctxs.entrySet()) {
-//            for (GridNode n : nodes) {
+//        for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
+//            for (ClusterNode n : nodes) {
 //                if (!n.equals(e.getKey()))
 //                    e.getValue().remoteNodes().add(n);
 //            }
@@ -136,10 +136,10 @@ package org.apache.ignite.loadtests.communication;
 //        assert spis.size() == 2;
 //        assert nodes.size() == 2;
 //
-//        Iterator<GridNode> it = nodes.iterator();
+//        Iterator<ClusterNode> it = nodes.iterator();
 //
-//        final GridNode sndNode = it.next();
-//        final GridNode rcvNode = it.next();
+//        final ClusterNode sndNode = it.next();
+//        final ClusterNode rcvNode = it.next();
 //
 //        final GridCommunicationSpi sndComm = spis.get(sndNode.id());
 //        final GridCommunicationSpi rcvComm = spis.get(rcvNode.id());
@@ -250,10 +250,10 @@ package org.apache.ignite.loadtests.communication;
 //        assert spis.size() == 2;
 //        assert nodes.size() == 2;
 //
-//        Iterator<GridNode> it = nodes.iterator();
+//        Iterator<ClusterNode> it = nodes.iterator();
 //
-//        final GridNode sndNode = it.next();
-//        final GridNode rcvNode = it.next();
+//        final ClusterNode sndNode = it.next();
+//        final ClusterNode rcvNode = it.next();
 //
 //        final GridCommunicationSpi sndComm = spis.get(sndNode.id());
 //        final GridCommunicationSpi rcvComm = spis.get(rcvNode.id());
@@ -377,10 +377,10 @@ package org.apache.ignite.loadtests.communication;
 //        assert spis.size() == 2;
 //        assert nodes.size() == 2;
 //
-//        Iterator<GridNode> it = nodes.iterator();
+//        Iterator<ClusterNode> it = nodes.iterator();
 //
-//        final GridNode sndNode = it.next();
-//        final GridNode rcvNode = it.next();
+//        final ClusterNode sndNode = it.next();
+//        final ClusterNode rcvNode = it.next();
 //
 //        final GridCommunicationSpi sndComm = spis.get(sndNode.id());
 //        final GridCommunicationSpi rcvComm = spis.get(rcvNode.id());

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PMissedResourceCacheSizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PMissedResourceCacheSizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PMissedResourceCacheSizeSelfTest.java
index 817b1ff..909089e 100644
--- a/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PMissedResourceCacheSizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/p2p/GridP2PMissedResourceCacheSizeSelfTest.java
@@ -189,8 +189,8 @@ public class GridP2PMissedResourceCacheSizeSelfTest extends GridCommonAbstractTe
 //
 //            g1.deployTask(task1);
 //            g1.deployTask(task2);
-//            g1.queryEvents(filter1, 0, F.<GridNode>localNode(g1)); // Deploy filter1.
-//            g1.queryEvents(filter2, 0, F.<GridNode>localNode(g2)); // Deploy filter2.
+//            g1.queryEvents(filter1, 0, F.<ClusterNode>localNode(g1)); // Deploy filter1.
+//            g1.queryEvents(filter2, 0, F.<ClusterNode>localNode(g2)); // Deploy filter2.
 //
 //            ldr.setExcludeClassNames(TASK_NAME1, TASK_NAME2, FILTER_NAME1, FILTER_NAME2);
 //
@@ -212,7 +212,7 @@ public class GridP2PMissedResourceCacheSizeSelfTest extends GridCommonAbstractTe
 //            executeFail(g1, filter2);
 //            executeFail(g1, g2, task2);
 //
-//            g1.queryEvents(filter1, 0, F.<GridNode>alwaysTrue());
+//            g1.queryEvents(filter1, 0, F.<ClusterNode>alwaysTrue());
 //
 //            g1.execute(task1, g2.localNode().id()).get();
 //        }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarProjectionPimp.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarProjectionPimp.scala b/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarProjectionPimp.scala
index c7fa9fe..737a798 100644
--- a/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarProjectionPimp.scala
+++ b/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarProjectionPimp.scala
@@ -579,7 +579,7 @@ class ScalarProjectionPimp[A <: ClusterGroup] extends PimpedType[A] with Iterabl
      * All default SPI implementations configured for this grid instance will be
      * used (i.e. failover, load balancing, collision resolution, etc.).
      * Note that if you need greater control on any aspects of Java code execution on the grid
-     * you should implement `GridComputeTask` which will provide you with full control over the execution.
+     * you should implement `ComputeTask` which will provide you with full control over the execution.
      *
      * Notice that `Runnable` and `Callable` implementations must support serialization as required
      * by the configured marshaller. For example, JDK marshaller will require that implementations would
@@ -616,7 +616,7 @@ class ScalarProjectionPimp[A <: ClusterGroup] extends PimpedType[A] with Iterabl
      * not block and returns immediately with future. All default SPI implementations
      * configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.).
      * Note that if you need greater control on any aspects of Java code execution on the grid
-     * you should implement `GridComputeTask` which will provide you with full control over the execution.
+     * you should implement `ComputeTask` which will provide you with full control over the execution.
      *
      * Note that class `GridAbsClosure` implements `Runnable` and class `GridOutClosure`
      * implements `Callable` interface. Note also that class `GridFunc` and typedefs provide rich

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarTaskThreadContext.scala
----------------------------------------------------------------------
diff --git a/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarTaskThreadContext.scala b/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarTaskThreadContext.scala
index 1fe0352..544ed40 100644
--- a/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarTaskThreadContext.scala
+++ b/modules/scalar/src/main/scala/org/apache/ignite/scalar/pimps/ScalarTaskThreadContext.scala
@@ -30,7 +30,7 @@ import org.jetbrains.annotations._
  */
 trait ScalarTaskThreadContext[T <: ClusterGroup] extends ScalarConversions { this: PimpedType[T] =>
     /**
-     * Properly typed version of `GridCompute#withName(...)` method.
+     * Properly typed version of `Compute#withName(...)` method.
      *
      * @param taskName Name of the task.
      */
@@ -38,7 +38,7 @@ trait ScalarTaskThreadContext[T <: ClusterGroup] extends ScalarConversions { thi
         value.ignite().compute(value).withName(taskName).asInstanceOf[T]
 
     /**
-     * Properly typed version of `GridCompute#withNoFailover()` method.
+     * Properly typed version of `Compute#withNoFailover()` method.
      */
     def withNoFailover$(): T =
         value.ignite().compute(value).withNoFailover().asInstanceOf[T]

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/urideploy/src/main/java/org/apache/ignite/spi/deployment/uri/GridUriDeploymentFileProcessor.java
----------------------------------------------------------------------
diff --git a/modules/urideploy/src/main/java/org/apache/ignite/spi/deployment/uri/GridUriDeploymentFileProcessor.java b/modules/urideploy/src/main/java/org/apache/ignite/spi/deployment/uri/GridUriDeploymentFileProcessor.java
index f507c11..d82a57e 100644
--- a/modules/urideploy/src/main/java/org/apache/ignite/spi/deployment/uri/GridUriDeploymentFileProcessor.java
+++ b/modules/urideploy/src/main/java/org/apache/ignite/spi/deployment/uri/GridUriDeploymentFileProcessor.java
@@ -343,7 +343,7 @@ final class GridUriDeploymentFileProcessor {
             for (Class<? extends ComputeTask<?, ?>> task : tasks) {
                 if (!isAllowedTaskClass(task)) {
                     U.warn(log, "Failed to load task. Task should be public none-abstract class " +
-                        "(might be inner static one) that implements GridComputeTask interface [taskCls=" + task + ']');
+                        "(might be inner static one) that implements ComputeTask interface [taskCls=" + task + ']');
                 }
                 else {
                     if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala
index d2ec662..63b6d2b 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala
@@ -152,7 +152,7 @@ class VisorTopologyCommand extends VisorConsoleCommand {
 
             val all = hasArgFlag("a", argLst)
 
-            var f: NodeFilter = (GridNode) => true
+            var f: NodeFilter = (ClusterNode) => true
 
             try {
                 argLst foreach (arg => {

http://git-wip-us.apache.org/repos/asf/ignite/blob/bc98fa58/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
index 335eb9f..3b4bf82 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala
@@ -244,7 +244,7 @@ object visor extends VisorTag {
      * Get grid node for specified ID.
      *
      * @param nid Node ID.
-     * @return GridNode instance.
+     * @return ClusterNode instance.
      * @throws IgniteException if Visor is disconnected or node not found.
      */
     def node(nid: UUID): ClusterNode = {


[23/50] [abbrv] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
deleted file mode 100644
index 274701f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.cache.distributed.dht;
-
-import java.util.Map;
-import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.util.lang.GridTriple;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Empty cache map that will never store any entries.
- */
-public class GridNoStorageCacheMap extends GridCacheConcurrentMap {
-    /** Empty triple. */
-    private final GridTriple<GridCacheMapEntry> emptyTriple =
-        new GridTriple<>(null, null, null);
-
-    /**
-     * @param ctx Cache context.
-     */
-    public GridNoStorageCacheMap(GridCacheContext ctx) {
-        super(ctx, 0, null, 0.75f, 1);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isEmpty() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int publicSize() {
-        return 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKey(Object key) {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheMapEntry randomEntry() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheMapEntry getEntry(Object key) {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheMapEntry putEntry(AffinityTopologyVersion topVer,
-        KeyCacheObject key,
-        @Nullable CacheObject val)
-    {
-        throw new AssertionError();
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridTriple<GridCacheMapEntry> putEntryIfObsoleteOrAbsent(
-        AffinityTopologyVersion topVer,
-        KeyCacheObject key,
-        @Nullable CacheObject val,
-        boolean create)
-    {
-        if (create) {
-            GridCacheMapEntry entry = ctx.useOffheapEntry() ?
-                new GridDhtOffHeapCacheEntry(ctx, topVer, key, hash(key.hashCode()), val) :
-                new GridDhtCacheEntry(ctx, topVer, key, hash(key.hashCode()), val);
-
-            return new GridTriple<>(entry, null, null);
-        }
-        else
-            return emptyTriple;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void putAll(Map<KeyCacheObject, CacheObject> m) {
-        throw new AssertionError();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean removeEntry(GridCacheEntryEx e) {
-        throw new AssertionError();
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheMapEntry removeEntryIfObsolete(KeyCacheObject key) {
-        throw new AssertionError();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridNoStorageCacheMap.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index e9873b7..9561ad8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -490,7 +490,7 @@ public class GridPartitionedGetFuture<K, V> extends CacheDistributedGetFutureAda
                     // Entry was not in memory or in swap, so we remove it from cache.
                     if (v == null) {
                         if (isNew && entry.markObsoleteIfEmpty(ver))
-                            cache.removeIfObsolete(key);
+                            cache.removeEntry(entry);
                     }
                     else {
                         cctx.addResult(locVals,

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
index 62c287a..fd59f48 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
@@ -414,7 +414,7 @@ public class GridPartitionedSingleGetFuture extends GridFutureAdapter<Object> im
                     // Entry was not in memory or in swap, so we remove it from cache.
                     if (v == null) {
                         if (isNew && entry.markObsoleteIfEmpty(ver))
-                            colocated.removeIfObsolete(key);
+                            colocated.removeEntry(entry);
                     }
                     else {
                         if (!skipVals && cctx.config().isStatisticsEnabled())

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index d28aaaa..ee909e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -175,9 +175,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
     }
 
     /** {@inheritDoc} */
-    @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            /** {@inheritDoc} */
+    @Override protected GridCacheMapEntryFactory entryFactory() {
+        return new GridCacheMapEntryFactory() {
             @Override public GridCacheMapEntry create(
                 GridCacheContext ctx,
                 AffinityTopologyVersion topVer,
@@ -190,7 +189,12 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
                 return new GridDhtAtomicCacheEntry(ctx, topVer, key, hash, val);
             }
-        });
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void init() {
+        super.init();
 
         updateReplyClos = new CI2<GridNearAtomicUpdateRequest, GridNearAtomicUpdateResponse>() {
             @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@@ -330,16 +334,24 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         final boolean skipStore = opCtx != null && opCtx.skipStore();
 
-        return getAsync0(ctx.toCacheKeyObject(key),
-            !ctx.config().isReadFromBackup(),
-            subjId,
-            taskName,
-            deserializeBinary,
-            expiryPlc,
-            false,
-            skipStore,
-            true,
-            needVer).get();
+        try {
+            return getAsync0(ctx.toCacheKeyObject(key, true),
+                !ctx.config().isReadFromBackup(),
+                subjId,
+                taskName,
+                deserializeBinary,
+                expiryPlc,
+                false,
+                skipStore,
+                true,
+                needVer).get();
+        }
+        catch (IgniteException e) {
+            if (e.getCause(IgniteCheckedException.class) != null)
+                throw e.getCause(IgniteCheckedException.class);
+            else
+                throw e;
+        }
     }
 
     /** {@inheritDoc} */
@@ -369,7 +381,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         return asyncOp(new CO<IgniteInternalFuture<V>>() {
             @Override public IgniteInternalFuture<V> apply() {
-                return getAsync0(ctx.toCacheKeyObject(key),
+                return getAsync0(ctx.toCacheKeyObject(key, true),
                     forcePrimary,
                     subjId0,
                     taskName,
@@ -415,7 +427,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         return asyncOp(new CO<IgniteInternalFuture<Map<K, V>>>() {
             @Override public IgniteInternalFuture<Map<K, V>> apply() {
-                return getAllAsync0(ctx.cacheKeysView(keys),
+                return getAllAsync0(ctx.cacheKeysView(keys, true),
                     forcePrimary,
                     subjId0,
                     taskName,
@@ -808,13 +820,16 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
             true,
             TRANSFORM);
 
-        return resFut.chain(new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, Map<K, EntryProcessorResult<T>>>() {
-            @Override public Map<K, EntryProcessorResult<T>> applyx(IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut) throws IgniteCheckedException {
-                Map<Object, EntryProcessorResult> resMap = (Map)fut.get();
+        return resFut.chain(
+            new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, Map<K, EntryProcessorResult<T>>>() {
+                @Override public Map<K, EntryProcessorResult<T>> applyx(
+                    IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut
+                ) throws IgniteCheckedException {
+                    Map<Object, EntryProcessorResult> resMap = (Map)fut.get();
 
-                return ctx.unwrapInvokeResult(resMap, keepBinary);
-            }
-        });
+                    return ctx.unwrapInvokeResult(resMap, keepBinary);
+                }
+            });
     }
 
     /** {@inheritDoc} */
@@ -1372,7 +1387,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                                 GridCacheVersion obsoleteVer = context().versions().next();
 
                                 if (isNew && entry.markObsoleteIfEmpty(obsoleteVer))
-                                    removeIfObsolete(key);
+                                    removeEntry(entry);
 
                                 success = false;
                             }
@@ -1952,9 +1967,15 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                             null,
                             req.keepBinary());
 
-                        Object val = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(ctx, entry.key(),
-                            old, req.keepBinary()),
-                            updated.value(ctx.cacheObjectContext(), false));
+                        Object val = ctx.config().getInterceptor().onBeforePut(
+                            new CacheLazyEntry(
+                                ctx,
+                                entry.key(),
+                                old,
+                                req.keepBinary()),
+                            updated.value(
+                                ctx.cacheObjectContext(),
+                                false));
 
                         if (val == null)
                             continue;
@@ -3329,7 +3350,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
                 respVers.add(ver);
 
-                if  (respVers.sizex() > DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE && guard.compareAndSet(false, true))
+                if (respVers.sizex() > DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE && guard.compareAndSet(false, true))
                     snd = true;
             }
             finally {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
index b5e2835..6b050b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
@@ -681,6 +681,13 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
             if (nearEntryProcessors == null)
                 nearEntryProcessors = unmarshalCollection(nearEntryProcessorsBytes, ctx, ldr);
         }
+
+        if (partIds != null && !partIds.isEmpty()) {
+            assert partIds.size() == keys.size();
+
+            for (int i = 0; i < keys.size(); i++)
+                keys.get(i).partition(partIds.get(i));
+        }
     }
 
     /** {@inheritDoc} */
@@ -835,6 +842,12 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
 
                 writer.incrementState();
 
+            case 25:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -1031,6 +1044,13 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
 
                 reader.incrementState();
 
+            case 25:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
         }
 
         return reader.afterMessageRead(GridDhtAtomicUpdateRequest.class);
@@ -1056,7 +1076,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 25;
+        return 26;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index edebd8c..dfdf1a5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -854,7 +854,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
             if (val == null && op != GridCacheOperation.DELETE)
                 continue;
 
-            KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
+            KeyCacheObject cacheKey = cctx.toCacheKeyObject(key, true);
 
             if (remapKeys != null && !remapKeys.contains(cacheKey))
                 continue;
@@ -969,12 +969,12 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
         if (val == null && op != GridCacheOperation.DELETE)
             throw new NullPointerException("Null value.");
 
-        KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
+        KeyCacheObject cacheKey = cctx.toCacheKeyObject(key, true);
 
         if (op != TRANSFORM)
             val = cctx.toCacheObject(val);
 
-        ClusterNode primary = cctx.affinity().primary(cacheKey, topVer);
+        ClusterNode primary = cctx.affinity().primary(cacheKey.partition(), topVer);
 
         if (primary == null)
             throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes " +

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
index 375c02f..e847c7c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
@@ -99,6 +99,10 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
     @GridDirectCollection(CacheObject.class)
     private List<CacheObject> vals;
 
+    /** Partitions of keys. */
+    @GridDirectCollection(int.class)
+    private List<Integer> partIds;
+
     /** Entry processors. */
     @GridDirectTransient
     private List<EntryProcessor<Object, Object, Object>> entryProcessors;
@@ -246,6 +250,8 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
         initSize = Math.min(maxEntryCnt, 10);
 
         keys = new ArrayList<>(initSize);
+
+        partIds = new ArrayList<>(initSize);
     }
 
     /** {@inheritDoc} */
@@ -384,12 +390,13 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
         if (op == TRANSFORM) {
             assert val instanceof EntryProcessor : val;
 
-            entryProcessor = (EntryProcessor<Object, Object, Object>) val;
+            entryProcessor = (EntryProcessor<Object, Object, Object>)val;
         }
 
         assert val != null || op == DELETE;
 
         keys.add(key);
+        partIds.add(key.partition());
 
         if (entryProcessor != null) {
             if (entryProcessors == null)
@@ -652,6 +659,13 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
 
         if (expiryPlcBytes != null && expiryPlc == null)
             expiryPlc = ctx.marshaller().unmarshal(expiryPlcBytes, U.resolveClassLoader(ldr, ctx.gridConfig()));
+
+        if (partIds != null && !partIds.isEmpty()) {
+            assert partIds.size() == keys.size();
+
+            for (int i = 0; i < keys.size(); i++)
+                keys.get(i).partition(partIds.get(i));
+        }
     }
 
     /** {@inheritDoc} */
@@ -812,6 +826,11 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
 
                 writer.incrementState();
 
+            case 26:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
         }
 
         return true;
@@ -1020,6 +1039,14 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
 
                 reader.incrementState();
 
+            case 26:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridNearAtomicUpdateRequest.class);
@@ -1048,7 +1075,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 26;
+        return 27;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index 9c699fa..0ae434a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -116,9 +116,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
     }
 
     /** {@inheritDoc} */
-    @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            /** {@inheritDoc} */
+    @Override protected GridCacheMapEntryFactory entryFactory() {
+        return new GridCacheMapEntryFactory() {
             @Override public GridCacheMapEntry create(
                 GridCacheContext ctx,
                 AffinityTopologyVersion topVer,
@@ -131,7 +130,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
 
                 return new GridDhtColocatedCacheEntry(ctx, topVer, key, hash, val);
             }
-        });
+        };
     }
 
     /** {@inheritDoc} */
@@ -245,8 +244,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
         }
 
         AffinityTopologyVersion topVer = tx == null ?
-                (canRemap ? ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) :
-                tx.topologyVersion();
+            (canRemap ? ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) :
+            tx.topologyVersion();
 
         subjId = ctx.subjectIdPerCall(subjId, opCtx);
 
@@ -526,7 +525,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
                                 GridCacheVersion obsoleteVer = context().versions().next();
 
                                 if (isNew && entry.markObsoleteIfEmpty(obsoleteVer))
-                                    removeIfObsolete(key);
+                                    removeEntry(entry);
 
                                 success = false;
                             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java
index dc225cf..821d2e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemander.java
@@ -675,7 +675,7 @@ public class GridDhtPartitionDemander {
                         "value, will ignore rebalance entries)");
 
                     if (cached.markObsoleteIfEmpty(null))
-                        cached.context().cache().removeIfObsolete(cached.key());
+                        cached.context().cache().removeEntry(cached);
 
                     return true;
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java
index d301ba9..b082c47 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplier.java
@@ -32,8 +32,8 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryInfoCollectSwapListener;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.cache.GridCacheSwapEntry;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
@@ -298,8 +298,8 @@ class GridDhtPartitionSupplier {
                         phase = SupplyContextPhase.ONHEAP;
 
                     if (phase == SupplyContextPhase.ONHEAP) {
-                        Iterator<GridDhtCacheEntry> entIt = sctx != null ?
-                            (Iterator<GridDhtCacheEntry>)sctx.entryIt : loc.entries().iterator();
+                        Iterator<GridCacheMapEntry> entIt = sctx != null ?
+                            (Iterator<GridCacheMapEntry>)sctx.entryIt : loc.allEntries().iterator();
 
                         while (entIt.hasNext()) {
                             if (!cctx.affinity().belongs(node, part, d.topologyVersion())) {
@@ -807,7 +807,7 @@ class GridDhtPartitionSupplier {
 
                     boolean partMissing = false;
 
-                    for (GridCacheEntryEx e : loc.entries()) {
+                    for (GridCacheEntryEx e : loc.allEntries()) {
                         if (!cctx.affinity().belongs(node, part, d.topologyVersion())) {
                             // Demander no longer needs this partition, so we send '-1' partition and move on.
                             s.missed(part);

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
index 4b876b4..7971173 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
@@ -39,12 +39,10 @@ import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheClearAllRunnable;
-import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap;
+import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheEntrySet;
-import org.apache.ignite.internal.processors.cache.GridCacheKeySet;
 import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.GridCachePreloader;
@@ -54,16 +52,14 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter;
 import org.apache.ignite.internal.processors.cache.distributed.dht.CacheGetFuture;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
-import org.apache.ignite.internal.util.typedef.C1;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.P1;
 import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.jetbrains.annotations.NotNull;
@@ -94,9 +90,8 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
     }
 
     /** {@inheritDoc} */
-    @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            /** {@inheritDoc} */
+    @Override protected GridCacheMapEntryFactory entryFactory() {
+        return new GridCacheMapEntryFactory() {
             @Override public GridCacheMapEntry create(
                 GridCacheContext ctx,
                 AffinityTopologyVersion topVer,
@@ -111,7 +106,7 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
 
                 return new GridNearCacheEntry(ctx, key, hash, val);
             }
-        });
+        };
     }
 
     /**
@@ -121,10 +116,10 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
 
     /** {@inheritDoc} */
     @Override public void onReconnected() {
-        map = new GridCacheConcurrentMap(
+        map = new GridCacheConcurrentMapImpl(
             ctx,
-            ctx.config().getNearConfiguration().getNearStartSize(),
-            map.getEntryFactory());
+            entryFactory(),
+            ctx.config().getNearConfiguration().getNearStartSize());
     }
 
     /** {@inheritDoc} */
@@ -138,7 +133,7 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
     }
 
     /** {@inheritDoc} */
-    @Override public GridCacheEntryEx entryEx(KeyCacheObject key, boolean touch) {
+    @Override public GridCacheMapEntry entryEx(KeyCacheObject key, boolean touch) {
         GridNearCacheEntry entry = null;
 
         while (true) {
@@ -157,7 +152,7 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
     }
 
     /** {@inheritDoc} */
-    @Override public GridCacheEntryEx entryEx(KeyCacheObject key, AffinityTopologyVersion topVer) {
+    @Override public GridCacheMapEntry entryEx(KeyCacheObject key, AffinityTopologyVersion topVer) {
         GridNearCacheEntry entry = null;
 
         while (true) {
@@ -311,7 +306,7 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
 
     /** {@inheritDoc} */
     @Override public long sizeLong() {
-        return nearEntries().size() + dht().sizeLong();
+        return nearEntries().size() + dht().size();
     }
 
     /** {@inheritDoc} */
@@ -339,15 +334,23 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
             @Override public boolean apply(GridCacheEntryEx entry) {
                 GridNearCacheEntry nearEntry = (GridNearCacheEntry)entry;
 
-                return nearEntry.valid(topVer);
+                return !nearEntry.deleted() && nearEntry.visitable(CU.empty0()) && nearEntry.valid(topVer);
             }
         });
     }
 
     /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<K, V>> entrySet(
-        @Nullable CacheEntryPredicate... filter) {
-        return new EntrySet(super.entrySet(filter), dht().entrySet(filter));
+    @Override public Set<Cache.Entry<K, V>> entrySet(@Nullable final CacheEntryPredicate... filter) {
+        CacheEntryPredicate p = new CacheEntryPredicateAdapter() {
+            @Override public boolean apply(GridCacheEntryEx ex) {
+                if (ex instanceof GridCacheMapEntry)
+                    return ((GridCacheMapEntry)ex).visitable(filter);
+                else
+                    return !ex.deleted() && F.isAll(ex, filter);
+            }
+        };
+
+        return new EntrySet(super.entrySet(p), dht().entrySet(p));
     }
 
     /** {@inheritDoc} */
@@ -355,49 +358,11 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
         return dht().entrySet(part);
     }
 
-    /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<K, V>> primaryEntrySet() {
-        final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
-
-        Collection<Cache.Entry<K, V>> entries =
-            F.flatCollections(
-                F.viewReadOnly(
-                    dht().topology().currentLocalPartitions(),
-                    new C1<GridDhtLocalPartition, Collection<Cache.Entry<K, V>>>() {
-                        @Override public Collection<Cache.Entry<K, V>> apply(GridDhtLocalPartition p) {
-                            Collection<GridDhtCacheEntry> entries0 = p.entries();
-
-                            return F.viewReadOnly(
-                                entries0,
-                                new C1<GridDhtCacheEntry, Cache.Entry<K, V>>() {
-                                    @Override public Cache.Entry<K, V> apply(GridDhtCacheEntry e) {
-                                        return e.wrapLazyValue();
-                                    }
-                                },
-                                new P1<GridDhtCacheEntry>() {
-                                    @Override public boolean apply(GridDhtCacheEntry e) {
-                                        return !e.obsoleteOrDeleted();
-                                    }
-                                });
-                        }
-                    },
-                    new P1<GridDhtLocalPartition>() {
-                        @Override public boolean apply(GridDhtLocalPartition p) {
-                            return p.primary(topVer);
-                        }
-                    }));
-
-        return new GridCacheEntrySet<>(ctx, entries, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<K> keySet() {
-        return new GridCacheKeySet<>(ctx, entrySet(), null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<K> primaryKeySet() {
-        return new GridCacheKeySet<>(ctx, primaryEntrySet(), null);
+    /**
+     * @return Keys for near cache only.
+     */
+    public Set<K> nearKeySet() {
+        return super.keySet();
     }
 
     /** {@inheritDoc} */
@@ -500,7 +465,8 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
     }
 
     /** {@inheritDoc} */
-    @Override public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, boolean near, boolean readers) {
+    @Override public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, boolean near,
+        boolean readers) {
         assert configuration().getNearConfiguration() != null;
 
         if (ctx.affinityNode()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
index 1b30afb..7d29381 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
@@ -619,7 +619,7 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
 
                     // Entry was not in memory or in swap, so we remove it from cache.
                     if (v == null && isNew && dhtEntry.markObsoleteIfEmpty(ver))
-                        dht.removeIfObsolete(key);
+                        dht.removeEntry(dhtEntry);
                 }
 
                 if (v != null) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java
index 0c2451e..fa7f367 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java
@@ -19,9 +19,11 @@ package org.apache.ignite.internal.processors.cache.distributed.near;
 
 import java.io.Externalizable;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
@@ -69,7 +71,11 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
 
     /** */
     @GridDirectCollection(KeyCacheObject.class)
-    private Collection<KeyCacheObject> keys;
+    private List<KeyCacheObject> keys;
+
+    /** Partition IDs. */
+    @GridDirectCollection(int.class)
+    private List<Integer> partIds;
 
     /** */
     @GridDirectCollection(boolean.class)
@@ -140,8 +146,17 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
         this.futId = futId;
         this.miniId = miniId;
         this.ver = ver;
-        this.keys = keys.keySet();
-        this.flags = keys.values();
+
+        this.keys = new ArrayList<>(keys.size());
+        flags = new ArrayList<>(keys.size());
+        partIds = new ArrayList<>(keys.size());
+
+        for (Map.Entry<KeyCacheObject, Boolean> entry : keys.entrySet()) {
+            this.keys.add(entry.getKey());
+            flags.add(entry.getValue());
+            partIds.add(entry.getKey().partition());
+        }
+
         this.readThrough = readThrough;
         this.topVer = topVer;
         this.subjId = subjId;
@@ -269,6 +284,13 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
             while (keysIt.hasNext())
                 keyMap.put(keysIt.next(), flagsIt.next());
         }
+
+        if (partIds != null && !partIds.isEmpty()) {
+            assert partIds.size() == keys.size();
+
+            for (int i = 0; i < keys.size(); i++)
+                keys.get(i).partition(partIds.get(i));
+        }
     }
 
     /** {@inheritDoc} */
@@ -363,6 +385,12 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
 
                 writer.incrementState();
 
+            case 15:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -475,6 +503,14 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
 
                 reader.incrementState();
 
+            case 15:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridNearGetRequest.class);
@@ -485,10 +521,9 @@ public class GridNearGetRequest extends GridCacheMessage implements GridCacheDep
         return 49;
     }
 
-
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 15;
+        return 16;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
index 2a6b0a8..2e8cd6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
@@ -445,6 +445,12 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 writer.incrementState();
 
+            case 34:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -573,6 +579,14 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
+            case 34:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridNearLockRequest.class);
@@ -585,7 +599,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 34;
+        return 35;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
index aa96720..62d37af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java
@@ -62,6 +62,9 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
     /** */
     private KeyCacheObject key;
 
+    /** Partition ID. */
+    private int partId = -1;
+
     /** Flags. */
     private byte flags;
 
@@ -118,6 +121,7 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
         this.cacheId = cacheId;
         this.futId = futId;
         this.key = key;
+        this.partId = key.partition();
         this.topVer = topVer;
         this.subjId = subjId;
         this.taskNameHash = taskNameHash;
@@ -233,6 +237,8 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
 
         assert key != null;
 
+        key.partition(partId);
+
         GridCacheContext cctx = ctx.cacheContext(cacheId);
 
         key.finishUnmarshal(cctx.cacheObjectContext(), ldr);
@@ -305,6 +311,14 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
 
                 reader.incrementState();
 
+            case 10:
+                partId = reader.readInt("partId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridNearSingleGetRequest.class);
@@ -367,6 +381,12 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
 
                 writer.incrementState();
 
+            case 10:
+                if (!writer.writeInt("partId", partId))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -384,7 +404,7 @@ public class GridNearSingleGetRequest extends GridCacheMessage implements GridCa
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 10;
+        return 11;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java
index 7652a4a..be78868 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearUnlockRequest.java
@@ -21,6 +21,7 @@ import java.io.Externalizable;
 import java.nio.ByteBuffer;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedUnlockRequest;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType;
 import org.apache.ignite.plugin.extensions.communication.MessageReader;
 import org.apache.ignite.plugin.extensions.communication.MessageWriter;
 
@@ -61,6 +62,14 @@ public class GridNearUnlockRequest extends GridDistributedUnlockRequest {
             writer.onHeaderWritten();
         }
 
+        switch (writer.state()) {
+            case 8:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
+        }
+
         return true;
     }
 
@@ -74,6 +83,16 @@ public class GridNearUnlockRequest extends GridDistributedUnlockRequest {
         if (!super.readFrom(buf, reader))
             return false;
 
+        switch (reader.state()) {
+            case 8:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+        }
+
         return reader.afterMessageRead(GridNearUnlockRequest.class);
     }
 
@@ -84,7 +103,7 @@ public class GridNearUnlockRequest extends GridDistributedUnlockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 8;
+        return 9;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
index 4ce1f36..16a35d3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCache.java
@@ -80,9 +80,8 @@ public class GridLocalCache<K, V> extends GridCacheAdapter<K, V> {
     }
 
     /** {@inheritDoc} */
-    @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            /** {@inheritDoc} */
+    @Override protected GridCacheMapEntryFactory entryFactory() {
+        return new GridCacheMapEntryFactory() {
             @Override public GridCacheMapEntry create(
                 GridCacheContext ctx,
                 AffinityTopologyVersion topVer,
@@ -92,7 +91,7 @@ public class GridLocalCache<K, V> extends GridCacheAdapter<K, V> {
             ) {
                 return new GridLocalCacheEntry(ctx, key, hash, val);
             }
-        });
+        };
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 3e0e2c2..cb6152d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -45,19 +45,16 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheOperationContext;
 import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
 import org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException;
-import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
-import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.GridCachePreloader;
 import org.apache.ignite.internal.processors.cache.GridCachePreloaderAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheReturn;
 import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.local.GridLocalCacheEntry;
+import org.apache.ignite.internal.processors.cache.local.GridLocalCache;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.F0;
@@ -85,7 +82,7 @@ import static org.apache.ignite.internal.processors.cache.GridCacheOperation.UPD
 /**
  * Non-transactional local cache.
  */
-public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
+public class GridLocalAtomicCache<K, V> extends GridLocalCache<K, V> {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -103,27 +100,12 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
      * @param ctx Cache context.
      */
     public GridLocalAtomicCache(GridCacheContext<K, V> ctx) {
-        super(ctx, ctx.config().getStartSize());
+        super(ctx);
 
         preldr = new GridCachePreloaderAdapter(ctx);
     }
 
     /** {@inheritDoc} */
-    @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            @Override public GridCacheMapEntry create(
-                GridCacheContext ctx,
-                AffinityTopologyVersion topVer,
-                KeyCacheObject key,
-                int hash,
-                CacheObject val
-            ) {
-                return new GridLocalCacheEntry(ctx, key, hash, val);
-            }
-        });
-    }
-
-    /** {@inheritDoc} */
     @Override public boolean isLocal() {
         return true;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
index e08f9b0..87b8e07 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteInternalTx.java
@@ -25,7 +25,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 17bed0b..b8447f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -40,7 +40,6 @@ import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CacheInvokeEntry;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
index e75ce91..4d8139f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
@@ -98,6 +98,9 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
     /** Cache ID. */
     private int cacheId;
 
+    /** Partition ID. */
+    private int partId = -1;
+
     /** Transient tx key. */
     @GridDirectTransient
     private IgniteTxKey txKey;
@@ -251,11 +254,12 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
         keepBinary(keepBinary);
 
         key = entry.key();
+        partId = entry.key().partition();
 
         cacheId = entry.context().cacheId();
     }
 
-     /**
+    /**
      * This constructor is meant for local transactions.
      *
      * @param ctx Cache registry.
@@ -303,6 +307,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
             addEntryProcessor(entryProcessor, invokeArgs);
 
         key = entry.key();
+        partId = entry.key().partition();
 
         cacheId = entry.context().cacheId();
     }
@@ -336,6 +341,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
         IgniteTxEntry cp = new IgniteTxEntry();
 
         cp.key = key;
+        cp.partId = partId;
         cp.cacheId = cacheId;
         cp.ctx = ctx;
 
@@ -476,7 +482,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
      *
      * @param skipStore Skip store flag.
      */
-    public void skipStore(boolean skipStore){
+    public void skipStore(boolean skipStore) {
         setFlag(skipStore, SKIP_STORE_FLAG_MASK);
     }
 
@@ -853,7 +859,8 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
      * @param clsLdr Class loader.
      * @throws IgniteCheckedException If un-marshalling failed.
      */
-    public void unmarshal(GridCacheSharedContext<?, ?> ctx, boolean near, ClassLoader clsLdr) throws IgniteCheckedException {
+    public void unmarshal(GridCacheSharedContext<?, ?> ctx, boolean near,
+        ClassLoader clsLdr) throws IgniteCheckedException {
         if (this.ctx == null) {
             GridCacheContext<?, ?> cacheCtx = ctx.cacheContext(cacheId);
 
@@ -884,6 +891,8 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
         key.finishUnmarshal(context().cacheObjectContext(), clsLdr);
 
+        key.partition(partId);
+
         val.unmarshal(this.ctx, clsLdr);
 
         if (expiryPlcBytes != null && expiryPlc == null)
@@ -933,7 +942,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
     /**
      * @param ver Entry version.
      */
-    public void entryReadVersion(GridCacheVersion  ver) {
+    public void entryReadVersion(GridCacheVersion ver) {
         assert this.serReadVer == null;
         assert ver != null;
 
@@ -1037,6 +1046,12 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
                 writer.incrementState();
 
+            case 12:
+                if (!writer.writeInt("partId", partId))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -1146,6 +1161,14 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
                 reader.incrementState();
 
+            case 12:
+                partId = reader.readInt("partId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(IgniteTxEntry.class);
@@ -1158,7 +1181,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 12;
+        return 13;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index cadf1a9..686f308 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -136,6 +136,16 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
 
     /**
      * @param ctx Cache context.
+     * @param obj Key value.
+     * @param userObj If {@code true} then given object is object provided by user and should be copied
+     *        before stored in cache.
+     * @param partition ID of partition this key belongs to.
+     * @return Cache key object.
+     */
+    public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj, int partition);
+
+    /**
+     * @param ctx Cache context.
      * @param obj Object.
      * @param userObj If {@code true} then given object is object provided by user and should be copied
      *        before stored in cache.

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index 9a70911..9b47e59 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -102,18 +102,24 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
 
     /** {@inheritDoc} */
     @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
-        throws IgniteCheckedException
-    {
+        throws IgniteCheckedException {
         return ctx.kernalContext().cache().context().marshaller().unmarshal(bytes, U.resolveClassLoader(clsLdr,
             ctx.kernalContext().config()));
     }
 
     /** {@inheritDoc} */
     @Override @Nullable public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
-        if (obj instanceof KeyCacheObject)
+        return toCacheKeyObject(ctx, obj, userObj, -1);
+    }
+
+    /** {@inheritDoc} */
+    @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj, int partition) {
+        if (obj instanceof KeyCacheObject) {
+            ((KeyCacheObject)obj).partition(partition);
             return (KeyCacheObject)obj;
+        }
 
-        return toCacheKeyObject0(obj, userObj);
+        return toCacheKeyObject0(obj, userObj, partition);
     }
 
     /**
@@ -123,17 +129,16 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
      * @return Key cache object.
      */
     @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
-    protected KeyCacheObject toCacheKeyObject0(Object obj, boolean userObj) {
+    protected KeyCacheObject toCacheKeyObject0(Object obj, boolean userObj, int partititon) {
         if (!userObj)
-            return new KeyCacheObjectImpl(obj, null);
+            return new KeyCacheObjectImpl(obj, null, partititon);
 
-        return new UserKeyCacheObjectImpl(obj);
+        return new UserKeyCacheObjectImpl(obj, partititon);
     }
 
     /** {@inheritDoc} */
     @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
-        throws IgniteCheckedException
-    {
+        throws IgniteCheckedException {
         assert valPtr != 0;
 
         int size = GridUnsafe.getInt(valPtr);
@@ -172,8 +177,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
     /** {@inheritDoc} */
     @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx,
         @Nullable Object obj,
-        boolean userObj)
-    {
+        boolean userObj) {
         if (obj == null || obj instanceof CacheObject)
             return (CacheObject)obj;
 
@@ -241,7 +245,6 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
         return 0;
     }
 
-
     /** {@inheritDoc} */
     @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws IgniteException {
         return obj;
@@ -290,7 +293,14 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
          * @param key Key.
          */
         UserKeyCacheObjectImpl(Object key) {
-            super(key, null);
+            this(key, -1);
+        }
+
+        /**
+         * @param key Key.
+         */
+        UserKeyCacheObjectImpl(Object key, int partition) {
+            super(key, null, partition);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/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 b6cbf3b..448dd8b 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
@@ -36,9 +36,9 @@ 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 static org.apache.ignite.internal.processors.cache.GridCacheUtils.retryTopologySafe;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-import static org.apache.ignite.internal.processors.cache.GridCacheUtils.retryTopologySafe;
 
 /**
  * Cache atomic reference implementation.

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/util/PartitionedReadOnlySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/PartitionedReadOnlySet.java b/modules/core/src/main/java/org/apache/ignite/internal/util/PartitionedReadOnlySet.java
new file mode 100644
index 0000000..5ab75c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/PartitionedReadOnlySet.java
@@ -0,0 +1,71 @@
+/*
+ * 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.util;
+
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.ignite.internal.util.typedef.F;
+
+/**
+ * Read-only wrapper over multiple sets.
+ */
+public class PartitionedReadOnlySet<T> extends AbstractSet<T> {
+    /** */
+    private final Collection<Set<T>> sets;
+
+    /**
+     * Constructor.
+     * @param sets Internal sets.
+     */
+    public PartitionedReadOnlySet(Collection<Set<T>> sets) {
+        this.sets = sets;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<T> iterator() {
+        Collection<Iterator<T>> iterators = new ArrayList<>(sets.size());
+
+        for (Set<T> set : sets)
+            iterators.add(set.iterator());
+
+        return F.flatIterators(iterators);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        int size = 0;
+
+        for (Set<T> set : sets)
+            size += set.size();
+
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean contains(Object o) {
+        for (Set<T> set : sets)
+            if (set.contains(o))
+                return true;
+
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/util/StripedCompositeReadWriteLock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/StripedCompositeReadWriteLock.java b/modules/core/src/main/java/org/apache/ignite/internal/util/StripedCompositeReadWriteLock.java
index 96445d8..12940e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/StripedCompositeReadWriteLock.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/StripedCompositeReadWriteLock.java
@@ -86,6 +86,16 @@ public class StripedCompositeReadWriteLock implements ReadWriteLock {
     }
 
     /**
+     * Queries if the write lock is held by the current thread.
+     *
+     * @return {@code true} if the current thread holds the write lock and
+     *         {@code false} otherwise
+     */
+    public boolean isWriteLockedByCurrentThread() {
+        return locks[locks.length - 1].isWriteLockedByCurrentThread();
+    }
+
+    /**
      * Read lock.
      */
     @SuppressWarnings("unused")

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 8234dc4..ab31625 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -287,7 +287,6 @@ public class GridFunc {
         }
     };
 
-
     /** */
     private static final IgniteClosure CACHE_ENTRY_VAL_GET = new IgniteClosure() {
         @SuppressWarnings({"unchecked"})
@@ -4665,4 +4664,4 @@ public class GridFunc {
     public static IgnitePredicate<IgniteInternalFuture<?>> unfinishedFutures() {
         return UNFINISHED_FUTURE;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
index b5151c7..1be7af8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java
@@ -233,9 +233,9 @@ public class VisorCache implements Serializable {
     protected void estimateMemorySize(IgniteEx ignite, GridCacheAdapter ca, int sample) throws IgniteCheckedException {
         int size = ca.size();
 
-        Set<GridCacheEntryEx> set = ca.context().isNear()
-            ? ((GridNearCacheAdapter)ca).dht().map().entries0()
-            : ca.map().entries0();
+        Iterable<GridCacheEntryEx> set = ca.context().isNear()
+            ? ((GridNearCacheAdapter)ca).dht().entries()
+            : ca.entries();
 
         long memSz = 0;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePreloadingEvictionsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePreloadingEvictionsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePreloadingEvictionsSelfTest.java
index ba43454..bcdab3e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePreloadingEvictionsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePreloadingEvictionsSelfTest.java
@@ -108,7 +108,7 @@ public class GridCachePreloadingEvictionsSelfTest extends GridCommonAbstractTest
         try {
             final Ignite ignite1 = startGrid(1);
 
-            IgniteCache<Integer, Object> cache1 = ignite1.cache(null);
+            final IgniteCache<Integer, Object> cache1 = ignite1.cache(null);
 
             for (int i = 0; i < 5000; i++)
                 cache1.put(i, VALUE + i);
@@ -129,7 +129,7 @@ public class GridCachePreloadingEvictionsSelfTest extends GridCommonAbstractTest
                         info("Started evicting...");
 
                         for (int i = 0; i < 3000 && !done.get(); i++) {
-                            Cache.Entry<Integer, Object> entry = randomEntry(ignite1);
+                            Cache.Entry<Integer, Object> entry = cache1.getEntry(i);
 
                             if (entry != null)
                                 ignite1.cache(null).localEvict(Collections.<Object>singleton(entry.getKey()));

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java
index 5e746c3..7b4a5ac 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTtlManagerSelfTest.java
@@ -112,7 +112,7 @@ public class GridCacheTtlManagerSelfTest extends GridCommonAbstractTest {
                     assertNull(g.cache(null).get(key));
 
                     if (!g.internalCache().context().deferredDelete())
-                        assertNull(g.internalCache().map().getEntry(key));
+                        assertNull(g.internalCache().map().getEntry(g.internalCache().context().toCacheKeyObject(key)));
                 }
             });
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
index dc6a503..aec448b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.typedef.F;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE;
 import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
@@ -432,7 +433,7 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach
         for (Object ignored : keys)
             itSize++;
 
-        int valsSize = cache.values().size();
+        int valsSize = F.size(cache.values().iterator());
 
         info("cacheSize=" + cacheSize + ", keysSize=" + keySetSize + ", valsSize=" + valsSize +
             ", itSize=" + itSize + ']');

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicClientCacheStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicClientCacheStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicClientCacheStartSelfTest.java
index b661b52..a88ad15 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicClientCacheStartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicClientCacheStartSelfTest.java
@@ -28,8 +28,6 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridNoStorageCacheMap;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
@@ -313,14 +311,6 @@ public class IgniteDynamicClientCacheStartSelfTest extends GridCommonAbstractTes
 
         assertEquals(near, cache.context().isNear());
 
-        if (near)
-            cache = ((GridNearCacheAdapter)cache).dht();
-
-        if (srv)
-            assertSame(GridCacheConcurrentMap.class, cache.map().getClass());
-        else
-            assertSame(GridNoStorageCacheMap.class, cache.map().getClass());
-
         ClusterNode node = ((IgniteKernal)ignite).localNode();
 
         for (Ignite ignite0 : Ignition.allGrids()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java
index 9c8f7f8..b65b441 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxStoreExceptionAbstractSelfTest.java
@@ -369,7 +369,7 @@ public abstract class IgniteTxStoreExceptionAbstractSelfTest extends GridCacheAb
 
             GridCacheAdapter cache = grid.internalCache(null);
 
-            GridCacheMapEntry entry = cache.map().getEntry(key);
+            GridCacheMapEntry entry = cache.map().getEntry(cache.context().toCacheKeyObject(key));
 
             log.info("Entry: " + entry);
 
@@ -378,11 +378,11 @@ public abstract class IgniteTxStoreExceptionAbstractSelfTest extends GridCacheAb
                 assertEquals("Unexpected entry for grid [idx=" + i + ", entry=" + entry + ']', putBefore,
                     entry.hasValue());
                 assertEquals("Unexpected entry for grid [idx=" + i + ", entry=" + entry + ']', putBefore ? 1 : null,
-                    entry.rawGetOrUnmarshal(false));
+                    entry.rawGetOrUnmarshal(false).value(cache.ctx.cacheObjectContext(), false));
             }
 
             if (cache.isNear()) {
-                entry = ((GridNearCacheAdapter)cache).dht().map().getEntry(key);
+                entry = ((GridNearCacheAdapter)cache).dht().map().getEntry(cache.context().toCacheKeyObject(key));
 
                 log.info("Dht entry: " + entry);
 
@@ -391,7 +391,7 @@ public abstract class IgniteTxStoreExceptionAbstractSelfTest extends GridCacheAb
                     assertEquals("Unexpected entry for grid [idx=" + i + ", entry=" + entry + ']', putBefore,
                         entry.hasValue());
                     assertEquals("Unexpected entry for grid [idx=" + i + ", entry=" + entry + ']', putBefore ? 1 : null,
-                        entry.rawGetOrUnmarshal(false));
+                        entry.rawGetOrUnmarshal(false).value(cache.ctx.cacheObjectContext(), false));
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index f776146..be20b68 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -145,7 +145,7 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonA
         for (int i = 0; i < gridCount(); i++) {
             GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
 
-            for (GridCacheEntryEx e : c.map().entries0()) {
+            for (GridCacheEntryEx e : c.map().entries()) {
                 Object key = e.key().value(c.context().cacheObjectContext(), false);
                 Object val = CU.value(e.rawGet(), c.context(), false);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java
index 2504105..45b4b9f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractQueueFailoverDataConsistencySelfTest.java
@@ -364,7 +364,7 @@ public abstract class GridCacheAbstractQueueFailoverDataConsistencySelfTest exte
         GridCacheAffinityManager aff = cctx.affinity();
 
         for (int i = 0; i < gridCount(); i++) {
-            for (GridCacheEntryEx e : ((IgniteKernal)grid(i)).context().cache().internalCache(cctx.name()).map().allEntries0()) {
+            for (GridCacheEntryEx e : ((IgniteKernal)grid(i)).context().cache().internalCache(cctx.name()).allEntries()) {
                 if (aff.primary(grid(i).localNode(), e.key(), AffinityTopologyVersion.NONE)
                     && e.key().value(cctx.cacheObjectContext(), false) instanceof GridCacheQueueHeaderKey)
                     return i;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java
index d67e725..1eac282 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheQueueCleanupSelfTest.java
@@ -31,7 +31,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey;
 import org.apache.ignite.internal.util.typedef.PAX;
 import org.apache.ignite.testframework.GridTestUtils;
@@ -191,7 +191,7 @@ public class GridCacheQueueCleanupSelfTest extends IgniteCollectionAbstractTest
                     GridCacheAdapter<Object, Object> cache =
                         ((IgniteKernal)grid(i)).context().cache().internalCache(queueCacheName);
 
-                    Iterator<GridCacheEntryEx> entries = cache.map().allEntries0().iterator();
+                    Iterator<GridCacheMapEntry> entries = cache.map().entries().iterator();
 
                     while (entries.hasNext()) {
                         cnt++;


[32/50] [abbrv] ignite git commit: fixed compilation

Posted by sh...@apache.org.
fixed compilation


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

Branch: refs/heads/ignite-2788
Commit: 6994a435705abf41d99870b0786b6f6d184fedfe
Parents: 1e72589
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Wed Apr 27 13:02:50 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 72 ++++++++++++--------
 1 file changed, 42 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6994a435/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 450f628..d7dd8c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -3224,28 +3224,35 @@ class ServerImpl extends TcpDiscoveryImpl {
                 boolean locLateAssignBool = locLateAssign != null ? locLateAssign : false;
 
                 if (locMarshUseDfltSuidBool != rmtMarshUseDfltSuidBool) {
-                    utilityPool.submit(new Runnable() {
-                        @Override public void run() {
-                            String errMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
-                                " property value differs from remote node's value " +
-                                "(to make sure all nodes in topology have identical marshaller settings, " +
-                                "configure system property explicitly) " +
-                                "[locMarshUseDfltSuid=" + locMarshUseDfltSuid + ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
-                                ", locNodeAddrs=" + U.addressesAsString(locNode) +
-                                ", rmtNodeAddrs=" + U.addressesAsString(node) +
-                                ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
-
-                    String sndMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
-                        " property value differs from remote node's value " +
-                        "(to make sure all nodes in topology have identical marshaller settings, " +
-                        "configure system property explicitly) " +
-                        "[locMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
-                        ", rmtMarshUseDfltSuid=" + locMarshUseDfltSuid +
-                        ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
-                        ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
-                        ", rmtNodeId=" + locNode.id() + ']';
+                    utilityPool.submit(
+                        new Runnable() {
+                            @Override public void run() {
+                                String errMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
+                                    " property value differs from remote node's value " +
+                                    "(to make sure all nodes in topology have identical marshaller settings, " +
+                                    "configure system property explicitly) " +
+                                    "[locMarshUseDfltSuid=" + locMarshUseDfltSuid +
+                                    ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
+                                    ", locNodeAddrs=" + U.addressesAsString(locNode) +
+                                    ", rmtNodeAddrs=" + U.addressesAsString(node) +
+                                    ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
 
-                    nodeCheckError(node, errMsg, sndMsg);
+                                String sndMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
+                                    " property value differs from remote node's value " +
+                                    "(to make sure all nodes in topology have identical marshaller settings, " +
+                                    "configure system property explicitly) " +
+                                    "[locMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
+                                    ", rmtMarshUseDfltSuid=" + locMarshUseDfltSuid +
+                                    ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
+                                    ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
+                                    ", rmtNodeId=" + locNode.id() + ']';
+
+                                nodeCheckError(
+                                    node,
+                                    errMsg,
+                                    sndMsg);
+                            }
+                        });
 
                     // Ignore join request.
                     return;
@@ -3270,15 +3277,20 @@ class ServerImpl extends TcpDiscoveryImpl {
                                     ", rmtNodeAddrs=" + U.addressesAsString(node) +
                                     ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
 
-                    String sndMsg = "Local node's binary marshaller \"compactFooter\" property differs from " +
-                        "the same property on remote node (make sure all nodes in topology have the same value " +
-                        "of \"compactFooter\" property) [locMarshallerCompactFooter=" + rmtMarshCompactFooterBool +
-                        ", rmtMarshallerCompactFooter=" + locMarshCompactFooterBool +
-                        ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
-                        ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
-                        ", rmtNodeId=" + locNode.id() + ']';
-
-                    nodeCheckError(node, errMsg, sndMsg);
+                                String sndMsg = "Local node's binary marshaller \"compactFooter\" property differs from " +
+                                    "the same property on remote node (make sure all nodes in topology have the same value " +
+                                    "of \"compactFooter\" property) [locMarshallerCompactFooter=" + rmtMarshCompactFooterBool +
+                                    ", rmtMarshallerCompactFooter=" + locMarshCompactFooterBool +
+                                    ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
+                                    ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
+                                    ", rmtNodeId=" + locNode.id() + ']';
+
+                                nodeCheckError(
+                                    node,
+                                    errMsg,
+                                    sndMsg);
+                            }
+                        });
 
                     // Ignore join request.
                     return;


[44/50] [abbrv] ignite git commit: IGNITE-2383 Non-string system properties should be ignored in node attributes and update checker

Posted by sh...@apache.org.
IGNITE-2383 Non-string system properties should be ignored in node attributes and update checker


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

Branch: refs/heads/ignite-2788
Commit: 3adc493b0616e4b5f56a253513b8ab684c394010
Parents: 1beea53
Author: sboikov <sb...@gridgain.com>
Authored: Thu Apr 28 15:30:39 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../apache/ignite/IgniteSystemProperties.java   |  16 ++-
 .../processors/cluster/GridUpdateNotifier.java  |   3 +-
 ...GridServiceProxyClientReconnectSelfTest.java |   2 +-
 .../properties/NotStringSystemPropertyTest.java | 124 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +
 5 files changed, 144 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3adc493b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 858cb71..c8a2566 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -19,6 +19,8 @@ package org.apache.ignite;
 
 import java.io.Serializable;
 import java.lang.management.RuntimeMXBean;
+import java.util.Iterator;
+import java.util.Map;
 import java.util.Properties;
 import javax.net.ssl.HostnameVerifier;
 import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
@@ -542,10 +544,22 @@ public final class IgniteSystemProperties {
     /**
      * Gets snapshot of system properties.
      * Snapshot could be used for thread safe iteration over system properties.
+     * Non-string properties are removed before return.
      *
      * @return Snapshot of system properties.
      */
     public static Properties snapshot() {
-        return (Properties)System.getProperties().clone();
+        Properties sysProps = (Properties)System.getProperties().clone();
+
+        Iterator<Map.Entry<Object, Object>> iter = sysProps.entrySet().iterator();
+
+        while (iter.hasNext()) {
+            Map.Entry entry = iter.next();
+
+            if (!(entry.getValue() instanceof String) || !(entry.getKey() instanceof String))
+                iter.remove();
+        }
+
+        return sysProps;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/3adc493b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
index 2e2f9e4..b41bf28 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridUpdateNotifier.java
@@ -37,6 +37,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.internal.GridKernalGateway;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgniteProperties;
@@ -201,7 +202,7 @@ class GridUpdateNotifier {
             StringWriter sw = new StringWriter();
 
             try {
-                System.getProperties().store(new PrintWriter(sw), "");
+                IgniteSystemProperties.snapshot().store(new PrintWriter(sw), "");
             }
             catch (IOException ignore) {
                 return null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/3adc493b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProxyClientReconnectSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProxyClientReconnectSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProxyClientReconnectSelfTest.java
index 2488e7a..1fa6b0f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProxyClientReconnectSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProxyClientReconnectSelfTest.java
@@ -82,7 +82,7 @@ public class GridServiceProxyClientReconnectSelfTest extends GridCommonAbstractT
 
         startGrid("server");
 
-        assert latch.await(2000, TimeUnit.MILLISECONDS);
+        assert latch.await(10, TimeUnit.SECONDS);
 
         client.services().deployClusterSingleton("my-service", new MyServiceImpl());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/3adc493b/modules/core/src/test/java/org/apache/ignite/startup/properties/NotStringSystemPropertyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/startup/properties/NotStringSystemPropertyTest.java b/modules/core/src/test/java/org/apache/ignite/startup/properties/NotStringSystemPropertyTest.java
new file mode 100644
index 0000000..5e108a6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/startup/properties/NotStringSystemPropertyTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.startup.properties;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * The test checks start of Ignite with non-string properties.
+ */
+public class NotStringSystemPropertyTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration optimize(IgniteConfiguration cfg) throws IgniteCheckedException {
+        IgniteConfiguration oCfg = super.optimize(cfg);
+
+        oCfg.setIncludeProperties(null);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If fail.
+     */
+    public void testGridStart() throws Exception {
+        Some some = new Some(0, "prop");
+
+        String p = "NotStringSystemPropertyTest";
+
+        System.getProperties().put(p, p);
+        System.getProperties().put(some, "prop");
+        System.getProperties().put("prop", new Some(0, "prop"));
+
+        try {
+            Ignite ignite = startGridsMultiThreaded(2);
+
+            assertNull(ignite.configuration().getIncludeProperties());
+
+            assertEquals(p, ignite.cluster().localNode().attribute(p));
+
+            checkTopology(2);
+        }
+        finally {
+            System.getProperties().remove(some);
+            System.getProperties().remove("prop");
+            System.getProperties().remove(p);
+
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * Some non-string class.
+     */
+    private static class Some {
+        /**
+         * Int field.
+         */
+        private int cnt = 0;
+
+        /**
+         * String field.
+         */
+        private String name;
+
+        /**
+         * @param cnt Int value.
+         * @param name String value.
+         */
+        public Some(int cnt, String name) {
+            this.cnt = cnt;
+            this.name = name;
+        }
+
+        /**
+         * @return Count.
+         */
+        public int getCount() {
+            return cnt;
+        }
+
+        /**
+         * @param cnt Count.
+         */
+        public void setCount(int cnt) {
+            this.cnt = cnt;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Some [cnt=" + cnt + ", name=" + name + ']';
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3adc493b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index c67a07d..6b4ef70 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -50,6 +50,7 @@ import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest;
 import org.apache.ignite.messaging.GridMessagingSelfTest;
 import org.apache.ignite.messaging.IgniteMessagingWithClientTest;
 import org.apache.ignite.spi.GridSpiLocalHostInjectionTest;
+import org.apache.ignite.startup.properties.NotStringSystemPropertyTest;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.test.ConfigVariationsTestSuiteBuilderTest;
 import org.apache.ignite.testframework.test.ParametersTest;
@@ -130,6 +131,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(ParametersTest.class);
         suite.addTestSuite(VariationsIteratorTest.class);
         suite.addTestSuite(ConfigVariationsTestSuiteBuilderTest.class);
+        suite.addTestSuite(NotStringSystemPropertyTest.class);
 
         return suite;
     }


[05/50] [abbrv] ignite git commit: IGNITE-2004 Fixed "Asynchronous execution of ContinuousQuery's remote filter & local list".

Posted by sh...@apache.org.
IGNITE-2004 Fixed "Asynchronous execution of ContinuousQuery's remote filter & local list".


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

Branch: refs/heads/ignite-2788
Commit: 395f47388ef515301e7e49cea7a444063712b9f9
Parents: 24b24bf
Author: nikolay_tikhonov <nt...@gridgain.com>
Authored: Fri Apr 22 18:41:58 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../CacheContinuousAsyncQueryExample.java       | 138 +++
 .../datagrid/CacheContinuousQueryExample.java   |  13 +-
 .../ignite/cache/query/ContinuousQuery.java     |  27 +
 .../configuration/IgniteConfiguration.java      |  32 +
 .../ignite/internal/GridKernalContext.java      |   8 +
 .../ignite/internal/GridKernalContextImpl.java  |  12 +
 .../apache/ignite/internal/IgniteKernal.java    |   3 +
 .../org/apache/ignite/internal/IgnitionEx.java  |  16 +-
 .../processors/cache/GridCacheEntryEx.java      |   5 +-
 .../processors/cache/GridCacheMapEntry.java     |  49 +-
 .../dht/atomic/GridDhtAtomicCache.java          |  98 +-
 .../dht/atomic/GridDhtAtomicUpdateFuture.java   | 121 +--
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |  33 +-
 .../distributed/near/GridNearAtomicCache.java   |   3 +-
 .../continuous/CacheContinuousQueryEvent.java   |   7 +
 .../continuous/CacheContinuousQueryHandler.java | 446 +++++++--
 .../CacheContinuousQueryListener.java           |   6 +-
 .../continuous/CacheContinuousQueryManager.java |  62 +-
 .../apache/ignite/lang/IgniteAsyncCallback.java | 111 +++
 .../thread/IgniteStripedThreadPoolExecutor.java | 164 +--
 .../processors/cache/GridCacheTestEntryEx.java  |   4 +-
 ...FailoverAtomicPrimaryWriteOrderSelfTest.java |  50 +
 ...sQueryAsyncFailoverTxReplicatedSelfTest.java |  37 +
 ...eContinuousQueryAsyncFailoverTxSelfTest.java |  44 +
 ...eContinuousQueryAsyncFilterListenerTest.java | 986 +++++++++++++++++++
 ...ryFactoryAsyncFilterRandomOperationTest.java | 131 +++
 ...usQueryFactoryFilterRandomOperationTest.java | 725 ++++++++++++++
 .../CacheContinuousQueryFactoryFilterTest.java  | 714 --------------
 ...ContinuousQueryFailoverAbstractSelfTest.java |  63 +-
 .../CacheContinuousQueryLostPartitionTest.java  |  14 +
 ...ontinuousQueryOperationFromCallbackTest.java | 627 ++++++++++++
 .../CacheContinuousQueryOrderingEventTest.java  | 722 ++++++++++++++
 ...acheContinuousQueryRandomOperationsTest.java |  23 +
 .../junits/GridTestKernalContext.java           |   1 +
 .../IgniteBinaryCacheQueryTestSuite.java        |   1 -
 .../IgniteCacheQuerySelfTestSuite3.java         |  14 +-
 .../IgniteCacheQuerySelfTestSuite4.java         |   7 +
 .../cache/CacheEntryEventAsyncProbe.java        |  61 ++
 .../yardstick/cache/CacheEntryEventProbe.java   |  33 +-
 39 files changed, 4408 insertions(+), 1203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousAsyncQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousAsyncQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousAsyncQueryExample.java
new file mode 100644
index 0000000..4ac7ecb
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousAsyncQueryExample.java
@@ -0,0 +1,138 @@
+/*
+ * 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.examples.datagrid;
+
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.examples.ExampleNodeStartup;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+/**
+ * This examples demonstrates asynchronous continuous query API.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
+ * <p>
+ * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
+ * start node with {@code examples/config/example-ignite.xml} configuration.
+ */
+public class CacheContinuousAsyncQueryExample {
+    /** Cache name. */
+    private static final String CACHE_NAME = CacheContinuousAsyncQueryExample.class.getSimpleName();
+
+    /**
+     * Executes example.
+     *
+     * @param args Command line arguments, none required.
+     * @throws Exception If example execution failed.
+     */
+    public static void main(String[] args) throws Exception {
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            System.out.println();
+            System.out.println(">>> Cache continuous query example started.");
+
+            // Auto-close cache at the end of the example.
+            try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) {
+                int keyCnt = 20;
+
+                // These entries will be queried by initial predicate.
+                for (int i = 0; i < keyCnt; i++)
+                    cache.put(i, Integer.toString(i));
+
+                // Create new continuous query.
+                ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
+
+                qry.setInitialQuery(new ScanQuery<>(new IgniteBiPredicate<Integer, String>() {
+                    @Override public boolean apply(Integer key, String val) {
+                        return key > 10;
+                    }
+                }));
+
+                // Callback that is called locally when update notifications are received.
+                qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
+                    @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> evts) {
+                        for (CacheEntryEvent<? extends Integer, ? extends String> e : evts)
+                            System.out.println("Updated entry [key=" + e.getKey() + ", val=" + e.getValue() + ']');
+                    }
+                });
+
+                // This filter will be evaluated remotely on all nodes.
+                // Entry that pass this filter will be sent to the caller.
+                qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter<Integer, String>>() {
+                    @Override public CacheEntryEventFilter<Integer, String> create() {
+                        return new CacheEntryFilter();
+                    }
+                });
+
+                // Execute query.
+                try (QueryCursor<Cache.Entry<Integer, String>> cur = cache.query(qry)) {
+                    // Iterate through existing data.
+                    for (Cache.Entry<Integer, String> e : cur)
+                        System.out.println("Queried existing entry [key=" + e.getKey() + ", val=" + e.getValue() + ']');
+
+                    // Add a few more keys and watch more query notifications.
+                    for (int i = 0; i < keyCnt; i++)
+                        cache.put(i, Integer.toString(i));
+
+                    // Wait for a while while callback is notified about remaining puts.
+                    Thread.sleep(2000);
+                }
+
+                // Iterate through entries which was updated from filter.
+                for (int i = 0; i < 10; i++)
+                    System.out.println("Entry updated from filter [key=" + i + ", val=" + cache.get(i) + ']');
+            }
+            finally {
+                // Distributed cache could be removed from cluster only by #destroyCache() call.
+                ignite.destroyCache(CACHE_NAME);
+            }
+        }
+    }
+
+    /**
+     * Filter returns {@code true} for entries which have key bigger than 10.
+     */
+    @IgniteAsyncCallback
+    private static class CacheEntryFilter implements CacheEntryEventFilter<Integer, String> {
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e)
+            throws CacheEntryListenerException {
+            // This cache operation is safe because filter has Ignite AsyncCallback annotation.
+            if (e.getKey() < 10 && String.valueOf(e.getKey()).equals(e.getValue()))
+                ignite.cache(CACHE_NAME).put(e.getKey(), e.getValue() + "_less_than_10");
+
+            return e.getKey() > 10;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java
index 59759af..aad5b5d 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java
@@ -18,12 +18,13 @@
 package org.apache.ignite.examples.datagrid;
 
 import javax.cache.Cache;
+import javax.cache.configuration.Factory;
 import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryEventFilter;
 import javax.cache.event.CacheEntryUpdatedListener;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
 import org.apache.ignite.cache.query.ContinuousQuery;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
@@ -81,9 +82,13 @@ public class CacheContinuousQueryExample {
 
                 // This filter will be evaluated remotely on all nodes.
                 // Entry that pass this filter will be sent to the caller.
-                qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Integer, String>() {
-                    @Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e) {
-                        return e.getKey() > 10;
+                qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter<Integer, String>>() {
+                    @Override public CacheEntryEventFilter<Integer, String> create() {
+                        return new CacheEntryEventFilter<Integer, String>() {
+                            @Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e) {
+                                return e.getKey() > 10;
+                            }
+                        };
                     }
                 });
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
index 3ea8f93..bbfe8cc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/ContinuousQuery.java
@@ -23,6 +23,8 @@ import javax.cache.event.CacheEntryEventFilter;
 import javax.cache.event.CacheEntryUpdatedListener;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.lang.IgniteAsyncCallback;
 
 /**
  * API for configuring continuous cache queries.
@@ -92,6 +94,16 @@ import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
  * Note that this works even if you didn't provide initial query. Cursor will
  * be empty in this case, but it will still unregister listeners when {@link QueryCursor#close()}
  * is called.
+ * <p>
+ * {@link IgniteAsyncCallback} annotation is supported for {@link CacheEntryEventFilter}
+ * (see {@link #setRemoteFilterFactory(Factory)}) and {@link CacheEntryUpdatedListener}
+ * (see {@link #setLocalListener(CacheEntryUpdatedListener)}).
+ * If filter and/or listener are annotated with {@link IgniteAsyncCallback} then annotated callback
+ * is executed in async callback pool (see {@link IgniteConfiguration#getAsyncCallbackPoolSize()})
+ * and notification order is kept the same as update order for given cache key.
+ *
+ * @see IgniteAsyncCallback
+ * @see IgniteConfiguration#getAsyncCallbackPoolSize()
  */
 public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
     /** */
@@ -173,9 +185,14 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
      * <b>WARNING:</b> all operations that involve any kind of JVM-local or distributed locking (e.g.,
      * synchronization or transactional cache operations), should be executed asynchronously without
      * blocking the thread that called the callback. Otherwise, you can get deadlocks.
+     * <p>
+     * If local listener are annotated with {@link IgniteAsyncCallback} then it is executed in async callback pool
+     * (see {@link IgniteConfiguration#getAsyncCallbackPoolSize()}) that allow to perform a cache operations.
      *
      * @param locLsnr Local callback.
      * @return {@code this} for chaining.
+     * @see IgniteAsyncCallback
+     * @see IgniteConfiguration#getAsyncCallbackPoolSize()
      */
     public ContinuousQuery<K, V> setLocalListener(CacheEntryUpdatedListener<K, V> locLsnr) {
         this.locLsnr = locLsnr;
@@ -198,11 +215,16 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
      * <b>WARNING:</b> all operations that involve any kind of JVM-local or distributed locking
      * (e.g., synchronization or transactional cache operations), should be executed asynchronously
      * without blocking the thread that called the filter. Otherwise, you can get deadlocks.
+     * <p>
+     * If remote filter are annotated with {@link IgniteAsyncCallback} then it is executed in async callback
+     * pool (see {@link IgniteConfiguration#getAsyncCallbackPoolSize()}) that allow to perform a cache operations.
      *
      * @param rmtFilter Key-value filter.
      * @return {@code this} for chaining.
      *
      * @deprecated Use {@link #setRemoteFilterFactory(Factory)} instead.
+     * @see IgniteAsyncCallback
+     * @see IgniteConfiguration#getAsyncCallbackPoolSize()
      */
     @Deprecated
     public ContinuousQuery<K, V> setRemoteFilter(CacheEntryEventSerializableFilter<K, V> rmtFilter) {
@@ -227,9 +249,14 @@ public final class ContinuousQuery<K, V> extends Query<Cache.Entry<K, V>> {
      * <b>WARNING:</b> all operations that involve any kind of JVM-local or distributed locking
      * (e.g., synchronization or transactional cache operations), should be executed asynchronously
      * without blocking the thread that called the filter. Otherwise, you can get deadlocks.
+     * <p>
+     * If remote filter are annotated with {@link IgniteAsyncCallback} then it is executed in async callback
+     * pool (see {@link IgniteConfiguration#getAsyncCallbackPoolSize()}) that allow to perform a cache operations.
      *
      * @param rmtFilterFactory Key-value filter factory.
      * @return {@code this} for chaining.
+     * @see IgniteAsyncCallback
+     * @see IgniteConfiguration#getAsyncCallbackPoolSize()
      */
     public ContinuousQuery<K, V> setRemoteFilterFactory(
         Factory<? extends CacheEntryEventFilter<K, V>> rmtFilterFactory) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index ca112c2..c7ebbb6 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -43,6 +43,7 @@ import org.apache.ignite.events.Event;
 import org.apache.ignite.events.EventType;
 import org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteAsyncCallback;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lifecycle.LifecycleBean;
@@ -223,6 +224,9 @@ public class IgniteConfiguration {
     /** Public pool size. */
     private int pubPoolSize = DFLT_PUBLIC_THREAD_CNT;
 
+    /** Async Callback pool size. */
+    private int callbackPoolSize = DFLT_PUBLIC_THREAD_CNT;
+
     /** System pool size. */
     private int sysPoolSize = DFLT_SYSTEM_CORE_THREAD_CNT;
 
@@ -723,6 +727,20 @@ public class IgniteConfiguration {
     }
 
     /**
+     * Size of thread pool that is in charge of processing asynchronous callbacks.
+     * <p>
+     * This pool is used for callbacks annotated with {@link IgniteAsyncCallback}.
+     * <p>
+     * If not provided, executor service will have size {@link #DFLT_PUBLIC_THREAD_CNT}.
+     *
+     * @return Thread pool size to be used.
+     * @see IgniteAsyncCallback
+     */
+    public int getAsyncCallbackPoolSize() {
+        return callbackPoolSize;
+    }
+
+    /**
      * Size of thread pool that is in charge of processing internal and Visor
      * {@link ComputeJob GridJobs}.
      * <p>
@@ -831,6 +849,20 @@ public class IgniteConfiguration {
     }
 
     /**
+     * Sets async callback thread pool size to use within grid.
+     *
+     * @param poolSize Thread pool size to use within grid.
+     * @return {@code this} for chaining.
+     * @see IgniteConfiguration#getAsyncCallbackPoolSize()
+     * @see IgniteAsyncCallback
+     */
+    public IgniteConfiguration setAsyncCallbackPoolSize(int poolSize) {
+        this.callbackPoolSize = poolSize;
+
+        return this;
+    }
+
+    /**
      * Sets management thread pool size to use within grid.
      *
      * @param poolSize Thread pool size to use within grid.

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index 77c8794..f51727d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -67,6 +67,7 @@ import org.apache.ignite.internal.util.IgniteExceptionRegistry;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.plugin.PluginNotFoundException;
 import org.apache.ignite.plugin.PluginProvider;
+import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 
 /**
  *
@@ -298,6 +299,13 @@ public interface GridKernalContext extends Iterable<GridComponent> {
     public ExecutorService marshallerCachePool();
 
     /**
+     * Gets async callback pool.
+     *
+     * @return Async callback pool.
+     */
+    public IgniteStripedThreadPoolExecutor asyncCallbackPool();
+
+    /**
      * Gets cache object processor.
      *
      * @return Cache object processor.

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 753dbe8..79d67df 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -89,6 +89,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.plugin.PluginNotFoundException;
 import org.apache.ignite.plugin.PluginProvider;
+import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_DAEMON;
@@ -305,6 +306,10 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
 
     /** */
     @GridToStringExclude
+    protected IgniteStripedThreadPoolExecutor callbackExecSvc;
+
+    /** */
+    @GridToStringExclude
     private Map<String, Object> attrs = new HashMap<>();
 
     /** */
@@ -379,6 +384,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
         ExecutorService mgmtExecSvc,
         ExecutorService igfsExecSvc,
         ExecutorService restExecSvc,
+        IgniteStripedThreadPoolExecutor callbackExecSvc,
         List<PluginProvider> plugins) throws IgniteCheckedException {
         assert grid != null;
         assert cfg != null;
@@ -395,6 +401,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
         this.mgmtExecSvc = mgmtExecSvc;
         this.igfsExecSvc = igfsExecSvc;
         this.restExecSvc = restExecSvc;
+        this.callbackExecSvc = callbackExecSvc;
 
         marshCtx = new MarshallerContextImpl(plugins);
 
@@ -746,6 +753,11 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteStripedThreadPoolExecutor asyncCallbackPool() {
+        return callbackExecSvc;
+    }
+
+    /** {@inheritDoc} */
     @Override public IgniteCacheObjectProcessor cacheObjects() {
         return cacheObjProc;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 20795fc..d6655d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -167,6 +167,7 @@ import org.apache.ignite.plugin.PluginProvider;
 import org.apache.ignite.spi.IgniteSpi;
 import org.apache.ignite.spi.IgniteSpiVersionCheckException;
 import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
+import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONFIG_URL;
@@ -667,6 +668,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
         ExecutorService mgmtExecSvc,
         ExecutorService igfsExecSvc,
         ExecutorService restExecSvc,
+        IgniteStripedThreadPoolExecutor callbackExecSvc,
         GridAbsClosure errHnd)
         throws IgniteCheckedException
     {
@@ -771,6 +773,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
                 mgmtExecSvc,
                 igfsExecSvc,
                 restExecSvc,
+                callbackExecSvc,
                 plugins);
 
             cfg.getMarshaller().setContext(ctx.marshallerContext());

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index c46a05c..7776687 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -95,6 +95,7 @@ import org.apache.ignite.spi.indexing.noop.NoopIndexingSpi;
 import org.apache.ignite.spi.loadbalancing.roundrobin.RoundRobinLoadBalancingSpi;
 import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
 import org.apache.ignite.spi.swapspace.noop.NoopSwapSpaceSpi;
+import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 import org.apache.ignite.thread.IgniteThread;
 import org.apache.ignite.thread.IgniteThreadPoolExecutor;
 import org.jetbrains.annotations.Nullable;
@@ -1476,6 +1477,9 @@ public class IgnitionEx {
         /** Marshaller cache executor service. */
         private ExecutorService marshCacheExecSvc;
 
+        /** Continuous query executor service. */
+        private IgniteStripedThreadPoolExecutor callbackExecSvc;
+
         /** Grid state. */
         private volatile IgniteState state = STOPPED;
 
@@ -1688,6 +1692,12 @@ public class IgnitionEx {
                 0,
                 new LinkedBlockingQueue<Runnable>());
 
+            // Note that we do not pre-start threads here as this pool may not be needed.
+            callbackExecSvc = new IgniteStripedThreadPoolExecutor(
+                cfg.getAsyncCallbackPoolSize(),
+                cfg.getGridName(),
+                "callback");
+
             if (myCfg.getConnectorConfiguration() != null) {
                 restExecSvc = new IgniteThreadPoolExecutor(
                     "rest",
@@ -1727,7 +1737,7 @@ public class IgnitionEx {
                 grid = grid0;
 
                 grid0.start(myCfg, utilityCacheExecSvc, marshCacheExecSvc, execSvc, sysExecSvc, p2pExecSvc, mgmtExecSvc,
-                    igfsExecSvc, restExecSvc,
+                    igfsExecSvc, restExecSvc, callbackExecSvc,
                     new CA() {
                         @Override public void apply() {
                             startLatch.countDown();
@@ -2335,6 +2345,10 @@ public class IgnitionEx {
             U.shutdownNow(getClass(), marshCacheExecSvc, log);
 
             marshCacheExecSvc = null;
+
+            U.shutdownNow(getClass(), callbackExecSvc, log);
+
+            callbackExecSvc = null;
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index d6d7335..e679dfd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -27,6 +27,7 @@ import org.apache.ignite.cache.eviction.EvictableEntry;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -462,6 +463,7 @@ public interface GridCacheEntryEx {
      * @param subjId Subject ID initiated this update.
      * @param taskName Task name.
      * @param updateCntr Update counter.
+     * @param fut Dht atomic future.
      * @return Tuple where first value is flag showing whether operation succeeded,
      *      second value is old entry value if return value is requested, third is updated entry value,
      *      fourth is the version to enqueue for deferred delete the fifth is DR conflict context
@@ -497,7 +499,8 @@ public interface GridCacheEntryEx {
         @Nullable UUID subjId,
         String taskName,
         @Nullable CacheObject prevVal,
-        @Nullable Long updateCntr
+        @Nullable Long updateCntr,
+        @Nullable GridDhtAtomicUpdateFuture fut
     ) throws IgniteCheckedException, GridCacheEntryRemovedException;
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 735e20a..75d96d8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -40,6 +40,7 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry;
 import org.apache.ignite.internal.processors.cache.extras.GridCacheEntryExtras;
 import org.apache.ignite.internal.processors.cache.extras.GridCacheMvccEntryExtras;
@@ -1248,6 +1249,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                     tx.local(),
                     false,
                     updateCntr0,
+                    null,
                     topVer);
             }
 
@@ -1445,6 +1447,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                     tx.local(),
                     false,
                     updateCntr0,
+                    null,
                     topVer);
             }
 
@@ -1821,6 +1824,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                     true,
                     false,
                     updateCntr,
+                    null,
                     AffinityTopologyVersion.NONE);
             }
 
@@ -1870,7 +1874,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
         @Nullable final UUID subjId,
         final String taskName,
         @Nullable final CacheObject prevVal,
-        @Nullable final Long updateCntr
+        @Nullable final Long updateCntr,
+        @Nullable GridDhtAtomicUpdateFuture fut
     ) throws IgniteCheckedException, GridCacheEntryRemovedException, GridClosureException {
         assert cctx.atomic();
 
@@ -1899,7 +1904,12 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
         Long updateCntr0 = null;
 
         synchronized (this) {
-            boolean needVal = intercept || retval || op == GridCacheOperation.TRANSFORM || !F.isEmptyOrNulls(filter);
+            boolean internal = isInternal() || !context().userCache();
+
+            Map<UUID, CacheContinuousQueryListener> lsnrs = cctx.continuousQueries().updateListeners(internal, false);
+
+            boolean needVal = lsnrs != null || intercept || retval || op == GridCacheOperation.TRANSFORM
+                || !F.isEmptyOrNulls(filter);
 
             checkObsolete();
 
@@ -2093,6 +2103,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                                 primary,
                                 false,
                                 updateCntr0,
+                                null,
                                 topVer);
                         }
 
@@ -2501,13 +2512,42 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
             if (res)
                 updateMetrics(op, metrics);
 
+            // Continuous query filter should be perform under lock.
+            if (lsnrs != null) {
+                CacheObject evtVal = updated;
+                CacheObject evtOldVal = oldVal;
+
+                if (isOffHeapValuesOnly()) {
+                    evtVal = cctx.toCacheObject(cctx.unwrapTemporary(evtVal));
+
+                    evtOldVal = cctx.toCacheObject(cctx.unwrapTemporary(evtOldVal));
+                }
+
+                cctx.continuousQueries().onEntryUpdated(lsnrs, key, evtVal, evtOldVal, internal,
+                    partition(), primary, false, updateCntr0, fut, topVer);
+            }
+
             cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE, keepBinary);
 
             if (intercept) {
                 if (op == GridCacheOperation.UPDATE)
-                    cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0, keepBinary, updateCntr0));
+                    cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(
+                        cctx,
+                        key,
+                        key0,
+                        updated,
+                        updated0,
+                        keepBinary,
+                        updateCntr0));
                 else
-                    cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, oldVal, old0, keepBinary, updateCntr0));
+                    cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(
+                        cctx,
+                        key,
+                        key0,
+                        oldVal,
+                        old0,
+                        keepBinary,
+                        updateCntr0));
 
                 if (interceptRes != null)
                     oldVal = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2()));
@@ -3302,6 +3342,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
                         true,
                         preload,
                         updateCntr,
+                        null,
                         topVer);
 
                     cctx.dataStructures().onEntryUpdated(key, false, true);

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 013184b..d28aaaa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -76,7 +76,6 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSing
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSingleGetResponse;
 import org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo;
 import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
-import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext;
@@ -2141,10 +2140,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         boolean intercept = ctx.config().getInterceptor() != null;
 
-        boolean initLsnrs = false;
-        Map<UUID, CacheContinuousQueryListener> lsnrs = null;
-        boolean internal = false;
-
         // Avoid iterator creation.
         for (int i = 0; i < keys.size(); i++) {
             KeyCacheObject k = keys.get(i);
@@ -2159,14 +2154,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                 if (entry == null)
                     continue;
 
-                if (!initLsnrs) {
-                    internal = entry.isInternal() || !context().userCache();
-
-                    lsnrs = ctx.continuousQueries().updateListeners(internal, false);
-
-                    initLsnrs = true;
-                }
-
                 GridCacheVersion newConflictVer = req.conflictVersion(i);
                 long newConflictTtl = req.conflictTtl(i);
                 long newConflictExpireTime = req.conflictExpireTime(i);
@@ -2195,7 +2182,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                     req.invokeArguments(),
                     primary && writeThrough() && !req.skipStore(),
                     !req.skipStore(),
-                    lsnrs != null || sndPrevVal || req.returnValue(),
+                    sndPrevVal || req.returnValue(),
                     req.keepBinary(),
                     expiry,
                     true,
@@ -2213,7 +2200,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                     req.subjectId(),
                     taskName,
                     null,
-                    null);
+                    null,
+                    dhtFut);
 
                 if (dhtFut == null && !F.isEmpty(filteredReaders)) {
                     dhtFut = createDhtFuture(ver, req, res, completionCb, true);
@@ -2222,8 +2210,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                 }
 
                 if (dhtFut != null) {
-                    dhtFut.listeners(lsnrs);
-
                     if (updRes.sendToDht()) { // Send to backups even in case of remove-remove scenarios.
                         GridCacheVersionConflictContext<?, ?> conflictCtx = updRes.conflictResolveResult();
 
@@ -2260,19 +2246,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                                 "[entry=" + entry + ", filter=" + Arrays.toString(req.filter()) + ']');
                     }
                 }
-                else if (lsnrs != null && updRes.updateCounter() != 0) {
-                    ctx.continuousQueries().onEntryUpdated(
-                        lsnrs,
-                        entry.key(),
-                        updRes.newValue(),
-                        updRes.oldValue(),
-                        internal,
-                        entry.partition(),
-                        primary,
-                        false,
-                        updRes.updateCounter(),
-                        topVer);
-                }
 
                 if (hasNear) {
                     if (primary && updRes.sendToDht()) {
@@ -2446,9 +2419,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
             boolean intercept = ctx.config().getInterceptor() != null;
 
-            boolean initLsnrs = false;
-            Map<UUID, CacheContinuousQueryListener> lsnrs = null;
-
             // Avoid iterator creation.
             for (int i = 0; i < entries.size(); i++) {
                 GridDhtCacheEntry entry = entries.get(i);
@@ -2482,14 +2452,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                         filteredReaders = F.view(entry.readers(), F.notEqualTo(node.id()));
                     }
 
-                    if (!initLsnrs) {
-                        lsnrs = ctx.continuousQueries().updateListeners(
-                            entry.isInternal() || !context().userCache(),
-                            false);
-
-                        initLsnrs = true;
-                    }
-
                     GridCacheUpdateAtomicResult updRes = entry.innerUpdate(
                         ver,
                         node.id(),
@@ -2499,7 +2461,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                         null,
                         /*write-through*/false,
                         /*read-through*/false,
-                        /*retval*/sndPrevVal || lsnrs != null,
+                        /*retval*/sndPrevVal,
                         req.keepBinary(),
                         expiry,
                         /*event*/true,
@@ -2517,7 +2479,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                         req.subjectId(),
                         taskName,
                         null,
-                        null);
+                        null,
+                        dhtFut);
 
                     assert !updRes.success() || updRes.newTtl() == CU.TTL_NOT_CHANGED || expiry != null :
                         "success=" + updRes.success() + ", newTtl=" + updRes.newTtl() + ", expiry=" + expiry;
@@ -2548,12 +2511,10 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                     }
 
                     if (dhtFut != null) {
-                        dhtFut.listeners(lsnrs);
-
                         EntryProcessor<Object, Object, Object> entryProcessor =
                             entryProcessorMap == null ? null : entryProcessorMap.get(entry.key());
 
-                        if (!batchRes.readersOnly())
+                        if (!batchRes.readersOnly()) {
                             dhtFut.addWriteEntry(entry,
                                 writeVal,
                                 entryProcessor,
@@ -2563,6 +2524,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                                 sndPrevVal,
                                 updRes.oldValue(),
                                 updRes.updateCounter());
+                        }
 
                         if (!F.isEmpty(filteredReaders))
                             dhtFut.addNearWriteEntries(filteredReaders,
@@ -2572,19 +2534,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                                 updRes.newTtl(),
                                 CU.EXPIRE_TIME_CALCULATE);
                     }
-                    else if (lsnrs != null && updRes.updateCounter() != 0) {
-                        ctx.continuousQueries().onEntryUpdated(
-                            lsnrs,
-                            entry.key(),
-                            updRes.newValue(),
-                            updRes.oldValue(),
-                            entry.isInternal() || !context().userCache(),
-                            entry.partition(),
-                            primary,
-                            false,
-                            updRes.updateCounter(),
-                            topVer);
-                    }
 
                     if (hasNear) {
                         if (primary) {
@@ -2965,10 +2914,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
 
         String taskName = ctx.kernalContext().task().resolveTaskName(req.taskNameHash());
 
-        boolean initLsnrs = false;
-        Map<UUID, CacheContinuousQueryListener> lsnrs = null;
-        boolean internal = false;
-
         for (int i = 0; i < req.size(); i++) {
             KeyCacheObject key = req.key(i);
 
@@ -2991,14 +2936,6 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                         long ttl = req.ttl(i);
                         long expireTime = req.conflictExpireTime(i);
 
-                        if (!initLsnrs) {
-                            internal = entry.isInternal() || !context().userCache();
-
-                            lsnrs = ctx.continuousQueries().updateListeners(internal, false);
-
-                            initLsnrs = true;
-                        }
-
                         GridCacheUpdateAtomicResult updRes = entry.innerUpdate(
                             ver,
                             nodeId,
@@ -3008,7 +2945,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                             op == TRANSFORM ? req.invokeArguments() : null,
                             /*write-through*/false,
                             /*read-through*/false,
-                            /*retval*/lsnrs != null,
+                            /*retval*/false,
                             req.keepBinary(),
                             /*expiry policy*/null,
                             /*event*/true,
@@ -3026,25 +2963,12 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
                             req.subjectId(),
                             taskName,
                             prevVal,
-                            updateIdx);
+                            updateIdx,
+                            null);
 
                         if (updRes.removeVersion() != null)
                             ctx.onDeferredDelete(entry, updRes.removeVersion());
 
-                        if (lsnrs != null && updRes.updateCounter() != 0) {
-                            ctx.continuousQueries().onEntryUpdated(
-                                lsnrs,
-                                entry.key(),
-                                updRes.newValue(),
-                                updRes.oldValue(),
-                                internal,
-                                entry.partition(),
-                                false,
-                                false,
-                                updRes.updateCounter(),
-                                req.topologyVersion());
-                        }
-
                         entry.onUnlock();
 
                         break; // While.

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
index 4721d6e..5760596 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
@@ -37,11 +37,11 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
-import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.CI2;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -97,15 +97,15 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
     /** Future keys. */
     private final Collection<KeyCacheObject> keys;
 
+    /** Continuous query closures. */
+    private Collection<CI1<Boolean>> cntQryClsrs;
+
     /** */
     private final boolean waitForExchange;
 
     /** Response count. */
     private volatile int resCnt;
 
-    /** */
-    private Map<UUID, CacheContinuousQueryListener> lsnrs;
-
     /**
      * @param cctx Cache context.
      * @param completionCb Callback to invoke when future is completed.
@@ -138,13 +138,6 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
         waitForExchange = !(updateReq.topologyLocked() || (updateReq.fastMap() && !updateReq.clientRequest()));
     }
 
-    /**
-     * @param lsnrs Continuous query listeners.
-     */
-    void listeners(@Nullable Map<UUID, CacheContinuousQueryListener> lsnrs) {
-        this.lsnrs = lsnrs;
-    }
-
     /** {@inheritDoc} */
     @Override public IgniteUuid futureId() {
         return futVer.asGridUuid();
@@ -276,27 +269,7 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
                     addPrevVal,
                     entry.partition(),
                     prevVal,
-                    updateCntr,
-                    lsnrs != null);
-            }
-            else if (lsnrs != null && dhtNodes.size() == 1) {
-                try {
-                    cctx.continuousQueries().onEntryUpdated(
-                        lsnrs,
-                        entry.key(),
-                        val,
-                        prevVal,
-                        entry.key().internal() || !cctx.userCache(),
-                        entry.partition(),
-                        true,
-                        false,
-                        updateCntr,
-                        updateReq.topologyVersion());
-                }
-                catch (IgniteCheckedException e) {
-                    U.warn(log, "Failed to send continuous query message. [key=" + entry.key() + ", newVal="
-                        + val + ", err=" + e + "]");
-                }
+                    updateCntr);
             }
         }
     }
@@ -361,77 +334,33 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
         }
     }
 
+    /**
+     * @param clsr Continuous query closure.
+     */
+    public void addContinuousQueryClosure(CI1<Boolean> clsr){
+        assert !isDone() : this;
+
+        if (cntQryClsrs == null)
+            cntQryClsrs = new ArrayList<>(10);
+
+        cntQryClsrs.add(clsr);
+    }
+
     /** {@inheritDoc} */
     @Override public boolean onDone(@Nullable Void res, @Nullable Throwable err) {
         if (super.onDone(res, err)) {
             cctx.mvcc().removeAtomicFuture(version());
 
-            if (err != null) {
-                if (!mappings.isEmpty() && lsnrs != null) {
-                    Collection<KeyCacheObject> hndKeys = new ArrayList<>(keys.size());
-
-                    exit: for (GridDhtAtomicUpdateRequest req : mappings.values()) {
-                        for (int i = 0; i < req.size(); i++) {
-                            KeyCacheObject key = req.key(i);
-
-                            if (!hndKeys.contains(key)) {
-                                updateRes.addFailedKey(key, err);
+            boolean suc = err == null;
 
-                                cctx.continuousQueries().skipUpdateEvent(
-                                    lsnrs,
-                                    key,
-                                    req.partitionId(i),
-                                    req.updateCounter(i),
-                                    updateReq.topologyVersion());
-
-                                hndKeys.add(key);
-
-                                if (hndKeys.size() == keys.size())
-                                    break exit;
-                            }
-                        }
-                    }
-                }
-                else
-                    for (KeyCacheObject key : keys)
-                        updateRes.addFailedKey(key, err);
+            if (!suc) {
+                for (KeyCacheObject key : keys)
+                    updateRes.addFailedKey(key, err);
             }
-            else {
-                if (lsnrs != null) {
-                    Collection<KeyCacheObject> hndKeys = new ArrayList<>(keys.size());
-
-                    exit: for (GridDhtAtomicUpdateRequest req : mappings.values()) {
-                        for (int i = 0; i < req.size(); i++) {
-                            KeyCacheObject key = req.key(i);
-
-                            if (!hndKeys.contains(key)) {
-                                try {
-                                    cctx.continuousQueries().onEntryUpdated(
-                                        lsnrs,
-                                        key,
-                                        req.value(i),
-                                        req.localPreviousValue(i),
-                                        key.internal() || !cctx.userCache(),
-                                        req.partitionId(i),
-                                        true,
-                                        false,
-                                        req.updateCounter(i),
-                                        updateReq.topologyVersion());
-                                }
-                                catch (IgniteCheckedException e) {
-                                    U.warn(log, "Failed to send continuous query message. [key=" + key +
-                                        ", newVal=" + req.value(i) +
-                                        ", err=" + e + "]");
-                                }
-
-                                hndKeys.add(key);
-
-                                if (hndKeys.size() == keys.size())
-                                    break exit;
-                            }
-                        }
-                    }
-                }
+
+            if (cntQryClsrs != null) {
+                for (CI1<Boolean> clsr : cntQryClsrs)
+                    clsr.apply(suc);
             }
 
             if (updateReq.writeSynchronizationMode() == FULL_SYNC)

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
index c8e33c2..b5e2835 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
@@ -155,10 +155,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
     @GridDirectTransient
     private List<Integer> partIds;
 
-    /** */
-    @GridDirectTransient
-    private List<CacheObject> locPrevVals;
-
     /** Keep binary flag. */
     private boolean keepBinary;
 
@@ -242,7 +238,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
      * @param partId Partition.
      * @param prevVal Previous value.
      * @param updateCntr Update counter.
-     * @param storeLocPrevVal If {@code true} stores previous value.
      */
     public void addWriteValue(KeyCacheObject key,
         @Nullable CacheObject val,
@@ -253,19 +248,12 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
         boolean addPrevVal,
         int partId,
         @Nullable CacheObject prevVal,
-        @Nullable Long updateCntr,
-        boolean storeLocPrevVal) {
+        @Nullable Long updateCntr
+    ) {
         keys.add(key);
 
         partIds.add(partId);
 
-        if (storeLocPrevVal) {
-            if (locPrevVals == null)
-                locPrevVals = new ArrayList<>();
-
-            locPrevVals.add(prevVal);
-        }
-
         if (forceTransformBackups) {
             assert entryProcessor != null;
 
@@ -526,16 +514,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
 
     /**
      * @param idx Key index.
-     * @return Value.
-     */
-    @Nullable public CacheObject localPreviousValue(int idx) {
-        assert locPrevVals != null;
-
-        return locPrevVals.get(idx);
-    }
-
-    /**
-     * @param idx Key index.
      * @return Entry processor.
      */
     @Nullable public EntryProcessor<Object, Object, Object> entryProcessor(int idx) {
@@ -1069,13 +1047,6 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
     private void cleanup() {
         nearVals = null;
         prevVals = null;
-
-        // Do not keep values if they are not needed for continuous query notification.
-        if (locPrevVals == null) {
-            keys = null;
-            vals = null;
-            locPrevVals = null;
-        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
index a7481d3..3e0e392 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
@@ -37,7 +37,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
-import org.apache.ignite.internal.processors.cache.GridCacheReturn;
 import org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
@@ -271,6 +270,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
                         subjId,
                         taskName,
                         null,
+                        null,
                         null);
 
                     if (updRes.removeVersion() != null)
@@ -372,6 +372,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
                             req.subjectId(),
                             taskName,
                             null,
+                            null,
                             null);
 
                         if (updRes.removeVersion() != null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
index eab5dbd..db70e2e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
@@ -56,6 +56,13 @@ class CacheContinuousQueryEvent<K, V> extends CacheQueryEntryEvent<K, V> {
         return e;
     }
 
+    /**
+     * @return Partition ID.
+     */
+    public int partitionId() {
+        return e.partition();
+    }
+
     /** {@inheritDoc} */
     @Override public K getKey() {
         return (K)cctx.cacheObjectContext().unwrapBinaryIfNeeded(e.key(), e.isKeepBinary(), false);

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
index 16513b0..9ae2972 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
@@ -48,6 +48,7 @@ import org.apache.ignite.events.CacheQueryExecutedEvent;
 import org.apache.ignite.events.CacheQueryReadEvent;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteDeploymentCheckedException;
+import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.managers.communication.GridIoPolicy;
 import org.apache.ignite.internal.managers.deployment.GridDeployment;
@@ -58,7 +59,10 @@ import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityManager;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager.JCacheQueryLocalListener;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager.JCacheQueryRemoteFilter;
 import org.apache.ignite.internal.processors.continuous.GridContinuousBatch;
 import org.apache.ignite.internal.processors.continuous.GridContinuousBatchAdapter;
 import org.apache.ignite.internal.processors.continuous.GridContinuousHandler;
@@ -66,13 +70,14 @@ import org.apache.ignite.internal.processors.platform.cache.query.PlatformContin
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
 import org.apache.ignite.internal.util.GridLongList;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.C1;
+import org.apache.ignite.internal.util.typedef.CI1;
 import org.apache.ignite.internal.util.typedef.F;
 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.IgniteAsyncCallback;
 import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentLinkedDeque8;
@@ -159,6 +164,21 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     /** */
     private transient boolean ignoreClsNotFound;
 
+    /** */
+    private transient boolean asyncCallback;
+
+    /** */
+    private transient UUID nodeId;
+
+    /** */
+    private transient UUID routineId;
+
+    /** */
+    private transient GridKernalContext ctx;
+
+    /** */
+    private transient IgniteLogger log;
+
     /**
      * Required by {@link Externalizable}.
      */
@@ -283,13 +303,36 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
         assert routineId != null;
         assert ctx != null;
 
-        if (locLsnr != null)
-            ctx.resource().injectGeneric(locLsnr);
+        if (locLsnr != null) {
+            if (locLsnr instanceof JCacheQueryLocalListener) {
+                ctx.resource().injectGeneric(((JCacheQueryLocalListener)locLsnr).impl);
+
+                asyncCallback = ((JCacheQueryLocalListener)locLsnr).async();
+            }
+            else {
+                ctx.resource().injectGeneric(locLsnr);
+
+                asyncCallback = U.hasAnnotation(locLsnr, IgniteAsyncCallback.class);
+            }
+        }
 
         final CacheEntryEventFilter filter = getEventFilter();
 
-        if (filter != null)
-            ctx.resource().injectGeneric(filter);
+        if (filter != null) {
+            if (filter instanceof JCacheQueryRemoteFilter) {
+                if (((JCacheQueryRemoteFilter)filter).impl != null)
+                    ctx.resource().injectGeneric(((JCacheQueryRemoteFilter)filter).impl);
+
+                if (!asyncCallback)
+                    asyncCallback = ((JCacheQueryRemoteFilter)filter).async();
+            }
+            else {
+                ctx.resource().injectGeneric(filter);
+
+                if (!asyncCallback)
+                    asyncCallback = U.hasAnnotation(filter, IgniteAsyncCallback.class);
+            }
+        }
 
         entryBufs = new ConcurrentHashMap<>();
 
@@ -299,10 +342,18 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
         rcvs = new ConcurrentHashMap<>();
 
+        this.nodeId = nodeId;
+
+        this.routineId = routineId;
+
+        this.ctx = ctx;
+
         final boolean loc = nodeId.equals(ctx.localNodeId());
 
         assert !skipPrimaryCheck || loc;
 
+        log = ctx.log(CacheContinuousQueryHandler.class);
+
         CacheContinuousQueryListener<K, V> lsnr = new CacheContinuousQueryListener<K, V>() {
             @Override public void onExecution() {
                 if (ctx.event().isRecordable(EVT_CACHE_QUERY_EXECUTED)) {
@@ -324,15 +375,16 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 }
             }
 
-            /** {@inheritDoc} */
             @Override public boolean keepBinary() {
                 return keepBinary;
             }
 
-            @Override public void onEntryUpdated(CacheContinuousQueryEvent<K, V> evt, boolean primary,
-                boolean recordIgniteEvt) {
+            @Override public void onEntryUpdated(final CacheContinuousQueryEvent<K, V> evt,
+                boolean primary,
+                final boolean recordIgniteEvt,
+                GridDhtAtomicUpdateFuture fut) {
                 if (ignoreExpired && evt.getEventType() == EventType.EXPIRED)
-                    return;
+                    return ;
 
                 final GridCacheContext<K, V> cctx = cacheContext(ctx);
 
@@ -343,93 +395,33 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 // skipPrimaryCheck is set only when listen locally for replicated cache events.
                 assert !skipPrimaryCheck || (cctx.isReplicated() && ctx.localNodeId().equals(nodeId));
 
-                boolean notify = !evt.entry().isFiltered();
+                if (asyncCallback) {
+                    ContinuousQueryAsyncClosure clsr = new ContinuousQueryAsyncClosure(
+                        primary,
+                        evt,
+                        recordIgniteEvt,
+                        fut);
 
-                if (notify && filter != null) {
-                    try {
-                        notify = filter.evaluate(evt);
-                    }
-                    catch (Exception e) {
-                        U.error(cctx.logger(CacheContinuousQueryHandler.class), "CacheEntryEventFilter failed: " + e);
-                    }
+                    ctx.asyncCallbackPool().execute(clsr, evt.partitionId());
                 }
-
-                try {
-                    final CacheContinuousQueryEntry entry = evt.entry();
-
-                    if (!notify)
-                        entry.markFiltered();
+                else {
+                    final boolean notify = filter(evt, primary);
 
                     if (primary || skipPrimaryCheck) {
-                        if (loc) {
-                            if (!locCache) {
-                                Collection<CacheEntryEvent<? extends K, ? extends V>> entries = handleEvent(ctx, entry);
-
-                                if (!entries.isEmpty()) {
-                                    locLsnr.onUpdated(entries);
-
-                                    if (!internal && !skipPrimaryCheck)
-                                        sendBackupAcknowledge(ackBuf.onAcknowledged(entry), routineId, ctx);
-                                }
-                            }
-                            else {
-                                if (!entry.isFiltered())
-                                    locLsnr.onUpdated(F.<CacheEntryEvent<? extends K, ? extends V>>asList(evt));
-                            }
-                        }
+                        if (fut == null)
+                            onEntryUpdate(evt, notify, loc, recordIgniteEvt);
                         else {
-                            if (!entry.isFiltered())
-                                prepareEntry(cctx, nodeId, entry);
-
-                            CacheContinuousQueryEntry e = handleEntry(entry);
-
-                            if (e != null)
-                                ctx.continuous().addNotification(nodeId, routineId, entry, topic, sync, true);
-                        }
-                    }
-                    else {
-                        if (!internal) {
-                            // Skip init query and expire entries.
-                            if (entry.updateCounter() != -1L) {
-                                entry.markBackup();
+                            fut.addContinuousQueryClosure(new CI1<Boolean>() {
+                                @Override public void apply(Boolean suc) {
+                                    if (!suc)
+                                        evt.entry().markFiltered();
 
-                                backupQueue.add(entry);
-                            }
+                                    onEntryUpdate(evt, notify, loc, recordIgniteEvt);
+                                }
+                            });
                         }
                     }
                 }
-                catch (ClusterTopologyCheckedException ex) {
-                    IgniteLogger log = ctx.log(getClass());
-
-                    if (log.isDebugEnabled())
-                        log.debug("Failed to send event notification to node, node left cluster " +
-                            "[node=" + nodeId + ", err=" + ex + ']');
-                }
-                catch (IgniteCheckedException ex) {
-                    U.error(ctx.log(getClass()), "Failed to send event notification to node: " + nodeId, ex);
-                }
-
-                if (recordIgniteEvt && notify) {
-                    ctx.event().record(new CacheQueryReadEvent<>(
-                        ctx.discovery().localNode(),
-                        "Continuous query executed.",
-                        EVT_CACHE_QUERY_OBJECT_READ,
-                        CacheQueryType.CONTINUOUS.name(),
-                        cacheName,
-                        null,
-                        null,
-                        null,
-                        filter instanceof CacheEntryEventSerializableFilter ?
-                            (CacheEntryEventSerializableFilter)filter : null,
-                        null,
-                        nodeId,
-                        taskName(),
-                        evt.getKey(),
-                        evt.getValue(),
-                        evt.getOldValue(),
-                        null
-                    ));
-                }
             }
 
             @Override public void onUnregister() {
@@ -475,15 +467,15 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
                 sendBackupAcknowledge(ackBuf.acknowledgeOnTimeout(), routineId, ctx);
             }
 
-            @Override public void skipUpdateEvent(CacheContinuousQueryEvent<K, V> evt, AffinityTopologyVersion topVer,
-                boolean primary) {
+            @Override public void skipUpdateEvent(CacheContinuousQueryEvent<K, V> evt,
+                AffinityTopologyVersion topVer, boolean primary) {
                 assert evt != null;
 
                 CacheContinuousQueryEntry e = evt.entry();
 
                 e.markFiltered();
 
-                onEntryUpdated(evt, primary, false);
+                onEntryUpdated(evt, primary, false, null);
             }
 
             @Override public void onPartitionEvicted(int part) {
@@ -580,17 +572,73 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Override public void notifyCallback(UUID nodeId, UUID routineId, Collection<?> objs, GridKernalContext ctx) {
+    @Override public void notifyCallback(final UUID nodeId,
+        final UUID routineId,
+        Collection<?> objs,
+        final GridKernalContext ctx) {
         assert nodeId != null;
         assert routineId != null;
         assert objs != null;
         assert ctx != null;
 
-        Collection<CacheContinuousQueryEntry> entries = (Collection<CacheContinuousQueryEntry>)objs;
+        final List<CacheContinuousQueryEntry> entries = (List<CacheContinuousQueryEntry>)objs;
+
+        if (entries.isEmpty())
+            return;
+
+        if (asyncCallback) {
+            IgniteStripedThreadPoolExecutor asyncPool = ctx.asyncCallbackPool();
+
+            int threadId = asyncPool.threadId(entries.get(0).partition());
+
+            int startIdx = 0;
+
+            if (entries.size() != 1) {
+                for (int i = 1; i < entries.size(); i++) {
+                    int curThreadId = asyncPool.threadId(entries.get(i).partition());
+
+                    // If all entries from one partition avoid creation new collections.
+                    if (curThreadId == threadId)
+                        continue;
+
+                    final int i0 = i;
+                    final int startIdx0 = startIdx;
+
+                    asyncPool.execute(new Runnable() {
+                        @Override public void run() {
+                            notifyCallback0(nodeId, ctx, entries.subList(startIdx0, i0));
+                        }
+                    }, threadId);
+
+                    startIdx = i0;
+                    threadId = curThreadId;
+                }
+            }
+
+            final int startIdx0 = startIdx;
+
+            asyncPool.execute(new Runnable() {
+                @Override public void run() {
+                    notifyCallback0(nodeId, ctx,
+                        startIdx0 == 0 ? entries : entries.subList(startIdx0, entries.size()));
+                }
+            }, threadId);
+        }
+        else
+            notifyCallback0(nodeId, ctx, entries);
+    }
 
+    /**
+     * @param nodeId Node id.
+     * @param ctx Kernal context.
+     * @param entries Entries.
+     */
+    private void notifyCallback0(UUID nodeId,
+        final GridKernalContext ctx,
+        Collection<CacheContinuousQueryEntry> entries) {
         final GridCacheContext cctx = cacheContext(ctx);
 
-        Collection<CacheEntryEvent<? extends K, ? extends V>> entries0 = new ArrayList<>();
+        final Collection<CacheEntryEvent<? extends K, ? extends V>> entries0 = new ArrayList<>(entries.size());
 
         for (CacheContinuousQueryEntry e : entries) {
             GridCacheDeploymentManager depMgr = cctx.deploy();
@@ -609,7 +657,10 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
             try {
                 e.unmarshal(cctx, ldr);
 
-                entries0.addAll(handleEvent(ctx, e));
+                Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, e);
+
+                if (evts != null && !evts.isEmpty())
+                    entries0.addAll(evts);
             }
             catch (IgniteCheckedException ex) {
                 if (ignoreClsNotFound)
@@ -640,8 +691,8 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
             if (e.isFiltered())
                 return Collections.emptyList();
             else
-                return F.<CacheEntryEvent<? extends K, ? extends V>>asList(
-                    new CacheContinuousQueryEvent<K, V>(cache, cctx, e));
+                return F.<CacheEntryEvent<? extends K, ? extends V>>
+                    asList(new CacheContinuousQueryEvent<K, V>(cache, cctx, e));
         }
 
         // Initial query entry or evicted entry. These events should be fired immediately.
@@ -653,7 +704,117 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
 
         PartitionRecovery rec = getOrCreatePartitionRecovery(ctx, e.partition());
 
-        return rec.collectEntries(cctx, cache, e);
+        return rec.collectEntries(e, cctx, cache);
+    }
+
+    /**
+     * @param primary Primary.
+     * @param evt Query event.
+     * @return {@code True} if event passed filter otherwise {@code true}.
+     */
+    public boolean filter(CacheContinuousQueryEvent evt, boolean primary) {
+        CacheContinuousQueryEntry entry = evt.entry();
+
+        boolean notify = !entry.isFiltered();
+
+        try {
+            if (notify && getEventFilter() != null)
+                notify = getEventFilter().evaluate(evt);
+        }
+        catch (Exception e) {
+            U.error(log, "CacheEntryEventFilter failed: " + e);
+        }
+
+        if (!notify)
+            entry.markFiltered();
+
+        if (!primary && !internal && entry.updateCounter() != -1L /* Skip init query and expire entries */) {
+            entry.markBackup();
+
+            backupQueue.add(entry);
+        }
+
+        return notify;
+    }
+
+    /**
+     * @param evt Continuous query event.
+     * @param notify Notify flag.
+     * @param loc Listener deployed on this node.
+     * @param recordIgniteEvt Record ignite event.
+     */
+    private void onEntryUpdate(CacheContinuousQueryEvent evt, boolean notify, boolean loc, boolean recordIgniteEvt) {
+        try {
+            GridCacheContext<K, V> cctx = cacheContext(ctx);
+
+            if (cctx == null)
+                return;
+
+            final CacheContinuousQueryEntry entry = evt.entry();
+
+            if (loc) {
+                if (!locCache) {
+                    Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, entry);
+
+                    if (!evts.isEmpty()) {
+                        locLsnr.onUpdated(evts);
+
+                        if (!internal && !skipPrimaryCheck)
+                            sendBackupAcknowledge(ackBuf.onAcknowledged(entry), routineId, ctx);
+                    }
+                }
+                else {
+                    if (!entry.isFiltered())
+                        locLsnr.onUpdated(F.<CacheEntryEvent<? extends K, ? extends V>>asList(evt));
+                }
+            }
+            else {
+                if (!entry.isFiltered())
+                    prepareEntry(cctx, nodeId, entry);
+
+                CacheContinuousQueryEntry e = handleEntry(entry);
+
+                if (e != null)
+                    ctx.continuous().addNotification(nodeId, routineId, entry, topic, sync, true);
+            }
+        }
+        catch (ClusterTopologyCheckedException ex) {
+            if (log.isDebugEnabled())
+                log.debug("Failed to send event notification to node, node left cluster " +
+                    "[node=" + nodeId + ", err=" + ex + ']');
+        }
+        catch (IgniteCheckedException ex) {
+            U.error(ctx.log(getClass()), "Failed to send event notification to node: " + nodeId, ex);
+        }
+
+        if (recordIgniteEvt && notify) {
+            ctx.event().record(new CacheQueryReadEvent<>(
+                ctx.discovery().localNode(),
+                "Continuous query executed.",
+                EVT_CACHE_QUERY_OBJECT_READ,
+                CacheQueryType.CONTINUOUS.name(),
+                cacheName,
+                null,
+                null,
+                null,
+                getEventFilter() instanceof CacheEntryEventSerializableFilter ?
+                    (CacheEntryEventSerializableFilter)getEventFilter() : null,
+                null,
+                nodeId,
+                taskName(),
+                evt.getKey(),
+                evt.getValue(),
+                evt.getOldValue(),
+                null
+            ));
+        }
+    }
+
+    /**
+     * @return Task name.
+     */
+    private String taskName() {
+        return ctx.security().enabled() ? ctx.task().resolveTaskName(taskHash) : null;
     }
 
     /**
@@ -781,9 +942,11 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
          * @param entry Cache continuous query entry.
          * @return Collection entries which will be fired. This collection should contains only non-filtered events.
          */
-        public <K, V> Collection<CacheEntryEvent<? extends K, ? extends V>> collectEntries(GridCacheContext cctx,
-            IgniteCache cache,
-            CacheContinuousQueryEntry entry) {
+        <K, V> Collection<CacheEntryEvent<? extends K, ? extends V>> collectEntries(
+            CacheContinuousQueryEntry entry,
+            GridCacheContext cctx,
+            IgniteCache cache
+        ) {
             assert entry != null;
 
             if (entry.topologyVersion() == null) { // Possible if entry is sent from old node.
@@ -1241,6 +1404,87 @@ public class CacheContinuousQueryHandler<K, V> implements GridContinuousHandler
     }
 
     /**
+     *
+     */
+    private class ContinuousQueryAsyncClosure implements Runnable {
+        /** */
+        private final CacheContinuousQueryEvent<K, V> evt;
+
+        /** */
+        private final boolean primary;
+
+        /** */
+        private final boolean recordIgniteEvt;
+
+        /** */
+        private final IgniteInternalFuture<?> fut;
+
+        /**
+         * @param primary Primary flag.
+         * @param evt Event.
+         * @param recordIgniteEvt Fired event.
+         * @param fut Dht future.
+         */
+        ContinuousQueryAsyncClosure(
+            boolean primary,
+            CacheContinuousQueryEvent<K, V> evt,
+            boolean recordIgniteEvt,
+            IgniteInternalFuture<?> fut) {
+            this.primary = primary;
+            this.evt = evt;
+            this.recordIgniteEvt = recordIgniteEvt;
+            this.fut = fut;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            final boolean notify = filter(evt, primary);
+
+            if (!primary())
+                return;
+
+            if (fut == null) {
+                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+
+                return;
+            }
+
+            if (fut.isDone()) {
+                if (fut.error() != null)
+                    evt.entry().markFiltered();
+
+                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+            }
+            else {
+                fut.listen(new CI1<IgniteInternalFuture<?>>() {
+                    @Override public void apply(IgniteInternalFuture<?> f) {
+                        if (f.error() != null)
+                            evt.entry().markFiltered();
+
+                        ctx.asyncCallbackPool().execute(new Runnable() {
+                            @Override public void run() {
+                                onEntryUpdate(evt, notify, nodeId.equals(ctx.localNodeId()), recordIgniteEvt);
+                            }
+                        }, evt.entry().partition());
+                    }
+                });
+            }
+        }
+
+        /**
+         * @return {@code True} if event fired on this node.
+         */
+        private boolean primary() {
+            return primary || skipPrimaryCheck;
+        }
+
+        /** {@inheritDoc} */
+        public String toString() {
+            return S.toString(ContinuousQueryAsyncClosure.class, this);
+        }
+    }
+
+    /**
      * Deployable object.
      */
     protected static class DeployableObject implements Externalizable {

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
index 83ff32c..8eca81c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java
@@ -20,6 +20,8 @@ package org.apache.ignite.internal.processors.cache.query.continuous;
 import java.util.Map;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicUpdateFuture;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Continuous query listener.
@@ -36,8 +38,10 @@ public interface CacheContinuousQueryListener<K, V> {
      * @param evt Event
      * @param primary Primary flag.
      * @param recordIgniteEvt Whether to record event.
+     * @param fut Dht atomic future.
      */
-    public void onEntryUpdated(CacheContinuousQueryEvent<K, V> evt, boolean primary, boolean recordIgniteEvt);
+    public void onEntryUpdated(CacheContinuousQueryEvent<K, V> evt, boolean primary,
+        boolean recordIgniteEvt, @Nullable GridDhtAtomicUpdateFuture fut);
 
     /**
      * Listener unregistered callback.


[07/50] [abbrv] ignite git commit: IGNITE-2115: Hadoop: Added warning when Hadoop module is not loaded due to enabled peer-class-loading. This closes #615.

Posted by sh...@apache.org.
IGNITE-2115: Hadoop: Added warning when Hadoop module is not loaded due to enabled peer-class-loading. This closes #615.


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

Branch: refs/heads/ignite-2788
Commit: f1d35aa47380aaaf6a97add260c73bd66305b669
Parents: 395f473
Author: iveselovskiy <iv...@gridgain.com>
Authored: Mon Apr 25 10:39:54 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 examples/config/filesystem/example-igfs.xml     |  3 --
 .../apache/ignite/internal/IgniteKernal.java    | 31 ++++++++++++++++++--
 modules/core/src/test/config/igfs-loopback.xml  |  7 -----
 modules/core/src/test/config/igfs-shmem.xml     |  7 -----
 4 files changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f1d35aa4/examples/config/filesystem/example-igfs.xml
----------------------------------------------------------------------
diff --git a/examples/config/filesystem/example-igfs.xml b/examples/config/filesystem/example-igfs.xml
index 0a0b1b4..a72ddce 100644
--- a/examples/config/filesystem/example-igfs.xml
+++ b/examples/config/filesystem/example-igfs.xml
@@ -50,9 +50,6 @@
         Configuration below demonstrates how to setup a IgniteFs node with file data.
     -->
     <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <!-- Set to true to enable cluster-aware class loading for examples, default is false. -->
-        <property name="peerClassLoadingEnabled" value="true"/>
-
         <property name="marshaller">
             <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
                 <!-- Set to false to allow non-serializable objects in examples, default is true. -->

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1d35aa4/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index d6655d9..5094415 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -113,6 +113,7 @@ import org.apache.ignite.internal.processors.continuous.GridContinuousProcessor;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessor;
 import org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor;
 import org.apache.ignite.internal.processors.hadoop.Hadoop;
+import org.apache.ignite.internal.processors.hadoop.HadoopNoopProcessor;
 import org.apache.ignite.internal.processors.job.GridJobProcessor;
 import org.apache.ignite.internal.processors.jobmetrics.GridJobMetricsProcessor;
 import org.apache.ignite.internal.processors.nodevalidation.DiscoveryNodeValidationProcessor;
@@ -872,9 +873,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
             startProcessor(new DataStreamProcessor(ctx));
             startProcessor((GridProcessor)IGFS.create(ctx, F.isEmpty(cfg.getFileSystemConfiguration())));
             startProcessor(new GridContinuousProcessor(ctx));
-            startProcessor((GridProcessor)(cfg.isPeerClassLoadingEnabled() ?
-                IgniteComponentType.HADOOP.create(ctx, true): // No-op when peer class loading is enabled.
-                IgniteComponentType.HADOOP.createIfInClassPath(ctx, cfg.getHadoopConfiguration() != null)));
+            startProcessor((GridProcessor)createHadoopComponent());
             startProcessor(new DataStructuresProcessor(ctx));
             startProcessor(createComponent(PlatformProcessor.class, ctx));
 
@@ -1105,6 +1104,32 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
     }
 
     /**
+     * Create Hadoop component.
+     *
+     * @return Non-null Hadoop component: workable or no-op.
+     * @throws IgniteCheckedException if the component is mandatory and cannot be initialized.
+     */
+    private GridComponent createHadoopComponent() throws IgniteCheckedException {
+        GridComponent cmp;
+
+        if (cfg.isPeerClassLoadingEnabled()) {
+            cmp = IgniteComponentType.HADOOP.createIfInClassPath(ctx, false);
+
+            if (!(cmp instanceof HadoopNoopProcessor)) {
+                U.warn(log, "Hadoop module is found in classpath, but it will not be started because peer class " +
+                    "loading is enabled (set IgniteConfiguration.peerClassLoadingEnabled to \"false\" to start " +
+                    "Hadoop module).");
+
+                cmp = IgniteComponentType.HADOOP.create(ctx, true/*no-op*/);
+            }
+        }
+        else
+            cmp = IgniteComponentType.HADOOP.createIfInClassPath(ctx, cfg.getHadoopConfiguration() != null);
+
+        return cmp;
+    }
+
+    /**
      * Validates common configuration parameters.
      *
      * @param cfg Configuration.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1d35aa4/modules/core/src/test/config/igfs-loopback.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/igfs-loopback.xml b/modules/core/src/test/config/igfs-loopback.xml
index c01fb98..dbbfb4e 100644
--- a/modules/core/src/test/config/igfs-loopback.xml
+++ b/modules/core/src/test/config/igfs-loopback.xml
@@ -54,13 +54,6 @@
     -->
     <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
         <!--
-            For better performance set this property to false in case
-            peer deployment is not used.
-            Default value is false.
-        -->
-        <property name="peerClassLoadingEnabled" value="true"/>
-
-        <!--
             Configure optimized marshaller.
         -->
         <property name="marshaller">

http://git-wip-us.apache.org/repos/asf/ignite/blob/f1d35aa4/modules/core/src/test/config/igfs-shmem.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/igfs-shmem.xml b/modules/core/src/test/config/igfs-shmem.xml
index b38544f..c4c8704 100644
--- a/modules/core/src/test/config/igfs-shmem.xml
+++ b/modules/core/src/test/config/igfs-shmem.xml
@@ -54,13 +54,6 @@
     -->
     <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
         <!--
-            For better performance set this property to false in case
-            peer deployment is not used.
-            Default value is false.
-        -->
-        <property name="peerClassLoadingEnabled" value="true"/>
-
-        <!--
             Configure optimized marshaller.
         -->
         <property name="marshaller">


[48/50] [abbrv] ignite git commit: Added a test for IGNITE-3077

Posted by sh...@apache.org.
Added a test for IGNITE-3077


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

Branch: refs/heads/ignite-2788
Commit: 377c405579d9267463561ab5f8b32a2f15112408
Parents: 3624e18
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Fri Apr 29 18:14:46 2016 -0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:17 2016 +0900

----------------------------------------------------------------------
 .../org/apache/ignite/spark/IgniteRDDSpec.scala | 40 +++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/377c4055/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
----------------------------------------------------------------------
diff --git a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
index 071897a..a41839d 100644
--- a/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
+++ b/modules/spark/src/test/scala/org/apache/ignite/spark/IgniteRDDSpec.scala
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.spark
 
+import java.time.LocalDate
+
 import org.apache.ignite.Ignition
 import org.apache.ignite.cache.query.annotations.{QueryTextField, QuerySqlField}
 import org.apache.ignite.configuration.{CacheConfiguration, IgniteConfiguration}
@@ -165,6 +167,33 @@ class IgniteRDDSpec extends FunSpec with Matchers with BeforeAndAfterAll with Be
                 sc.stop()
             }
         }
+
+        it("should successfully query complex object fields") {
+            assert(false, "https://issues.apache.org/jira/browse/IGNITE-3077")
+
+            val sc = new SparkContext("local[*]", "test")
+
+            try {
+                val ic = new IgniteContext[Integer, WithObjectField](sc,
+                    () \u21d2 configuration("client", client = true))
+
+                val cache: IgniteRDD[Integer, WithObjectField] = ic.fromCache(PARTITIONED_CACHE_NAME)
+
+                cache.savePairs(sc.parallelize(0 to 1000, 2).map(i \u21d2 (i:java.lang.Integer, new WithObjectField(i, new Entity(i, "", i)))))
+
+                val df = cache.sql("select i, ts from WithLocalDate where i = ?", 50)
+
+                df.printSchema()
+
+                val res = df.collect()
+
+                assert(res.length == 1, "Invalid result length")
+                assert(50 == res(0)(0), "Invalid result")
+            }
+            finally {
+                sc.stop()
+            }
+        }
     }
 
     override protected def beforeEach() = {
@@ -188,6 +217,12 @@ class IgniteRDDSpec extends FunSpec with Matchers with BeforeAndAfterAll with Be
     }
 }
 
+case class WithObjectField(
+    @(QuerySqlField @field)(index = true) val i : Int,
+    @(QuerySqlField @field)(index = false) val ts : Object
+) {
+}
+
 /**
  * Constants and utility methods.
  */
@@ -242,7 +277,10 @@ object IgniteRDDSpec {
 
         ccfg.setName(PARTITIONED_CACHE_NAME)
 
-        ccfg.setIndexedTypes(classOf[String], classOf[Entity])
+        ccfg.setIndexedTypes(
+            classOf[String], classOf[Entity],
+            classOf[Integer], classOf[WithObjectField]
+        )
 
         ccfg
     }


[19/50] [abbrv] ignite git commit: IGNITE-2977: .NET: Added ability to use Java filter in .NET continuous queries: fix VS2010 compilation.

Posted by sh...@apache.org.
IGNITE-2977: .NET: Added ability to use Java filter in .NET continuous queries: fix VS2010 compilation.


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

Branch: refs/heads/ignite-2788
Commit: 91fd8ff61a2373fd584a347348215ed638488903
Parents: 6994a43
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Apr 27 15:47:19 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/91fd8ff6/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
index ed9d2ad..76be0fd 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Continuous/ContinuousQueryJavaFilterTest.cs
@@ -295,8 +295,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Continuous
                 String = s;
             }
 
-            private int Int { get; }
-            private string String { get; }
+            private int Int { get; set; }
+            private string String { get; set; }
 
             private bool Equals(TestBinary other)
             {


[50/50] [abbrv] ignite git commit: IGNITE-2788: Moved handlers.

Posted by sh...@apache.org.
IGNITE-2788: Moved handlers.


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

Branch: refs/heads/ignite-2788
Commit: 3ade1cb184271e588c0ae6ec8cda19a4205e614d
Parents: 377c405
Author: shtykh_roman <rs...@yahoo.com>
Authored: Tue Nov 1 11:27:41 2016 +0900
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Tue Nov 1 11:27:41 2016 +0900

----------------------------------------------------------------------
 modules/clients/pom.xml                         |   2 +-
 .../handlers/redis/GridRedisCommandHandler.java |  39 ++++++
 .../GridRedisConnectionCommandHandler.java      |  71 ++++++++++
 .../redis/GridRedisThruRestCommandHandler.java  |  99 ++++++++++++++
 .../exception/GridRedisGenericException.java    |  20 +++
 .../redis/exception/GridRedisTypeException.java |  20 +++
 .../redis/key/GridRedisDelCommandHandler.java   |  91 +++++++++++++
 .../key/GridRedisExistsCommandHandler.java      |  90 +++++++++++++
 .../server/GridRedisDbSizeCommandHandler.java   |  75 +++++++++++
 .../string/GridRedisAppendCommandHandler.java   | 108 +++++++++++++++
 .../string/GridRedisGetCommandHandler.java      |  76 +++++++++++
 .../string/GridRedisGetRangeCommandHandler.java | 124 +++++++++++++++++
 .../string/GridRedisGetSetCommandHandler.java   |  84 ++++++++++++
 .../string/GridRedisIncrDecrCommandHandler.java | 133 +++++++++++++++++++
 .../string/GridRedisMGetCommandHandler.java     |  90 +++++++++++++
 .../string/GridRedisMSetCommandHandler.java     |  86 ++++++++++++
 .../string/GridRedisSetCommandHandler.java      |  90 +++++++++++++
 .../string/GridRedisSetRangeCommandHandler.java | 131 ++++++++++++++++++
 .../string/GridRedisStrlenCommandHandler.java   |  80 +++++++++++
 .../tcp/redis/GridRedisNioListener.java         |  31 +++--
 .../redis/handler/GridRedisCommandHandler.java  |  39 ------
 .../GridRedisConnectionCommandHandler.java      |  71 ----------
 .../GridRedisThruRestCommandHandler.java        |  99 --------------
 .../exception/GridRedisGenericException.java    |  20 ---
 .../exception/GridRedisTypeException.java       |  20 ---
 .../handler/key/GridRedisDelCommandHandler.java |  91 -------------
 .../key/GridRedisExistsCommandHandler.java      |  90 -------------
 .../server/GridRedisDbSizeCommandHandler.java   |  75 -----------
 .../string/GridRedisAppendCommandHandler.java   | 108 ---------------
 .../string/GridRedisGetCommandHandler.java      |  76 -----------
 .../string/GridRedisGetRangeCommandHandler.java | 124 -----------------
 .../string/GridRedisGetSetCommandHandler.java   |  84 ------------
 .../string/GridRedisIncrDecrCommandHandler.java | 133 -------------------
 .../string/GridRedisMGetCommandHandler.java     |  90 -------------
 .../string/GridRedisMSetCommandHandler.java     |  86 ------------
 .../string/GridRedisSetCommandHandler.java      |  90 -------------
 .../string/GridRedisSetRangeCommandHandler.java | 131 ------------------
 .../string/GridRedisStrlenCommandHandler.java   |  80 -----------
 38 files changed, 1523 insertions(+), 1524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/clients/pom.xml
----------------------------------------------------------------------
diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml
index 729bc89..88eed4d 100644
--- a/modules/clients/pom.xml
+++ b/modules/clients/pom.xml
@@ -58,7 +58,7 @@
         <dependency>
             <groupId>redis.clients</groupId>
             <artifactId>jedis</artifactId>
-            <version>2.8.1</version>
+            <version>2.9.0</version>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
new file mode 100644
index 0000000..16c3f3e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
@@ -0,0 +1,39 @@
+/*
+ * 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.rest.handlers.redis;
+
+import java.util.Collection;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+
+/**
+ * Command handler.
+ */
+public interface GridRedisCommandHandler {
+    /**
+     * @return Collection of supported commands.
+     */
+    Collection<GridRedisCommand> supportedCommands();
+
+    /**
+     * @param msg Request message.
+     * @return Future.
+     */
+    IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
new file mode 100644
index 0000000..a5993c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
@@ -0,0 +1,71 @@
+/*
+ * 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.rest.handlers.redis;
+
+import java.util.Collection;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.ECHO;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.PING;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.QUIT;
+
+/**
+ * Redis connection handler.
+ */
+public class GridRedisConnectionCommandHandler implements GridRedisCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        PING,
+        QUIT,
+        ECHO
+    );
+
+    /** PONG response to PING. */
+    private static final String PONG = "PONG";
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg) {
+        assert msg != null;
+
+        switch (msg.command()) {
+            case PING:
+                msg.setResponse(GridRedisProtocolParser.toSimpleString(PONG));
+                return new GridFinishedFuture<>(msg);
+
+            case QUIT:
+                msg.setResponse(GridRedisProtocolParser.OkString());
+                return new GridFinishedFuture<>(msg);
+
+            case ECHO:
+                msg.setResponse(GridRedisProtocolParser.toSimpleString(msg.key()));
+                return new GridFinishedFuture<>(msg);
+        }
+
+        return new GridFinishedFuture<>();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
new file mode 100644
index 0000000..73a4131
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
@@ -0,0 +1,99 @@
+/*
+ * 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.rest.handlers.redis;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisTypeException;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.CX1;
+
+/**
+ * Redis command handler done via REST.
+ */
+public abstract class GridRedisThruRestCommandHandler implements GridRedisCommandHandler {
+    /** REST protocol handler. */
+    protected final GridRestProtocolHandler hnd;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param hnd REST protocol handler.
+     */
+    public GridRedisThruRestCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        this.hnd = hnd;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(final GridRedisMessage msg) {
+        assert msg != null;
+
+        try {
+            return hnd.handleAsync(asRestRequest(msg))
+                .chain(new CX1<IgniteInternalFuture<GridRestResponse>, GridRedisMessage>() {
+                    @Override
+                    public GridRedisMessage applyx(IgniteInternalFuture<GridRestResponse> f)
+                        throws IgniteCheckedException {
+                        GridRestResponse restRes = f.get();
+
+                        if (restRes.getSuccessStatus() == GridRestResponse.STATUS_SUCCESS)
+                            msg.setResponse(makeResponse(restRes, msg.auxMKeys()));
+                        else
+                            msg.setResponse(GridRedisProtocolParser.toGenericError("Operation error!"));
+
+                        return msg;
+                    }
+                });
+        }
+        catch (IgniteCheckedException e) {
+            if (e instanceof GridRedisTypeException)
+                msg.setResponse(GridRedisProtocolParser.toTypeError(e.getMessage()));
+            else
+                msg.setResponse(GridRedisProtocolParser.toGenericError(e.getMessage()));
+
+            return new GridFinishedFuture<>(msg);
+        }
+    }
+
+    /**
+     * Converts {@link GridRedisMessage} to {@link GridRestRequest}.
+     *
+     * @param msg {@link GridRedisMessage}
+     * @return {@link GridRestRequest}
+     * @throws IgniteCheckedException If fails.
+     */
+    public abstract GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException;
+
+    /**
+     * Prepares a response according to the request.
+     *
+     * @param resp REST response.
+     * @param params Auxiliary parameters.
+     * @return
+     */
+    public abstract ByteBuffer makeResponse(GridRestResponse resp, List<String> params);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
new file mode 100644
index 0000000..2e457b6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
@@ -0,0 +1,20 @@
+package org.apache.ignite.internal.processors.rest.handlers.redis.exception;
+
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Generic Redis protocol exception.
+ */
+public class GridRedisGenericException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Creates a generic exception with given error message.
+     *
+     * @param msg Error message.
+     */
+    public GridRedisGenericException(String msg) {
+        super(msg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
new file mode 100644
index 0000000..cf24b6d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
@@ -0,0 +1,20 @@
+package org.apache.ignite.internal.processors.rest.handlers.redis.exception;
+
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Exception on operation on the wrong data type.
+ */
+public class GridRedisTypeException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Creates a type exception with given error message.
+     *
+     * @param msg Error message.
+     */
+    public GridRedisTypeException(String msg) {
+        super(msg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
new file mode 100644
index 0000000..62fa2b0
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
@@ -0,0 +1,91 @@
+/*
+ * 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.rest.handlers.redis.key;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DEL;
+
+/**
+ * Redis DEL command handler.
+ */
+public class GridRedisDelCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        DEL
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisDelCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_REMOVE_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        // It has to respond with the number of removed entries...
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(String.valueOf(params.size())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
new file mode 100644
index 0000000..3802517
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.key;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.EXISTS;
+
+/**
+ * Redis EXISTS command handler.
+ */
+public class GridRedisExistsCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        EXISTS
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisExistsCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_GET_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(((Map<Object, Object>)restRes.getResponse()).size()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
new file mode 100644
index 0000000..27daad4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
@@ -0,0 +1,75 @@
+/*
+ * 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.rest.handlers.redis.server;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_SIZE;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DBSIZE;
+
+/**
+ * Redis DBSIZE command handler.
+ */
+public class GridRedisDbSizeCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        DBSIZE
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisDbSizeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_SIZE);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(String.valueOf(restRes.getResponse())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
new file mode 100644
index 0000000..331f7fe
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
@@ -0,0 +1,108 @@
+/*
+ * 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.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_APPEND;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.APPEND;
+
+/**
+ * Redis APPEND command handler.
+ */
+public class GridRedisAppendCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        APPEND
+    );
+
+    /** Position of the value. */
+    private static final int VAL_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisAppendCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 3)
+            throw new GridRedisGenericException("Wrong syntax!");
+
+        GridRestCacheRequest appendReq = new GridRestCacheRequest();
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        String val = msg.aux(VAL_POS);
+
+        appendReq.clientId(msg.clientId());
+        appendReq.key(msg.key());
+        appendReq.value(val);
+        appendReq.command(CACHE_APPEND);
+
+        if ((boolean)hnd.handle(appendReq).getResponse() == false) {
+            // append on on-existing key in REST returns false.
+            GridRestCacheRequest setReq = new GridRestCacheRequest();
+
+            setReq.clientId(msg.clientId());
+            setReq.key(msg.key());
+            setReq.value(val);
+            setReq.command(CACHE_PUT);
+
+            hnd.handle(setReq);
+        }
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        return getReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.nil();
+        else {
+            int resLen = ((String)restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
new file mode 100644
index 0000000..b06e411
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
@@ -0,0 +1,76 @@
+/*
+ * 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.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GET;
+
+/**
+ * Redis GET command handler.
+ */
+public class GridRedisGetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_GET);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
+            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
new file mode 100644
index 0000000..481e07a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
@@ -0,0 +1,124 @@
+/*
+ * 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.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETRANGE;
+
+/**
+ * Redis SETRANGE command handler.
+ */
+public class GridRedisGetRangeCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GETRANGE
+    );
+
+    /** Start offset position in Redis message parameters. */
+    private static final int START_OFFSET_POS = 1;
+
+    /** End offset position in Redis message parameters. */
+    private static final int END_OFFSET_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisGetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 4)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        return getReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toBulkString("");
+        else {
+            String res = String.valueOf(restRes.getResponse());
+            int startOffset;
+            int endOffset;
+
+            try {
+                startOffset = boundedStartOffset(Integer.parseInt(params.get(START_OFFSET_POS)), res.length());
+                endOffset = boundedEndOffset(Integer.parseInt(params.get(END_OFFSET_POS)), res.length());
+            }
+            catch (NumberFormatException e) {
+                return GridRedisProtocolParser.toGenericError("Offset is not an integer!");
+            }
+
+            return GridRedisProtocolParser.toBulkString(res.substring(startOffset, endOffset));
+        }
+    }
+
+    /**
+     * @param idx Index.
+     * @param size Bounds.
+     * @return Offset within the bounds.
+     */
+    private int boundedStartOffset(int idx, int size) {
+        if (idx >= 0)
+            return Math.min(idx, size);
+        else
+            return size + idx;
+    }
+
+    /**
+     * @param idx Index.
+     * @param size Bounds.
+     * @return Offset within the bounds.
+     */
+    private int boundedEndOffset(int idx, int size) {
+        if (idx >= 0)
+            return Math.min(idx + 1, size);
+        else
+            return size + idx + 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
new file mode 100644
index 0000000..0f302e5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
@@ -0,0 +1,84 @@
+/*
+ * 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.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETSET;
+
+/**
+ * Redis GETSET command handler.
+ */
+public class GridRedisGetSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GETSET
+    );
+
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisGetSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 3)
+            throw new GridRedisGenericException("Wrong syntax!");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.value(msg.aux(VAL_POS));
+
+        restReq.command(CACHE_GET_AND_PUT);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
+            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
new file mode 100644
index 0000000..34d4b31
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.string;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.DataStructuresRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_DECREMENT;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_INCREMENT;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECR;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECRBY;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCR;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCRBY;
+
+/**
+ * Redis INCR/DECR command handler.
+ */
+public class GridRedisIncrDecrCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        INCR,
+        DECR,
+        INCRBY,
+        DECRBY
+    );
+
+    /** Delta position in the message. */
+    private static final int DELTA_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisIncrDecrCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        DataStructuresRequest restReq = new DataStructuresRequest();
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        GridRestResponse getResp = hnd.handle(getReq);
+
+        if (getResp.getResponse() == null) {
+            restReq.initial(0L);
+        }
+        else {
+            if (getResp.getResponse() instanceof Long && (Long)getResp.getResponse() <= Long.MAX_VALUE)
+                restReq.initial((Long)getResp.getResponse());
+            else
+                throw new GridRedisGenericException("An initial value must be numeric and in range!");
+        }
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.delta(1L);
+
+        if (msg.messageSize() > 2) {
+            try {
+                restReq.delta(Long.valueOf(msg.aux(DELTA_POS)));
+            }
+            catch (NumberFormatException e) {
+                throw new GridRedisGenericException("An increment value must be numeric and in range!");
+            }
+        }
+
+        switch (msg.command()) {
+            case INCR:
+            case INCRBY:
+                restReq.command(ATOMIC_INCREMENT);
+                break;
+
+            case DECR:
+            case DECRBY:
+                restReq.command(ATOMIC_DECREMENT);
+                break;
+        }
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toGenericError("Failed to increment!");
+
+        if (restRes.getResponse() instanceof Long && (Long)restRes.getResponse() <= Long.MAX_VALUE)
+            return GridRedisProtocolParser.toInteger(new BigDecimal((Long)restRes.getResponse()).toString());
+        else
+            return GridRedisProtocolParser.toTypeError("Value is non-numeric or out of range!");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
new file mode 100644
index 0000000..4cf8345
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MGET;
+
+/**
+ * Redis MGET command handler.
+ */
+public class GridRedisMGetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        MGET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisMGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_GET_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
+            : GridRedisProtocolParser.toArray((Map<Object, Object>)restRes.getResponse()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
new file mode 100644
index 0000000..783fed5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
@@ -0,0 +1,86 @@
+/*
+ * 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.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MSET;
+
+/**
+ * Redis MSET command handler.
+ */
+public class GridRedisMSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        MSET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisMSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_PUT_ALL);
+
+        List<String> els = msg.auxMKeys();
+        Map<Object, Object> mset = U.newHashMap(els.size() / 2);
+        Iterator<String> msetIt = els.iterator();
+
+        while (msetIt.hasNext())
+            mset.put(msetIt.next(), msetIt.hasNext() ? msetIt.next() : null);
+
+        restReq.values(mset);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return GridRedisProtocolParser.OkString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
new file mode 100644
index 0000000..09b97ab
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SET;
+
+/**
+ * Redis SET command handler.
+ * <p>
+ * No key expiration is currently supported.
+ */
+public class GridRedisSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        SET
+    );
+
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_PUT);
+
+        if (msg.messageSize() < 3)
+            throw new IgniteCheckedException("Invalid request!");
+
+        restReq.value(msg.aux(VAL_POS));
+
+        if (msg.messageSize() >= 4) {
+            // handle options.
+        }
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
+            : GridRedisProtocolParser.OkString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
new file mode 100644
index 0000000..0063c66
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SETRANGE;
+
+/**
+ * Redis SETRANGE command handler.
+ */
+public class GridRedisSetRangeCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        SETRANGE
+    );
+
+    /** Offset position in Redis message among parameters. */
+    private static final int OFFSET_POS = 2;
+
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 3;
+
+    /** {@inheritDoc} */
+    public GridRedisSetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        if (msg.messageSize() < 4)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        int offset;
+        try {
+            offset = Integer.parseInt(msg.aux(OFFSET_POS));
+        }
+        catch (NumberFormatException e) {
+            throw new GridRedisGenericException("Offset is not an integer!");
+        }
+
+        String val = String.valueOf(msg.aux(VAL_POS));
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        if (val.length() == 0)
+            return getReq;
+
+        Object resp = hnd.handle(getReq).getResponse();
+
+        int totalLen = offset + val.length();
+        if (offset < 0 || totalLen > 536870911)
+            throw new GridRedisGenericException("Offset is out of range!");
+
+        GridRestCacheRequest putReq = new GridRestCacheRequest();
+
+        putReq.clientId(msg.clientId());
+        putReq.key(msg.key());
+        putReq.command(CACHE_PUT);
+
+        if (resp == null) {
+            byte[] dst = new byte[totalLen];
+            System.arraycopy(val.getBytes(), 0, dst, offset, val.length());
+
+            putReq.value(new String(dst));
+        }
+        else {
+            String cacheVal = String.valueOf(resp);
+
+            cacheVal = cacheVal.substring(0, offset) + val;
+
+            putReq.value(cacheVal);
+        }
+
+        hnd.handle(putReq);
+
+        return getReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toInteger("0");
+        else {
+            int resLen = ((String)restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
new file mode 100644
index 0000000..441bf42
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
@@ -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.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.STRLEN;
+
+/**
+ * Redis STRLEN command handler.
+ */
+public class GridRedisStrlenCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        STRLEN
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisStrlenCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_GET);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toInteger("0");
+        else {
+            int len = String.valueOf(restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(len));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
index 555787b..1ff4a4a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
@@ -24,22 +24,21 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisConnectionCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key.GridRedisDelCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key.GridRedisExistsCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server.GridRedisDbSizeCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server.GridRedisFlushDbCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisAppendCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetRangeCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetSetCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisIncrDecrCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisMGetCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisMSetCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisSetCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisSetRangeCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisStrlenCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisConnectionCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.key.GridRedisDelCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.key.GridRedisExistsCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.server.GridRedisDbSizeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisAppendCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetRangeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisIncrDecrCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisMGetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisMSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisSetRangeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisStrlenCommandHandler;
 import org.apache.ignite.internal.util.nio.GridNioFuture;
 import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter;
 import org.apache.ignite.internal.util.nio.GridNioSession;

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
deleted file mode 100644
index a1f292d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler;
-
-import java.util.Collection;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-
-/**
- * Command handler.
- */
-public interface GridRedisCommandHandler {
-    /**
-     * @return Collection of supported commands.
-     */
-    Collection<GridRedisCommand> supportedCommands();
-
-    /**
-     * @param msg Request message.
-     * @return Future.
-     */
-    IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
deleted file mode 100644
index 6dcaecb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler;
-
-import java.util.Collection;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.util.future.GridFinishedFuture;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.ECHO;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.PING;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.QUIT;
-
-/**
- * Redis connection handler.
- */
-public class GridRedisConnectionCommandHandler implements GridRedisCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        PING,
-        QUIT,
-        ECHO
-    );
-
-    /** PONG response to PING. */
-    private static final String PONG = "PONG";
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg) {
-        assert msg != null;
-
-        switch (msg.command()) {
-            case PING:
-                msg.setResponse(GridRedisProtocolParser.toSimpleString(PONG));
-                return new GridFinishedFuture<>(msg);
-
-            case QUIT:
-                msg.setResponse(GridRedisProtocolParser.OkString());
-                return new GridFinishedFuture<>(msg);
-
-            case ECHO:
-                msg.setResponse(GridRedisProtocolParser.toSimpleString(msg.key()));
-                return new GridFinishedFuture<>(msg);
-        }
-
-        return new GridFinishedFuture<>();
-    }
-}


[18/50] [abbrv] ignite git commit: fixed slow exchange on topology startup (cherry picked from commit c88182c)

Posted by sh...@apache.org.
fixed slow exchange on topology startup
(cherry picked from commit c88182c)


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

Branch: refs/heads/ignite-2788
Commit: 1e725899e42c3e1f1dfde8f5ae2405d52d2a9b79
Parents: 3ab39af
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Thu Apr 21 16:15:02 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../ignite/internal/IgniteEventsImpl.java       |  11 +-
 .../ignite/internal/IgniteMessagingImpl.java    |   7 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |   2 +-
 .../continuous/CacheContinuousQueryManager.java |   1 +
 .../continuous/GridContinuousProcessor.java     |  29 ++-
 .../ignite/spi/IgniteNodeValidationResult.java  |   8 +-
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 194 +++++++++++--------
 .../tcp/internal/TcpDiscoveryNode.java          |   2 +-
 .../messages/TcpDiscoveryAbstractMessage.java   |   4 +-
 .../TcpDiscoveryCustomEventMessage.java         |  13 +-
 .../TcpDiscoveryJoinRequestMessage.java         |  16 +-
 .../TcpDiscoveryStatusCheckMessage.java         |  18 +-
 12 files changed, 208 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
index 505bc9d..3c6218d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
@@ -108,9 +108,16 @@ public class IgniteEventsImpl extends AsyncSupportAdapter<IgniteEvents> implemen
         guard();
 
         try {
+            GridEventConsumeHandler hnd = new GridEventConsumeHandler((IgniteBiPredicate<UUID, Event>)locLsnr,
+                (IgnitePredicate<Event>)rmtFilter, types);
+
             return saveOrGet(ctx.continuous().startRoutine(
-                new GridEventConsumeHandler((IgniteBiPredicate<UUID, Event>)locLsnr,
-                    (IgnitePredicate<Event>)rmtFilter, types), bufSize, interval, autoUnsubscribe, prj.predicate()));
+                hnd,
+                false,
+                bufSize,
+                interval,
+                autoUnsubscribe,
+                prj.predicate()));
         }
         catch (IgniteCheckedException e) {
             throw U.convertException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
index 17c06fc..2800777 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
@@ -184,7 +184,12 @@ public class IgniteMessagingImpl extends AsyncSupportAdapter<IgniteMessaging>
         try {
             GridContinuousHandler hnd = new GridMessageListenHandler(topic, (IgniteBiPredicate<UUID, Object>)p);
 
-            return saveOrGet(ctx.continuous().startRoutine(hnd, 1, 0, false, prj.predicate()));
+            return saveOrGet(ctx.continuous().startRoutine(hnd,
+                false,
+                1,
+                0,
+                false,
+                prj.predicate()));
         }
         catch (IgniteCheckedException e) {
             throw U.convertException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 7776687..783debf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -1278,7 +1278,7 @@ public class IgnitionEx {
     }
 
     /**
-     * Gets a name of the grid, which is owner of current thread. An Exception is thrown if
+     * Gets the grid, which is owner of current thread. An Exception is thrown if
      * current thread is not an {@link IgniteThread}.
      *
      * @return Grid instance related to current thread

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
index 9efc456..fafb830 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
@@ -641,6 +641,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter {
 
         UUID id = cctx.kernalContext().continuous().startRoutine(
             hnd,
+            internal && loc,
             bufSize,
             timeInterval,
             autoUnsubscribe,

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
index d7838f3..fd5e446 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
@@ -540,11 +540,13 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
      * @param bufSize Buffer size.
      * @param interval Time interval.
      * @param autoUnsubscribe Automatic unsubscribe flag.
+     * @param locOnly Local only flag.
      * @param prjPred Projection predicate.
      * @return Future.
      */
     @SuppressWarnings("TooBroadScope")
     public IgniteInternalFuture<UUID> startRoutine(GridContinuousHandler hnd,
+        boolean locOnly,
         int bufSize,
         long interval,
         boolean autoUnsubscribe,
@@ -553,12 +555,30 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
         assert bufSize > 0;
         assert interval >= 0;
 
-        // Whether local node is included in routine.
-        boolean locIncluded = prjPred == null || prjPred.apply(ctx.discovery().localNode());
-
         // Generate ID.
         final UUID routineId = UUID.randomUUID();
 
+        // Register routine locally.
+        locInfos.put(routineId, new LocalRoutineInfo(prjPred, hnd, bufSize, interval, autoUnsubscribe));
+
+        if (locOnly) {
+            try {
+                registerHandler(ctx.localNodeId(), routineId, hnd, bufSize, interval, autoUnsubscribe, true);
+
+                hnd.onListenerRegistered(routineId, ctx);
+
+                return new GridFinishedFuture<>(routineId);
+            }
+            catch (IgniteCheckedException e) {
+                unregisterHandler(routineId, hnd, true);
+
+                return new GridFinishedFuture<>(e);
+            }
+        }
+
+        // Whether local node is included in routine.
+        boolean locIncluded = prjPred == null || prjPred.apply(ctx.discovery().localNode());
+
         StartRequestData reqData = new StartRequestData(prjPred, hnd.clone(), bufSize, interval, autoUnsubscribe);
 
         try {
@@ -613,9 +633,6 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
             });
         }
 
-        // Register routine locally.
-        locInfos.put(routineId, new LocalRoutineInfo(prjPred, hnd, bufSize, interval, autoUnsubscribe));
-
         StartFuture fut = new StartFuture(ctx, routineId);
 
         startFuts.put(routineId, fut);

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/IgniteNodeValidationResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteNodeValidationResult.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteNodeValidationResult.java
index 2473a9e..3dd4caf 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteNodeValidationResult.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteNodeValidationResult.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.spi;
 
 import java.util.UUID;
+import org.apache.ignite.internal.util.typedef.internal.S;
 
 /**
  * Result of joining node validation.
@@ -63,4 +64,9 @@ public class IgniteNodeValidationResult {
     public String sendMessage() {
         return sndMsg;
     }
-}
\ No newline at end of file
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(IgniteNodeValidationResult.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 3283d99..450f628 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -2584,6 +2584,9 @@ class ServerImpl extends TcpDiscoveryImpl {
                             }
                             finally {
                                 if (!success) {
+                                    if (log.isDebugEnabled())
+                                        log.debug("Closing socket to next: " + next);
+
                                     U.closeQuiet(sock);
 
                                     sock = null;
@@ -2747,6 +2750,9 @@ class ServerImpl extends TcpDiscoveryImpl {
                             forceSndPending = false;
 
                             if (!sent) {
+                                if (log.isDebugEnabled())
+                                    log.debug("Closing socket to next (not sent): " + next);
+
                                 U.closeQuiet(sock);
 
                                 sock = null;
@@ -2897,12 +2903,12 @@ class ServerImpl extends TcpDiscoveryImpl {
          *
          * @param msg Join request message.
          */
-        private void processJoinRequestMessage(TcpDiscoveryJoinRequestMessage msg) {
+        private void processJoinRequestMessage(final TcpDiscoveryJoinRequestMessage msg) {
             assert msg != null;
 
-            TcpDiscoveryNode node = msg.node();
+            final TcpDiscoveryNode node = msg.node();
 
-            UUID locNodeId = getLocalNodeId();
+            final UUID locNodeId = getLocalNodeId();
 
             if (!msg.client()) {
                 boolean rmtHostLoopback = node.socketAddresses().size() == 1 &&
@@ -3110,92 +3116,107 @@ class ServerImpl extends TcpDiscoveryImpl {
                     }
                 }
 
-                IgniteNodeValidationResult err = spi.getSpiContext().validateNode(node);
+                final IgniteNodeValidationResult err = spi.getSpiContext().validateNode(node);
 
                 if (err != null) {
-                    boolean ping = node.id().equals(err.nodeId()) ? pingNode(node) : pingNode(err.nodeId());
+                    if (log.isDebugEnabled())
+                        log.debug("Node validation failed [res=" + err + ", node=" + node + ']');
 
-                    if (!ping) {
-                        if (log.isDebugEnabled())
-                            log.debug("Conflicting node has already left, need to wait for event. " +
-                                "Will ignore join request for now since it will be recent [req=" + msg +
-                                ", err=" + err.message() + ']');
+                    utilityPool.submit(
+                        new Runnable() {
+                            @Override public void run() {
+                                boolean ping = node.id().equals(err.nodeId()) ? pingNode(node) : pingNode(err.nodeId());
 
-                        // Ignore join request.
-                        return;
-                    }
+                                if (!ping) {
+                                    if (log.isDebugEnabled())
+                                        log.debug("Conflicting node has already left, need to wait for event. " +
+                                            "Will ignore join request for now since it will be recent [req=" + msg +
+                                            ", err=" + err.message() + ']');
 
-                    LT.warn(log, null, err.message());
+                                    // Ignore join request.
+                                    return;
+                                }
 
-                    // Always output in debug.
-                    if (log.isDebugEnabled())
-                        log.debug(err.message());
+                                LT.warn(log, null, err.message());
 
-                    try {
-                        trySendMessageDirectly(node,
-                            new TcpDiscoveryCheckFailedMessage(locNodeId, err.sendMessage()));
-                    }
-                    catch (IgniteSpiException e) {
-                        if (log.isDebugEnabled())
-                            log.debug("Failed to send hash ID resolver validation failed message to node " +
-                                "[node=" + node + ", err=" + e.getMessage() + ']');
+                                // Always output in debug.
+                                if (log.isDebugEnabled())
+                                    log.debug(err.message());
 
-                        onException("Failed to send hash ID resolver validation failed message to node " +
-                            "[node=" + node + ", err=" + e.getMessage() + ']', e);
-                    }
+                                try {
+                                    trySendMessageDirectly(node,
+                                        new TcpDiscoveryCheckFailedMessage(locNodeId, err.sendMessage()));
+                                }
+                                catch (IgniteSpiException e) {
+                                    if (log.isDebugEnabled())
+                                        log.debug("Failed to send hash ID resolver validation failed message to node " +
+                                            "[node=" + node + ", err=" + e.getMessage() + ']');
+
+                                    onException("Failed to send hash ID resolver validation failed message to node " +
+                                        "[node=" + node + ", err=" + e.getMessage() + ']', e);
+                                }
+                            }
+                        }
+                    );
 
                     // Ignore join request.
                     return;
                 }
 
-                String locMarsh = locNode.attribute(ATTR_MARSHALLER);
-                String rmtMarsh = node.attribute(ATTR_MARSHALLER);
+                final String locMarsh = locNode.attribute(ATTR_MARSHALLER);
+                final String rmtMarsh = node.attribute(ATTR_MARSHALLER);
 
                 if (!F.eq(locMarsh, rmtMarsh)) {
-                    String errMsg = "Local node's marshaller differs from remote node's marshaller " +
-                        "(to make sure all nodes in topology have identical marshaller, " +
-                        "configure marshaller explicitly in configuration) " +
-                        "[locMarshaller=" + locMarsh + ", rmtMarshaller=" + rmtMarsh +
-                        ", locNodeAddrs=" + U.addressesAsString(locNode) +
-                        ", rmtNodeAddrs=" + U.addressesAsString(node) +
-                        ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
+                    utilityPool.submit(
+                        new Runnable() {
+                            @Override public void run() {
+                                String errMsg = "Local node's marshaller differs from remote node's marshaller " +
+                                    "(to make sure all nodes in topology have identical marshaller, " +
+                                    "configure marshaller explicitly in configuration) " +
+                                    "[locMarshaller=" + locMarsh + ", rmtMarshaller=" + rmtMarsh +
+                                    ", locNodeAddrs=" + U.addressesAsString(locNode) +
+                                    ", rmtNodeAddrs=" + U.addressesAsString(node) +
+                                    ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
 
-                    LT.warn(log, null, errMsg);
+                                LT.warn(log, null, errMsg);
 
-                    // Always output in debug.
-                    if (log.isDebugEnabled())
-                        log.debug(errMsg);
+                                // Always output in debug.
+                                if (log.isDebugEnabled())
+                                    log.debug(errMsg);
 
-                    try {
-                        String sndMsg = "Local node's marshaller differs from remote node's marshaller " +
-                            "(to make sure all nodes in topology have identical marshaller, " +
-                            "configure marshaller explicitly in configuration) " +
-                            "[locMarshaller=" + rmtMarsh + ", rmtMarshaller=" + locMarsh +
-                            ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
-                            ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
-                            ", rmtNodeId=" + locNode.id() + ']';
-
-                        trySendMessageDirectly(node,
-                            new TcpDiscoveryCheckFailedMessage(locNodeId, sndMsg));
-                    }
-                    catch (IgniteSpiException e) {
-                        if (log.isDebugEnabled())
-                            log.debug("Failed to send marshaller check failed message to node " +
-                                "[node=" + node + ", err=" + e.getMessage() + ']');
+                                try {
+                                    String sndMsg = "Local node's marshaller differs from remote node's marshaller " +
+                                        "(to make sure all nodes in topology have identical marshaller, " +
+                                        "configure marshaller explicitly in configuration) " +
+                                        "[locMarshaller=" + rmtMarsh + ", rmtMarshaller=" + locMarsh +
+                                        ", locNodeAddrs=" + U.addressesAsString(node) + ", locPort=" + node.discoveryPort() +
+                                        ", rmtNodeAddr=" + U.addressesAsString(locNode) + ", locNodeId=" + node.id() +
+                                        ", rmtNodeId=" + locNode.id() + ']';
+
+                                    trySendMessageDirectly(node,
+                                        new TcpDiscoveryCheckFailedMessage(locNodeId, sndMsg));
+                                }
+                                catch (IgniteSpiException e) {
+                                    if (log.isDebugEnabled())
+                                        log.debug("Failed to send marshaller check failed message to node " +
+                                            "[node=" + node + ", err=" + e.getMessage() + ']');
 
-                        onException("Failed to send marshaller check failed message to node " +
-                            "[node=" + node + ", err=" + e.getMessage() + ']', e);
-                    }
+                                    onException("Failed to send marshaller check failed message to node " +
+                                        "[node=" + node + ", err=" + e.getMessage() + ']', e);
+                                }
+                            }
+                        }
+                    );
 
                     // Ignore join request.
                     return;
                 }
 
                 // If node have no value for this attribute then we treat it as true.
-                Boolean locMarshUseDfltSuid = locNode.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
+                final Boolean locMarshUseDfltSuid = locNode.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
                 boolean locMarshUseDfltSuidBool = locMarshUseDfltSuid == null ? true : locMarshUseDfltSuid;
 
-                Boolean rmtMarshUseDfltSuid = node.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
+                final Boolean rmtMarshUseDfltSuid = node.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
                 boolean rmtMarshUseDfltSuidBool = rmtMarshUseDfltSuid == null ? true : rmtMarshUseDfltSuid;
 
                 Boolean locLateAssign = locNode.attribute(ATTR_LATE_AFFINITY_ASSIGNMENT);
@@ -3203,14 +3224,16 @@ class ServerImpl extends TcpDiscoveryImpl {
                 boolean locLateAssignBool = locLateAssign != null ? locLateAssign : false;
 
                 if (locMarshUseDfltSuidBool != rmtMarshUseDfltSuidBool) {
-                    String errMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
-                        " property value differs from remote node's value " +
-                        "(to make sure all nodes in topology have identical marshaller settings, " +
-                        "configure system property explicitly) " +
-                        "[locMarshUseDfltSuid=" + locMarshUseDfltSuid + ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
-                        ", locNodeAddrs=" + U.addressesAsString(locNode) +
-                        ", rmtNodeAddrs=" + U.addressesAsString(node) +
-                        ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
+                    utilityPool.submit(new Runnable() {
+                        @Override public void run() {
+                            String errMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
+                                " property value differs from remote node's value " +
+                                "(to make sure all nodes in topology have identical marshaller settings, " +
+                                "configure system property explicitly) " +
+                                "[locMarshUseDfltSuid=" + locMarshUseDfltSuid + ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid +
+                                ", locNodeAddrs=" + U.addressesAsString(locNode) +
+                                ", rmtNodeAddrs=" + U.addressesAsString(node) +
+                                ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
 
                     String sndMsg = "Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID +
                         " property value differs from remote node's value " +
@@ -3230,19 +3253,22 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                 // Validate compact footer flags.
                 Boolean locMarshCompactFooter = locNode.attribute(ATTR_MARSHALLER_COMPACT_FOOTER);
-                boolean locMarshCompactFooterBool = locMarshCompactFooter != null ? locMarshCompactFooter : false;
+                final boolean locMarshCompactFooterBool = locMarshCompactFooter != null ? locMarshCompactFooter : false;
 
                 Boolean rmtMarshCompactFooter = node.attribute(ATTR_MARSHALLER_COMPACT_FOOTER);
-                boolean rmtMarshCompactFooterBool = rmtMarshCompactFooter != null ? rmtMarshCompactFooter : false;
+                final boolean rmtMarshCompactFooterBool = rmtMarshCompactFooter != null ? rmtMarshCompactFooter : false;
 
                 if (locMarshCompactFooterBool != rmtMarshCompactFooterBool) {
-                    String errMsg = "Local node's binary marshaller \"compactFooter\" property differs from " +
-                        "the same property on remote node (make sure all nodes in topology have the same value " +
-                        "of \"compactFooter\" property) [locMarshallerCompactFooter=" + locMarshCompactFooterBool +
-                        ", rmtMarshallerCompactFooter=" + rmtMarshCompactFooterBool +
-                        ", locNodeAddrs=" + U.addressesAsString(locNode) +
-                        ", rmtNodeAddrs=" + U.addressesAsString(node) +
-                        ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
+                    utilityPool.submit(
+                        new Runnable() {
+                            @Override public void run() {
+                                String errMsg = "Local node's binary marshaller \"compactFooter\" property differs from " +
+                                    "the same property on remote node (make sure all nodes in topology have the same value " +
+                                    "of \"compactFooter\" property) [locMarshallerCompactFooter=" + locMarshCompactFooterBool +
+                                    ", rmtMarshallerCompactFooter=" + rmtMarshCompactFooterBool +
+                                    ", locNodeAddrs=" + U.addressesAsString(locNode) +
+                                    ", rmtNodeAddrs=" + U.addressesAsString(node) +
+                                    ", locNodeId=" + locNode.id() + ", rmtNodeId=" + msg.creatorNodeId() + ']';
 
                     String sndMsg = "Local node's binary marshaller \"compactFooter\" property differs from " +
                         "the same property on remote node (make sure all nodes in topology have the same value " +
@@ -5871,6 +5897,16 @@ class ServerImpl extends TcpDiscoveryImpl {
          * @param msg Message to add.
          */
         void addMessage(TcpDiscoveryAbstractMessage msg) {
+            if ((msg instanceof TcpDiscoveryStatusCheckMessage ||
+                msg instanceof TcpDiscoveryJoinRequestMessage ||
+                msg instanceof TcpDiscoveryCustomEventMessage) &&
+                queue.contains(msg)) {
+                if (log.isDebugEnabled())
+                    log.debug("Ignoring duplicate message: " + msg);
+
+                return;
+            }
+
             if (msg.highPriority())
                 queue.addFirst(msg);
             else

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
index d1fbecf..307aefe 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/internal/TcpDiscoveryNode.java
@@ -645,4 +645,4 @@ public class TcpDiscoveryNode extends GridMetadataAwareAdapter implements Cluste
     @Override public String toString() {
         return S.toString(TcpDiscoveryNode.class, this, "isClient", isClient());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java
index 9cb47af..24f2a5a 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryAbstractMessage.java
@@ -274,7 +274,7 @@ public abstract class TcpDiscoveryAbstractMessage implements Serializable {
     }
 
     /** {@inheritDoc} */
-    @Override public final boolean equals(Object obj) {
+    @Override public boolean equals(Object obj) {
         if (this == obj)
             return true;
         else if (obj instanceof TcpDiscoveryAbstractMessage)
@@ -292,4 +292,4 @@ public abstract class TcpDiscoveryAbstractMessage implements Serializable {
     @Override public String toString() {
         return S.toString(TcpDiscoveryAbstractMessage.class, this, "isClient", getFlag(CLIENT_FLAG_POS));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
index 2c759a1..c0e39d3 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
@@ -18,8 +18,8 @@
 package org.apache.ignite.spi.discovery.tcp.messages;
 
 import java.util.UUID;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
 import org.jetbrains.annotations.NotNull;
@@ -86,7 +86,16 @@ public class TcpDiscoveryCustomEventMessage extends TcpDiscoveryAbstractMessage
     }
 
     /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        return super.equals(obj) &&
+            obj instanceof TcpDiscoveryCustomEventMessage &&
+            F.eq(
+                ((TcpDiscoveryCustomEventMessage)obj).verifierNodeId(),
+                verifierNodeId());
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(TcpDiscoveryCustomEventMessage.class, this, "super", super.toString());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryJoinRequestMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryJoinRequestMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryJoinRequestMessage.java
index 2586a8b..22ffae8 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryJoinRequestMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryJoinRequestMessage.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.spi.discovery.tcp.messages;
 
 import java.util.Map;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 
@@ -79,7 +80,20 @@ public class TcpDiscoveryJoinRequestMessage extends TcpDiscoveryAbstractMessage
     }
 
     /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        // NOTE!
+        // Do not call super. As IDs will differ, but we can ignore this.
+
+        if (!(obj instanceof TcpDiscoveryJoinRequestMessage))
+            return false;
+
+        TcpDiscoveryJoinRequestMessage other = (TcpDiscoveryJoinRequestMessage)obj;
+
+        return F.eqNodes(other.node, node);
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(TcpDiscoveryJoinRequestMessage.class, this, "super", super.toString());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1e725899/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryStatusCheckMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryStatusCheckMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryStatusCheckMessage.java
index 70b0080..fdbeb75 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryStatusCheckMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryStatusCheckMessage.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.spi.discovery.tcp.messages;
 
 import java.util.UUID;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
 
@@ -109,7 +110,22 @@ public class TcpDiscoveryStatusCheckMessage extends TcpDiscoveryAbstractMessage
     }
 
     /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        // NOTE!
+        // Do not call super. As IDs will differ, but we can ignore this.
+
+        if (!(obj instanceof TcpDiscoveryStatusCheckMessage))
+            return false;
+
+        TcpDiscoveryStatusCheckMessage other = (TcpDiscoveryStatusCheckMessage)obj;
+
+        return F.eqNodes(other.creatorNode, creatorNode) &&
+            F.eq(other.failedNodeId, failedNodeId) &&
+            status == other.status;
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(TcpDiscoveryStatusCheckMessage.class, this, "super", super.toString());
     }
-}
\ No newline at end of file
+}


[49/50] [abbrv] ignite git commit: IGNITE-2788: Moved handlers.

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java
deleted file mode 100644
index 21f3de2..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler;
-
-import java.nio.ByteBuffer;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisTypeException;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.future.GridFinishedFuture;
-import org.apache.ignite.internal.util.typedef.CX1;
-
-/**
- * Redis command handler done via REST.
- */
-public abstract class GridRedisThruRestCommandHandler implements GridRedisCommandHandler {
-    /** REST protocol handler. */
-    protected final GridRestProtocolHandler hnd;
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Context.
-     * @param hnd REST protocol handler.
-     */
-    public GridRedisThruRestCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        this.hnd = hnd;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(final GridRedisMessage msg) {
-        assert msg != null;
-
-        try {
-            return hnd.handleAsync(asRestRequest(msg))
-                .chain(new CX1<IgniteInternalFuture<GridRestResponse>, GridRedisMessage>() {
-                    @Override
-                    public GridRedisMessage applyx(IgniteInternalFuture<GridRestResponse> f)
-                        throws IgniteCheckedException {
-                        GridRestResponse restRes = f.get();
-
-                        if (restRes.getSuccessStatus() == GridRestResponse.STATUS_SUCCESS)
-                            msg.setResponse(makeResponse(restRes, msg.auxMKeys()));
-                        else
-                            msg.setResponse(GridRedisProtocolParser.toGenericError("Operation error!"));
-
-                        return msg;
-                    }
-                });
-        }
-        catch (IgniteCheckedException e) {
-            if (e instanceof GridRedisTypeException)
-                msg.setResponse(GridRedisProtocolParser.toTypeError(e.getMessage()));
-            else
-                msg.setResponse(GridRedisProtocolParser.toGenericError(e.getMessage()));
-
-            return new GridFinishedFuture<>(msg);
-        }
-    }
-
-    /**
-     * Converts {@link GridRedisMessage} to {@link GridRestRequest}.
-     *
-     * @param msg {@link GridRedisMessage}
-     * @return {@link GridRestRequest}
-     * @throws IgniteCheckedException If fails.
-     */
-    public abstract GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException;
-
-    /**
-     * Prepares a response according to the request.
-     *
-     * @param resp REST response.
-     * @param params Auxiliary parameters.
-     * @return
-     */
-    public abstract ByteBuffer makeResponse(GridRestResponse resp, List<String> params);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java
deleted file mode 100644
index 6c7c688..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception;
-
-import org.apache.ignite.IgniteCheckedException;
-
-/**
- * Generic Redis protocol exception.
- */
-public class GridRedisGenericException extends IgniteCheckedException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * Creates a generic exception with given error message.
-     *
-     * @param msg Error message.
-     */
-    public GridRedisGenericException(String msg) {
-        super(msg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java
deleted file mode 100644
index 99cb577..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception;
-
-import org.apache.ignite.IgniteCheckedException;
-
-/**
- * Exception on operation on the wrong data type.
- */
-public class GridRedisTypeException extends IgniteCheckedException {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * Creates a type exception with given error message.
-     *
-     * @param msg Error message.
-     */
-    public GridRedisTypeException(String msg) {
-        super(msg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java
deleted file mode 100644
index 6644082..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_ALL;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DEL;
-
-/**
- * Redis DEL command handler.
- */
-public class GridRedisDelCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        DEL
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisDelCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 2)
-            throw new GridRedisGenericException("Wrong number of arguments");
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.command(CACHE_REMOVE_ALL);
-
-        List<String> keys = msg.auxMKeys();
-        Map<Object, Object> mget = U.newHashMap(keys.size());
-        Iterator<String> mgetIt = keys.iterator();
-
-        while (mgetIt.hasNext())
-            mget.put(mgetIt.next(), null);
-
-        restReq.values(mget);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        // It has to respond with the number of removed entries...
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
-            : GridRedisProtocolParser.toInteger(String.valueOf(params.size())));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java
deleted file mode 100644
index 4882603..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.EXISTS;
-
-/**
- * Redis EXISTS command handler.
- */
-public class GridRedisExistsCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        EXISTS
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisExistsCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 2)
-            throw new GridRedisGenericException("Wrong number of arguments");
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.command(CACHE_GET_ALL);
-
-        List<String> keys = msg.auxMKeys();
-        Map<Object, Object> mget = U.newHashMap(keys.size());
-        Iterator<String> mgetIt = keys.iterator();
-
-        while (mgetIt.hasNext())
-            mget.put(mgetIt.next(), null);
-
-        restReq.values(mget);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
-            : GridRedisProtocolParser.toInteger(((Map<Object, Object>)restRes.getResponse()).size()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java
deleted file mode 100644
index b4de44c..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_SIZE;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DBSIZE;
-
-/**
- * Redis DBSIZE command handler.
- */
-public class GridRedisDbSizeCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        DBSIZE
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisDbSizeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.command(CACHE_SIZE);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
-            : GridRedisProtocolParser.toInteger(String.valueOf(restRes.getResponse())));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
deleted file mode 100644
index 0c4a744..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_APPEND;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.APPEND;
-
-/**
- * Redis APPEND command handler.
- */
-public class GridRedisAppendCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        APPEND
-    );
-
-    /** Position of the value. */
-    private static final int VAL_POS = 2;
-
-    /** {@inheritDoc} */
-    public GridRedisAppendCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 3)
-            throw new GridRedisGenericException("Wrong syntax!");
-
-        GridRestCacheRequest appendReq = new GridRestCacheRequest();
-        GridRestCacheRequest getReq = new GridRestCacheRequest();
-
-        String val = msg.aux(VAL_POS);
-
-        appendReq.clientId(msg.clientId());
-        appendReq.key(msg.key());
-        appendReq.value(val);
-        appendReq.command(CACHE_APPEND);
-
-        if ((boolean)hnd.handle(appendReq).getResponse() == false) {
-            // append on on-existing key in REST returns false.
-            GridRestCacheRequest setReq = new GridRestCacheRequest();
-
-            setReq.clientId(msg.clientId());
-            setReq.key(msg.key());
-            setReq.value(val);
-            setReq.command(CACHE_PUT);
-
-            hnd.handle(setReq);
-        }
-
-        getReq.clientId(msg.clientId());
-        getReq.key(msg.key());
-        getReq.command(CACHE_GET);
-
-        return getReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        if (restRes.getResponse() == null)
-            return GridRedisProtocolParser.nil();
-        else {
-            int resLen = ((String)restRes.getResponse()).length();
-            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
deleted file mode 100644
index 52779b3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GET;
-
-/**
- * Redis GET command handler.
- */
-public class GridRedisGetCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        GET
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-
-        restReq.command(CACHE_GET);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
deleted file mode 100644
index 6406f23..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETRANGE;
-
-/**
- * Redis SETRANGE command handler.
- */
-public class GridRedisGetRangeCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        GETRANGE
-    );
-
-    /** Start offset position in Redis message parameters. */
-    private static final int START_OFFSET_POS = 1;
-
-    /** End offset position in Redis message parameters. */
-    private static final int END_OFFSET_POS = 2;
-
-    /** {@inheritDoc} */
-    public GridRedisGetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 4)
-            throw new GridRedisGenericException("Wrong number of arguments");
-
-        GridRestCacheRequest getReq = new GridRestCacheRequest();
-
-        getReq.clientId(msg.clientId());
-        getReq.key(msg.key());
-        getReq.command(CACHE_GET);
-
-        return getReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        if (restRes.getResponse() == null)
-            return GridRedisProtocolParser.toBulkString("");
-        else {
-            String res = String.valueOf(restRes.getResponse());
-            int startOffset;
-            int endOffset;
-
-            try {
-                startOffset = boundedStartOffset(Integer.parseInt(params.get(START_OFFSET_POS)), res.length());
-                endOffset = boundedEndOffset(Integer.parseInt(params.get(END_OFFSET_POS)), res.length());
-            }
-            catch (NumberFormatException e) {
-                return GridRedisProtocolParser.toGenericError("Offset is not an integer!");
-            }
-
-            return GridRedisProtocolParser.toBulkString(res.substring(startOffset, endOffset));
-        }
-    }
-
-    /**
-     * @param idx Index.
-     * @param size Bounds.
-     * @return Offset within the bounds.
-     */
-    private int boundedStartOffset(int idx, int size) {
-        if (idx >= 0)
-            return Math.min(idx, size);
-        else
-            return size + idx;
-    }
-
-    /**
-     * @param idx Index.
-     * @param size Bounds.
-     * @return Offset within the bounds.
-     */
-    private int boundedEndOffset(int idx, int size) {
-        if (idx >= 0)
-            return Math.min(idx + 1, size);
-        else
-            return size + idx + 1;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
deleted file mode 100644
index 7df2ac2..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_PUT;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETSET;
-
-/**
- * Redis GETSET command handler.
- */
-public class GridRedisGetSetCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        GETSET
-    );
-
-    /** Value position in Redis message. */
-    private static final int VAL_POS = 2;
-
-    /** {@inheritDoc} */
-    public GridRedisGetSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 3)
-            throw new GridRedisGenericException("Wrong syntax!");
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.value(msg.aux(VAL_POS));
-
-        restReq.command(CACHE_GET_AND_PUT);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
deleted file mode 100644
index c479832..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.math.BigDecimal;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.DataStructuresRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_DECREMENT;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_INCREMENT;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECR;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECRBY;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCR;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCRBY;
-
-/**
- * Redis INCR/DECR command handler.
- */
-public class GridRedisIncrDecrCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        INCR,
-        DECR,
-        INCRBY,
-        DECRBY
-    );
-
-    /** Delta position in the message. */
-    private static final int DELTA_POS = 2;
-
-    /** {@inheritDoc} */
-    public GridRedisIncrDecrCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        DataStructuresRequest restReq = new DataStructuresRequest();
-
-        GridRestCacheRequest getReq = new GridRestCacheRequest();
-
-        getReq.clientId(msg.clientId());
-        getReq.key(msg.key());
-        getReq.command(CACHE_GET);
-
-        GridRestResponse getResp = hnd.handle(getReq);
-
-        if (getResp.getResponse() == null) {
-            restReq.initial(0L);
-        }
-        else {
-            if (getResp.getResponse() instanceof Long && (Long)getResp.getResponse() <= Long.MAX_VALUE)
-                restReq.initial((Long)getResp.getResponse());
-            else
-                throw new GridRedisGenericException("An initial value must be numeric and in range!");
-        }
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.delta(1L);
-
-        if (msg.messageSize() > 2) {
-            try {
-                restReq.delta(Long.valueOf(msg.aux(DELTA_POS)));
-            }
-            catch (NumberFormatException e) {
-                throw new GridRedisGenericException("An increment value must be numeric and in range!");
-            }
-        }
-
-        switch (msg.command()) {
-            case INCR:
-            case INCRBY:
-                restReq.command(ATOMIC_INCREMENT);
-                break;
-
-            case DECR:
-            case DECRBY:
-                restReq.command(ATOMIC_DECREMENT);
-                break;
-        }
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        if (restRes.getResponse() == null)
-            return GridRedisProtocolParser.toGenericError("Failed to increment!");
-
-        if (restRes.getResponse() instanceof Long && (Long)restRes.getResponse() <= Long.MAX_VALUE)
-            return GridRedisProtocolParser.toInteger(new BigDecimal((Long)restRes.getResponse()).toString());
-        else
-            return GridRedisProtocolParser.toTypeError("Value is non-numeric or out of range!");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
deleted file mode 100644
index 846b997..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MGET;
-
-/**
- * Redis MGET command handler.
- */
-public class GridRedisMGetCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        MGET
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisMGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 2)
-            throw new GridRedisGenericException("Wrong number of arguments");
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-        restReq.command(CACHE_GET_ALL);
-
-        List<String> keys = msg.auxMKeys();
-        Map<Object, Object> mget = U.newHashMap(keys.size());
-        Iterator<String> mgetIt = keys.iterator();
-
-        while (mgetIt.hasNext())
-            mget.put(mgetIt.next(), null);
-
-        restReq.values(mget);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.toArray((Map<Object, Object>)restRes.getResponse()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
deleted file mode 100644
index cbb229a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MSET;
-
-/**
- * Redis MSET command handler.
- */
-public class GridRedisMSetCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        MSET
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisMSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-
-        restReq.command(CACHE_PUT_ALL);
-
-        List<String> els = msg.auxMKeys();
-        Map<Object, Object> mset = U.newHashMap(els.size() / 2);
-        Iterator<String> msetIt = els.iterator();
-
-        while (msetIt.hasNext())
-            mset.put(msetIt.next(), msetIt.hasNext() ? msetIt.next() : null);
-
-        restReq.values(mset);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return GridRedisProtocolParser.OkString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
deleted file mode 100644
index 2c29766..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SET;
-
-/**
- * Redis SET command handler.
- * <p>
- * No key expiration is currently supported.
- */
-public class GridRedisSetCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        SET
-    );
-
-    /** Value position in Redis message. */
-    private static final int VAL_POS = 2;
-
-    /** {@inheritDoc} */
-    public GridRedisSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-
-        restReq.command(CACHE_PUT);
-
-        if (msg.messageSize() < 3)
-            throw new IgniteCheckedException("Invalid request!");
-
-        restReq.value(msg.aux(VAL_POS));
-
-        if (msg.messageSize() >= 4) {
-            // handle options.
-        }
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.OkString());
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
deleted file mode 100644
index f559db3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SETRANGE;
-
-/**
- * Redis SETRANGE command handler.
- */
-public class GridRedisSetRangeCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        SETRANGE
-    );
-
-    /** Offset position in Redis message among parameters. */
-    private static final int OFFSET_POS = 2;
-
-    /** Value position in Redis message. */
-    private static final int VAL_POS = 3;
-
-    /** {@inheritDoc} */
-    public GridRedisSetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        if (msg.messageSize() < 4)
-            throw new GridRedisGenericException("Wrong number of arguments");
-
-        int offset;
-        try {
-            offset = Integer.parseInt(msg.aux(OFFSET_POS));
-        }
-        catch (NumberFormatException e) {
-            throw new GridRedisGenericException("Offset is not an integer!");
-        }
-
-        String val = String.valueOf(msg.aux(VAL_POS));
-
-        GridRestCacheRequest getReq = new GridRestCacheRequest();
-
-        getReq.clientId(msg.clientId());
-        getReq.key(msg.key());
-        getReq.command(CACHE_GET);
-
-        if (val.length() == 0)
-            return getReq;
-
-        Object resp = hnd.handle(getReq).getResponse();
-
-        int totalLen = offset + val.length();
-        if (offset < 0 || totalLen > 536870911)
-            throw new GridRedisGenericException("Offset is out of range!");
-
-        GridRestCacheRequest putReq = new GridRestCacheRequest();
-
-        putReq.clientId(msg.clientId());
-        putReq.key(msg.key());
-        putReq.command(CACHE_PUT);
-
-        if (resp == null) {
-            byte[] dst = new byte[totalLen];
-            System.arraycopy(val.getBytes(), 0, dst, offset, val.length());
-
-            putReq.value(new String(dst));
-        }
-        else {
-            String cacheVal = String.valueOf(resp);
-
-            cacheVal = cacheVal.substring(0, offset) + val;
-
-            putReq.value(cacheVal);
-        }
-
-        hnd.handle(putReq);
-
-        return getReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        if (restRes.getResponse() == null)
-            return GridRedisProtocolParser.toInteger("0");
-        else {
-            int resLen = ((String)restRes.getResponse()).length();
-            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/3ade1cb1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
deleted file mode 100644
index 5d7632f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
-
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.GridRestResponse;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler;
-import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
-import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.STRLEN;
-
-/**
- * Redis STRLEN command handler.
- */
-public class GridRedisStrlenCommandHandler extends GridRedisThruRestCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        STRLEN
-    );
-
-    /** {@inheritDoc} */
-    public GridRedisStrlenCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
-        super(ctx, hnd);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
-        assert msg != null;
-
-        GridRestCacheRequest restReq = new GridRestCacheRequest();
-
-        restReq.clientId(msg.clientId());
-        restReq.key(msg.key());
-
-        restReq.command(CACHE_GET);
-
-        return restReq;
-    }
-
-    /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
-        if (restRes.getResponse() == null)
-            return GridRedisProtocolParser.toInteger("0");
-        else {
-            int len = String.valueOf(restRes.getResponse()).length();
-            return GridRedisProtocolParser.toInteger(String.valueOf(len));
-        }
-    }
-}


[24/50] [abbrv] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
deleted file mode 100644
index 6d18b7d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.cache;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.cache.Cache;
-import org.apache.ignite.internal.util.GridSerializableSet;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.lang.IgnitePredicate;
-
-/**
- * Key set based on provided entries with all remove operations backed
- * by underlying cache.
- */
-public class GridCacheKeySet<K, V> extends GridSerializableSet<K> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Cache context. */
-    private final GridCacheContext<K, V> ctx;
-
-    /** Filter. */
-    private final IgnitePredicate<Cache.Entry<K, V>>[] filter;
-
-    /** Base map. */
-    private final Map<K, Cache.Entry<K, V>> map;
-
-    /**
-     * @param ctx Cache context.
-     * @param c Entry collection.
-     * @param filter Filter.
-     */
-    public GridCacheKeySet(GridCacheContext<K, V> ctx, Collection<? extends Cache.Entry<K, V>> c,
-        IgnitePredicate<Cache.Entry<K, V>>[] filter) {
-        map = new HashMap<>();
-
-        assert ctx != null;
-
-        this.ctx = ctx;
-        this.filter = filter == null ? CU.<K, V>empty() : filter;
-
-        for (Cache.Entry<K, V> e : c) {
-            if (e != null)
-                map.put(e.getKey(), e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<K> iterator() {
-        return new GridCacheIterator<>(ctx, map.values(), F.<K, V>cacheEntry2Key(), filter);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"SuspiciousMethodCalls"})
-    @Override public boolean remove(Object o) {
-        Cache.Entry<K, V> e = map.get(o);
-
-        if (e == null || !F.isAll(e, filter))
-            return false;
-
-        map.remove(o);
-
-        ctx.grid().cache(ctx.name()).remove(e.getKey());
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return F.size(map.values(), filter);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"SuspiciousMethodCalls"})
-    @Override public boolean contains(Object o) {
-        Cache.Entry<K, V> e = map.get(o);
-
-        return e != null && F.isAll(e, filter);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 75d96d8..c9ff138 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -3192,7 +3192,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
             if (rmv) {
                 onMarkedObsolete();
 
-                cctx.cache().map().removeEntry(this);
+                cctx.cache().removeEntry(this);
             }
         }
     }
@@ -4229,7 +4229,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
             if (rmv) {
                 onMarkedObsolete();
 
-                cctx.cache().map().removeEntry(this);
+                cctx.cache().removeEntry(this);
             }
         }
 
@@ -4287,18 +4287,32 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
 
             flags |= IS_DELETED_MASK;
 
-            cctx.decrementPublicSize(this);
+            decrementMapPublicSize();
         }
         else {
             assert deletedUnlocked() : this;
 
             flags &= ~IS_DELETED_MASK;
 
-            cctx.incrementPublicSize(this);
+            incrementMapPublicSize();
         }
     }
 
     /**
+     *  Increments public size of map.
+     */
+    protected void incrementMapPublicSize() {
+        cctx.incrementPublicSize(this);
+    }
+
+    /**
+     * Decrements public size of map.
+     */
+    protected void decrementMapPublicSize() {
+        cctx.decrementPublicSize(this);
+    }
+
+    /**
      * @return MVCC.
      */
     @Nullable protected GridCacheMvcc mvccExtras() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 5214078..3d5052b 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -79,7 +79,6 @@ import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProce
 import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridNoStorageCacheMap;
 import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache;
 import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index 84c5d73..a58c209 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -891,7 +891,7 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
     }
 
     /** {@inheritDoc} */
-    @Override public Collection<V> values() {
+    @Override public Iterable<V> values() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 98b1b59..e7010f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -51,7 +51,6 @@ import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.cache.store.CacheStoreSessionListener;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.FileSystemConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.GridKernalContext;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java
new file mode 100644
index 0000000..2532882
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridNoStorageCacheMap.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Collections;
+import java.util.Set;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtOffHeapCacheEntry;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Empty cache map that will never store any entries.
+ */
+public class GridNoStorageCacheMap implements GridCacheConcurrentMap {
+    /** Context. */
+    private final GridCacheContext ctx;
+
+    /**
+     * @param ctx Cache context.
+     */
+    public GridNoStorageCacheMap(GridCacheContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(AffinityTopologyVersion topVer, KeyCacheObject key,
+        @Nullable CacheObject val, boolean create, boolean touch) {
+        if (create)
+            return ctx.useOffheapEntry() ?
+                new GridDhtOffHeapCacheEntry(ctx, topVer, key, key.hashCode(), val) :
+                new GridDhtCacheEntry(ctx, topVer, key, key.hashCode(), val);
+        else
+            return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removeEntry(GridCacheEntryEx entry) {
+        throw new AssertionError();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int publicSize() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void incrementPublicSize(GridCacheEntryEx e) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void decrementPublicSize(GridCacheEntryEx e) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry randomEntry() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<KeyCacheObject> keySet(CacheEntryPredicate... filter) {
+        return Collections.emptySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> entries(CacheEntryPredicate... filter) {
+        return Collections.emptySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> allEntries(CacheEntryPredicate... filter) {
+        return Collections.emptySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<GridCacheMapEntry> entrySet(CacheEntryPredicate... filter) {
+        return Collections.emptySet();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
index 5294f6a..3dc3471 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
@@ -911,7 +911,7 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
      *
      * @return Collection of cached values.
      */
-    public Collection<V> values();
+    public Iterable<V> values();
 
     /**
      * Gets set of all entries cached on this node. You can remove

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
index c214ce3..ffb846c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
@@ -30,4 +30,15 @@ public interface KeyCacheObject extends CacheObject {
      * @return {@code True} if internal cache key.
      */
     public boolean internal();
+
+    /**
+     * @return Partition ID for this key or -1 if it is unknown.
+     */
+    public int partition();
+
+    /**
+     * Sets partition ID for this key.
+     * @param part Partition ID.
+     */
+    public void partition(int part);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index e557c28..35e681c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridDirectTransient;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -27,6 +28,10 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** */
+    @GridDirectTransient
+    private int part = -1;
+
     /**
      *
      */
@@ -39,10 +44,30 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
      * @param valBytes Value bytes.
      */
     public KeyCacheObjectImpl(Object val, byte[] valBytes) {
+        this(val, valBytes, -1);
+    }
+
+    /**
+     * @param val Value.
+     * @param valBytes Value bytes.
+     * @param part Partition.
+     */
+    public KeyCacheObjectImpl(Object val, byte[] valBytes, int part) {
         assert val != null;
 
         this.val = val;
         this.valBytes = valBytes;
+        this.part = part;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int partition() {
+        return part;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void partition(int part) {
+        this.part = part;
     }
 
     /** {@inheritDoc} */
@@ -96,6 +121,11 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
     @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
             valBytes = ctx.kernalContext().cacheObjects().marshal(ctx, val);
@@ -119,4 +149,4 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
 
         return val.equals(other.val);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 18e2d09..c043bc7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -773,20 +773,36 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
+        return toCacheKeyObject(ctx, obj, userObj, -1);
+    }
+
+    /** {@inheritDoc} */
+    @Override public KeyCacheObject toCacheKeyObject(
+        CacheObjectContext ctx,
+        Object obj,
+        boolean userObj,
+        int partition
+    ) {
         if (!((CacheObjectBinaryContext)ctx).binaryEnabled())
-            return super.toCacheKeyObject(ctx, obj, userObj);
+            return super.toCacheKeyObject(ctx, obj, userObj, partition);
+
+        if (obj instanceof KeyCacheObject) {
+            ((KeyCacheObject)obj).partition(partition);
 
-        if (obj instanceof KeyCacheObject)
             return (KeyCacheObject)obj;
+        }
 
         if (((CacheObjectBinaryContext)ctx).binaryEnabled()) {
             obj = toBinary(obj);
 
-            if (obj instanceof KeyCacheObject)
+            if (obj instanceof KeyCacheObject) {
+                ((KeyCacheObject)obj).partition(partition);
+
                 return (KeyCacheObject)obj;
+            }
         }
 
-        return toCacheKeyObject0(obj, userObj);
+        return toCacheKeyObject0(obj, userObj, partition);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
index 6e97ec5..03f6474 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
@@ -405,7 +405,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
 
                         try {
                             if (!locPart.isEmpty()) {
-                                for (GridDhtCacheEntry o : locPart.entries()) {
+                                for (GridCacheEntryEx o : locPart.allEntries()) {
                                     if (!o.obsoleteOrDeleted())
                                         dataLdr.removeDataInternal(o.key());
                                 }
@@ -428,7 +428,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
                 if (near != null) {
                     GridCacheVersion obsoleteVer = ctx.versions().next();
 
-                    for (GridCacheEntryEx e : near.map().allEntries0()) {
+                    for (GridCacheEntryEx e : near.allEntries()) {
                         if (!e.valid(topVer) && e.markObsolete(obsoleteVer))
                             near.removeEntry(e);
                     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
index 5d07b6f..20cd52c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
@@ -78,6 +78,10 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
     @GridDirectCollection(KeyCacheObject.class)
     private List<KeyCacheObject> keys;
 
+    /** Partition IDs of keys to lock. */
+    @GridDirectCollection(int.class)
+    protected List<Integer> partIds;
+
     /** Array indicating whether value should be returned for a key. */
     @GridToStringInclude
     private boolean[] retVals;
@@ -232,7 +236,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
      *
      * @param skipStore Skip store flag.
      */
-    private void skipStore(boolean skipStore){
+    private void skipStore(boolean skipStore) {
         flags = skipStore ? (byte)(flags | SKIP_STORE_FLAG_MASK) : (byte)(flags & ~SKIP_STORE_FLAG_MASK);
     }
 
@@ -284,11 +288,15 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         boolean retVal,
         GridCacheContext ctx
     ) throws IgniteCheckedException {
-        if (keys == null)
+        if (keys == null) {
             keys = new ArrayList<>(keysCount());
+            partIds = new ArrayList<>(keysCount());
+        }
 
         keys.add(key);
 
+        partIds.add(key.partition());
+
         retVals[idx] = retVal;
 
         idx++;
@@ -325,6 +333,13 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
         GridCacheContext cctx = ctx.cacheContext(cacheId);
 
         finishUnmarshalCacheObjects(keys, cctx, ldr);
+
+        if (partIds != null && !partIds.isEmpty()) {
+            assert partIds.size() == keys.size();
+
+            for (int i = 0; i < keys.size(); i++)
+                keys.get(i).partition(partIds.get(i));
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
index 2cf7276..2bb6bf3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
@@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java
index 213a0ff..7854ace 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedUnlockRequest.java
@@ -44,6 +44,10 @@ public class GridDistributedUnlockRequest extends GridDistributedBaseMessage {
     @GridDirectCollection(KeyCacheObject.class)
     private List<KeyCacheObject> keys;
 
+    /** Partition IDs. */
+    @GridDirectCollection(int.class)
+    protected List<Integer> partIds;
+
     /**
      * Empty constructor required by {@link Externalizable}.
      */
@@ -75,10 +79,13 @@ public class GridDistributedUnlockRequest extends GridDistributedBaseMessage {
      * @throws IgniteCheckedException If failed.
      */
     public void addKey(KeyCacheObject key, GridCacheContext ctx) throws IgniteCheckedException {
-        if (keys == null)
+        if (keys == null) {
             keys = new ArrayList<>(keysCount());
+            partIds = new ArrayList<>(keysCount());
+        }
 
         keys.add(key);
+        partIds.add(key.partition());
     }
 
     /** {@inheritDoc}
@@ -94,6 +101,13 @@ public class GridDistributedUnlockRequest extends GridDistributedBaseMessage {
         super.finishUnmarshal(ctx, ldr);
 
         finishUnmarshalCacheObjects(keys, ctx.cacheContext(cacheId), ldr);
+
+        if (partIds != null && !partIds.isEmpty()) {
+            assert partIds.size() == keys.size();
+
+            for (int i = 0; i < keys.size(); i++)
+                keys.get(i).partition(partIds.get(i));
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java
new file mode 100644
index 0000000..ff95de9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedConcurrentMap.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ignite.internal.processors.cache.distributed.dht;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.util.PartitionedReadOnlySet;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * An implementation of GridCacheConcurrentMap that will delegate all method calls to corresponding local partition.
+ */
+public class GridCachePartitionedConcurrentMap implements GridCacheConcurrentMap {
+    /** Context. */
+    private final GridCacheContext ctx;
+
+    /**
+     * Constructor.
+     * @param ctx Context.
+     */
+    public GridCachePartitionedConcurrentMap(GridCacheContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /**
+     * @param key Key.
+     * @param topVer Topology version.
+     * @param create Create flag.
+     * @return Local partition.
+     */
+    @Nullable private GridDhtLocalPartition localPartition(
+        KeyCacheObject key,
+        AffinityTopologyVersion topVer,
+        boolean create
+    ) {
+        int p = key.partition();
+
+        if (p == -1)
+            p = ctx.affinity().partition(key);
+
+        return ctx.topology().localPartition(p, topVer, create);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry getEntry(KeyCacheObject key) {
+        GridDhtLocalPartition part = localPartition(key, AffinityTopologyVersion.NONE, false);
+
+        if (part == null)
+            return null;
+
+        return part.getEntry(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(AffinityTopologyVersion topVer, KeyCacheObject key,
+        @Nullable CacheObject val, boolean create, boolean touch) {
+        GridDhtLocalPartition part = localPartition(key, topVer, create);
+
+        if (part == null)
+            return null;
+
+        return part.putEntryIfObsoleteOrAbsent(topVer, key, val, create, touch);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        int size = 0;
+
+        for (GridDhtLocalPartition part : ctx.topology().localPartitions())
+            size += part.size();
+
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int publicSize() {
+        int size = 0;
+
+        for (GridDhtLocalPartition part : ctx.topology().localPartitions())
+            size += part.publicSize();
+
+        return size;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void incrementPublicSize(GridCacheEntryEx e) {
+        localPartition(e.key(), AffinityTopologyVersion.NONE, true).incrementPublicSize(e);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void decrementPublicSize(GridCacheEntryEx e) {
+        localPartition(e.key(), AffinityTopologyVersion.NONE, true).decrementPublicSize(e);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removeEntry(GridCacheEntryEx entry) {
+        GridDhtLocalPartition part = localPartition(entry.key(), AffinityTopologyVersion.NONE, false);
+
+        if (part == null)
+            return false;
+
+        return part.removeEntry(entry);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridCacheMapEntry randomEntry() {
+        return entries().iterator().next();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<KeyCacheObject> keySet(CacheEntryPredicate... filter) {
+        Collection<Set<KeyCacheObject>> sets = new ArrayList<>();
+
+        for (GridDhtLocalPartition partition : ctx.topology().localPartitions())
+            sets.add(partition.keySet(filter));
+
+        return new PartitionedReadOnlySet<>(sets);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> entries(final CacheEntryPredicate... filter) {
+        return new Iterable<GridCacheMapEntry>() {
+            @Override public Iterator<GridCacheMapEntry> iterator() {
+                List<Iterator<GridCacheMapEntry>> iterators = new ArrayList<>();
+
+                for (GridDhtLocalPartition partition : ctx.topology().localPartitions())
+                    iterators.add(partition.entries(filter).iterator());
+
+                return F.flatIterators(iterators);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> allEntries(final CacheEntryPredicate... filter) {
+        return new Iterable<GridCacheMapEntry>() {
+            @Override public Iterator<GridCacheMapEntry> iterator() {
+                List<Iterator<GridCacheMapEntry>> iterators = new ArrayList<>();
+
+                for (GridDhtLocalPartition partition : ctx.topology().localPartitions())
+                    iterators.add(partition.allEntries(filter).iterator());
+
+                return F.flatIterators(iterators);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<GridCacheMapEntry> entrySet(CacheEntryPredicate... filter) {
+        Collection<Set<GridCacheMapEntry>> sets = new ArrayList<>();
+
+        for (GridDhtLocalPartition partition : ctx.topology().localPartitions())
+            sets.add(partition.entrySet(filter));
+
+        return new PartitionedReadOnlySet<>(sets);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCachePartitionedConcurrentMap.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index 3761d77..4635cad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -357,13 +357,6 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
-    @Override public GridDhtLocalPartition onAdded(AffinityTopologyVersion topVer, GridDhtCacheEntry e) {
-        assert false : "Entry should not be added to client topology: " + e;
-
-        return null;
-    }
-
-    /** {@inheritDoc} */
     @Override public void onRemoved(GridDhtCacheEntry e) {
         assert false : "Entry should not be removed from client topology: " + e;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
index faa980e..5ff674f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
@@ -158,9 +158,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
      * @param ctx Context.
      */
     protected GridDhtCacheAdapter(GridCacheContext<K, V> ctx) {
-        super(ctx, ctx.config().getStartSize());
-
-        top = new GridDhtPartitionTopologyImpl(ctx);
+        this(ctx, new GridCachePartitionedConcurrentMap(ctx));
     }
 
     /**
@@ -171,27 +169,13 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
      */
     protected GridDhtCacheAdapter(GridCacheContext<K, V> ctx, GridCacheConcurrentMap map) {
         super(ctx, map);
-
-        top = new GridDhtPartitionTopologyImpl(ctx);
     }
 
     /** {@inheritDoc} */
     @Override protected void init() {
-        map.setEntryFactory(new GridCacheMapEntryFactory() {
-            /** {@inheritDoc} */
-            @Override public GridCacheMapEntry create(
-                GridCacheContext ctx,
-                AffinityTopologyVersion topVer,
-                KeyCacheObject key,
-                int hash,
-                CacheObject val
-            ) {
-                if (ctx.useOffheapEntry())
-                    return new GridDhtOffHeapCacheEntry(ctx, topVer, key, hash, val);
+        super.init();
 
-                return new GridDhtCacheEntry(ctx, topVer, key, hash, val);
-            }
-        });
+        top = new GridDhtPartitionTopologyImpl(ctx, entryFactory());
     }
 
     /** {@inheritDoc} */
@@ -252,6 +236,26 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
     }
 
     /**
+     * @return Cache map entry factory.
+     */
+    protected GridCacheMapEntryFactory entryFactory() {
+        return new GridCacheMapEntryFactory() {
+            @Override public GridCacheMapEntry create(
+                GridCacheContext ctx,
+                AffinityTopologyVersion topVer,
+                KeyCacheObject key,
+                int hash,
+                CacheObject val
+            ) {
+                if (ctx.useOffheapEntry())
+                    return new GridDhtOffHeapCacheEntry(ctx, topVer, key, hash, val);
+
+                return new GridDhtCacheEntry(ctx, topVer, key, hash, val);
+            }
+        };
+    }
+
+    /**
      * @return Near cache.
      */
     public abstract GridNearCacheAdapter<K, V> near();
@@ -404,7 +408,8 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
      *
      * @throws GridDhtInvalidPartitionException If partition for the key is no longer valid.
      */
-    @Override public GridCacheEntryEx entryEx(KeyCacheObject key, AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException {
+    @Override public GridCacheEntryEx entryEx(KeyCacheObject key,
+        AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException {
         return super.entryEx(key, topVer);
     }
 
@@ -423,7 +428,8 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
      * @return DHT entry.
      * @throws GridDhtInvalidPartitionException If partition for the key is no longer valid.
      */
-    public GridDhtCacheEntry entryExx(KeyCacheObject key, AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException {
+    public GridDhtCacheEntry entryExx(KeyCacheObject key,
+        AffinityTopologyVersion topVer) throws GridDhtInvalidPartitionException {
         return (GridDhtCacheEntry)entryEx(key, topVer);
     }
 
@@ -640,7 +646,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
         @Nullable IgniteCacheExpiryPolicy expiry,
         boolean skipVals,
         boolean canRemap
-        ) {
+    ) {
         return getAllAsync0(keys,
             readThrough,
             /*don't check local tx. */false,
@@ -1084,7 +1090,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
             final GridDhtLocalPartition part = ctx.topology().localPartition(partId,
                 ctx.discovery().topologyVersionEx(), false);
 
-            Iterator<GridDhtCacheEntry> partIt = part == null ? null : part.entries().iterator();
+            Iterator<GridCacheMapEntry> partIt = part == null ? null : part.entries().iterator();
 
             return new PartitionEntryIterator(partIt);
         }
@@ -1152,7 +1158,8 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
     }
 
     /** {@inheritDoc} */
-    @Override public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, boolean near, boolean readers) {
+    @Override public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, boolean near,
+        boolean readers) {
         return ctx.affinityNode() ? super.splitClearLocally(srv, near, readers) :
             Collections.<GridCacheClearAllRunnable<K, V>>emptyList();
     }
@@ -1164,8 +1171,6 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
         GridDhtLocalPartition part = topology().localPartition(entry.partition(), AffinityTopologyVersion.NONE,
             false);
 
-        // Do not remove entry on replica topology. Instead, add entry to removal queue.
-        // It will be cleared eventually.
         if (part != null) {
             try {
                 part.onDeferredDelete(entry.key(), ver);
@@ -1211,16 +1216,16 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
         assert primary || backup;
 
         if (primary && backup)
-            return iterator(map.entries0().iterator(), !ctx.keepBinary());
+            return iterator(entries().iterator(), !ctx.keepBinary());
         else {
             final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
 
             final Iterator<GridDhtLocalPartition> partIt = topology().currentLocalPartitions().iterator();
 
-            Iterator<GridCacheEntryEx> it = new Iterator<GridCacheEntryEx>() {
-                private GridCacheEntryEx next;
+            Iterator<GridCacheMapEntry> it = new Iterator<GridCacheMapEntry>() {
+                private GridCacheMapEntry next;
 
-                private Iterator<GridDhtCacheEntry> curIt;
+                private Iterator<GridCacheMapEntry> curIt;
 
                 {
                     advance();
@@ -1230,11 +1235,11 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
                     return next != null;
                 }
 
-                @Override public GridCacheEntryEx next() {
+                @Override public GridCacheMapEntry next() {
                     if (next == null)
                         throw new NoSuchElementException();
 
-                    GridCacheEntryEx e = next;
+                    GridCacheMapEntry e = next;
 
                     advance();
 
@@ -1293,12 +1298,12 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
         private Cache.Entry<K, V> last;
 
         /** Partition iterator. */
-        private final Iterator<GridDhtCacheEntry> partIt;
+        private final Iterator<GridCacheMapEntry> partIt;
 
         /**
          * @param partIt Partition iterator.
          */
-        private PartitionEntryIterator(@Nullable Iterator<GridDhtCacheEntry> partIt) {
+        private PartitionEntryIterator(@Nullable Iterator<GridCacheMapEntry> partIt) {
             this.partIt = partIt;
 
             advance();
@@ -1335,9 +1340,9 @@ public abstract class GridDhtCacheAdapter<K, V> extends GridDistributedCacheAdap
         private void advance() {
             if (partIt != null) {
                 while (partIt.hasNext()) {
-                    GridDhtCacheEntry next = partIt.next();
+                    GridCacheEntryEx next = partIt.next();
 
-                    if (next.isInternal() || !next.visitable(CU.empty0()))
+                    if (next instanceof GridCacheMapEntry && (!((GridCacheMapEntry)next).visitable(CU.empty0())))
                         continue;
 
                     entry = next.wrapLazyValue();

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
index ab51bdb..95ef10b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
@@ -88,7 +88,11 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
         super(ctx, key, hash, val);
 
         // Record this entry with partition.
-        locPart = ctx.dht().topology().onAdded(topVer, this);
+        int p = cctx.affinity().partition(key);
+
+        locPart = ctx.topology().localPartition(p, topVer, true);
+
+        assert locPart != null;
     }
 
     /** {@inheritDoc} */
@@ -182,8 +186,7 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
         boolean reenter,
         boolean tx,
         boolean implicitSingle)
-        throws GridCacheEntryRemovedException, GridDistributedLockCancelledException
-    {
+        throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
         assert serReadVer == null || serOrder != null;
         assert !reenter || serOrder == null;
 
@@ -331,7 +334,8 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
      * @throws GridCacheEntryRemovedException If entry has been removed.
      */
     @SuppressWarnings({"NonPrivateFieldAccessedInSynchronizedContext"})
-    @Nullable public synchronized IgniteBiTuple<GridCacheVersion, CacheObject> versionedValue(AffinityTopologyVersion topVer)
+    @Nullable public synchronized IgniteBiTuple<GridCacheVersion, CacheObject> versionedValue(
+        AffinityTopologyVersion topVer)
         throws GridCacheEntryRemovedException {
         if (isNew() || !valid(AffinityTopologyVersion.NONE) || deletedUnlocked())
             return null;
@@ -599,7 +603,7 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
         }
         finally {
             if (rmv)
-                cctx.cache().removeIfObsolete(key); // Clear cache.
+                cctx.cache().removeEntry(this); // Clear cache.
         }
     }
 
@@ -713,6 +717,16 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
         return S.toString(GridDhtCacheEntry.class, this, "super", super.toString());
     }
 
+    /** {@inheritDoc} */
+    @Override protected void incrementMapPublicSize() {
+        locPart.incrementPublicSize(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void decrementMapPublicSize() {
+        locPart.decrementPublicSize(this);
+    }
+
     /**
      * Reader ID.
      */
@@ -793,7 +807,6 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
             return txFut;
         }
 
-
         /** {@inheritDoc} */
         @Override public boolean equals(Object o) {
             if (this == o)

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 4fc1eaf..3ac4a41 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -17,12 +17,10 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.dht;
 
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
@@ -33,8 +31,15 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap;
+import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.GridCacheSwapEntry;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPreloader;
@@ -53,8 +58,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteUuid;
 import org.jetbrains.annotations.NotNull;
-import org.jsr166.ConcurrentHashMap8;
-import org.jsr166.LongAdder8;
+import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE;
 import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED;
@@ -66,7 +70,7 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
 /**
  * Key partition.
  */
-public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>, GridReservable {
+public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>, GridReservable, GridCacheConcurrentMap {
     /** Maximum size for delete queue. */
     public static final int MAX_DELETE_QUEUE_SIZE = Integer.getInteger(IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE,
         200_000);
@@ -89,7 +93,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
     private final GridFutureAdapter<?> rent;
 
     /** Entries map. */
-    private final ConcurrentMap<KeyCacheObject, GridDhtCacheEntry> map;
+    private final GridCacheConcurrentMap map;
 
     /** Context. */
     private final GridCacheContext cctx;
@@ -104,9 +108,6 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
     /** Lock. */
     private final ReentrantLock lock = new ReentrantLock();
 
-    /** Public size counter. */
-    private final LongAdder8 mapPubSize = new LongAdder8();
-
     /** Remove queue. */
     private final GridCircularBuffer<T2<KeyCacheObject, GridCacheVersion>> rmvQueue;
 
@@ -120,8 +121,8 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
      * @param cctx Context.
      * @param id Partition ID.
      */
-    @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
-    GridDhtLocalPartition(GridCacheContext cctx, int id) {
+    @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition(GridCacheContext cctx, int id,
+        GridCacheMapEntryFactory entryFactory) {
         assert cctx != null;
 
         this.id = id;
@@ -135,8 +136,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
             }
         };
 
-        map = new ConcurrentHashMap8<>(cctx.config().getStartSize() /
-            cctx.affinity().partitions());
+        map = new GridCacheConcurrentMapImpl(cctx, entryFactory, cctx.config().getStartSize() / cctx.affinity().partitions());
 
         int delQueueSize = CU.isSystemCache(cctx.name()) ? 100 :
             Math.max(MAX_DELETE_QUEUE_SIZE / cctx.affinity().partitions(), 20);
@@ -202,45 +202,30 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
     }
 
     /**
-     * @return Entries belonging to partition.
-     */
-    public Collection<GridDhtCacheEntry> entries() {
-        return map.values();
-    }
-
-    /**
      * @return {@code True} if partition is empty.
      */
     public boolean isEmpty() {
-        return map.isEmpty();
+        return map.size() == 0;
     }
 
-    /**
-     * @return Number of entries in this partition (constant-time method).
-     */
-    public int size() {
+    /** {@inheritDoc} */
+    @Override public int size() {
         return map.size();
     }
 
-    /**
-     * Increments public size of the map.
-     */
-    public void incrementPublicSize() {
-        mapPubSize.increment();
+    /** {@inheritDoc} */
+    @Override public int publicSize() {
+        return map.publicSize();
     }
 
-    /**
-     * Decrements public size of the map.
-     */
-    public void decrementPublicSize() {
-        mapPubSize.decrement();
+    /** {@inheritDoc} */
+    @Override public void incrementPublicSize(GridCacheEntryEx e) {
+        map.incrementPublicSize(e);
     }
 
-    /**
-     * @return Number of public (non-internal) entries in this partition.
-     */
-    public int publicSize() {
-        return mapPubSize.intValue();
+    /** {@inheritDoc} */
+    @Override public void decrementPublicSize(GridCacheEntryEx e) {
+        map.decrementPublicSize(e);
     }
 
     /**
@@ -252,39 +237,57 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
         return state == MOVING || state == OWNING || state == RENTING;
     }
 
-    /**
-     * @param entry Entry to add.
-     */
-    void onAdded(GridDhtCacheEntry entry) {
-        GridDhtPartitionState state = state();
+    /** {@inheritDoc} */
+    @Override @Nullable public GridCacheMapEntry getEntry(KeyCacheObject key) {
+        return map.getEntry(key);
+    }
 
-        if (state == EVICTED)
-            throw new GridDhtInvalidPartitionException(id, "Adding entry to invalid partition " +
-                "(often may be caused by inconsistent 'key.hashCode()' implementation) [part=" + id + ']');
+    /** {@inheritDoc} */
+    @Override public boolean removeEntry(GridCacheEntryEx entry) {
+        return map.removeEntry(entry);
+    }
 
-        map.put(entry.key(), entry);
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> entries(
+        CacheEntryPredicate... filter) {
+        return map.entries(filter);
+    }
 
-        if (!entry.isInternal()) {
-            assert !entry.deleted() : entry;
+    /** {@inheritDoc} */
+    @Override public Iterable<GridCacheMapEntry> allEntries(CacheEntryPredicate... filter) {
+        return map.allEntries(filter);
+    }
 
-            mapPubSize.increment();
-        }
+    /** {@inheritDoc} */
+    @Override public Set<GridCacheMapEntry> entrySet(CacheEntryPredicate... filter) {
+        return map.entrySet(filter);
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public GridCacheMapEntry randomEntry() {
+        return map.randomEntry();
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheMapEntry putEntryIfObsoleteOrAbsent(
+        AffinityTopologyVersion topVer, KeyCacheObject key,
+        @Nullable CacheObject val, boolean create, boolean touch) {
+        return map.putEntryIfObsoleteOrAbsent(topVer, key, val, create, touch);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<KeyCacheObject> keySet(CacheEntryPredicate... filter) {
+        return map.keySet(filter);
     }
 
     /**
      * @param entry Entry to remove.
      */
-    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
     void onRemoved(GridDhtCacheEntry entry) {
         assert entry.obsolete() : entry;
 
         // Make sure to remove exactly this entry.
-        synchronized (entry) {
-            map.remove(entry.key(), entry);
-
-            if (!entry.isInternal() && !entry.deleted())
-                mapPubSize.decrement();
-        }
+        map.removeEntry(entry);
 
         // Attempt to evict.
         tryEvict();
@@ -312,7 +315,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
     /**
      * Locks partition.
      */
-    @SuppressWarnings( {"LockAcquiredButNotSafelyReleased"})
+    @SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
     public void lock() {
         lock.lock();
     }
@@ -338,11 +341,11 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         Map<KeyCacheObject, GridCacheVersion> evictHist0 = evictHist;
 
-        if (evictHist0 != null ) {
+        if (evictHist0 != null) {
             GridCacheVersion ver0 = evictHist0.get(key);
 
             if (ver0 == null || ver0.isLess(ver)) {
-                GridCacheVersion ver1  = evictHist0.put(key, ver);
+                GridCacheVersion ver1 = evictHist0.put(key, ver);
 
                 assert ver1 == ver0;
             }
@@ -366,7 +369,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         Map<KeyCacheObject, GridCacheVersion> evictHist0 = evictHist;
 
-        if (evictHist0 != null)  {
+        if (evictHist0 != null) {
             GridCacheVersion ver0 = evictHist0.get(key);
 
             // Permit preloading if version in history
@@ -489,7 +492,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         int ord = (int)(reservations >> 32);
 
-        if (map.isEmpty() && !GridQueryProcessor.isEnabled(cctx.config()) &&
+        if (isEmpty() && !GridQueryProcessor.isEnabled(cctx.config()) &&
             ord == RENTING.ordinal() && (reservations & 0xFFFF) == 0 &&
             casState(reservations, EVICTED)) {
             if (log.isDebugEnabled())
@@ -538,7 +541,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
         // Attempt to evict partition entries from cache.
         clearAll();
 
-        if (map.isEmpty() && casState(reservations, EVICTED)) {
+        if (isEmpty() && casState(reservations, EVICTED)) {
             if (log.isDebugEnabled())
                 log.debug("Evicted partition: " + this);
 
@@ -655,7 +658,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         boolean rec = cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
 
-        Iterator<GridDhtCacheEntry> it = map.values().iterator();
+        Iterator<GridDhtCacheEntry> it = (Iterator)map.allEntries().iterator();
 
         GridCloseableIterator<Map.Entry<byte[], GridCacheSwapEntry>> swapIt = null;
 
@@ -684,11 +687,9 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
                     cached = it.next();
 
                     if (cached.clearInternal(clearVer, swap, extras)) {
-                        map.remove(cached.key(), cached);
+                        map.removeEntry(cached);
 
                         if (!cached.isInternal()) {
-                            mapPubSize.decrement();
-
                             if (rec) {
                                 cctx.events().addEvent(cached.partition(),
                                     cached.key(),
@@ -709,7 +710,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
                     }
                 }
                 catch (GridDhtInvalidPartitionException e) {
-                    assert map.isEmpty() && state() == EVICTED: "Invalid error [e=" + e + ", part=" + this + ']';
+                    assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
                     assert swapEmpty() : "Invalid error when swap is not cleared [e=" + e + ", part=" + this + ']';
 
                     break; // Partition is already concurrently cleared and evicted.
@@ -789,7 +790,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
             }
 
             @Override public void remove() {
-                map.remove(lastEntry.key(), lastEntry);
+                map.removeEntry(lastEntry);
             }
         };
     }
@@ -811,7 +812,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings( {"OverlyStrongTypeCast"})
+    @SuppressWarnings({"OverlyStrongTypeCast"})
     @Override public boolean equals(Object obj) {
         return obj instanceof GridDhtLocalPartition && (obj == this || ((GridDhtLocalPartition)obj).id() == id);
     }
@@ -829,8 +830,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
         return S.toString(GridDhtLocalPartition.class, this,
             "state", state(),
             "reservations", reservations(),
-            "empty", map.isEmpty(),
-            "createTime", U.format(createTime),
-            "mapPubSize", mapPubSize);
+            "empty", isEmpty(),
+            "createTime", U.format(createTime));
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
index 50167d8..95c6dfc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
@@ -419,6 +419,12 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 writer.incrementState();
 
+            case 30:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
+
         }
 
         return true;
@@ -515,6 +521,14 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
                 reader.incrementState();
 
+            case 30:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridDhtLockRequest.class);
@@ -527,7 +541,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 30;
+        return 31;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
index 7fba45d..2c483a1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
@@ -195,13 +195,6 @@ public interface GridDhtPartitionTopology {
     public GridDhtPartitionFullMap partitionMap(boolean onlyActive);
 
     /**
-     * @param topVer Topology version.
-     * @param e Entry added to cache.
-     * @return Local partition.
-     */
-    public GridDhtLocalPartition onAdded(AffinityTopologyVersion topVer, GridDhtCacheEntry e);
-
-    /**
      * @param e Entry removed from cache.
      */
     public void onRemoved(GridDhtCacheEntry e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index f0ce6d1..9f5fbfb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cluster.ClusterNode;
@@ -37,6 +36,7 @@ import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.affinity.GridAffinityAssignment;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap2;
@@ -50,7 +50,6 @@ import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
 
 import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST;
 import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED;
@@ -76,8 +75,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     private final IgniteLogger log;
 
     /** */
-    private final ConcurrentMap<Integer, GridDhtLocalPartition> locParts =
-        new ConcurrentHashMap8<>();
+    private final GridDhtLocalPartition[] locParts;
 
     /** Node to partition map. */
     private GridDhtPartitionFullMap node2part;
@@ -103,6 +101,9 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     /** Lock. */
     private final StripedCompositeReadWriteLock lock = new StripedCompositeReadWriteLock(16);
 
+    /** */
+    private final GridCacheMapEntryFactory entryFactory;
+
     /** Partition update counter. */
     private Map<Integer, Long> cntrMap = new HashMap<>();
 
@@ -112,12 +113,15 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     /**
      * @param cctx Context.
      */
-    GridDhtPartitionTopologyImpl(GridCacheContext<?, ?> cctx) {
+    GridDhtPartitionTopologyImpl(GridCacheContext<?, ?> cctx, GridCacheMapEntryFactory entryFactory) {
         assert cctx != null;
 
         this.cctx = cctx;
+        this.entryFactory = entryFactory;
 
         log = cctx.logger(getClass());
+
+        locParts = new GridDhtLocalPartition[cctx.config().getAffinity().partitions()];
     }
 
     /**
@@ -149,7 +153,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     /**
      * @return Full map string representation.
      */
-    @SuppressWarnings( {"ConstantConditions"})
+    @SuppressWarnings({"ConstantConditions"})
     private String fullMapString() {
         return node2part == null ? "null" : FULL_MAP_DEBUG ? node2part.toFullString() : node2part.toString();
     }
@@ -158,7 +162,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
      * @param map Map to get string for.
      * @return Full map string representation.
      */
-    @SuppressWarnings( {"ConstantConditions"})
+    @SuppressWarnings({"ConstantConditions"})
     private String mapString(GridDhtPartitionMap2 map) {
         return map == null ? "null" : FULL_MAP_DEBUG ? map.toFullString() : map.toString();
     }
@@ -172,34 +176,65 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     private boolean waitForRent() throws IgniteCheckedException {
         boolean changed = false;
 
-        // Synchronously wait for all renting partitions to complete.
-        for (Iterator<GridDhtLocalPartition> it = locParts.values().iterator(); it.hasNext();) {
-            GridDhtLocalPartition p = it.next();
+        GridDhtLocalPartition[] locPartsCopy = new GridDhtLocalPartition[locParts.length];
 
-            GridDhtPartitionState state = p.state();
+        lock.readLock().lock();
+
+        try {
+            for (int i = 0; i < locParts.length; i++)
+                locPartsCopy[i] = locParts[i];
+        }
+        finally {
+            lock.readLock().unlock();
+        }
+
+        GridDhtLocalPartition part;
+
+        for (int i = 0; i < locPartsCopy.length; i++) {
+            part = locPartsCopy[i];
+
+            if (part == null)
+                continue;
+
+            GridDhtPartitionState state = part.state();
 
             if (state == RENTING || state == EVICTED) {
                 if (log.isDebugEnabled())
-                    log.debug("Waiting for renting partition: " + p);
+                    log.debug("Waiting for renting partition: " + part);
 
                 // Wait for partition to empty out.
-                p.rent(true).get();
+                part.rent(true).get();
 
                 if (log.isDebugEnabled())
-                    log.debug("Finished waiting for renting partition: " + p);
+                    log.debug("Finished waiting for renting partition: " + part);
+            }
+        }
 
-                // Remove evicted partition.
-                it.remove();
+        // Remove evicted partition.
+        lock.writeLock().lock();
 
-                changed = true;
+        try {
+            for (int i = 0; i < locParts.length; i++) {
+                part = locParts[i];
+
+                if (part == null)
+                    continue;
+
+                if (part.state() == EVICTED) {
+                    locParts[i] = null;
+                    changed = true;
+                }
             }
         }
+        finally {
+            lock.writeLock().unlock();
+        }
 
         return changed;
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings( {"LockAcquiredButNotSafelyReleased"})
+    @SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
     @Override public void readLock() {
         lock.readLock().lock();
     }
@@ -267,7 +302,8 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
-    @Override public void initPartitions(GridDhtPartitionsExchangeFuture exchFut) throws IgniteInterruptedCheckedException {
+    @Override public void initPartitions(
+        GridDhtPartitionsExchangeFuture exchFut) throws IgniteInterruptedCheckedException {
         U.writeLock(lock);
 
         try {
@@ -300,12 +336,12 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
         assert topVer.equals(exchFut.topologyVersion()) :
             "Invalid topology [topVer=" + topVer +
-            ", cache=" + cctx.name() +
-            ", futVer=" + exchFut.topologyVersion() + ']';
+                ", cache=" + cctx.name() +
+                ", futVer=" + exchFut.topologyVersion() + ']';
         assert cctx.affinity().affinityTopologyVersion().equals(exchFut.topologyVersion()) :
             "Invalid affinity [topVer=" + cctx.affinity().affinityTopologyVersion() +
-            ", cache=" + cctx.name()+
-            ", futVer=" + exchFut.topologyVersion() + ']';
+                ", cache=" + cctx.name() +
+                ", futVer=" + exchFut.topologyVersion() + ']';
 
         List<List<ClusterNode>> aff = cctx.affinity().assignments(exchFut.topologyVersion());
 
@@ -587,7 +623,8 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, boolean create)
+    @Nullable @Override public GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer,
+        boolean create)
         throws GridDhtInvalidPartitionException {
         return localPartition(p, topVer, create, true);
     }
@@ -597,21 +634,12 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
      * @return Partition.
      */
     private GridDhtLocalPartition createPartition(int p) {
-        GridDhtLocalPartition loc = locParts.get(p);
-
-        if (loc != null && loc.state() == EVICTED) {
-            boolean rmv = locParts.remove(p, loc);
+        assert lock.isWriteLockedByCurrentThread();
 
-            assert rmv;
-
-            loc = null;
-        }
+        GridDhtLocalPartition loc = locParts[p];
 
-        if (loc == null) {
-            GridDhtLocalPartition old = locParts.putIfAbsent(p, loc = new GridDhtLocalPartition(cctx, p));
-
-            assert old == null : old;
-        }
+        if (loc == null || loc.state() == EVICTED)
+            locParts[p] = loc = new GridDhtLocalPartition(cctx, p, entryFactory);
 
         return loc;
     }
@@ -627,54 +655,59 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         AffinityTopologyVersion topVer,
         boolean create,
         boolean updateSeq) {
-        boolean belongs = create && cctx.affinity().localNode(p, topVer);
+        GridDhtLocalPartition loc;
 
-        while (true) {
-            GridDhtLocalPartition loc = locParts.get(p);
+        lock.readLock().lock();
 
-            if (loc != null && loc.state() == EVICTED) {
-                locParts.remove(p, loc);
+        try {
+            loc = locParts[p];
+        }
+        finally {
+            lock.readLock().unlock();
+        }
+
+        if (loc != null && loc.state() != EVICTED)
+            return loc;
+
+        if (!create)
+            return null;
+
+        lock.writeLock().lock();
+
+        try {
+            loc = locParts[p];
+
+            boolean belongs = cctx.affinity().localNode(p, topVer);
 
-                if (!create)
-                    return null;
+            if (loc != null && loc.state() == EVICTED) {
+                locParts[p] = loc = null;
 
                 if (!belongs)
                     throw new GridDhtInvalidPartitionException(p, "Adding entry to evicted partition " +
                         "(often may be caused by inconsistent 'key.hashCode()' implementation) " +
                         "[part=" + p + ", topVer=" + topVer + ", this.topVer=" + this.topVer + ']');
-
-                continue;
             }
 
-            if (loc == null && create) {
+            if (loc == null) {
                 if (!belongs)
                     throw new GridDhtInvalidPartitionException(p, "Creating partition which does not belong to " +
                         "local node (often may be caused by inconsistent 'key.hashCode()' implementation) " +
                         "[part=" + p + ", topVer=" + topVer + ", this.topVer=" + this.topVer + ']');
 
-                lock.writeLock().lock();
-
-                try {
-                    GridDhtLocalPartition old = locParts.putIfAbsent(p,
-                        loc = new GridDhtLocalPartition(cctx, p));
+                locParts[p] = loc = new GridDhtLocalPartition(cctx, p, entryFactory);
 
-                    if (old != null)
-                        loc = old;
-                    else {
-                        if (updateSeq)
-                            this.updateSeq.incrementAndGet();
+                if (updateSeq)
+                    this.updateSeq.incrementAndGet();
 
-                        if (log.isDebugEnabled())
-                            log.debug("Created local partition: " + loc);
-                    }
-                }
-                finally {
-                    lock.writeLock().unlock();
-                }
+                if (log.isDebugEnabled())
+                    log.debug("Created local partition: " + loc);
             }
-
-            return loc;
         }
+        finally {
+            lock.writeLock().unlock();
+        }
+
+        return loc;
     }
 
     /** {@inheritDoc} */
@@ -682,8 +715,20 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         assert parts != null;
         assert parts.length > 0;
 
+        GridDhtLocalPartition[] locPartsCopy = new GridDhtLocalPartition[parts.length];
+
+        lock.readLock().lock();
+
+        try {
+            for (int i = 0; i < parts.length; i++)
+                locPartsCopy[i] = locParts[parts[i]];
+        }
+        finally {
+            lock.readLock().unlock();
+        }
+
         for (int i = 0; i < parts.length; i++)
-            locParts.get(parts[i]).release();
+            locPartsCopy[i].release();
     }
 
     /** {@inheritDoc} */
@@ -693,31 +738,28 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
     /** {@inheritDoc} */
     @Override public List<GridDhtLocalPartition> localPartitions() {
-        return new LinkedList<>(locParts.values());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridDhtLocalPartition> currentLocalPartitions() {
-        return locParts.values();
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridDhtLocalPartition onAdded(AffinityTopologyVersion topVer, GridDhtCacheEntry e) {
-        /*
-         * Make sure not to acquire any locks here as this method
-         * may be called from sensitive synchronization blocks.
-         * ===================================================
-         */
+        LinkedList<GridDhtLocalPartition> list = new LinkedList<>();
 
-        int p = cctx.affinity().partition(e.key());
+        lock.readLock().lock();
 
-        GridDhtLocalPartition loc = localPartition(p, topVer, true);
+        try {
+            for (int i = 0; i < locParts.length; i++) {
+                GridDhtLocalPartition part = locParts[i];
 
-        assert loc != null;
+                if (part != null)
+                    list.add(part);
+            }
 
-        loc.onAdded(e);
+            return list;
+        }
+        finally {
+            lock.readLock().unlock();
+        }
+    }
 
-        return loc;
+    /** {@inheritDoc} */
+    @Override public Collection<GridDhtLocalPartition> currentLocalPartitions() {
+        return localPartitions();
     }
 
     /** {@inheritDoc} */
@@ -736,11 +778,22 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
     /** {@inheritDoc} */
     @Override public GridDhtPartitionMap2 localPartitionMap() {
+        Map<Integer, GridDhtPartitionState> map = new HashMap<>();
+
         lock.readLock().lock();
 
         try {
+            for (int i = 0; i < locParts.length; i++) {
+                GridDhtLocalPartition part = locParts[i];
+
+                if (part == null)
+                    continue;
+
+                map.put(i, part.state());
+            }
+
             return new GridDhtPartitionMap2(cctx.nodeId(), updateSeq.get(), topVer,
-                F.viewReadOnly(locParts, CU.part2state()), true);
+                Collections.unmodifiableMap(map), true);
         }
         finally {
             lock.readLock().unlock();
@@ -943,7 +996,12 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                         this.cntrMap.put(e.getKey(), e.getValue());
                 }
 
-                for (GridDhtLocalPartition part : locParts.values()) {
+                for (int i = 0; i < locParts.length; i++) {
+                    GridDhtLocalPartition part = locParts[i];
+
+                    if (part == null)
+                        continue;
+
                     Long cntr = cntrMap.get(part.id());
 
                     if (cntr != null)
@@ -992,7 +1050,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                     }
                 }
 
-                for (Iterator<UUID> it = partMap.keySet().iterator(); it.hasNext();) {
+                for (Iterator<UUID> it = partMap.keySet().iterator(); it.hasNext(); ) {
                     UUID nodeId = it.next();
 
                     if (!cctx.discovery().alive(nodeId)) {
@@ -1078,7 +1136,12 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                         this.cntrMap.put(e.getKey(), e.getValue());
                 }
 
-                for (GridDhtLocalPartition part : locParts.values()) {
+                for (int i = 0; i < locParts.length; i++) {
+                    GridDhtLocalPartition part = locParts[i];
+
+                    if (part == null)
+                        continue;
+
                     Long cntr = cntrMap.get(part.id());
 
                     if (cntr != null)
@@ -1178,12 +1241,15 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
 
         UUID locId = cctx.nodeId();
 
-        for (GridDhtLocalPartition part : locParts.values()) {
+        for (int p = 0; p < locParts.length; p++) {
+            GridDhtLocalPartition part = locParts[p];
+
+            if (part == null)
+                continue;
+
             GridDhtPartitionState state = part.state();
 
             if (state.active()) {
-                int p = part.id();
-
                 List<ClusterNode> affNodes = aff.get(p);
 
                 if (!affNodes.contains(cctx.localNode())) {
@@ -1403,7 +1469,12 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
         try {
             Map<Integer, Long> res = new HashMap<>(cntrMap);
 
-            for (GridDhtLocalPartition part : locParts.values()) {
+            for (int i = 0; i < locParts.length; i++) {
+                GridDhtLocalPartition part = locParts[i];
+
+                if (part == null)
+                    continue;
+
                 Long cntr0 = res.get(part.id());
                 Long cntr1 = part.updateCounter();
 
@@ -1429,11 +1500,23 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     @Override public void printMemoryStats(int threshold) {
         X.println(">>>  Cache partition topology stats [grid=" + cctx.gridName() + ", cache=" + cctx.name() + ']');
 
-        for (GridDhtLocalPartition part : locParts.values()) {
-            int size = part.size();
+        lock.readLock().lock();
+
+        try {
+            for (int i = 0; i < locParts.length; i++) {
+                GridDhtLocalPartition part = locParts[i];
+
+                if (part == null)
+                    continue;
+
+                int size = part.size();
 
-            if (size >= threshold)
-                X.println(">>>   Local partition [part=" + part.id() + ", size=" + size + ']');
+                if (size >= threshold)
+                    X.println(">>>   Local partition [part=" + part.id() + ", size=" + size + ']');
+            }
+        }
+        finally {
+            lock.readLock().unlock();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
index 38152a7..1d067da 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
@@ -120,6 +120,11 @@ public class GridDhtUnlockRequest extends GridDistributedUnlockRequest {
 
                 writer.incrementState();
 
+            case 9:
+                if (!writer.writeCollection("partIds", partIds, MessageCollectionItemType.INT))
+                    return false;
+
+                writer.incrementState();
         }
 
         return true;
@@ -144,6 +149,14 @@ public class GridDhtUnlockRequest extends GridDistributedUnlockRequest {
 
                 reader.incrementState();
 
+            case 9:
+                partIds = reader.readCollection("partIds", MessageCollectionItemType.INT);
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
         }
 
         return reader.afterMessageRead(GridDhtUnlockRequest.class);
@@ -156,6 +169,6 @@ public class GridDhtUnlockRequest extends GridDistributedUnlockRequest {
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        return 9;
+        return 10;
     }
 }


[34/50] [abbrv] ignite git commit: IGNITE-642 Implement IgniteReentrantLock data structure

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockImpl.java
new file mode 100644
index 0000000..3ab7289
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockImpl.java
@@ -0,0 +1,1538 @@
+/*
+ * 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.datastructures;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteCondition;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.IgniteLock;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
+import org.apache.ignite.internal.util.typedef.X;
+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.transactions.TransactionRollbackException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.processors.cache.GridCacheUtils.retryTopologySafe;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ * Cache reentrant lock implementation based on AbstractQueuedSynchronizer.
+ */
+public final class GridCacheLockImpl implements GridCacheLockEx, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Deserialization stash. */
+    private static final ThreadLocal<String> stash = new ThreadLocal<>();
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Reentrant lock name. */
+    private String name;
+
+    /** Removed flag. */
+    private volatile boolean rmvd;
+
+    /** Reentrant lock key. */
+    private GridCacheInternalKey key;
+
+    /** Reentrant lock projection. */
+    private IgniteInternalCache<GridCacheInternalKey, GridCacheLockState> lockView;
+
+    /** Cache context. */
+    private final GridCacheContext ctx;
+
+    /** Initialization guard. */
+    private final AtomicBoolean initGuard = new AtomicBoolean();
+
+    /** Initialization latch. */
+    private final CountDownLatch initLatch = new CountDownLatch(1);
+
+    /** Lock that provides non-overlapping processing of updates. */
+    private Lock updateLock = new ReentrantLock();
+
+    /** Internal synchronization object. */
+    private Sync sync;
+
+    /** Flag indicating that every operation on this lock should be interrupted. */
+    private volatile boolean interruptAll;
+
+    /**
+     * Empty constructor required by {@link Externalizable}.
+     */
+    public GridCacheLockImpl() {
+        // This instance should never be used directly.
+        ctx = null;
+    }
+
+    /**
+     * Synchronization implementation for reentrant lock using AbstractQueuedSynchronizer.
+     */
+    @SuppressWarnings({"CallToThreadYield", "CallToSignalInsteadOfSignalAll"})
+    private class Sync extends AbstractQueuedSynchronizer {
+        /** */
+        private static final long serialVersionUID = 1192457210091910933L;
+
+        /** */
+        private static final long LOCK_FREE = 0;
+
+        /** Map containing condition objects. */
+        private Map<String, ConditionObject> conditionMap;
+
+        /** List of condition signal calls on this node. */
+        private Map<String, Integer> outgoingSignals;
+
+        /** Last condition waited on. */
+        @Nullable
+        private volatile String lastCondition;
+
+        /** True if any node owning the lock had failed. */
+        private volatile boolean isBroken;
+
+        /** UUID of the node that currently owns the lock. */
+        private volatile UUID currentOwnerNode;
+
+        /** ID of the thread that currently owns the lock. */
+        private volatile long currentOwnerThreadId;
+
+        /** UUID of this node. */
+        private final UUID thisNode;
+
+        /** FailoverSafe flag. */
+        private final boolean failoverSafe;
+
+        /** Fairness flag. */
+        private final boolean fair;
+
+        /** Threads that are waiting on this lock. */
+        private Set<Long> waitingThreads;
+
+        /**
+         * @param state State.
+         */
+        protected Sync(GridCacheLockState state) {
+            setState(state.get());
+
+            thisNode = ctx.localNodeId();
+
+            currentOwnerNode = state.getId();
+
+            currentOwnerThreadId = state.getThreadId();
+
+            conditionMap = new HashMap<>();
+
+            outgoingSignals = new HashMap<>();
+
+            failoverSafe = state.isFailoverSafe();
+
+            fair = state.isFair();
+
+            waitingThreads = new ConcurrentSkipListSet<>();
+        }
+
+        /**
+         *
+         */
+        protected void addOutgoingSignal(String condition) {
+            int cnt = 0;
+
+            if (outgoingSignals.containsKey(condition)) {
+                cnt = outgoingSignals.get(condition);
+
+                // SignalAll has already been called.
+                if (cnt == 0)
+                    return;
+            }
+
+            outgoingSignals.put(condition, cnt + 1);
+        }
+
+        protected void addOutgoingSignalAll(String condition) {
+            outgoingSignals.put(condition, 0);
+        }
+
+        /**
+         * Process any condition await calls on this node.
+         */
+        private String processAwait() {
+            if (lastCondition == null)
+                return null;
+
+            String ret = lastCondition;
+
+            lastCondition = null;
+
+            return ret;
+        }
+
+        /** */
+        private Map<String, Integer> processSignal() {
+            Map<String,Integer> ret = new HashMap<>(outgoingSignals);
+
+            outgoingSignals.clear();
+
+            return ret;
+        }
+
+        /** Interrupt every thread on this node waiting on this lock. */
+        private synchronized void interruptAll() {
+            // First release all threads waiting on associated condition queues.
+            if (!conditionMap.isEmpty()) {
+                // Temporarily obtain ownership of the lock,
+                // in order to signal all conditions.
+                UUID tempUUID = getOwnerNode();
+
+                long tempThreadID = currentOwnerThreadId;
+
+                setCurrentOwnerNode(thisNode);
+
+                currentOwnerThreadId = Thread.currentThread().getId();
+
+                for (Condition c : conditionMap.values())
+                    c.signalAll();
+
+                // Restore owner node and owner thread.
+                setCurrentOwnerNode(tempUUID);
+
+                currentOwnerThreadId = tempThreadID;
+            }
+
+            // Interrupt any future call to acquire/release on this sync object.
+            interruptAll = true;
+
+            // Interrupt any ongoing transactions.
+            for (Thread t: getQueuedThreads())
+                t.interrupt();
+        }
+
+        /** Check if lock is in correct state (i.e. not broken in non-failoversafe mode),
+         * if not throw  {@linkplain IgniteInterruptedException} */
+        private void validate(final boolean throwInterrupt) {
+            // Interrupted flag shouldn't be always cleared
+            // (e.g. lock() method doesn't throw exception and doesn't clear interrupted)
+            // but should be cleared if this method is called after lock breakage or node stop.
+            // If interruptAll is set, exception is thrown anyway.
+            boolean interrupted = Thread.currentThread().isInterrupted();
+
+            // Clear interrupt flag.
+            if (throwInterrupt || interruptAll)
+                Thread.interrupted();
+
+            if (interruptAll)
+                throw new IgniteException("Lock broken (possible reason: node stopped" +
+                    " or node owning lock failed while in non-failoversafe mode).");
+
+            // Global queue should be synchronized only if interrupted exception should be thrown.
+            if (fair && (throwInterrupt && interrupted) && !interruptAll) {
+                synchronizeQueue(true, Thread.currentThread());
+
+                throw new IgniteInterruptedException("Lock is interrupted.");
+            }
+        }
+
+        /**
+         * Sets the number of permits currently acquired on this lock. This method should only be used in {@linkplain
+         * GridCacheLockImpl#onUpdate(GridCacheLockState)}.
+         *
+         * @param permits Number of permits acquired at this reentrant lock.
+         */
+        final synchronized void setPermits(int permits) {
+            setState(permits);
+        }
+
+        /**
+         * Gets the number of permissions currently acquired at this lock.
+         *
+         * @return Number of permits acquired at this reentrant lock.
+         */
+        final int getPermits() {
+            return getState();
+        }
+
+        /**
+         * Sets the UUID of the node that currently owns this lock. This method should only be used in {@linkplain
+         * GridCacheLockImpl#onUpdate(GridCacheLockState)}.
+         *
+         * @param ownerNode UUID of the node owning this lock.
+         */
+        final synchronized void setCurrentOwnerNode(UUID ownerNode) {
+            currentOwnerNode = ownerNode;
+        }
+
+        /**
+         * Gets the UUID of the node that currently owns the lock.
+         *
+         * @return UUID of the node that currently owns the lock.
+         */
+        final UUID getOwnerNode() {
+            return currentOwnerNode;
+        }
+
+        /**
+         * Checks if latest call to acquire/release was called on this node.
+         * Should only be called from update method.
+         *
+         * @param newOwnerID ID of the node that is about to acquire this lock (or null).
+         * @return true if acquire/release that triggered last update came from this node.
+         */
+        protected boolean isLockedLocally(UUID newOwnerID) {
+            return thisNode.equals(getOwnerNode()) || thisNode.equals(newOwnerID);
+        }
+
+        protected void setCurrentOwnerThread(long newOwnerThreadId) {
+            currentOwnerThreadId = newOwnerThreadId;
+        }
+
+        /**
+         * Returns true if node that owned the locked failed before call to unlock.
+         *
+         * @return true if any node failed while owning the lock.
+         */
+        protected boolean isBroken() {
+            return isBroken;
+        }
+
+        /** */
+        protected void setBroken(boolean isBroken) {
+            this.isBroken = isBroken;
+        }
+
+        /** */
+        protected synchronized boolean hasPredecessor(LinkedList<UUID> nodes) {
+            if (!fair)
+                return false;
+
+            for (Iterator<UUID> it = nodes.iterator(); it.hasNext(); ) {
+                UUID node = it.next();
+
+                if (ctx.discovery().node(node) == null) {
+                    it.remove();
+
+                    continue;
+                }
+
+                return !node.equals(thisNode);
+            }
+
+            return false;
+        }
+
+        /**
+         * Performs tryLock.
+         * @param acquires Number of permits to acquire.
+         * @param fair Fairness parameter.
+         * @return {@code True} if succeeded, false otherwise.
+         */
+        final boolean tryAcquire(final int acquires, final boolean fair) {
+            // If broken in non-failoversafe mode, exit immediately.
+            if (interruptAll)
+                return true;
+
+            final Thread current = Thread.currentThread();
+
+            boolean failed = false;
+
+            int c = getState();
+
+            // Wait for lock to reach stable state.
+            while (c != 0) {
+                UUID currentOwner = currentOwnerNode;
+
+                if (currentOwner != null) {
+                    failed = ctx.discovery().node(currentOwner) == null;
+
+                    break;
+                }
+
+                c = getState();
+            }
+
+            // Check if lock is released or current owner failed.
+            if (c == 0 || failed) {
+                if (compareAndSetGlobalState(0, acquires, current, fair)) {
+
+                    // Not used for synchronization (we use ThreadID), but updated anyway.
+                    setExclusiveOwnerThread(current);
+
+                    while (!isHeldExclusively() && !interruptAll)
+                        Thread.yield();
+
+                    return true;
+                }
+            }
+            else if (isHeldExclusively()) {
+                int nextc = c + acquires;
+
+                if (nextc < 0) // overflow
+                    throw new Error("Maximum lock count exceeded.");
+
+                setState(nextc);
+
+                return true;
+            }
+
+            if (fair && !isQueued(current))
+                synchronizeQueue(false, current);
+
+            return false;
+        }
+
+        /**
+         * Performs lock.
+         */
+        final void lock() {
+            acquire(1);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected final boolean tryAcquire(int acquires) {
+            return tryAcquire(acquires, fair);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected final boolean tryRelease(int releases) {
+            // This method is called with release==0 only when trying to wake through update,
+            // to check if some other node released the lock.
+            if (releases == 0)
+                return true;
+
+            // If broken in non-failoversafe mode, exit immediately.
+            if (interruptAll)
+                return true;
+
+            int c = getState() - releases;
+
+            if (!isHeldExclusively()) {
+                log.error("Lock.unlock() is called in illegal state [callerNodeId=" + thisNode + ", ownerNodeId="
+                    + currentOwnerNode + ", callerThreadId=" + Thread.currentThread().getId() + ", ownerThreadId="
+                    + currentOwnerThreadId + ", lockState=" + getState() + "]");
+
+                throw new IllegalMonitorStateException();
+            }
+
+            boolean free = false;
+
+            if (c == 0) {
+                free = true;
+
+                setGlobalState(0, processAwait(), processSignal());
+
+                while (isHeldExclusively() && !interruptAll)
+                    Thread.yield();
+            }
+            else
+                setState(c);
+
+            return free;
+        }
+
+
+        /** {@inheritDoc} */
+        @Override protected final boolean isHeldExclusively() {
+            // While we must in general read state before owner,
+            // we don't need to do so to check if current thread is owner
+
+            return currentOwnerThreadId == Thread.currentThread().getId() && thisNode.equals(currentOwnerNode);
+        }
+
+        /**
+         * @param name Condition name.
+         * @return Condition object.
+         */
+        final synchronized IgniteCondition newCondition(String name) {
+            if (conditionMap.containsKey(name))
+                return new IgniteConditionObject(name, conditionMap.get(name));
+
+            ConditionObject cond = new ConditionObject();
+
+            conditionMap.put(name, cond);
+
+            return new IgniteConditionObject(name, cond);
+        }
+
+        // Methods relayed from outer class
+
+        final int getHoldCount() {
+            return isHeldExclusively() ? getState() : 0;
+        }
+
+        final boolean isLocked() throws IgniteCheckedException {
+            return getState() != 0 || lockView.get(key).get() != 0;
+        }
+
+        /**
+         * This method is used for synchronizing the reentrant lock state across all nodes.
+         */
+        protected boolean compareAndSetGlobalState(final int expVal, final int newVal,
+            final Thread newThread, final boolean bargingProhibited) {
+            try {
+                return CU.outTx(
+                    retryTopologySafe(new Callable<Boolean>() {
+                        @Override public Boolean call() throws Exception {
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, lockView, PESSIMISTIC, REPEATABLE_READ)) {
+
+                                GridCacheLockState val = lockView.get(key);
+
+                                if (val == null)
+                                    throw new IgniteCheckedException("Failed to find reentrant lock with given name: " + name);
+
+                                final long newThreadID = newThread.getId();
+
+                                LinkedList<UUID> nodes = val.getNodes();
+
+                                // Barging is prohibited in fair mode unless tryLock() is called.
+                                if (!(bargingProhibited && hasPredecessor(nodes))) {
+                                    if (val.get() == expVal || ctx.discovery().node(val.getId()) == null) {
+                                        val.set(newVal);
+
+                                        val.setId(thisNode);
+
+                                        val.setThreadId(newThreadID);
+
+                                        val.setSignals(null);
+
+                                        // This node is already in queue, except in cases where this is the only node
+                                        // or this is a call to tryLock(), in which case barging is ok.
+                                        // Queue is only updated if this is fair lock.
+                                        if (val.isFair() && (nodes.isEmpty() || !bargingProhibited))
+                                            nodes.addFirst(thisNode);
+
+                                        val.setNodes(nodes);
+
+                                        val.setChanged(true);
+
+                                        lockView.put(key, val);
+
+                                        tx.commit();
+
+                                        return true;
+                                    }
+                                }
+
+                                return false;
+                            }
+                            catch (Exception e) {
+                                if (interruptAll) {
+                                    log.info("Node is stopped (or lock is broken in non-failover safe mode)," +
+                                        " aborting transaction.");
+
+                                    // Return immediately, exception will be thrown later.
+                                    return true;
+                                }
+                                else {
+                                    if (Thread.currentThread().isInterrupted()) {
+                                        log.info("Thread is interrupted while attempting to acquire lock.");
+
+                                        // Delegate the decision to throw InterruptedException to the AQS.
+                                        sync.release(0);
+
+                                        return false;
+                                    }
+
+                                    U.error(log, "Failed to compare and set: " + this, e);
+                                }
+
+                                throw e;
+                            }
+                        }
+                    }),
+                    ctx
+                );
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+        }
+
+        /**
+         * This method is used for synchronizing the number of acquire attempts on this lock across all nodes.
+         *
+         * @param cancelled true if acquire attempt is cancelled, false if acquire attempt should be registered.
+         */
+        protected boolean synchronizeQueue(final boolean cancelled, final Thread thread) {
+            final AtomicBoolean interrupted = new AtomicBoolean(false);
+
+            try {
+                return CU.outTx(
+                    retryTopologySafe(new Callable<Boolean>() {
+                        @Override public Boolean call() throws Exception {
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, lockView, PESSIMISTIC, REPEATABLE_READ)) {
+                                GridCacheLockState val = lockView.get(key);
+
+                                if (val == null)
+                                    throw new IgniteCheckedException("Failed to find reentrant lock with given name: " + name);
+
+                                LinkedList<UUID> nodes = val.getNodes();
+
+                                if (!cancelled) {
+                                    nodes.add(thisNode);
+
+                                    val.setChanged(false);
+
+                                    lockView.put(key, val);
+
+                                    tx.commit();
+
+                                    // Keep track of all threads that are queued in global queue.
+                                    // We deliberately don't use #sync.isQueued(), because AQS
+                                    // cancel threads immediately after throwing interrupted exception.
+                                    sync.waitingThreads.add(thread.getId());
+
+                                    return true;
+                                }
+                                else {
+                                    if (sync.waitingThreads.contains(thread.getId())) {
+                                        // Update other nodes if this is the first node in queue.
+                                        val.setChanged(nodes.lastIndexOf(thisNode) == 0);
+
+                                        nodes.removeLastOccurrence(thisNode);
+
+                                        lockView.put(key, val);
+
+                                        tx.commit();
+
+                                        sync.waitingThreads.remove(thread.getId());
+
+                                        return true;
+                                    }
+                                }
+
+                                return false;
+                            }
+                            catch (Exception e) {
+                                if (interruptAll) {
+                                    log.info("Node is stopped (or lock is broken in non-failover safe mode)," +
+                                        " aborting transaction.");
+
+                                    // Abort this attempt to synchronize queue and start another one,
+                                    // that will return immediately.
+                                    sync.release(0);
+
+                                    return false;
+                                }
+                                else {
+                                    // If thread got interrupted, abort this attempt to synchronize queue,
+                                    // clear interrupt flag and try again, and let the AQS decide
+                                    // whether to throw an exception or ignore it.
+                                    if (Thread.interrupted() || X.hasCause(e, InterruptedException.class)) {
+                                        interrupted.set(true);
+
+                                        throw new TransactionRollbackException("Thread got interrupted " +
+                                            "while synchronizing the global queue, retrying. ");
+                                    }
+
+                                    U.error(log, "Failed to synchronize global lock queue: " + this, e);
+                                }
+
+                                throw e;
+                            }
+                        }
+                    }),
+                    ctx
+                );
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+            finally {
+                // Restore interrupt flag and let AQS decide what to do with it.
+                if (interrupted.get())
+                    Thread.currentThread().interrupt();
+            }
+        }
+
+        /**
+         * Sets the global state across all nodes after releasing the reentrant lock.
+         *
+         * @param newVal New state.
+         * @param lastCondition Id of the condition await is called.
+         * @param outgoingSignals Map containing signal calls on this node since the last acquisition of the lock.
+         */
+        protected boolean setGlobalState(final int newVal, @Nullable final String lastCondition, final Map<String, Integer> outgoingSignals) {
+            try {
+                return CU.outTx(
+                    retryTopologySafe(new Callable<Boolean>() {
+                        @Override public Boolean call() throws Exception {
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, lockView, PESSIMISTIC, REPEATABLE_READ)) {
+                                GridCacheLockState val = lockView.get(key);
+
+                                if (val == null)
+                                    throw new IgniteCheckedException("Failed to find reentrant lock with given name: " + name);
+
+                                val.set(newVal);
+
+                                if (newVal == 0) {
+                                    val.setId(null);
+
+                                    val.setThreadId(LOCK_FREE);
+                                }
+
+                                val.setChanged(true);
+
+                                // If this lock is fair, remove this node from queue.
+                                if (val.isFair() && newVal == 0) {
+                                    UUID removedNode = val.getNodes().removeFirst();
+
+                                    assert(thisNode.equals(removedNode));
+                                }
+
+                                // Get global condition queue.
+                                Map<String, LinkedList<UUID>> condMap = val.getConditionMap();
+
+                                // Create map containing signals from this node.
+                                Map<UUID, LinkedList<String>> signalMap = new HashMap<>();
+
+                                // Put any signal calls on this node to global state.
+                                if (!outgoingSignals.isEmpty()) {
+                                    for (String condition : outgoingSignals.keySet()) {
+                                        int cnt = outgoingSignals.get(condition);
+
+                                        // Get queue for this condition.
+                                        List<UUID> list = condMap.get(condition);
+
+                                        if (list != null && !list.isEmpty()) {
+                                            // Check if signalAll was called.
+                                            if (cnt == 0) {
+                                                cnt = list.size();
+                                            }
+
+                                            // Remove from global condition queue.
+                                            for (int i = 0; i < cnt; i++) {
+                                                if (list.isEmpty())
+                                                    break;
+
+                                                UUID uuid = list.remove(0);
+
+                                                // Skip if node to be released is not alive anymore.
+                                                if (ctx.discovery().node(uuid) == null) {
+                                                    cnt++;
+
+                                                    continue;
+                                                }
+
+                                                LinkedList<String> queue = signalMap.get(uuid);
+
+                                                if (queue == null) {
+                                                    queue = new LinkedList<>();
+
+                                                    signalMap.put(uuid, queue);
+                                                }
+
+                                                queue.add(condition);
+                                            }
+                                        }
+                                    }
+                                }
+
+                                val.setSignals(signalMap);
+
+                                // Check if this release is called after condition.await() call;
+                                // If true, add this node to the global waiting queue.
+                                if (lastCondition != null) {
+                                    LinkedList<UUID> queue;
+
+                                    //noinspection IfMayBeConditional
+                                    if (!condMap.containsKey(lastCondition))
+                                        // New condition object.
+                                        queue = new LinkedList<>();
+                                    else
+                                        // Existing condition object.
+                                        queue = condMap.get(lastCondition);
+
+                                    queue.add(thisNode);
+
+                                    condMap.put(lastCondition, queue);
+                                }
+
+                                val.setConditionMap(condMap);
+
+                                lockView.put(key, val);
+
+                                tx.commit();
+
+                                return true;
+                            }
+                            catch (Exception e) {
+                                if (interruptAll) {
+                                    log.info("Node is stopped (or lock is broken in non-failover safe mode)," +
+                                        " aborting transaction.");
+
+                                    return true;
+                                }
+                                else
+                                    U.error(log, "Failed to release: " + this, e);
+
+                                throw e;
+                            }
+                        }
+                    }),
+                    ctx
+                );
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+        }
+
+        protected synchronized boolean checkIncomingSignals(GridCacheLockState state) {
+            if (state.getSignals() == null)
+                return false;
+
+            LinkedList<String> signals = state.getSignals().get(thisNode);
+
+            if (signals == null || signals.isEmpty())
+                return false;
+
+            UUID tempUUID = getOwnerNode();
+
+            Thread tempThread = getExclusiveOwnerThread();
+
+            long tempThreadID = currentOwnerThreadId;
+
+            // Temporarily allow current thread to signal condition object.
+            // This is safe to do because:
+            // 1. if release was called on this node,
+            // it was called from currently active thread;
+            // 2. if release came from a thread on any other node,
+            // all threads on this node are already blocked.
+            setCurrentOwnerNode(thisNode);
+
+            setExclusiveOwnerThread(Thread.currentThread());
+
+            currentOwnerThreadId = Thread.currentThread().getId();
+
+            for (String signal: signals)
+                conditionMap.get(signal).signal();
+
+            // Restore owner node and owner thread.
+            setCurrentOwnerNode(tempUUID);
+
+            setExclusiveOwnerThread(tempThread);
+
+            currentOwnerThreadId = tempThreadID;
+
+            return true;
+        }
+
+        /**
+         *  Condition implementation for {@linkplain IgniteLock}.
+         *
+         **/
+        private class IgniteConditionObject implements IgniteCondition {
+            /** */
+            private final String name;
+
+            /** */
+            private final AbstractQueuedSynchronizer.ConditionObject object;
+
+            /**
+             * @param name Condition name.
+             * @param object Condition object.
+             */
+            protected IgniteConditionObject(String name, ConditionObject object) {
+                this.name = name;
+
+                this.object = object;
+            }
+
+            /**
+             * Name of this condition.
+             *
+             * @return name Name of this condition object.
+             */
+            @Override public String name() {
+                return name;
+            }
+
+            /** {@inheritDoc} */
+            @Override public void await() throws IgniteInterruptedException {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    lastCondition = name;
+
+                    object.await();
+
+                    sync.validate(true);
+                }
+                catch (InterruptedException e) {
+                    throw new IgniteInterruptedException(e);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public void awaitUninterruptibly() {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    lastCondition = name;
+
+                    object.awaitUninterruptibly();
+
+                    sync.validate(false);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public long awaitNanos(long nanosTimeout) throws IgniteInterruptedException {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    lastCondition = name;
+
+                    long result =  object.awaitNanos(nanosTimeout);
+
+                    sync.validate(true);
+
+                    return result;
+                }
+                catch (InterruptedException e) {
+                    throw new IgniteInterruptedException(e);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean await(long time, TimeUnit unit) throws IgniteInterruptedException {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    lastCondition = name;
+
+                    boolean result = object.await(time, unit);
+
+                    sync.validate(true);
+
+                    return result;
+                }
+                catch (InterruptedException e) {
+                    throw new IgniteInterruptedException(e);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public boolean awaitUntil(Date deadline) throws IgniteInterruptedException {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    lastCondition = name;
+
+                    boolean result = object.awaitUntil(deadline);
+
+                    sync.validate(true);
+
+                    return result;
+                }
+                catch (InterruptedException e) {
+                    throw new IgniteInterruptedException(e);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public void signal() {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    validate(false);
+
+                    addOutgoingSignal(name);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+
+            /** {@inheritDoc} */
+            @Override public void signalAll() {
+                ctx.kernalContext().gateway().readLock();
+
+                try {
+                    if (!isHeldExclusively())
+                        throw new IllegalMonitorStateException();
+
+                    sync.validate(false);
+
+                    addOutgoingSignalAll(name);
+                }
+                finally {
+                    ctx.kernalContext().gateway().readUnlock();
+                }
+            }
+        }
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param name Reentrant lock name.
+     * @param key Reentrant lock key.
+     * @param lockView Reentrant lock projection.
+     * @param ctx Cache context.
+     */
+    @SuppressWarnings("unchecked")
+    public GridCacheLockImpl(String name,
+        GridCacheInternalKey key,
+        IgniteInternalCache<GridCacheInternalKey, GridCacheLockState> lockView,
+        GridCacheContext ctx) {
+        assert name != null;
+        assert key != null;
+        assert ctx != null;
+        assert lockView != null;
+
+        this.name = name;
+        this.key = key;
+        this.lockView = lockView;
+        this.ctx = ctx;
+
+        log = ctx.logger(getClass());
+    }
+
+    /**
+     * @throws IgniteCheckedException If operation failed.
+     */
+    private void initializeReentrantLock() throws IgniteCheckedException {
+        if (initGuard.compareAndSet(false, true)) {
+            try {
+                sync = CU.outTx(
+                    retryTopologySafe(new Callable<Sync>() {
+                        @Override public Sync call() throws Exception {
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, lockView, PESSIMISTIC, REPEATABLE_READ)) {
+                                GridCacheLockState val = lockView.get(key);
+
+                                if (val == null) {
+                                    if (log.isDebugEnabled())
+                                        log.debug("Failed to find reentrant lock with given name: " + name);
+
+                                    return null;
+                                }
+
+                                tx.rollback();
+
+                                return new Sync(val);
+                            }
+                        }
+                    }),
+                    ctx
+                );
+
+                if (log.isDebugEnabled())
+                    log.debug("Initialized internal sync structure: " + sync);
+            }
+            finally {
+                initLatch.countDown();
+            }
+        }
+        else {
+            U.await(initLatch);
+
+            if (sync == null)
+                throw new IgniteCheckedException("Internal reentrant lock has not been properly initialized.");
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onUpdate(GridCacheLockState val) {
+        // Called only on initialization, so it's safe to ignore update.
+        if (sync == null)
+            return;
+
+        updateLock.lock();
+
+        try {
+            // If this update is a result of unsuccessful acquire in fair mode, no local update should be done.
+            if (!val.isChanged())
+                return;
+
+            // Check if update came from this node.
+            boolean local = sync.isLockedLocally(val.getId());
+
+            // Process any incoming signals.
+            boolean incomingSignals = sync.checkIncomingSignals(val);
+
+            // Update permission count.
+            sync.setPermits(val.get());
+
+            // Update owner's node id.
+            sync.setCurrentOwnerNode(val.getId());
+
+            // Update owner's thread id.
+            sync.setCurrentOwnerThread(val.getThreadId());
+
+            // Check if any threads waiting on this node need to be notified.
+            if ((incomingSignals || sync.getPermits() == 0) && !local) {
+                // Try to notify any waiting threads.
+                sync.release(0);
+            }
+
+        } finally{
+            updateLock.unlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onNodeRemoved(UUID nodeId) {
+        updateLock.lock();
+
+        try {
+            if (nodeId.equals(sync.getOwnerNode())) {
+                sync.setBroken(true);
+
+                if (!sync.failoverSafe) {
+                    sync.interruptAll();
+                }
+            }
+
+            // Try to notify any waiting threads.
+            sync.release(0);
+        }
+        finally {
+            updateLock.unlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onStop() {
+        if (sync == null) {
+            interruptAll = true;
+
+            return;
+        }
+
+        sync.setBroken(true);
+
+        sync.interruptAll();
+
+        // Try to notify any waiting threads.
+        sync.release(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock() {
+        ctx.kernalContext().gateway().readLock();
+
+        try{
+            initializeReentrantLock();
+
+            sync.lock();
+
+            sync.validate(false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lockInterruptibly() throws IgniteInterruptedException {
+        ctx.kernalContext().gateway().readLock();
+
+        try {
+            initializeReentrantLock();
+
+            sync.acquireInterruptibly(1);
+
+            sync.validate(true);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        catch (InterruptedException e) {
+            if (sync.fair)
+                sync.synchronizeQueue(true, Thread.currentThread());
+
+            throw new IgniteInterruptedException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean tryLock() {
+        ctx.kernalContext().gateway().readLock();
+
+        try{
+            initializeReentrantLock();
+
+            boolean result = sync.tryAcquire(1, false);
+
+            sync.validate(false);
+
+            return result;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean tryLock(long timeout, TimeUnit unit) throws IgniteInterruptedException {
+        ctx.kernalContext().gateway().readLock();
+
+        try{
+            initializeReentrantLock();
+
+            boolean result = sync.tryAcquireNanos(1, unit.toNanos(timeout));
+
+            sync.validate(true);
+
+            return result;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        catch (InterruptedException e) {
+            if (sync.fair)
+                sync.synchronizeQueue(true, Thread.currentThread());
+
+            throw new IgniteInterruptedException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock() {
+        ctx.kernalContext().gateway().readLock();
+
+        try{
+            initializeReentrantLock();
+
+            // Validate before release.
+            sync.validate(false);
+
+            sync.release(1);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    @NotNull @Override public Condition newCondition() {
+        throw new UnsupportedOperationException("IgniteLock does not allow creation of nameless conditions. ");
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteCondition getOrCreateCondition(String name) {
+        ctx.kernalContext().gateway().readLock();
+
+        try{
+            initializeReentrantLock();
+
+            IgniteCondition result = sync.newCondition(name);
+
+            sync.validate(false);
+
+            return result;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+        finally {
+            ctx.kernalContext().gateway().readUnlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getHoldCount() {
+        try{
+            initializeReentrantLock();
+
+            return sync.getHoldCount();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isHeldByCurrentThread() {
+        try{
+            initializeReentrantLock();
+
+            return sync.isHeldExclusively();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isLocked() {
+        try{
+            initializeReentrantLock();
+
+            return sync.isLocked();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasQueuedThreads() {
+        try{
+            initializeReentrantLock();
+
+            return sync.hasQueuedThreads();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasQueuedThread(Thread thread) {
+        try{
+            initializeReentrantLock();
+
+            return sync.isQueued(thread);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasWaiters(IgniteCondition condition) {
+        try{
+            initializeReentrantLock();
+
+            AbstractQueuedSynchronizer.ConditionObject c = sync.conditionMap.get(condition.name());
+
+            if (c == null)
+                throw new IllegalArgumentException();
+
+            return sync.hasWaiters(c);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getWaitQueueLength(IgniteCondition condition) {
+        try{
+            initializeReentrantLock();
+
+            AbstractQueuedSynchronizer.ConditionObject c = sync.conditionMap.get(condition.name());
+
+            if (c == null)
+                throw new IllegalArgumentException();
+
+            return sync.getWaitQueueLength(c);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    @Override public boolean isFailoverSafe() {
+        try{
+            initializeReentrantLock();
+
+            return sync.failoverSafe;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    @Override public boolean isFair() {
+        try{
+            initializeReentrantLock();
+
+            return sync.fair;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isBroken() {
+        try{
+            initializeReentrantLock();
+
+            return sync.isBroken();
+        }
+        catch (IgniteCheckedException e) {
+            throw U.convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheInternalKey key() {
+        return key;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removed() {
+        return rmvd;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onRemoved() {
+        return rmvd = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void needCheckNotRemoved() {
+
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeUTF(name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        stash.set(in.readUTF());
+    }
+
+    /**
+     * Reconstructs object on unmarshalling.
+     *
+     * @return Reconstructed object.
+     * @throws ObjectStreamException Thrown in case of unmarshalling error.
+     */
+    private Object readResolve() throws ObjectStreamException {
+        String name = stash.get();
+
+        assert name != null;
+
+        try {
+            IgniteLock lock = IgnitionEx.localIgnite().context().dataStructures().reentrantLock(
+                name,
+                false,
+                false,
+                false);
+
+            if (lock == null)
+                throw new IllegalStateException("Lock was not found on deserialization: " + name);
+
+            return lock;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        if (!rmvd) {
+            try {
+                boolean force = sync != null && (sync.isBroken() && !sync.failoverSafe);
+
+                ctx.kernalContext().dataStructures().removeReentrantLock(name, force);
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheLockImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
new file mode 100644
index 0000000..3feb9bf
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
@@ -0,0 +1,353 @@
+/*
+ * 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.datastructures;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.GridCacheInternal;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ *  Grid cache reentrant lock state.
+ */
+public final class GridCacheLockState implements GridCacheInternal, Externalizable, Cloneable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Count. */
+    private int cnt;
+
+    /** Owner thread local ID. */
+    private long threadId;
+
+    /** Owner node ID. */
+    private UUID id;
+
+    /** FailoverSafe flag. */
+    private boolean failoverSafe;
+
+    /** Map containing state for each condition object associated with this lock. */
+    @GridToStringInclude
+    private Map<String, LinkedList<UUID>> conditionMap;
+
+    /** Map containing unprocessed signals for condition objects that are associated with this lock. */
+    @GridToStringInclude
+    private Map<UUID, LinkedList<String>> signals;
+
+    /** Flag indicating lock fairness. */
+    private boolean fair;
+
+    /** Queue containing nodes that are waiting to acquire this lock, used to ensure fairness. */
+    @GridToStringInclude
+    private LinkedList<UUID> nodes;
+
+    /**
+     * Flag indicating that global state changed.
+     * Used in fair mode to ensure that only successful acquires and releases trigger update.
+     */
+    private boolean changed;
+
+    /**
+     * Constructor.
+     *
+     * @param cnt Initial count.
+     * @param id UUID of owning node.
+     * @param threadID ID of the current thread.
+     * @param failoverSafe true if created in failoverSafe mode.
+     * @param fair true if created in fair mode.
+     */
+    public GridCacheLockState(int cnt, UUID id, long threadID, boolean failoverSafe, boolean fair) {
+        assert cnt >= 0;
+
+        this.id = id;
+
+        this.threadId = threadID;
+
+        conditionMap = new HashMap();
+
+        signals = null;
+
+        nodes = new LinkedList<UUID>();
+
+        this.fair = fair;
+
+        this.failoverSafe = failoverSafe;
+    }
+
+    /**
+     * Empty constructor required for {@link Externalizable}.
+     */
+    public GridCacheLockState() {
+        // No-op.
+    }
+
+    /**
+     * @param cnt New count.
+     */
+    public void set(int cnt) {
+        this.cnt = cnt;
+    }
+
+    /**
+     * @return Current count.
+     */
+    public int get() {
+        return cnt;
+    }
+
+    /**
+     * @return Current owner thread ID.
+     */
+    public long getThreadId() {
+        return threadId;
+    }
+
+    /**
+     * @param threadId New thread owner ID.
+     */
+    public void setThreadId(long threadId) {
+        this.threadId = threadId;
+    }
+
+    /**
+     * @return Current owner node ID.
+     */
+    public UUID getId() {
+        return id;
+    }
+
+    /**
+     * @return New owner node ID.
+     */
+    public void setId(UUID id) {
+        this.id = id;
+    }
+
+    /**
+     * @return Failover safe flag.
+     */
+    public boolean isFailoverSafe() {
+        return failoverSafe;
+    }
+
+    /**
+     * @return Condition count.
+     */
+    public int condtionCount(){
+        return conditionMap.size();
+    }
+
+    /**
+     * @return Condition map.
+     */
+    public Map<String, LinkedList<UUID>> getConditionMap() {
+        return conditionMap;
+    }
+
+    /**
+     * @param conditionMap Condition map.
+     */
+    public void setConditionMap(Map<String, LinkedList<UUID>> conditionMap) {
+        this.conditionMap = conditionMap;
+    }
+
+    /**
+     * @return Signals.
+     */
+    public Map<UUID, LinkedList<String>> getSignals() {
+        return signals;
+    }
+
+    /**
+     * @param signals Signals.
+     */
+    public void setSignals(Map<UUID, LinkedList<String>> signals) {
+        this.signals = signals;
+    }
+
+    /**
+     * @return Nodes.
+     */
+    public LinkedList<UUID> getNodes() {
+        return nodes;
+    }
+
+    /**
+     * @param nodes Nodes.
+     */
+    public void setNodes(LinkedList<UUID> nodes) {
+        this.nodes = nodes;
+    }
+
+    /**
+     * @return Fair flag.
+     */
+    public boolean isFair() {
+        return fair;
+    }
+
+    /**
+     * @return Changed flag.
+     */
+    public boolean isChanged() {
+        return changed;
+    }
+
+    /**
+     * @param changed Changed flag.
+     */
+    public void setChanged(boolean changed) {
+        this.changed = changed;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(cnt);
+        out.writeLong(threadId);
+        U.writeUuid(out, id);
+
+        out.writeBoolean(failoverSafe);
+
+        out.writeBoolean(fair);
+
+        out.writeBoolean(changed);
+
+        out.writeBoolean(conditionMap != null);
+
+        if (conditionMap != null) {
+            out.writeInt(conditionMap.size());
+
+            for (Map.Entry<String, LinkedList<UUID>> e : conditionMap.entrySet()) {
+                U.writeString(out, e.getKey());
+
+                out.writeInt(e.getValue().size());
+
+                for (UUID uuid:e.getValue())
+                    U.writeUuid(out, uuid);
+            }
+        }
+
+        out.writeBoolean(signals != null);
+
+        if (signals != null) {
+            out.writeInt(signals.size());
+
+            for (Map.Entry<UUID, LinkedList<String>> e : signals.entrySet()) {
+                U.writeUuid(out, e.getKey());
+
+                out.writeInt(e.getValue().size());
+
+                for (String condition:e.getValue())
+                    U.writeString(out, condition);
+            }
+        }
+
+        out.writeBoolean(nodes != null);
+
+        if (nodes != null) {
+            out.writeInt(nodes.size());
+
+            for (UUID uuid: nodes)
+                U.writeUuid(out, uuid);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException {
+        cnt = in.readInt();
+        threadId = in.readLong();
+        id = U.readUuid(in);
+
+        failoverSafe = in.readBoolean();
+
+        fair = in.readBoolean();
+
+        changed = in.readBoolean();
+
+        if (in.readBoolean()) {
+            int size = in.readInt();
+
+            conditionMap = U.newLinkedHashMap(size);
+
+            for (int i = 0; i < size; i++) {
+                String key = U.readString(in);
+
+                int size1 = in.readInt();
+
+                LinkedList<UUID> list = new LinkedList();
+
+                for (int j = 0; j < size1; j++)
+                    list.add(U.readUuid(in));
+
+                conditionMap.put(key, list);
+            }
+        }
+
+        if (in.readBoolean()) {
+            assert (conditionMap != null);
+
+            int size = in.readInt();
+
+            signals = U.newLinkedHashMap(size);
+
+            for (int i = 0; i < size; i++) {
+                UUID node = U.readUuid(in);
+
+                int size1 = in.readInt();
+
+                LinkedList<String> list = new LinkedList();
+
+                for (int j = 0; j < size1; j++)
+                    list.add(U.readString(in));
+
+                signals.put(node, list);
+            }
+        }
+        else
+            signals = null;
+
+        if (in.readBoolean()) {
+            int size = in.readInt();
+
+            nodes = new LinkedList();
+
+            for (int i = 0; i < size; i++)
+                nodes.add(U.readUuid(in));
+        }
+        else
+            nodes = null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheLockState.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
index c365f9d..8f196be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
@@ -19,8 +19,10 @@ package org.apache.ignite.internal.processors.datastructures;
 
 import java.io.Externalizable;
 import java.io.IOException;
+import java.io.InvalidObjectException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.Callable;
@@ -32,7 +34,9 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgnitionEx;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
@@ -885,6 +889,35 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx, Exter
         t.set2(in.readUTF());
     }
 
+    /**
+     * Reconstructs object on unmarshalling.
+     *
+     * @return Reconstructed object.
+     * @throws ObjectStreamException Thrown in case of unmarshalling error.
+     */
+    private Object readResolve() throws ObjectStreamException {
+        try {
+            IgniteBiTuple<GridKernalContext, String> t = stash.get();
+
+            IgniteSemaphore sem = IgnitionEx.localIgnite().context().dataStructures().semaphore(
+                t.get2(),
+                0,
+                false,
+                false);
+
+            if (sem == null)
+                throw new IllegalStateException("Semaphore was not found on deserialization: " + t.get2());
+
+            return sem;
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public void close() {
         if (!rmvd) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 034c314..9ae74a7 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -1037,6 +1037,8 @@ org.apache.ignite.internal.processors.datastructures.GridCacheQueueItemKey
 org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy
 org.apache.ignite.internal.processors.datastructures.GridCacheSemaphoreImpl
 org.apache.ignite.internal.processors.datastructures.GridCacheSemaphoreState
+org.apache.ignite.internal.processors.datastructures.GridCacheLockImpl
+org.apache.ignite.internal.processors.datastructures.GridCacheLockState
 org.apache.ignite.internal.processors.datastructures.GridCacheSetHeader
 org.apache.ignite.internal.processors.datastructures.GridCacheSetHeaderKey
 org.apache.ignite.internal.processors.datastructures.GridCacheSetImpl$CollocatedItemKey

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectAtomicsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectAtomicsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectAtomicsTest.java
index 4653ce9..4622fff 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectAtomicsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectAtomicsTest.java
@@ -28,6 +28,7 @@ import org.apache.ignite.IgniteAtomicSequence;
 import org.apache.ignite.IgniteAtomicStamped;
 import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse;
 import org.apache.ignite.testframework.GridTestUtils;
@@ -774,4 +775,61 @@ public class IgniteClientReconnectAtomicsTest extends IgniteClientReconnectAbstr
         assertFalse(srvSemaphore.tryAcquire());
         assertFalse(srvSemaphore.tryAcquire());
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockReconnect() throws Exception {
+        testReentrantLockReconnect(false);
+
+        testReentrantLockReconnect(true);
+    }
+
+    private void testReentrantLockReconnect(final boolean fair) throws Exception {
+        Ignite client = grid(serverCount());
+
+        assertTrue(client.cluster().localNode().isClient());
+
+        Ignite srv = clientRouter(client);
+
+        IgniteLock clientLock = client.reentrantLock("lock1", true, fair, true);
+
+        assertEquals(false, clientLock.isLocked());
+
+        final IgniteLock srvLock = srv.reentrantLock("lock1", true, fair, true);
+
+        assertEquals(false, srvLock.isLocked());
+
+        reconnectClientNode(client, srv, new Runnable() {
+            @Override public void run() {
+                srvLock.lock();
+            }
+        });
+
+        assertTrue(srvLock.isLocked());
+        assertTrue(clientLock.isLocked());
+
+        assertEquals(1, srvLock.getHoldCount());
+
+        srvLock.lock();
+
+        assertTrue(srvLock.isLocked());
+        assertTrue(clientLock.isLocked());
+
+        assertEquals(2, srvLock.getHoldCount());
+
+        srvLock.unlock();
+
+        assertTrue(srvLock.isLocked());
+        assertTrue(clientLock.isLocked());
+
+        assertEquals(1, srvLock.getHoldCount());
+
+        srvLock.unlock();
+
+        assertFalse(srvLock.isLocked());
+        assertFalse(clientLock.isLocked());
+
+        assertEquals(0, srvLock.getHoldCount());
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractDataStructuresFailoverSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractDataStructuresFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractDataStructuresFailoverSelfTest.java
index 74023e9..6ba65ab 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractDataStructuresFailoverSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheAbstractDataStructuresFailoverSelfTest.java
@@ -33,9 +33,11 @@ import org.apache.ignite.IgniteAtomicLong;
 import org.apache.ignite.IgniteAtomicReference;
 import org.apache.ignite.IgniteAtomicSequence;
 import org.apache.ignite.IgniteAtomicStamped;
+import org.apache.ignite.IgniteCompute;
 import org.apache.ignite.IgniteCountDownLatch;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteQueue;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.cache.CacheMode;
@@ -75,10 +77,10 @@ public abstract class GridCacheAbstractDataStructuresFailoverSelfTest extends Ig
     private static final String TRANSACTIONAL_CACHE_NAME = "tx_cache";
 
     /** */
-    private static final int TOP_CHANGE_CNT = 5;
+    private static final int TOP_CHANGE_CNT = 2;
 
     /** */
-    private static final int TOP_CHANGE_THREAD_CNT = 3;
+    private static final int TOP_CHANGE_THREAD_CNT = 2;
 
     /** */
     private boolean client;
@@ -586,6 +588,208 @@ public abstract class GridCacheAbstractDataStructuresFailoverSelfTest extends Ig
     /**
      * @throws Exception If failed.
      */
+    public void testReentrantLockFailsWhenServersLeft() throws Exception {
+        testReentrantLockFailsWhenServersLeft(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFairReentrantLockFailsWhenServersLeft() throws Exception {
+        testReentrantLockFailsWhenServersLeft(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockFailsWhenServersLeft(final boolean fair) throws Exception {
+        client = true;
+
+        Ignite client = startGrid(gridCount());
+
+        Ignite server = grid(0);
+
+        // Initialize lock.
+        IgniteLock srvLock = server.reentrantLock("lock", true, fair, true);
+
+        IgniteSemaphore semaphore = server.semaphore("sync", 0, true, true);
+
+        IgniteCompute compute = client.compute().withAsync();
+
+        compute.apply(new IgniteClosure<Ignite, Object>() {
+            @Override public Object apply(Ignite ignite) {
+                final IgniteLock l = ignite.reentrantLock("lock", true, fair, true);
+
+                l.lock();
+
+                assertTrue(l.isHeldByCurrentThread());
+
+                l.unlock();
+
+                assertFalse(l.isHeldByCurrentThread());
+
+                // Signal the server to go down.
+                ignite.semaphore("sync", 0, true, true).release();
+
+                boolean isExceptionThrown = false;
+
+                try {
+                    // Wait for the server to go down.
+                    Thread.sleep(1000);
+
+                    l.lock();
+
+                    fail("Exception must be thrown.");
+                }
+                catch (InterruptedException e) {
+                    fail("Interrupted exception not expected here.");
+                }
+                catch (IgniteException e) {
+                    isExceptionThrown = true;
+                }
+                finally {
+                    assertTrue(isExceptionThrown);
+
+                    assertFalse(l.isHeldByCurrentThread());
+                }
+                return null;
+            }
+        }, client);
+
+        // Wait for the lock on client to be acquired then released.
+        semaphore.acquire();
+
+        for (int i = 0; i < gridCount(); i++)
+            stopGrid(i);
+
+        compute.future().get();
+
+        client.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockConstantTopologyChangeFailoverSafe() throws Exception {
+        doTestReentrantLock(new ConstantTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockConstantMultipleTopologyChangeFailoverSafe() throws Exception {
+        doTestReentrantLock(multipleTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockConstantTopologyChangeNonFailoverSafe() throws Exception {
+        doTestReentrantLock(new ConstantTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockConstantMultipleTopologyChangeNonFailoverSafe() throws Exception {
+        doTestReentrantLock(multipleTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFairReentrantLockConstantTopologyChangeFailoverSafe() throws Exception {
+        doTestReentrantLock(new ConstantTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFairReentrantLockConstantMultipleTopologyChangeFailoverSafe() throws Exception {
+        doTestReentrantLock(multipleTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFairReentrantLockConstantTopologyChangeNonFailoverSafe() throws Exception {
+        doTestReentrantLock(new ConstantTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFairReentrantLockConstantMultipleTopologyChangeNonFailoverSafe() throws Exception {
+        doTestReentrantLock(multipleTopologyChangeWorker(TOP_CHANGE_THREAD_CNT), false, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void doTestReentrantLock(ConstantTopologyChangeWorker topWorker, final boolean failoverSafe, final boolean fair) throws Exception {
+        try (IgniteLock lock = grid(0).reentrantLock(STRUCTURE_NAME, failoverSafe, fair, true)) {
+            IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {
+                @Override public Object apply(Ignite ignite) {
+                    final IgniteLock l = ignite.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false);
+
+                    final AtomicBoolean done = new AtomicBoolean(false);
+
+                    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
+                        @Override public Void call() throws Exception {
+                            try{
+                                l.lock();
+                            }
+                            finally {
+                                done.set(true);
+                            }
+
+                            return null;
+                        }
+                    });
+
+                    // Wait until l.lock() has been called.
+                    while(!l.hasQueuedThreads() && !done.get()){
+                        // No-op.
+                    }
+
+                    return null;
+                }
+            });
+
+            while (!fut.isDone()) {
+                while (true) {
+                    try {
+                        lock.lock();
+                    }
+                    catch (IgniteException e) {
+                        // Exception may happen in non-failoversafe mode.
+                        if (failoverSafe)
+                            throw e;
+                    }
+                    finally {
+                        // Broken lock cannot be used in non-failoversafe mode.
+                        if(!lock.isBroken() || failoverSafe) {
+                            assertTrue(lock.isHeldByCurrentThread());
+
+                            lock.unlock();
+
+                            assertFalse(lock.isHeldByCurrentThread());
+                        }
+                        break;
+                    }
+                }
+            }
+
+            fut.get();
+
+            for (Ignite g : G.allGrids())
+                assertFalse(g.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false).isHeldByCurrentThread());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testCountDownLatchConstantTopologyChange() throws Exception {
         doTestCountDownLatch(new ConstantTopologyChangeWorker(TOP_CHANGE_THREAD_CNT));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteClientDataStructuresAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteClientDataStructuresAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteClientDataStructuresAbstractTest.java
index 34e7080..5929d42 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteClientDataStructuresAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteClientDataStructuresAbstractTest.java
@@ -18,11 +18,13 @@
 package org.apache.ignite.internal.processors.cache.datastructures;
 
 import java.util.concurrent.Callable;
+import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteAtomicLong;
 import org.apache.ignite.IgniteAtomicSequence;
 import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteQueue;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteSet;
@@ -327,6 +329,74 @@ public abstract class IgniteClientDataStructuresAbstractTest extends GridCommonA
     /**
      * @throws Exception If failed.
      */
+    public void testReentrantLock() throws Exception {
+        Ignite clientNode = clientIgnite();
+        Ignite srvNode = serverNode();
+
+        testReentrantLock(clientNode, srvNode);
+        testReentrantLock(srvNode, clientNode);
+    }
+
+    /**
+     * @param creator Creator node.
+     * @param other Other node.
+     * @throws Exception If failed.
+     */
+    private void testReentrantLock(Ignite creator, final Ignite other) throws Exception {
+        assertNull(creator.reentrantLock("lock1", true, false, false));
+        assertNull(other.reentrantLock("lock1", true, false, false));
+
+        try (IgniteLock lock = creator.reentrantLock("lock1", true, false, true)) {
+            assertNotNull(lock);
+
+            assertFalse(lock.isLocked());
+
+            final Semaphore semaphore = new Semaphore(0);
+
+            IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    IgniteLock lock0 = other.reentrantLock("lock1", true, false, false);
+
+                    lock0.lock();
+
+                    assertTrue(lock0.isLocked());
+
+                    semaphore.release();
+
+                    U.sleep(1000);
+
+                    log.info("Release reentrant lock.");
+
+                    lock0.unlock();
+
+                    return null;
+                }
+            });
+
+            semaphore.acquire();
+
+            log.info("Try acquire lock.");
+
+            assertTrue(lock.tryLock(5000, TimeUnit.MILLISECONDS));
+
+            log.info("Finished wait.");
+
+            fut.get();
+
+            assertTrue(lock.isLocked());
+
+            lock.unlock();
+
+            assertFalse(lock.isLocked());
+        }
+
+        assertNull(creator.reentrantLock("lock1", true, false, false));
+        assertNull(other.reentrantLock("lock1", true, false, false));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testQueue() throws Exception {
         Ignite clientNode = clientIgnite();
         Ignite srvNode = serverNode();

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
index e88c97b..a8e0095 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
@@ -31,6 +31,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCountDownLatch;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteSet;
 import org.apache.ignite.cache.CacheAtomicityMode;
@@ -241,7 +242,7 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
     private void testUniqueName(final boolean singleGrid) throws Exception {
         final String name = IgniteUuid.randomUuid().toString();
 
-        final int DS_TYPES = 8;
+        final int DS_TYPES = 9;
 
         final int THREADS = DS_TYPES * 3;
 
@@ -322,6 +323,13 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
                                     res = ignite.semaphore(name, 0, false, true);
 
                                     break;
+
+                                case 8:
+                                    log.info("Create atomic reentrant lock, grid: " + ignite.name());
+
+                                    res = ignite.reentrantLock(name, true, true, true);
+
+                                    break;
                                 default:
                                     fail();
 
@@ -361,7 +369,8 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
                         res instanceof IgniteCountDownLatch ||
                         res instanceof IgniteQueue ||
                         res instanceof IgniteSet ||
-                        res instanceof IgniteSemaphore);
+                        res instanceof IgniteSemaphore ||
+                        res instanceof IgniteLock);
 
                 log.info("Data structure created: " + dataStructure);
 


[31/50] [abbrv] ignite git commit: IGNITE-2981: CPP: Added "EnableSharedFromThis" entity. This closes #636.

Posted by sh...@apache.org.
IGNITE-2981: CPP: Added "EnableSharedFromThis" entity. This closes #636.


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

Branch: refs/heads/ignite-2788
Commit: bb5cd16ac49f5804dc870a0aee1b8521e30070bb
Parents: fdb2f64
Author: Igor Sapego <is...@gridgain.com>
Authored: Wed Apr 27 11:34:44 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../common/include/ignite/common/concurrent.h   | 176 ++++++++++++++++---
 modules/platforms/cpp/common/src/concurrent.cpp |  13 +-
 .../cpp/core-test/src/concurrent_test.cpp       |  93 ++++++++++
 3 files changed, 253 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/bb5cd16a/modules/platforms/cpp/common/include/ignite/common/concurrent.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/include/ignite/common/concurrent.h b/modules/platforms/cpp/common/include/ignite/common/concurrent.h
index a4cc3f7..1c84cf5 100644
--- a/modules/platforms/cpp/common/include/ignite/common/concurrent.h
+++ b/modules/platforms/cpp/common/include/ignite/common/concurrent.h
@@ -18,6 +18,8 @@
 #ifndef _IGNITE_COMMON_CONCURRENT
 #define _IGNITE_COMMON_CONCURRENT
 
+#include <cassert>
+
 #include "ignite/common/concurrent_os.h"
 
 namespace ignite
@@ -43,12 +45,13 @@ namespace ignite
             class IGNITE_IMPORT_EXPORT SharedPointerImpl
             {
             public:
+                typedef void(*DeleterType)(void*);
                 /**
                  * Constructor.
                  *
                  * @param ptr Raw pointer.
                  */
-                SharedPointerImpl(void* ptr);
+                SharedPointerImpl(void* ptr, DeleterType deleter);
 
                 /**
                  * Get raw pointer.
@@ -65,6 +68,13 @@ namespace ignite
                 const void* Pointer() const;
 
                 /**
+                 * Get raw pointer.
+                 *
+                 * @return Raw pointer.
+                 */
+                DeleterType Deleter();
+
+                /**
                  * Increment usage counter.
                  */
                 void Increment();
@@ -79,12 +89,29 @@ namespace ignite
                 /** Raw pointer. */
                 void* ptr;
 
+                /** Deleter. */
+                DeleterType deleter;
+
                 /** Reference count. */
                 int32_t refCnt;
 
                 IGNITE_NO_COPY_ASSIGNMENT(SharedPointerImpl)
             };
 
+            /* Forward declaration. */
+            template<typename T>
+            class IGNITE_IMPORT_EXPORT EnableSharedFromThis;
+
+            /* Forward declaration. */
+            template<typename T>
+            inline void ImplEnableShared(EnableSharedFromThis<T>* some, SharedPointerImpl* impl);
+
+            // Do nothing if the instance is not derived from EnableSharedFromThis.
+            inline void ImplEnableShared(const volatile void*, const volatile void*)
+            {
+                // No-op.
+            }
+
             /**
              * Shared pointer.
              */
@@ -92,10 +119,12 @@ namespace ignite
             class IGNITE_IMPORT_EXPORT SharedPointer
             {
             public:
+                friend class EnableSharedFromThis<T>;
+
                 /**
                  * Constructor.
                  */
-                SharedPointer() : impl(NULL), deleter(NULL)
+                SharedPointer() : impl(0)
                 {
                     // No-op.
                 }
@@ -109,14 +138,11 @@ namespace ignite
                 {
                     if (ptr)
                     {
-                        impl = new SharedPointerImpl(ptr);
-                        deleter = SharedPointerDefaultDeleter;
+                        impl = new SharedPointerImpl(ptr, reinterpret_cast<SharedPointerImpl::DeleterType>(&SharedPointerDefaultDeleter<T>));
+                        ImplEnableShared(ptr, impl);
                     }
                     else
-                    {
-                        impl = NULL;
-                        deleter = NULL;
-                    }
+                        impl = 0;
                 }
 
                 /**
@@ -129,14 +155,11 @@ namespace ignite
                 {
                     if (ptr)
                     {
-                        this->impl = new SharedPointerImpl(ptr);
-                        this->deleter = deleter;
+                        impl = new SharedPointerImpl(ptr, reinterpret_cast<SharedPointerImpl::DeleterType>(deleter));
+                        ImplEnableShared(ptr, impl);
                     }
                     else
-                    {
-                        this->impl = NULL;
-                        this->deleter = NULL;
-                    }
+                        impl = 0;
                 }
 
                 /**
@@ -147,7 +170,6 @@ namespace ignite
                 SharedPointer(const SharedPointer& other)
                 {
                     impl = other.impl;
-                    deleter = other.deleter;
 
                     if (impl)
                         impl->Increment();
@@ -162,18 +184,9 @@ namespace ignite
                 {
                     if (this != &other)
                     {
-                        // 1. Create new instance.
                         SharedPointer tmp(other);
 
-                        // 2. Swap with temp.
-                        SharedPointerImpl* impl0 = impl;
-                        void(*deleter0)(T*) = deleter;
-
-                        impl = tmp.impl;
-                        deleter = tmp.deleter;
-
-                        tmp.impl = impl0;
-                        tmp.deleter = deleter0;
+                        std::swap(impl, tmp.impl);
                     }
 
                     return *this;
@@ -188,9 +201,11 @@ namespace ignite
                     {
                         T* ptr = Get();
 
-                        delete impl;
+                        void(*deleter)(T*) = reinterpret_cast<void(*)(T*)>(impl->Deleter());
 
                         deleter(ptr);
+
+                        delete impl;
                     }
                 }
 
@@ -226,10 +241,115 @@ namespace ignite
             private:
                 /** Implementation. */
                 SharedPointerImpl* impl;
+            };
+
+            /**
+             * The class provides functionality that allows objects of derived
+             * classes to create instances of shared_ptr pointing to themselves
+             * and sharing ownership with existing shared_ptr objects.
+             */
+            template<typename T>
+            class IGNITE_IMPORT_EXPORT EnableSharedFromThis
+            {
+            public:
+                /**
+                 * Default constructor.
+                 */
+                EnableSharedFromThis() : self(0)
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Copy constructor.
+                 */
+                EnableSharedFromThis(const EnableSharedFromThis&) : self(0)
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Assignment operator.
+                 */
+                EnableSharedFromThis& operator=(const EnableSharedFromThis&)
+                {
+                    return *this;
+                }
+
+                /**
+                 * Destructor.
+                 */
+                virtual ~EnableSharedFromThis()
+                {
+                    // No-op.
+                }
+
+                /**
+                 * Create shared pointer for this instance.
+                 *
+                 * Can only be called on already shared object.
+                 * @return New shared pointer instance.
+                 */
+                SharedPointer<T> SharedFromThis()
+                {
+                    assert(self != 0);
+
+                    SharedPointer<T> ptr;
+
+                    ptr.impl = self;
+
+                    self->Increment();
+
+                    return ptr;
+                }
+
+            private:
+                template<typename T0>
+                friend void ImplEnableShared(EnableSharedFromThis<T0>*, SharedPointerImpl*);
+
+                /** Shared pointer base. */
+                SharedPointerImpl* self;
+            };
 
-                /** Delete function. */
-                void(*deleter)(T*);
+            // Implementation for instances derived from EnableSharedFromThis.
+            template<typename T>
+            inline void ImplEnableShared(EnableSharedFromThis<T>* some, SharedPointerImpl* impl)
+            {
+                if (some)
+                    some->self = impl;
+            }
+
+            /**
+             * Lock guard.
+             */
+            template<typename T>
+            class LockGuard
+            {
+            public:
+                /**
+                 * Constructor.
+                 *
+                 * @param lock Lockable object.
+                 */
+                LockGuard(T& lock) :
+                    lock(lock)
+                {
+                    lock.Enter();
+                }
+
+                /**
+                 * Destructor.
+                 */
+                ~LockGuard()
+                {
+                    lock.Leave();
+                }
+
+            private:
+                T& lock;
             };
+
+            typedef LockGuard<CriticalSection> CsLockGuard;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/bb5cd16a/modules/platforms/cpp/common/src/concurrent.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/src/concurrent.cpp b/modules/platforms/cpp/common/src/concurrent.cpp
index 3f85b65..5b62387 100644
--- a/modules/platforms/cpp/common/src/concurrent.cpp
+++ b/modules/platforms/cpp/common/src/concurrent.cpp
@@ -70,7 +70,8 @@ namespace ignite
                 }
             }
 
-            SharedPointerImpl::SharedPointerImpl(void* ptr) : ptr(ptr), refCnt(1)
+            SharedPointerImpl::SharedPointerImpl(void* ptr, DeleterType deleter) :
+                ptr(ptr), deleter(deleter), refCnt(1)
             {
                 Memory::Fence();
             }
@@ -80,6 +81,16 @@ namespace ignite
                 return ptr;
             }
 
+            const void* SharedPointerImpl::Pointer() const
+            {
+                return ptr;
+            }
+
+            SharedPointerImpl::DeleterType SharedPointerImpl::Deleter()
+            {
+                return deleter;
+            }
+
             void SharedPointerImpl::Increment()
             {
                 Atomics::IncrementAndGet32(&refCnt);

http://git-wip-us.apache.org/repos/asf/ignite/blob/bb5cd16a/modules/platforms/cpp/core-test/src/concurrent_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core-test/src/concurrent_test.cpp b/modules/platforms/cpp/core-test/src/concurrent_test.cpp
index 2d89b7a..173973d 100644
--- a/modules/platforms/cpp/core-test/src/concurrent_test.cpp
+++ b/modules/platforms/cpp/core-test/src/concurrent_test.cpp
@@ -183,4 +183,97 @@ BOOST_AUTO_TEST_CASE(TestSharedPointer)
     delete target;    
 }
 
+struct SharedPointerTargetFromThis : public EnableSharedFromThis<SharedPointerTargetFromThis>
+{
+    bool& deleted;
+
+    SharedPointerTargetFromThis(bool& deleted) : deleted(deleted)
+    {
+        deleted = false;
+    }
+};
+
+void DeleteSharedPointerTarget(SharedPointerTargetFromThis* ptr)
+{
+    ptr->deleted = true;
+    delete ptr;
+}
+
+BOOST_AUTO_TEST_CASE(TestEnableSharedFromThis)
+{
+    typedef SharedPointerTargetFromThis TestT;
+
+    bool deleted;
+
+    // 1. Test the simple scenario.
+    TestT* target = new TestT(deleted);
+    BOOST_CHECK(!deleted);
+
+    SharedPointer<TestT>* ptr1 = new SharedPointer<TestT>(target, DeleteSharedPointerTarget);
+    BOOST_CHECK(!deleted);
+
+    delete ptr1;
+    BOOST_CHECK(deleted);
+
+    // 2. Test copy ctor.
+    target = new TestT(deleted);
+    BOOST_CHECK(!deleted);
+
+    ptr1 = new SharedPointer<TestT>(target, DeleteSharedPointerTarget);
+    BOOST_CHECK(!deleted);
+
+    SharedPointer<TestT>* ptr2 = new SharedPointer<TestT>(*ptr1);
+    BOOST_CHECK(!deleted);
+
+    delete ptr1;
+    BOOST_CHECK(!deleted);
+
+    delete ptr2;
+    BOOST_CHECK(deleted);
+
+    // 3. Test assignment logic.
+    target = new TestT(deleted);
+    BOOST_CHECK(!deleted);
+
+    ptr1 = new SharedPointer<TestT>(target, DeleteSharedPointerTarget);
+    BOOST_CHECK(!deleted);
+
+    SharedPointer<TestT> ptr3 = *ptr1;
+    BOOST_CHECK(!deleted);
+
+    delete ptr1;
+    BOOST_CHECK(!deleted);
+
+    ptr3 = SharedPointer<TestT>();
+    BOOST_CHECK(deleted);
+
+    // 4. Test self-assignment.
+    target = new TestT(deleted);
+    BOOST_CHECK(!deleted);
+
+    ptr1 = new SharedPointer<TestT>(target, DeleteSharedPointerTarget);
+
+    *ptr1 = *ptr1;
+
+    delete ptr1;
+
+    BOOST_CHECK(deleted);
+
+    // 5. Test shared from this
+    target = new TestT(deleted);
+    BOOST_CHECK(!deleted);
+
+    ptr1 = new SharedPointer<TestT>(target, DeleteSharedPointerTarget);
+    BOOST_CHECK(!deleted);
+
+    ptr3 = target->SharedFromThis();
+    BOOST_CHECK(!deleted);
+
+    delete ptr1;
+    BOOST_CHECK(!deleted);
+
+    ptr3 = SharedPointer<TestT>();
+    BOOST_CHECK(deleted);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file


[11/50] [abbrv] ignite git commit: IGNITE-3028 Implemented generation of fields aliases with database names in Schema Import Utility.

Posted by sh...@apache.org.
IGNITE-3028 Implemented generation of fields aliases with database names in Schema Import Utility.


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

Branch: refs/heads/ignite-2788
Commit: b6748651189f2226bcaf8084ec9671288b1b1f74
Parents: fd636e9
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Fri Apr 22 16:08:46 2016 +0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../ignite/schema/generator/CodeGenerator.java  | 26 ++++++++++-
 .../ignite/schema/generator/XmlGenerator.java   | 45 +++++++++++++++++---
 .../schema/parser/DatabaseMetadataParser.java   |  6 ++-
 .../ignite/schema/ui/SchemaImportApp.java       | 30 +++++++++----
 .../schema/test/AbstractSchemaImportTest.java   | 10 +++--
 .../schema/test/generator/XmlGeneratorTest.java |  4 +-
 .../apache/ignite/schema/test/model/Objects.txt | 31 +++++++++++++-
 .../ignite/schema/test/model/Primitives.txt     | 31 +++++++++++++-
 .../org/apache/ignite/schema/test/model/Tst.txt | 31 +++++++++++++-
 .../schema/test/model/ignite-type-metadata.xml  | 42 ++++++++++++++++++
 .../test/parser/DbMetadataParserTest.java       |  2 +-
 11 files changed, 232 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
index 68519d6..3ab0f4e 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/CodeGenerator.java
@@ -561,12 +561,13 @@ public class CodeGenerator {
      * @param pojos POJO descriptors.
      * @param pkg Types package.
      * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param generateAliases {@code true} if aliases should be generated for query fields.
      * @param outFolder Output folder.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      * @throws IOException If generation failed.
      */
     public static void snippet(Collection<PojoDescriptor> pojos, String pkg, boolean includeKeys,
-        String outFolder, ConfirmCallable askOverwrite) throws IOException {
+        boolean generateAliases, String outFolder, ConfirmCallable askOverwrite) throws IOException {
         File pkgFolder = new File(outFolder, pkg.replace('.', File.separatorChar));
 
         File cacheCfg = new File(pkgFolder, "CacheConfig.java");
@@ -663,6 +664,29 @@ public class CodeGenerator {
             add2(src, "qryEntity.setFields(fields);");
             add0(src, "");
 
+            // Aliases.
+            if (generateAliases) {
+                Collection<PojoField> aliases = new ArrayList<>();
+
+                for (PojoField field : pojo.fields()) {
+                    if (!field.javaName().equalsIgnoreCase(field.dbName()))
+                        aliases.add(field);
+                }
+
+                if (!aliases.isEmpty()) {
+                    add2(src, "// Aliases for fields.");
+                    add2(src, "LinkedHashMap<String, String> aliases = new LinkedHashMap<>();");
+                    add0(src, "");
+
+                    for (PojoField alias : aliases)
+                        add2(src, "aliases.put(\"" + alias.javaName() + "\", \"" + alias.dbName() + "\");");
+
+                    add0(src, "");
+                    add2(src, "qryEntity.setAliases(aliases);");
+                    add0(src, "");
+                }
+            }
+
             // Indexes.
             Collection<QueryIndex> idxs = pojo.indexes();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
index a1665ae..bb5a0cb 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/generator/XmlGenerator.java
@@ -209,6 +209,31 @@ public class XmlGenerator {
     }
 
     /**
+     * Add query field aliases to xml document.
+     *
+     * @param doc XML document.
+     * @param parent Parent XML node.
+     * @param fields Map with fields.
+     */
+    private static void addQueryFieldAliases(Document doc, Node parent, Collection<PojoField> fields) {
+        Collection<PojoField> aliases = new ArrayList<>();
+
+        for (PojoField field : fields) {
+            if (!field.javaName().equalsIgnoreCase(field.dbName()))
+                aliases.add(field);
+        }
+
+        if (!aliases.isEmpty()) {
+            Element prop = addProperty(doc, parent, "aliases", null);
+
+            Element map = addElement(doc, prop, "util:map", "map-class", "java.util.LinkedHashMap");
+
+            for (PojoField alias : aliases)
+                addElement(doc, map, "entry", "key", alias.javaName(), "value", alias.dbName());
+        }
+    }
+
+    /**
      * Add indexes to xml document.
      *
      * @param doc XML document.
@@ -298,8 +323,9 @@ public class XmlGenerator {
      * @param parent Parent XML node.
      * @param pkg Package fo types.
      * @param pojo POJO descriptor.
+     * @param generateAliases {@code true} if aliases should be generated for query fields.
      */
-    private static void addQueryEntity(Document doc, Node parent, String pkg, PojoDescriptor pojo) {
+    private static void addQueryEntity(Document doc, Node parent, String pkg, PojoDescriptor pojo, boolean generateAliases) {
         Element bean = addBean(doc, parent, QueryEntity.class);
 
         addProperty(doc, bean, "keyType", pkg + "." + pojo.keyClassName());
@@ -310,6 +336,9 @@ public class XmlGenerator {
 
         addQueryFields(doc, bean, fields);
 
+        if (generateAliases)
+            addQueryFieldAliases(doc, bean, fields);
+
         addQueryIndexes(doc, bean, fields, pojo.indexes());
     }
 
@@ -318,12 +347,14 @@ public class XmlGenerator {
      *
      * @param pkg Package fo types.
      * @param pojo POJO descriptor.
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param generateAliases {@code true} if aliases should be generated for query fields.
      * @param out File to output result.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      */
-    public static void generate(String pkg, PojoDescriptor pojo, boolean includeKeys, File out,
+    public static void generate(String pkg, PojoDescriptor pojo, boolean includeKeys, boolean generateAliases, File out,
         ConfirmCallable askOverwrite) {
-        generate(pkg, Collections.singleton(pojo), includeKeys, out, askOverwrite);
+        generate(pkg, Collections.singleton(pojo), includeKeys, generateAliases, out, askOverwrite);
     }
 
     /**
@@ -331,11 +362,13 @@ public class XmlGenerator {
      *
      * @param pkg Package fo types.
      * @param pojos POJO descriptors.
+     * @param includeKeys {@code true} if key fields should be included into value class.
+     * @param generateAliases {@code true} if aliases should be generated for query fields.
      * @param out File to output result.
      * @param askOverwrite Callback to ask user to confirm file overwrite.
      */
-    public static void generate(String pkg, Collection<PojoDescriptor> pojos, boolean includeKeys, File out,
-        ConfirmCallable askOverwrite) {
+    public static void generate(String pkg, Collection<PojoDescriptor> pojos, boolean includeKeys,
+        boolean generateAliases, File out, ConfirmCallable askOverwrite) {
 
         File outFolder = out.getParentFile();
 
@@ -383,7 +416,7 @@ public class XmlGenerator {
                 addJdbcPojoStoreFactory(doc, typesItemsElem, pkg, pojo, includeKeys);
 
             for (PojoDescriptor pojo : pojos)
-                addQueryEntity(doc, beans, pkg, pojo);
+                addQueryEntity(doc, beans, pkg, pojo, generateAliases);
 
             TransformerFactory transformerFactory = TransformerFactory.newInstance();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
index b68f90d..c4490ef 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
@@ -128,8 +128,10 @@ public class DatabaseMetadataParser {
 
         List<PojoDescriptor> res = new ArrayList<>();
 
-        for (String schema : parents.keySet()) {
-            PojoDescriptor parent = parents.get(schema);
+        for (Map.Entry<String, PojoDescriptor> item : parents.entrySet()) {
+            String schema = item.getKey();
+            PojoDescriptor parent = item.getValue();
+
             Collection<PojoDescriptor> children = childrens.get(schema);
 
             if (!children.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
index 98ac357..36363dd 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
@@ -222,6 +222,9 @@ public class SchemaImportApp extends Application {
     private static final String PREF_POJO_CONSTRUCTOR = "pojo.constructor";
 
     /** */
+    private static final String PREF_GENERATE_ALIASES = "sql.aliases";
+
+    /** */
     private static final String PREF_XML_SINGLE = "xml.single";
 
     /** */
@@ -305,6 +308,9 @@ public class SchemaImportApp extends Application {
     private CheckBox pojoConstructorCh;
 
     /** */
+    private CheckBox generateAliasesCh;
+
+    /** */
     private CheckBox pojoIncludeKeysCh;
 
     /** */
@@ -604,9 +610,11 @@ public class SchemaImportApp extends Application {
 
         final File destFolder = new File(outFolder);
 
+        final boolean includeKeys = pojoIncludeKeysCh.isSelected();
+
         final boolean constructor = pojoConstructorCh.isSelected();
 
-        final boolean includeKeys = pojoIncludeKeysCh.isSelected();
+        final boolean generateAliases = generateAliasesCh.isSelected();
 
         final boolean singleXml = xmlSingleFileCh.isSelected();
 
@@ -656,16 +664,17 @@ public class SchemaImportApp extends Application {
 
                 for (PojoDescriptor pojo : all) {
                     if (!singleXml)
-                        XmlGenerator.generate(pkg, pojo, includeKeys, new File(destFolder, pojo.table() + ".xml"),
-                            askOverwrite);
+                        XmlGenerator.generate(pkg, pojo, includeKeys, generateAliases,
+                            new File(destFolder, pojo.table() + ".xml"), askOverwrite);
 
                     CodeGenerator.pojos(pojo, outFolder, pkg, constructor, includeKeys, askOverwrite);
                 }
 
                 if (singleXml)
-                    XmlGenerator.generate(pkg, all, includeKeys, new File(outFolder, "ignite-type-metadata.xml"), askOverwrite);
+                    XmlGenerator.generate(pkg, all, includeKeys, generateAliases,
+                        new File(outFolder, "ignite-type-metadata.xml"), askOverwrite);
 
-                CodeGenerator.snippet(all, pkg, includeKeys, outFolder, askOverwrite);
+                CodeGenerator.snippet(all, pkg, includeKeys, generateAliases, outFolder, askOverwrite);
 
                 perceptualDelay(started);
 
@@ -778,7 +787,7 @@ public class SchemaImportApp extends Application {
                     String p1 = part1[idx];
                     String p2 = part2[idx];
 
-                    int cmp = p1.matches("\\d+") && p2.matches("\\d+") ? new Integer(p1).compareTo(new Integer(p2)) :
+                    int cmp = p1.matches("\\d+") && p2.matches("\\d+") ? Integer.valueOf(p1).compareTo(Integer.valueOf(p2)) :
                             part1[idx].compareTo(part2[idx]);
 
                     if (cmp != 0)
@@ -796,7 +805,7 @@ public class SchemaImportApp extends Application {
                     while (idx < parts.length) {
                         String p = parts[idx];
 
-                        int cmp = p.matches("\\d+") ? new Integer(p).compareTo(0) : 1;
+                        int cmp = p.matches("\\d+") ? Integer.valueOf(p).compareTo(0) : 1;
 
                         if (cmp != 0) return left ? cmp : -cmp;
 
@@ -1228,7 +1237,7 @@ public class SchemaImportApp extends Application {
         genPnl.addColumn(35, 35, 35, Priority.NEVER);
 
         genPnl.addRow(100, 100, Double.MAX_VALUE, Priority.ALWAYS);
-        genPnl.addRows(7);
+        genPnl.addRows(8);
 
         TableColumn<PojoDescriptor, Boolean> useCol = customColumn("Schema / Table", "use",
             "If checked then this table will be used for XML and POJOs generation", PojoDescriptorCell.cellFactory());
@@ -1343,6 +1352,9 @@ public class SchemaImportApp extends Application {
         pojoConstructorCh = genPnl.add(checkBox("Generate constructors for POJOs",
             "If selected then generate empty and full constructors for POJOs", false), 3);
 
+        generateAliasesCh = genPnl.add(checkBox("Generate aliases for SQL fields",
+            "If selected then generate aliases for SQL fields with db names", true), 3);
+
         xmlSingleFileCh = genPnl.add(checkBox("Write all configurations to a single XML file",
             "If selected then all configurations will be saved into the file 'ignite-type-metadata.xml'", true), 3);
 
@@ -1836,6 +1848,7 @@ public class SchemaImportApp extends Application {
         pkgTf.setText(getStringProp(PREF_POJO_PACKAGE, "org.apache.ignite"));
         pojoIncludeKeysCh.setSelected(getBoolProp(PREF_POJO_INCLUDE, true));
         pojoConstructorCh.setSelected(getBoolProp(PREF_POJO_CONSTRUCTOR, false));
+        generateAliasesCh.setSelected(getBoolProp(PREF_GENERATE_ALIASES, true));
 
         xmlSingleFileCh.setSelected(getBoolProp(PREF_XML_SINGLE, true));
 
@@ -1901,6 +1914,7 @@ public class SchemaImportApp extends Application {
         setStringProp(PREF_POJO_PACKAGE, pkgTf.getText());
         setBoolProp(PREF_POJO_INCLUDE, pojoIncludeKeysCh.isSelected());
         setBoolProp(PREF_POJO_CONSTRUCTOR, pojoConstructorCh.isSelected());
+        setBoolProp(PREF_GENERATE_ALIASES, generateAliasesCh.isSelected());
 
         setBoolProp(PREF_XML_SINGLE, xmlSingleFileCh.isSelected());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/AbstractSchemaImportTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/AbstractSchemaImportTest.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/AbstractSchemaImportTest.java
index 97f0f87..d4534be 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/AbstractSchemaImportTest.java
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/AbstractSchemaImportTest.java
@@ -79,7 +79,8 @@ public abstract class AbstractSchemaImportTest extends TestCase {
             " dateCol DATE," +
             " timeCol TIME," +
             " tsCol TIMESTAMP, " +
-            " arrCol BINARY(10))");
+            " arrCol BINARY(10)," +
+            " FIELD_WITH_ALIAS VARCHAR(10))");
 
         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS OBJECTS (pk INTEGER PRIMARY KEY, " +
             " boolCol BOOLEAN," +
@@ -95,7 +96,8 @@ public abstract class AbstractSchemaImportTest extends TestCase {
             " dateCol DATE," +
             " timeCol TIME," +
             " tsCol TIMESTAMP," +
-            " arrCol BINARY(10))");
+            " arrCol BINARY(10)," +
+            " FIELD_WITH_ALIAS VARCHAR(10))");
 
         stmt.executeUpdate("CREATE SCHEMA IF NOT EXISTS TESTSCHEMA");
 
@@ -113,7 +115,8 @@ public abstract class AbstractSchemaImportTest extends TestCase {
             " dateCol DATE," +
             " timeCol TIME," +
             " tsCol TIMESTAMP, " +
-            " arrCol BINARY(10))");
+            " arrCol BINARY(10)," +
+            " FIELD_WITH_ALIAS VARCHAR(10))");
 
         conn.commit();
 
@@ -144,6 +147,7 @@ public abstract class AbstractSchemaImportTest extends TestCase {
 
                     if (!baseLine.equals(generatedLine) && !baseLine.contains(excludePtrn)
                             && !generatedLine.contains(excludePtrn)) {
+                        System.out.println("Generated file: " + generated.toString());
                         System.out.println("Expected: " + baseLine);
                         System.out.println("Generated: " + generatedLine);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/XmlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/XmlGeneratorTest.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/XmlGeneratorTest.java
index 9a1356b..2ed36e9 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/XmlGeneratorTest.java
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/generator/XmlGeneratorTest.java
@@ -40,11 +40,11 @@ public class XmlGeneratorTest extends AbstractSchemaImportTest {
 
         String fileName = "ignite-type-metadata.xml";
 
-        XmlGenerator.generate("org.apache.ignite.schema.test.model", all, true, new File(OUT_DIR_PATH, fileName),
+        XmlGenerator.generate("org.apache.ignite.schema.test.model", all, true, true, new File(OUT_DIR_PATH, fileName),
             askOverwrite);
 
         assertTrue("Generated XML file content is differ from expected one",
             compareFilesInt(getClass().getResourceAsStream("/org/apache/ignite/schema/test/model/" + fileName),
                 new File(OUT_DIR_PATH + "/" + fileName), "XML generated by Apache Ignite Schema Import utility"));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Objects.txt
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Objects.txt b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Objects.txt
index c448ab5..380191b 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Objects.txt
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Objects.txt
@@ -73,6 +73,9 @@ public class Objects implements Serializable {
     /** Value for arrcol. */
     private Object arrcol;
 
+    /** Value for fieldWithAlias. */
+    private String fieldWithAlias;
+
     /**
      * Empty constructor.
      */
@@ -98,7 +101,8 @@ public class Objects implements Serializable {
         java.sql.Date datecol,
         java.sql.Time timecol,
         java.sql.Timestamp tscol,
-        Object arrcol
+        Object arrcol,
+        String fieldWithAlias
     ) {
         this.pk = pk;
         this.boolcol = boolcol;
@@ -115,6 +119,7 @@ public class Objects implements Serializable {
         this.timecol = timecol;
         this.tscol = tscol;
         this.arrcol = arrcol;
+        this.fieldWithAlias = fieldWithAlias;
     }
 
     /**
@@ -387,6 +392,24 @@ public class Objects implements Serializable {
         this.arrcol = arrcol;
     }
 
+    /**
+     * Gets fieldWithAlias.
+     *
+     * @return Value for fieldWithAlias.
+     */
+    public String getFieldWithAlias() {
+        return fieldWithAlias;
+    }
+
+    /**
+     * Sets fieldWithAlias.
+     *
+     * @param fieldWithAlias New value for fieldWithAlias.
+     */
+    public void setFieldWithAlias(String fieldWithAlias) {
+        this.fieldWithAlias = fieldWithAlias;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
@@ -442,6 +465,9 @@ public class Objects implements Serializable {
         if (arrcol != null ? !arrcol.equals(that.arrcol) : that.arrcol != null)
             return false;
 
+        if (fieldWithAlias != null ? !fieldWithAlias.equals(that.fieldWithAlias) : that.fieldWithAlias != null)
+            return false;
+
         return true;
     }
 
@@ -477,6 +503,8 @@ public class Objects implements Serializable {
 
         res = 31 * res + (arrcol != null ? arrcol.hashCode() : 0);
 
+        res = 31 * res + (fieldWithAlias != null ? fieldWithAlias.hashCode() : 0);
+
         return res;
     }
 
@@ -497,6 +525,7 @@ public class Objects implements Serializable {
             ", timecol=" + timecol +
             ", tscol=" + tscol +
             ", arrcol=" + arrcol +
+            ", fieldWithAlias=" + fieldWithAlias +
             "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Primitives.txt
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Primitives.txt b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Primitives.txt
index ef8f902..a07b379 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Primitives.txt
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Primitives.txt
@@ -73,6 +73,9 @@ public class Primitives implements Serializable {
     /** Value for arrcol. */
     private Object arrcol;
 
+    /** Value for fieldWithAlias. */
+    private String fieldWithAlias;
+
     /**
      * Empty constructor.
      */
@@ -98,7 +101,8 @@ public class Primitives implements Serializable {
         java.sql.Date datecol,
         java.sql.Time timecol,
         java.sql.Timestamp tscol,
-        Object arrcol
+        Object arrcol,
+        String fieldWithAlias
     ) {
         this.pk = pk;
         this.boolcol = boolcol;
@@ -115,6 +119,7 @@ public class Primitives implements Serializable {
         this.timecol = timecol;
         this.tscol = tscol;
         this.arrcol = arrcol;
+        this.fieldWithAlias = fieldWithAlias;
     }
 
     /**
@@ -387,6 +392,24 @@ public class Primitives implements Serializable {
         this.arrcol = arrcol;
     }
 
+    /**
+     * Gets fieldWithAlias.
+     *
+     * @return Value for fieldWithAlias.
+     */
+    public String getFieldWithAlias() {
+        return fieldWithAlias;
+    }
+
+    /**
+     * Sets fieldWithAlias.
+     *
+     * @param fieldWithAlias New value for fieldWithAlias.
+     */
+    public void setFieldWithAlias(String fieldWithAlias) {
+        this.fieldWithAlias = fieldWithAlias;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
@@ -442,6 +465,9 @@ public class Primitives implements Serializable {
         if (arrcol != null ? !arrcol.equals(that.arrcol) : that.arrcol != null)
             return false;
 
+        if (fieldWithAlias != null ? !fieldWithAlias.equals(that.fieldWithAlias) : that.fieldWithAlias != null)
+            return false;
+
         return true;
     }
 
@@ -481,6 +507,8 @@ public class Primitives implements Serializable {
 
         res = 31 * res + (arrcol != null ? arrcol.hashCode() : 0);
 
+        res = 31 * res + (fieldWithAlias != null ? fieldWithAlias.hashCode() : 0);
+
         return res;
     }
 
@@ -501,6 +529,7 @@ public class Primitives implements Serializable {
             ", timecol=" + timecol +
             ", tscol=" + tscol +
             ", arrcol=" + arrcol +
+            ", fieldWithAlias=" + fieldWithAlias +
             "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Tst.txt
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Tst.txt b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Tst.txt
index 23d61d0..f1db255 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Tst.txt
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/Tst.txt
@@ -73,6 +73,9 @@ public class Tst implements Serializable {
     /** Value for arrcol. */
     private Object arrcol;
 
+    /** Value for fieldWithAlias. */
+    private String fieldWithAlias;
+
     /**
      * Empty constructor.
      */
@@ -98,7 +101,8 @@ public class Tst implements Serializable {
         java.sql.Date datecol,
         java.sql.Time timecol,
         java.sql.Timestamp tscol,
-        Object arrcol
+        Object arrcol,
+        String fieldWithAlias
     ) {
         this.pk = pk;
         this.boolcol = boolcol;
@@ -115,6 +119,7 @@ public class Tst implements Serializable {
         this.timecol = timecol;
         this.tscol = tscol;
         this.arrcol = arrcol;
+        this.fieldWithAlias = fieldWithAlias;
     }
 
     /**
@@ -387,6 +392,24 @@ public class Tst implements Serializable {
         this.arrcol = arrcol;
     }
 
+    /**
+     * Gets fieldWithAlias.
+     *
+     * @return Value for fieldWithAlias.
+     */
+    public String getFieldWithAlias() {
+        return fieldWithAlias;
+    }
+
+    /**
+     * Sets fieldWithAlias.
+     *
+     * @param fieldWithAlias New value for fieldWithAlias.
+     */
+    public void setFieldWithAlias(String fieldWithAlias) {
+        this.fieldWithAlias = fieldWithAlias;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
@@ -442,6 +465,9 @@ public class Tst implements Serializable {
         if (arrcol != null ? !arrcol.equals(that.arrcol) : that.arrcol != null)
             return false;
 
+        if (fieldWithAlias != null ? !fieldWithAlias.equals(that.fieldWithAlias) : that.fieldWithAlias != null)
+            return false;
+
         return true;
     }
 
@@ -481,6 +507,8 @@ public class Tst implements Serializable {
 
         res = 31 * res + (arrcol != null ? arrcol.hashCode() : 0);
 
+        res = 31 * res + (fieldWithAlias != null ? fieldWithAlias.hashCode() : 0);
+
         return res;
     }
 
@@ -501,6 +529,7 @@ public class Tst implements Serializable {
             ", timecol=" + timecol +
             ", tscol=" + tscol +
             ", arrcol=" + arrcol +
+            ", fieldWithAlias=" + fieldWithAlias +
             "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/ignite-type-metadata.xml
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/ignite-type-metadata.xml b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/ignite-type-metadata.xml
index 95706ef..fd14ae2 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/ignite-type-metadata.xml
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/model/ignite-type-metadata.xml
@@ -169,6 +169,14 @@
                                 <property name="javaFieldType" value="java.lang.Object"/>
                                 <property name="javaFieldName" value="arrcol"/>
                             </bean>
+                            <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                <property name="databaseFieldType">
+                                    <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                </property>
+                                <property name="databaseFieldName" value="FIELD_WITH_ALIAS"/>
+                                <property name="javaFieldType" value="java.lang.String"/>
+                                <property name="javaFieldName" value="fieldWithAlias"/>
+                            </bean>
                         </list>
                     </property>
                 </bean>
@@ -311,6 +319,14 @@
                                 <property name="javaFieldType" value="java.lang.Object"/>
                                 <property name="javaFieldName" value="arrcol"/>
                             </bean>
+                            <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                <property name="databaseFieldType">
+                                    <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                </property>
+                                <property name="databaseFieldName" value="FIELD_WITH_ALIAS"/>
+                                <property name="javaFieldType" value="java.lang.String"/>
+                                <property name="javaFieldName" value="fieldWithAlias"/>
+                            </bean>
                         </list>
                     </property>
                 </bean>
@@ -453,6 +469,14 @@
                                 <property name="javaFieldType" value="java.lang.Object"/>
                                 <property name="javaFieldName" value="arrcol"/>
                             </bean>
+                            <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
+                                <property name="databaseFieldType">
+                                    <util:constant static-field="java.sql.Types.VARCHAR"/>
+                                </property>
+                                <property name="databaseFieldName" value="FIELD_WITH_ALIAS"/>
+                                <property name="javaFieldType" value="java.lang.String"/>
+                                <property name="javaFieldName" value="fieldWithAlias"/>
+                            </bean>
                         </list>
                     </property>
                 </bean>
@@ -479,6 +503,12 @@
                 <entry key="timecol" value="java.sql.Time"/>
                 <entry key="tscol" value="java.sql.Timestamp"/>
                 <entry key="arrcol" value="java.lang.Object"/>
+                <entry key="fieldWithAlias" value="java.lang.String"/>
+            </util:map>
+        </property>
+        <property name="aliases">
+            <util:map map-class="java.util.LinkedHashMap">
+                <entry key="fieldWithAlias" value="FIELD_WITH_ALIAS"/>
             </util:map>
         </property>
         <property name="indexes">
@@ -517,6 +547,12 @@
                 <entry key="timecol" value="java.sql.Time"/>
                 <entry key="tscol" value="java.sql.Timestamp"/>
                 <entry key="arrcol" value="java.lang.Object"/>
+                <entry key="fieldWithAlias" value="java.lang.String"/>
+            </util:map>
+        </property>
+        <property name="aliases">
+            <util:map map-class="java.util.LinkedHashMap">
+                <entry key="fieldWithAlias" value="FIELD_WITH_ALIAS"/>
             </util:map>
         </property>
         <property name="indexes">
@@ -555,6 +591,12 @@
                 <entry key="timecol" value="java.sql.Time"/>
                 <entry key="tscol" value="java.sql.Timestamp"/>
                 <entry key="arrcol" value="java.lang.Object"/>
+                <entry key="fieldWithAlias" value="java.lang.String"/>
+            </util:map>
+        </property>
+        <property name="aliases">
+            <util:map map-class="java.util.LinkedHashMap">
+                <entry key="fieldWithAlias" value="FIELD_WITH_ALIAS"/>
             </util:map>
         </property>
         <property name="indexes">

http://git-wip-us.apache.org/repos/asf/ignite/blob/b6748651/modules/schema-import/src/test/java/org/apache/ignite/schema/test/parser/DbMetadataParserTest.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/parser/DbMetadataParserTest.java b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/parser/DbMetadataParserTest.java
index a954029..f918012 100644
--- a/modules/schema-import/src/test/java/org/apache/ignite/schema/test/parser/DbMetadataParserTest.java
+++ b/modules/schema-import/src/test/java/org/apache/ignite/schema/test/parser/DbMetadataParserTest.java
@@ -66,7 +66,7 @@ public class DbMetadataParserTest extends AbstractSchemaImportTest {
 
         List<PojoField> fields = type.fields();
 
-        assertEquals("Value type should have 15 fields", 15, fields.size());
+        assertEquals("Value type should have 15 fields", 16, fields.size());
 
         Iterator<PojoField> fieldsIt = fields.iterator();
 


[22/50] [abbrv] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSequenceApiSelfAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSequenceApiSelfAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSequenceApiSelfAbstractTest.java
index 8669863..d988b2c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSequenceApiSelfAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSequenceApiSelfAbstractTest.java
@@ -31,7 +31,6 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
-import org.apache.ignite.internal.processors.cache.GridCacheInternal;
 import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl;
 import org.apache.ignite.internal.util.typedef.G;
@@ -317,25 +316,6 @@ public abstract class GridCacheSequenceApiSelfAbstractTest extends IgniteAtomics
     /**
      * @throws Exception If failed.
      */
-    public void testEviction() throws Exception {
-        String locSeqName = UUID.randomUUID().toString();
-
-        IgniteAtomicSequence locSeq = grid().atomicSequence(locSeqName, 0, true);
-
-        locSeq.addAndGet(153);
-
-        GridCacheAdapter cache = ((IgniteKernal)grid()).internalCache(GridCacheUtils.ATOMICS_CACHE_NAME);
-
-        assertNotNull(cache);
-
-        cache.evictAll(cache.keySet());
-
-        assert null != cache.get(new GridCacheInternalKeyImpl(locSeqName));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
     public void testRemove() throws Exception {
         String locSeqName = UUID.randomUUID().toString();
 
@@ -376,23 +356,6 @@ public abstract class GridCacheSequenceApiSelfAbstractTest extends IgniteAtomics
             }
         }, IllegalStateException.class, null);
 
-        for (Object o : cache.keySet())
-            assert !(o instanceof GridCacheInternal) : "Wrong keys [key=" + o + ']';
-
-        for (Object o : cache.values())
-            assert !(o instanceof GridCacheInternal) : "Wrong values [value=" + o + ']';
-
-        for (Object o : cache.entrySet())
-            assert !(o instanceof GridCacheInternal) : "Wrong entries [entry=" + o + ']';
-
-        assert cache.keySet().isEmpty();
-
-        assert cache.values().isEmpty();
-
-        assert cache.entrySet().isEmpty();
-
-        assert cache.size() == 0;
-
         for (String seqName : seqNames)
             assert null != cache.get(new GridCacheInternalKeyImpl(seqName));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java
index c63df40..9973b27 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetAbstractSelfTest.java
@@ -39,6 +39,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -798,8 +799,8 @@ public abstract class GridCacheSetAbstractSelfTest extends IgniteCollectionAbstr
         GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
 
         for (int i = 0; i < gridCount(); i++) {
-            Iterator<GridCacheEntryEx> entries =
-                (grid(i)).context().cache().internalCache(cctx.name()).map().allEntries0().iterator();
+            Iterator<GridCacheMapEntry> entries =
+                (grid(i)).context().cache().internalCache(cctx.name()).map().entries().iterator();
 
             while (entries.hasNext()) {
                 GridCacheEntryEx entry = entries.next();

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java
index ca57205..e6e09c7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/GridCacheSetFailoverAbstractSelfTest.java
@@ -29,8 +29,8 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSet;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.datastructures.SetItemKey;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteUuid;
@@ -174,8 +174,8 @@ public abstract class GridCacheSetFailoverAbstractSelfTest extends IgniteCollect
             Set<IgniteUuid> setIds = new HashSet<>();
 
             for (int i = 0; i < gridCount(); i++) {
-                Iterator<GridCacheEntryEx> entries =
-                    ((IgniteKernal)grid(i)).context().cache().internalCache().map().allEntries0().iterator();
+                Iterator<GridCacheMapEntry> entries =
+                    grid(i).context().cache().internalCache().map().entries().iterator();
 
                 while (entries.hasNext()) {
                     GridCacheEntryEx entry = entries.next();
@@ -228,4 +228,4 @@ public abstract class GridCacheSetFailoverAbstractSelfTest extends IgniteCollect
             }
         });
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
index 4a21765..e88c97b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.IgniteAtomicLong;
 import org.apache.ignite.IgniteAtomicReference;
 import org.apache.ignite.IgniteAtomicSequence;
 import org.apache.ignite.IgniteAtomicStamped;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCountDownLatch;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteQueue;
@@ -349,7 +350,7 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
             for (IgniteInternalFuture<Object> fut : futs) {
                 Object res = fut.get();
 
-                if (res instanceof IgniteException)
+                if (res instanceof IgniteException || res instanceof IgniteCheckedException)
                     continue;
 
                 assertTrue("Unexpected object: " + res,

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java
index 880c638..f57e1c9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedQueueNoBackupsTest.java
@@ -26,7 +26,7 @@ import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.configuration.CollectionConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.testframework.GridTestUtils;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
@@ -79,8 +79,8 @@ public class IgnitePartitionedQueueNoBackupsTest extends GridCachePartitionedQue
         for (int i = 0; i < gridCount(); i++) {
             IgniteKernal grid = (IgniteKernal)grid(i);
 
-            Iterator<GridCacheEntryEx> entries =
-                grid.context().cache().internalCache(cctx.name()).map().allEntries0().iterator();
+            Iterator<GridCacheMapEntry> entries =
+                grid.context().cache().internalCache(cctx.name()).map().entries().iterator();
 
             if (entries.hasNext()) {
                 if (setNodeId == null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java
index 2d23d2a..a73aa4a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedSetNoBackupsSelfTest.java
@@ -23,7 +23,7 @@ import java.util.UUID;
 import org.apache.ignite.configuration.CollectionConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.testframework.GridTestUtils;
 
 /**
@@ -57,8 +57,8 @@ public class IgnitePartitionedSetNoBackupsSelfTest extends GridCachePartitionedS
         for (int i = 0; i < gridCount(); i++) {
             IgniteKernal grid = (IgniteKernal)grid(i);
 
-            Iterator<GridCacheEntryEx> entries =
-                grid.context().cache().internalCache(cctx.name()).map().allEntries0().iterator();
+            Iterator<GridCacheMapEntry> entries =
+                grid.context().cache().internalCache(cctx.name()).map().entries().iterator();
 
             if (entries.hasNext()) {
                 if (setNodeId == null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtTestUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtTestUtils.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtTestUtils.java
index dd46e23..377a55f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtTestUtils.java
@@ -85,7 +85,12 @@ public class GridCacheDhtTestUtils {
         for (int i = 0; i < keyCnt; i++) {
             KeyCacheObject cacheKey = ctx.toCacheKeyObject(i);
 
-            cacheMap.putEntry(AffinityTopologyVersion.NONE, cacheKey, ctx.toCacheKeyObject("value" + i));
+            cacheMap.putEntryIfObsoleteOrAbsent(
+                AffinityTopologyVersion.NONE,
+                cacheKey,
+                ctx.toCacheKeyObject("value" + i),
+                false,
+                false);
 
             dht.preloader().request(Collections.singleton(cacheKey), AffinityTopologyVersion.NONE);
 
@@ -224,4 +229,4 @@ public class GridCacheDhtTestUtils {
                     ", entry=" + entry + ", node partitions=" + affParts + "]");
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOneNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOneNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOneNodeSelfTest.java
index 4c92f90..d0fe936 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOneNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOneNodeSelfTest.java
@@ -59,8 +59,8 @@ public class GridCacheNearOneNodeSelfTest extends GridCommonAbstractTest {
 
         jcache().removeAll();
 
-        assertEquals("DHT entries: " + dht().entries(), 0, dht().size());
-        assertEquals("Near entries: " + near().entries(), 0, near().size());
+        assertEquals("DHT entries: " + dht().entrySet(), 0, dht().size());
+        assertEquals("Near entries: " + near().entrySet(), 0, near().size());
         assertEquals(0, jcache().size());
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
index e4d39d6..d67092f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
@@ -75,7 +75,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Queue;
 import java.util.Random;
-import java.util.Set;
+
 import java.util.concurrent.Callable;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -1021,9 +1021,9 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest {
                 }
             }
         }, 10_000)) {
-            Set<GridCacheEntryEx> set = dataCache.allEntries();
+            Iterable<? extends GridCacheEntryEx> entries = dataCache.allEntries();
 
-            for (GridCacheEntryEx e: set) {
+            for (GridCacheEntryEx e: entries) {
                 X.println("deleted = " + e.deleted());
                 X.println("detached = " + e.detached());
                 X.println("info = " + e.info());
@@ -3238,9 +3238,9 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest {
     private static void dumpCache(String cacheName, GridCacheAdapter<?,?> cache) {
         X.println("=============================== " + cacheName + " cache dump: ");
 
-        Set<GridCacheEntryEx> set = cache.entries();
+        Iterable<? extends GridCacheEntryEx> entries = cache.entries();
 
-        for (GridCacheEntryEx e: set)
+        for (GridCacheEntryEx e: entries)
             X.println("Lost " + cacheName + " entry = " + e);
     }
 


[41/50] [abbrv] ignite git commit: Temporary disabled tests.

Posted by sh...@apache.org.
Temporary disabled tests.


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

Branch: refs/heads/ignite-2788
Commit: 2699235064586fa6f4cdb0df929698a4d97a68fd
Parents: 1aa9ef7
Author: sboikov <sb...@gridgain.com>
Authored: Fri Apr 29 11:06:55 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../testsuites/IgniteCacheDataStructuresSelfTestSuite.java     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/26992350/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
index 59a18e5..09e7c4d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
@@ -110,7 +110,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheLocalAtomicQueueApiSelfTest.class));
         suite.addTest(new TestSuite(IgniteLocalCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteLocalSemaphoreSelfTest.class));
-        suite.addTest(new TestSuite(IgniteLocalLockSelfTest.class));
+        //suite.addTest(new TestSuite(IgniteLocalLockSelfTest.class));
 
         suite.addTest(new TestSuite(GridCacheReplicatedSequenceApiSelfTest.class));
         suite.addTest(new TestSuite(GridCacheReplicatedSequenceMultiNodeSelfTest.class));
@@ -121,7 +121,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheReplicatedDataStructuresFailoverSelfTest.class));
         suite.addTest(new TestSuite(IgniteReplicatedCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteReplicatedSemaphoreSelfTest.class));
-        suite.addTest(new TestSuite(IgniteReplicatedLockSelfTest.class));
+        //suite.addTest(new TestSuite(IgniteReplicatedLockSelfTest.class));
         suite.addTest(new TestSuite(IgniteCacheAtomicReplicatedNodeRestartSelfTest.class));
 
         suite.addTest(new TestSuite(GridCachePartitionedSequenceApiSelfTest.class));
@@ -144,7 +144,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(IgnitePartitionedCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteDataStructureWithJobTest.class));
         suite.addTest(new TestSuite(IgnitePartitionedSemaphoreSelfTest.class));
-        suite.addTest(new TestSuite(IgnitePartitionedLockSelfTest.class));
+        //suite.addTest(new TestSuite(IgnitePartitionedLockSelfTest.class));
 
         suite.addTest(new TestSuite(GridCachePartitionedSetFailoverSelfTest.class));
         suite.addTest(new TestSuite(GridCachePartitionedOffheapSetFailoverSelfTest.class));


[08/50] [abbrv] ignite git commit: IGNITE-2594: Cached web session requires setAttribute() to be called on each update. This closes #654 Reviewed and merged by Denis Magda (dmagda@gridgain.com)

Posted by sh...@apache.org.
IGNITE-2594: Cached web session requires setAttribute() to be called on each update. This closes #654
Reviewed and merged by Denis Magda (dmagda@gridgain.com)


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

Branch: refs/heads/ignite-2788
Commit: 50171ebbdfed0f4edb98c1571d71cd3d9eae80c2
Parents: ef5531b
Author: Vladislav Pyatkov <vl...@gmail.com>
Authored: Tue Apr 19 06:54:43 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../ignite/cache/websession/WebSession.java     |  7 +-
 .../internal/websession/WebSessionSelfTest.java | 88 +++++++++++++++++++-
 2 files changed, 93 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/50171ebb/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
----------------------------------------------------------------------
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
index 5e0d49b..675c4ca 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
@@ -240,7 +240,12 @@ class WebSession implements HttpSession, Externalizable {
         if (!isValid)
             throw new IllegalStateException("Call on invalidated session!");
 
-        return attrs.get(name);
+        Object val = attrs.get(name);
+
+        if (val != null && updates != null)
+            updates.add(new T2<>(name, val));
+
+        return val;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/50171ebb/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
index 8706e1f..ccf0852 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.websession;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.Serializable;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Random;
@@ -27,6 +28,7 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.atomic.AtomicReferenceArray;
 import javax.servlet.ServletException;
@@ -86,6 +88,13 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
+    public void testImplicitlyAttributeModification() throws Exception {
+        testImplicitlyModification("ignite-webapp-config.xml");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testClientReconnectRequest() throws Exception {
         testClientReconnectRequest("/modules/core/src/test/config/websession/example-cache.xml",
             "/modules/core/src/test/config/websession/example-cache2.xml",
@@ -155,7 +164,50 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
     }
 
     /**
-     * Tests single request to a server. Checks the presence of session in cache.
+     * Tests implicitly modification attribute in session. Checks the presence of session in cache.
+     *
+     * @param cfg Configuration.
+     * @throws Exception If failed.
+     */
+    private void testImplicitlyModification(String cfg) throws Exception {
+        Server srv = null;
+
+        try {
+            srv = startServer(TEST_JETTY_PORT, cfg, null, new SessionCreateServlet());
+
+            String sesId = sendRequestAndCheckMarker("marker1", null);
+            sendRequestAndCheckMarker("test_string", sesId);
+            sendRequestAndCheckMarker("ignite_test_attribute", sesId);
+        }
+        finally {
+            stopServer(srv);
+        }
+    }
+
+    private String sendRequestAndCheckMarker(String reqMarker, String sesId) throws IOException {
+        URLConnection conn = new URL("http://localhost:" + TEST_JETTY_PORT +
+            "/ignitetest/test?marker=" + reqMarker).openConnection();
+        conn.addRequestProperty("Cookie", "JSESSIONID=" + sesId);
+
+        conn.connect();
+
+        try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
+            sesId = rdr.readLine();
+
+            IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
+
+            assertNotNull(cache);
+
+            HttpSession ses = cache.get(sesId);
+
+            assertNotNull(ses);
+            assertEquals(reqMarker, ((Profile)ses.getAttribute("profile")).getMarker());
+        }
+        return sesId;
+    }
+
+    /**
+     * Tests single request to a server. Checks modification attribute in cache.
      *
      * @param cfg Configuration.
      * @throws Exception If failed.
@@ -533,6 +585,15 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
             ses.setAttribute("key1", "val1");
             ses.setAttribute("key2", "val2");
 
+            Profile p = (Profile)ses.getAttribute("profile");
+
+            if (p == null) {
+                p = new Profile();
+                ses.setAttribute("profile", p);
+            }
+
+            p.setMarker(req.getParameter("marker"));
+
             X.println(">>>", "Created session: " + ses.getId(), ">>>");
 
             res.getWriter().write(ses.getId());
@@ -542,6 +603,31 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * Complex class for stored in session.
+     */
+    private static class Profile implements Serializable {
+
+        /**
+         * Marker string.
+         */
+        String marker;
+
+        /**
+         * @return marker
+         */
+        public String getMarker() {
+            return marker;
+        }
+
+        /**
+         * @param marker
+         */
+        public void setMarker(String marker) {
+            this.marker = marker;
+        }
+    }
+
+    /**
      * Test for invalidated sessions.
      */
     private static class InvalidatedSessionServlet extends HttpServlet {


[12/50] [abbrv] ignite git commit: IGNITE-2688: fixed InterruptException processing in RingMessageWorker caused by segmentation

Posted by sh...@apache.org.
IGNITE-2688: fixed InterruptException processing in RingMessageWorker caused by segmentation


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

Branch: refs/heads/ignite-2788
Commit: fd636e9958d53e11c881dadd4935afe24862ac48
Parents: 9aab9e1
Author: Denis Magda <dm...@gridgain.com>
Authored: Wed Apr 20 17:52:51 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../ignite/spi/discovery/tcp/ServerImpl.java    |   4 +-
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java | 148 +++++++++++++++++--
 2 files changed, 136 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fd636e99/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 572f540..3283d99 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -2179,8 +2179,8 @@ class ServerImpl extends TcpDiscoveryImpl {
                 super.body();
             }
             catch (Throwable e) {
-                if (!spi.isNodeStopping0()) {
-                    final Ignite ignite = spi.ignite();
+                if (!spi.isNodeStopping0() && spiStateCopy() != DISCONNECTING) {
+                        final Ignite ignite = spi.ignite();
 
                     if (ignite != null) {
                         U.error(log, "TcpDiscoverSpi's message worker thread failed abnormally. " +

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd636e99/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 7efaca0..45cd276 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -77,6 +77,7 @@ import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedM
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage;
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage;
 import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage;
+import org.apache.ignite.testframework.GridStringLogger;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.eclipse.jetty.util.ConcurrentHashSet;
@@ -108,6 +109,8 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
     /** */
     private static ThreadLocal<TcpDiscoverySpi> nodeSpi = new ThreadLocal<>();
 
+    private GridStringLogger strLogger;
+
     /**
      * @throws Exception If fails.
      */
@@ -188,6 +191,16 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
         }
         else if (gridName.contains("testPingInterruptedOnNodeFailedPingingNode"))
             cfg.setFailureDetectionTimeout(30_000);
+        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureNormalNode")) {
+            cfg.setFailureDetectionTimeout(3_000);
+        }
+        else if (gridName.contains("testNoRingMessageWorkerAbnormalFailureSegmentedNode")) {
+            cfg.setFailureDetectionTimeout(6_000);
+
+            cfg.setGridLogger(strLogger = new GridStringLogger());
+        }
+        else if (gridName.contains("testNodeShutdownOnRingMessageWorkerFailureFailedNode"))
+            cfg.setGridLogger(strLogger = new GridStringLogger());
 
         return cfg;
     }
@@ -1355,11 +1368,12 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
      */
     public void testNodeShutdownOnRingMessageWorkerFailure() throws Exception {
         try {
-            TestMessageWorkerFailureSpi1 spi0 = new TestMessageWorkerFailureSpi1();
+            final TestMessageWorkerFailureSpi1 spi0 = new TestMessageWorkerFailureSpi1(
+                TestMessageWorkerFailureSpi1.EXCEPTION_MODE);
 
             nodeSpi.set(spi0);
 
-            final Ignite ignite0 = startGrid(0);
+            final Ignite ignite0 = startGrid("testNodeShutdownOnRingMessageWorkerFailureFailedNode");
 
             nodeSpi.set(new TcpDiscoverySpi());
 
@@ -1374,10 +1388,11 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
             ignite1.events().localListen(new IgnitePredicate<Event>() {
                 @Override public boolean apply(Event evt) {
                     if (evt.type() == EventType.EVT_NODE_FAILED &&
-                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id())) {
                         disconnected.set(true);
 
-                    latch.countDown();
+                        latch.countDown();
+                    }
 
                     return false;
                 }
@@ -1389,20 +1404,98 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
 
             assertTrue(disconnected.get());
 
-            try {
-                ignite0.cluster().localNode().id();
-            }
-            catch (IllegalStateException e) {
-                if (e.getMessage().contains("Grid is in invalid state to perform this operation"))
-                    return;
-            }
+            String result = strLogger.toString();
 
-            fail();
+            assert result.contains("TcpDiscoverSpi's message worker thread failed abnormally") : result;
         }
         finally {
             stopAllGrids();
         }
     }
+
+    /**
+     * @throws Exception If failed
+     */
+    public void testNoRingMessageWorkerAbnormalFailureOnSegmentation() throws Exception {
+        try {
+            TestMessageWorkerFailureSpi1 spi1 = new TestMessageWorkerFailureSpi1(
+                TestMessageWorkerFailureSpi1.SEGMENTATION_MODE);
+
+            nodeSpi.set(spi1);
+
+            Ignite ignite1 = startGrid("testNoRingMessageWorkerAbnormalFailureNormalNode");
+
+
+            nodeSpi.set(new TcpDiscoverySpi());
+
+            final Ignite ignite2 = startGrid("testNoRingMessageWorkerAbnormalFailureSegmentedNode");
+
+
+            final AtomicBoolean disconnected = new AtomicBoolean();
+
+            final AtomicBoolean segmented = new AtomicBoolean();
+
+            final CountDownLatch disLatch = new CountDownLatch(1);
+
+            final CountDownLatch segLatch = new CountDownLatch(1);
+
+            final UUID failedNodeId = ignite2.cluster().localNode().id();
+
+            ignite1.events().localListen(new IgnitePredicate<Event>() {
+                @Override public boolean apply(Event evt) {
+                    if (evt.type() == EventType.EVT_NODE_FAILED &&
+                        failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                        disconnected.set(true);
+
+                    disLatch.countDown();
+
+                    return false;
+                }
+            }, EventType.EVT_NODE_FAILED);
+
+            ignite2.events().localListen(new IgnitePredicate<Event>() {
+                @Override public boolean apply(Event evt) {
+                    if (!failedNodeId.equals(((DiscoveryEvent)evt).eventNode().id()))
+                        return true;
+
+                    if (evt.type() == EventType.EVT_NODE_SEGMENTED) {
+                        segmented.set(true);
+
+                        segLatch.countDown();
+                    }
+
+                    return true;
+                }
+            }, EventType.EVT_NODE_SEGMENTED);
+
+
+            spi1.stop = true;
+
+            disLatch.await(15, TimeUnit.SECONDS);
+
+            assertTrue(disconnected.get());
+
+
+            spi1.stop = false;
+
+            segLatch.await(15, TimeUnit.SECONDS);
+
+            assertTrue(segmented.get());
+
+
+            Thread.sleep(10_000);
+
+
+            String result = strLogger.toString();
+
+            assert result.contains("Local node SEGMENTED") &&
+                !result.contains("TcpDiscoverSpi's message worker thread failed abnormally") : result;
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
     /**
      * @throws Exception If failed
      */
@@ -2071,14 +2164,41 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
      */
     private static class TestMessageWorkerFailureSpi1 extends TcpDiscoverySpi {
         /** */
+        private static int EXCEPTION_MODE = 0;
+
+        /** */
+        private static int SEGMENTATION_MODE = 1;
+
+        /** */
+        private final int failureMode;
+
+        /** */
         private volatile boolean stop;
 
+        /**
+         * @param failureMode Failure mode to use during the test.
+         */
+        public TestMessageWorkerFailureSpi1(int failureMode) {
+            this.failureMode = failureMode;
+        }
+
         /** {@inheritDoc} */
         @Override protected void writeToSocket(Socket sock, OutputStream out, TcpDiscoveryAbstractMessage msg,
             long timeout) throws IOException, IgniteCheckedException {
 
-            if (stop)
-                throw new RuntimeException("Failing ring message worker explicitly");
+            if (stop) {
+                if (failureMode == EXCEPTION_MODE)
+                    throw new RuntimeException("Failing ring message worker explicitly");
+                else {
+                    try {
+                        Thread.sleep(5_000);
+                    }
+                    catch (InterruptedException e) {
+                        // Ignore.
+                    }
+                }
+
+            }
 
             super.writeToSocket(sock, out, msg, timeout);
         }


[26/50] [abbrv] ignite git commit: IGNITE-2948 - Optimize usage of GridCacheConcurrentMap

Posted by sh...@apache.org.
IGNITE-2948 - Optimize usage of GridCacheConcurrentMap


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

Branch: refs/heads/ignite-2788
Commit: 0b7470b381cf6571577bef7a2dd3f1833dce61e5
Parents: bc98fa5
Author: Yakov Zhdanov <yz...@gridgain.com>
Authored: Tue Apr 26 15:07:28 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:15 2016 +0900

----------------------------------------------------------------------
 .../internal/benchmarks/model/IntValue.java     |   19 +-
 .../internal/binary/BinaryObjectImpl.java       |   14 +
 .../processors/cache/GridCacheAdapter.java      |  448 ++--
 .../cache/GridCacheAffinityManager.java         |   10 +-
 .../cache/GridCacheClearAllRunnable.java        |    2 +-
 .../cache/GridCacheConcurrentMap.java           | 1996 +-----------------
 .../cache/GridCacheConcurrentMapImpl.java       |  344 +++
 .../processors/cache/GridCacheContext.java      |   56 +-
 .../cache/GridCacheDeploymentManager.java       |    2 +-
 .../processors/cache/GridCacheEntrySet.java     |  113 -
 .../cache/GridCacheEvictionManager.java         |    2 +-
 .../processors/cache/GridCacheKeySet.java       |  104 -
 .../processors/cache/GridCacheMapEntry.java     |   22 +-
 .../processors/cache/GridCacheProcessor.java    |    1 -
 .../processors/cache/GridCacheProxyImpl.java    |    2 +-
 .../processors/cache/GridCacheUtils.java        |    1 -
 .../processors/cache/GridNoStorageCacheMap.java |  107 +
 .../processors/cache/IgniteInternalCache.java   |    2 +-
 .../processors/cache/KeyCacheObject.java        |   11 +
 .../processors/cache/KeyCacheObjectImpl.java    |   32 +-
 .../binary/CacheObjectBinaryProcessorImpl.java  |   24 +-
 .../GridDistributedCacheAdapter.java            |    4 +-
 .../distributed/GridDistributedLockRequest.java |   19 +-
 .../GridDistributedTxRemoteAdapter.java         |    1 -
 .../GridDistributedUnlockRequest.java           |   16 +-
 .../dht/GridCachePartitionedConcurrentMap.java  |  191 ++
 .../dht/GridClientPartitionTopology.java        |    7 -
 .../distributed/dht/GridDhtCacheAdapter.java    |   77 +-
 .../distributed/dht/GridDhtCacheEntry.java      |   25 +-
 .../distributed/dht/GridDhtLocalPartition.java  |  152 +-
 .../distributed/dht/GridDhtLockRequest.java     |   16 +-
 .../dht/GridDhtPartitionTopology.java           |    7 -
 .../dht/GridDhtPartitionTopologyImpl.java       |  281 ++-
 .../distributed/dht/GridDhtUnlockRequest.java   |   15 +-
 .../distributed/dht/GridNoStorageCacheMap.java  |  122 --
 .../dht/GridPartitionedGetFuture.java           |    2 +-
 .../dht/GridPartitionedSingleGetFuture.java     |    2 +-
 .../dht/atomic/GridDhtAtomicCache.java          |   75 +-
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |   22 +-
 .../dht/atomic/GridNearAtomicUpdateFuture.java  |    6 +-
 .../dht/atomic/GridNearAtomicUpdateRequest.java |   31 +-
 .../dht/colocated/GridDhtColocatedCache.java    |   13 +-
 .../dht/preloader/GridDhtPartitionDemander.java |    2 +-
 .../dht/preloader/GridDhtPartitionSupplier.java |    8 +-
 .../distributed/near/GridNearCacheAdapter.java  |   94 +-
 .../distributed/near/GridNearGetFuture.java     |    2 +-
 .../distributed/near/GridNearGetRequest.java    |   45 +-
 .../distributed/near/GridNearLockRequest.java   |   16 +-
 .../near/GridNearSingleGetRequest.java          |   22 +-
 .../distributed/near/GridNearUnlockRequest.java |   21 +-
 .../processors/cache/local/GridLocalCache.java  |    7 +-
 .../local/atomic/GridLocalAtomicCache.java      |   24 +-
 .../cache/transactions/IgniteInternalTx.java    |    1 -
 .../cache/transactions/IgniteTxAdapter.java     |    1 -
 .../cache/transactions/IgniteTxEntry.java       |   33 +-
 .../cacheobject/IgniteCacheObjectProcessor.java |   10 +
 .../IgniteCacheObjectProcessorImpl.java         |   36 +-
 .../GridCacheAtomicReferenceImpl.java           |    2 +-
 .../internal/util/PartitionedReadOnlySet.java   |   71 +
 .../util/StripedCompositeReadWriteLock.java     |   10 +
 .../ignite/internal/util/lang/GridFunc.java     |    3 +-
 .../ignite/internal/visor/cache/VisorCache.java |    6 +-
 .../GridCachePreloadingEvictionsSelfTest.java   |    4 +-
 .../cache/GridCacheTtlManagerSelfTest.java      |    2 +-
 ...idCacheValueConsistencyAbstractSelfTest.java |    3 +-
 .../IgniteDynamicClientCacheStartSelfTest.java  |   10 -
 .../IgniteTxStoreExceptionAbstractSelfTest.java |    8 +-
 .../GridCacheBinaryObjectsAbstractSelfTest.java |    2 +-
 ...actQueueFailoverDataConsistencySelfTest.java |    2 +-
 .../GridCacheQueueCleanupSelfTest.java          |    4 +-
 .../GridCacheSequenceApiSelfAbstractTest.java   |   37 -
 .../GridCacheSetAbstractSelfTest.java           |    5 +-
 .../GridCacheSetFailoverAbstractSelfTest.java   |    8 +-
 .../IgniteDataStructureUniqueNameTest.java      |    3 +-
 .../IgnitePartitionedQueueNoBackupsTest.java    |    6 +-
 .../IgnitePartitionedSetNoBackupsSelfTest.java  |    6 +-
 .../distributed/dht/GridCacheDhtTestUtils.java  |    9 +-
 .../near/GridCacheNearOneNodeSelfTest.java      |    4 +-
 .../processors/igfs/IgfsAbstractSelfTest.java   |   10 +-
 79 files changed, 1958 insertions(+), 2975 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java
----------------------------------------------------------------------
diff --git a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java
index 0a97e36..45fbe79 100644
--- a/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java
+++ b/modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/model/IntValue.java
@@ -85,7 +85,24 @@ public class IntValue implements Externalizable, Binarylizable {
     }
 
     /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        IntValue value = (IntValue)o;
+
+        return val == value.val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return val;
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return "Value [id=" + val + ']';
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 0997d6f..fa10de3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -72,6 +72,10 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
     @GridDirectTransient
     private boolean detachAllowed;
 
+    /** */
+    @GridDirectTransient
+    private int part = -1;
+
     /**
      * For {@link Externalizable}.
      */
@@ -94,6 +98,16 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
     }
 
     /** {@inheritDoc} */
+    @Override public int partition() {
+        return part;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void partition(int part) {
+        this.part = part;
+    }
+
+    /** {@inheritDoc} */
     @Override public byte cacheObjectType() {
         return TYPE_BINARY;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index d807e26..8c1a750 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -23,8 +23,8 @@ import java.io.InvalidObjectException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.ObjectStreamException;
+import java.util.AbstractSet;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -101,13 +101,11 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFi
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException;
 import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
-import org.apache.ignite.internal.util.F0;
 import org.apache.ignite.internal.util.future.GridCompoundFuture;
 import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.lang.GridClosureException;
-import org.apache.ignite.internal.util.lang.GridTriple;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.C1;
 import org.apache.ignite.internal.util.typedef.C2;
@@ -132,7 +130,6 @@ import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteOutClosure;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.lang.IgniteProductVersion;
-import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.mxbean.CacheMetricsMXBean;
 import org.apache.ignite.plugin.security.SecurityPermission;
 import org.apache.ignite.resources.IgniteInstanceResource;
@@ -146,8 +143,6 @@ import org.jsr166.LongAdder8;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_KEY_VALIDATION_DISABLED;
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT;
-import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_CREATED;
-import static org.apache.ignite.events.EventType.EVT_CACHE_ENTRY_DESTROYED;
 import static org.apache.ignite.internal.GridClosureCallMode.BROADCAST;
 import static org.apache.ignite.internal.processors.dr.GridDrType.DR_LOAD;
 import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE;
@@ -304,7 +299,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      */
     @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction")
     protected GridCacheAdapter(GridCacheContext<K, V> ctx, int startSize) {
-        this(ctx, new GridCacheConcurrentMap(ctx, startSize, null));
+        this(ctx, null);
     }
 
     /**
@@ -312,7 +307,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * @param map Concurrent map.
      */
     @SuppressWarnings({"OverriddenMethodCallDuringObjectConstruction", "deprecation"})
-    protected GridCacheAdapter(final GridCacheContext<K, V> ctx, GridCacheConcurrentMap map) {
+    protected GridCacheAdapter(final GridCacheContext<K, V> ctx, @Nullable GridCacheConcurrentMap map) {
         assert ctx != null;
 
         this.ctx = ctx;
@@ -393,6 +388,22 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /**
+     * Increments map public size.
+     * @param e Map entry.
+     */
+    public void incrementSize(GridCacheMapEntry e) {
+        map.incrementPublicSize(e);
+    }
+
+    /**
+     * Decrements map public size.
+     * @param e Map entry.
+     */
+    public void decrementSize(GridCacheMapEntry e) {
+        map.decrementPublicSize(e);
+    }
+
+    /**
      * @return Context.
      */
     @Override public GridCacheContext<K, V> context() {
@@ -483,7 +494,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         return new GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx, (GridCacheAdapter<K1, V1>)this, opCtx);
     }
 
-
     /** {@inheritDoc} */
     @Nullable @Override public ExpiryPolicy expiry() {
         return null;
@@ -541,13 +551,25 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /**
+     * @return Entry factory.
+     */
+    protected abstract GridCacheMapEntryFactory entryFactory();
+
+    /**
      * Starts this cache. Child classes should override this method
      * to provide custom start-up behavior.
      *
      * @throws IgniteCheckedException If start failed.
      */
     public void start() throws IgniteCheckedException {
-        // No-op.
+        if (map == null) {
+            int initSize = ctx.config().getStartSize();
+
+            if (!isLocal())
+                initSize /= ctx.affinity().partitions();
+
+            map = new GridCacheConcurrentMapImpl(ctx, entryFactory(), initSize);
+        }
     }
 
     /**
@@ -687,7 +709,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             modes.backup = true;
 
             if (modes.heap)
-                its.add(iterator(map.entries0().iterator(), !ctx.keepBinary()));
+                its.add(iterator(map.entries().iterator(), !ctx.keepBinary()));
         }
         else if (modes.heap) {
             if (modes.near && ctx.isNear())
@@ -946,74 +968,28 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         GridCacheMapEntry cur = map.getEntry(key);
 
         if (cur == null || cur.obsolete()) {
-            GridTriple<GridCacheMapEntry> t = map.putEntryIfObsoleteOrAbsent(
+            cur = map.putEntryIfObsoleteOrAbsent(
                 topVer,
                 key,
                 null,
-                create);
-
-            cur = t.get1();
-
-            GridCacheEntryEx created = t.get2();
-            GridCacheEntryEx doomed = t.get3();
-
-            if (doomed != null && ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
-                // Event notification.
-                ctx.events().addEvent(doomed.partition(),
-                    doomed.key(),
-                    locNodeId,
-                    (IgniteUuid)null,
-                    null,
-                    EVT_CACHE_ENTRY_DESTROYED,
-                    null,
-                    false,
-                    null,
-                    false,
-                    null,
-                    null,
-                    null,
-                    true);
-
-            if (created != null) {
-                // Event notification.
-                if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED))
-                    ctx.events().addEvent(created.partition(),
-                        created.key(),
-                        locNodeId,
-                        (IgniteUuid)null,
-                        null,
-                        EVT_CACHE_ENTRY_CREATED,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        null,
-                        true);
-
-                if (touch)
-                    ctx.evicts().touch(
-                        cur,
-                        topVer);
-            }
+                create, touch);
         }
 
         return cur;
     }
 
     /**
-     * @return Set of internal cached entry representations, excluding {@link GridCacheInternal} keys.
+     * @return Set of internal cached entry representations.
      */
-    public Set<GridCacheEntryEx> entries() {
-        return map.entries0();
+    public Iterable<? extends GridCacheEntryEx> entries() {
+        return allEntries();
     }
 
     /**
-     * @return Set of internal cached entry representations, including {@link GridCacheInternal} keys.
+     * @return Set of internal cached entry representations.
      */
-    public Set<GridCacheEntryEx> allEntries() {
-        return map.allEntries0();
+    public Iterable<? extends GridCacheEntryEx> allEntries() {
+        return map.entries();
     }
 
     /** {@inheritDoc} */
@@ -1022,8 +998,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<K, V>> entrySetx(CacheEntryPredicate... filter) {
-        return map.entriesx(filter);
+    @Override public Set<Cache.Entry<K, V>> entrySetx(final CacheEntryPredicate... filter) {
+        return new EntrySet(map.entrySet(filter));
     }
 
     /** {@inheritDoc} */
@@ -1033,22 +1009,57 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
     /** {@inheritDoc} */
     @Override public Set<K> keySet() {
-        return map.keySet();
+        return new KeySet(map.entrySet());
     }
 
     /** {@inheritDoc} */
     @Override public Set<K> keySetx() {
-        return map.keySetx();
+        return keySet();
     }
 
     /** {@inheritDoc} */
     @Override public Set<K> primaryKeySet() {
-        return map.keySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode()));
+        return new KeySet(map.entrySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode())));
     }
 
     /** {@inheritDoc} */
-    @Override public Collection<V> values() {
-        return map.values();
+    @Override public Iterable<V> values() {
+        return values((CacheEntryPredicate[])null);
+    }
+
+    /**
+     * Collection of values cached on this node. You cannot modify this collection.
+     * <p>
+     * Iterator over this collection will not fail if collection was
+     * concurrently updated by another thread. This means that iterator may or
+     * may not return latest values depending on whether they were added before
+     * or after current iterator position.
+     * <p>
+     * NOTE: this operation is not distributed and returns only the values cached on this node.
+     *
+     * @param filter Filters.
+     * @return Collection of cached values.
+     */
+    public Iterable<V> values(final CacheEntryPredicate... filter) {
+        return new Iterable<V>() {
+            @Override public Iterator<V> iterator() {
+                return new Iterator<V>() {
+                    private final Iterator<? extends GridCacheEntryEx> it = entries().iterator();
+
+                    @Override public boolean hasNext() {
+                        return it.hasNext();
+                    }
+
+                    @Override public V next() {
+                        return (V) it.next().wrap().getValue();
+                    }
+
+                    @Override public void remove() {
+                        throw new UnsupportedOperationException("remove");
+                    }
+                };
+            }
+        };
     }
 
     /**
@@ -1058,21 +1069,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     public void removeIfObsolete(KeyCacheObject key) {
         assert key != null;
 
-        GridCacheEntryEx entry = map.removeEntryIfObsolete(key);
+        GridCacheMapEntry entry = map.getEntry(key);
 
-        if (entry != null) {
-            assert entry.obsolete() : "Removed non-obsolete entry: " + entry;
-
-            if (log.isDebugEnabled())
-                log.debug("Removed entry from cache: " + entry);
-
-            if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
-                // Event notification.
-                ctx.events().addEvent(entry.partition(), entry.key(), locNodeId, (IgniteUuid)null, null,
-                    EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, false);
-        }
-        else if (log.isDebugEnabled())
-            log.debug("Remove will not be done for key (obsolete entry got replaced or removed): " + key);
+        if (entry.obsolete())
+            removeEntry(entry);
     }
 
     /**
@@ -1088,7 +1088,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             int keySize = size();
 
             int cnt = Math.min(keySize / CLEAR_ALL_SPLIT_THRESHOLD + (keySize % CLEAR_ALL_SPLIT_THRESHOLD != 0 ? 1 : 0),
-                    Runtime.getRuntime().availableProcessors());
+                Runtime.getRuntime().availableProcessors());
 
             if (cnt == 0)
                 cnt = 1; // Still perform cleanup since there could be entries in swap.
@@ -1256,7 +1256,14 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * @param entry Removes entry from cache if currently mapped value is the same as passed.
      */
     public void removeEntry(GridCacheEntryEx entry) {
-        map.removeEntry(entry);
+        boolean removed = map.removeEntry(entry);
+
+        if (log.isDebugEnabled()) {
+            if (removed)
+                log.debug("Removed entry from cache: " + entry);
+            else
+                log.debug("Remove will not be done for key (entry got replaced or removed): " + entry.key());
+        }
     }
 
     /**
@@ -1399,7 +1406,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         T2<V, GridCacheVersion> t = (T2<V, GridCacheVersion>)get(key, !ctx.keepBinary(), true);
 
-        CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()): null;
+        CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null;
 
         if (ctx.config().getInterceptor() != null) {
             V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
@@ -1424,7 +1431,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         IgniteInternalFuture<V> fut = getAsync(key, !ctx.keepBinary(), false);
 
         if (ctx.config().getInterceptor() != null)
-            fut =  fut.chain(new CX1<IgniteInternalFuture<V>, V>() {
+            fut = fut.chain(new CX1<IgniteInternalFuture<V>, V>() {
                 @Override public V applyx(IgniteInternalFuture<V> f) throws IgniteCheckedException {
                     return (V)ctx.config().getInterceptor().onGet(key, f.get());
                 }
@@ -1451,20 +1458,20 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         IgniteInternalFuture<CacheEntry<K, V>> fr = fut.chain(
             new CX1<IgniteInternalFuture<T2<V, GridCacheVersion>>, CacheEntry<K, V>>() {
-            @Override public CacheEntry<K, V> applyx(IgniteInternalFuture<T2<V, GridCacheVersion>> f)
-                throws IgniteCheckedException {
-                T2<V, GridCacheVersion> t = f.get();
+                @Override public CacheEntry<K, V> applyx(IgniteInternalFuture<T2<V, GridCacheVersion>> f)
+                    throws IgniteCheckedException {
+                    T2<V, GridCacheVersion> t = f.get();
 
-                CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null;
-                if (intercept) {
-                    V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
+                    CacheEntry<K, V> val = t != null ? new CacheEntryImplEx<>(key, t.get1(), t.get2()) : null;
+                    if (intercept) {
+                        V val0 = (V)ctx.config().getInterceptor().onGet(key, t != null ? val.getValue() : null);
 
-                    return new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null);
+                        return new CacheEntryImplEx<>(key, val0, t != null ? t.get2() : null);
+                    }
+                    else
+                        return val;
                 }
-                else
-                    return val;
-            }
-        });
+            });
 
         if (statsEnabled)
             fut.listen(new UpdateGetTimeStatClosure<T2<V, GridCacheVersion>>(metrics0(), start));
@@ -1516,7 +1523,6 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         return res;
     }
 
-
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final Collection<? extends K> keys) {
         A.notNull(keys, "keys");
@@ -1541,7 +1547,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
-    @Override  public IgniteInternalFuture<Collection<CacheEntry<K, V>>> getEntriesAsync(
+    @Override public IgniteInternalFuture<Collection<CacheEntry<K, V>>> getEntriesAsync(
         @Nullable final Collection<? extends K> keys) {
         A.notNull(keys, "keys");
 
@@ -1850,7 +1856,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                 final AffinityTopologyVersion topVer = tx == null ?
                     (canRemap ?
                         ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion()) :
-                        tx.topologyVersion();
+                    tx.topologyVersion();
 
                 int keysSize = keys.size();
 
@@ -2091,8 +2097,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * @throws IgniteCheckedException If failed.
      */
     @Nullable public V getAndPut(final K key, final V val, @Nullable final CacheEntryPredicate filter)
-        throws IgniteCheckedException
-    {
+        throws IgniteCheckedException {
         boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
         long start = statsEnabled ? System.nanoTime() : 0L;
@@ -2351,7 +2356,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         IgniteInternalFuture<?> fut = asyncOp(new AsyncOp() {
             @Override public IgniteInternalFuture op(IgniteTxLocalAdapter tx, AffinityTopologyVersion readyTopVer) {
                 Map<? extends K, EntryProcessor<K, V, Object>> invokeMap =
-                    Collections.singletonMap(key, (EntryProcessor<K, V, Object>) entryProcessor);
+                    Collections.singletonMap(key, (EntryProcessor<K, V, Object>)entryProcessor);
 
                 return tx.invokeAsync(ctx, readyTopVer, invokeMap, args);
             }
@@ -2578,7 +2583,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             }
         });
 
-        if(statsEnabled)
+        if (statsEnabled)
             fut.listen(new UpdatePutTimeStatClosure<V>(metrics0(), start));
 
         return fut;
@@ -2912,11 +2917,11 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         assert ctx.isLocal();
 
         for (Iterator<KeyCacheObject> it = ctx.swap().offHeapKeyIterator(true, true, AffinityTopologyVersion.NONE);
-             it.hasNext(); )
+            it.hasNext(); )
             remove((K)it.next());
 
         for (Iterator<KeyCacheObject> it = ctx.swap().swapKeyIterator(true, true, AffinityTopologyVersion.NONE);
-             it.hasNext(); )
+            it.hasNext(); )
             remove((K)it.next());
 
         removeAll(keySet());
@@ -3436,7 +3441,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
                         if (ttl == CU.TTL_ZERO)
                             return;
 
-                        loadEntry(key, val, ver0, (IgniteBiPredicate<Object, Object>) p, topVer, replicate, ttl);
+                        loadEntry(key, val, ver0, (IgniteBiPredicate<Object, Object>)p, topVer, replicate, ttl);
                     }
                 }, args);
             }
@@ -3490,8 +3495,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<?> localLoadCacheAsync(final IgniteBiPredicate<K, V> p,
-        final Object[] args)
-    {
+        final Object[] args) {
         return ctx.closures().callLocalSafe(
             ctx.projectSafe(new Callable<Object>() {
                 @Nullable @Override public Object call() throws IgniteCheckedException {
@@ -3596,8 +3600,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      */
     public void localLoad(Collection<? extends K> keys,
         @Nullable ExpiryPolicy plc)
-        throws IgniteCheckedException
-    {
+        throws IgniteCheckedException {
         final boolean replicate = ctx.isDrEnabled();
         final AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
 
@@ -4574,14 +4577,14 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * @return Entry set.
      */
     public Set<Cache.Entry<K, V>> entrySet(@Nullable CacheEntryPredicate... filter) {
-        return map.entries(filter);
+        return entrySetx(filter);
     }
 
     /**
      * @return Primary entry set.
      */
     public Set<Cache.Entry<K, V>> primaryEntrySet() {
-        return map.entries(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode()));
+        return new EntrySet(map.entrySet(CU.cachePrimary(ctx.grid().affinity(ctx.name()), ctx.localNode())));
     }
 
     /**
@@ -4612,15 +4615,23 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         String taskName,
         boolean deserializeBinary,
         boolean needVer) throws IgniteCheckedException {
-        return getAsync(key,
-            !ctx.config().isReadFromBackup(),
-            /*skip tx*/false,
-            null,
-            taskName,
-            deserializeBinary,
-            false,
-            /*can remap*/true,
-            needVer).get();
+        try {
+            return getAsync(key,
+                !ctx.config().isReadFromBackup(),
+                /*skip tx*/false,
+                null,
+                taskName,
+                deserializeBinary,
+                false,
+                /*can remap*/true,
+                needVer).get();
+        }
+        catch (IgniteException e) {
+            if (e.getCause(IgniteCheckedException.class) != null)
+                throw e.getCause(IgniteCheckedException.class);
+            else
+                throw e;
+        }
     }
 
     /**
@@ -4741,7 +4752,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      * @param deserializeBinary Deserialize binary flag.
      * @return Public API iterator.
      */
-    protected Iterator<Cache.Entry<K, V>> iterator(final Iterator<GridCacheEntryEx> it,
+    protected Iterator<Cache.Entry<K, V>> iterator(final Iterator<? extends GridCacheEntryEx> it,
         final boolean deserializeBinary) {
         return new Iterator<Cache.Entry<K, V>>() {
             {
@@ -4807,8 +4818,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
      */
     @Nullable private Cache.Entry<K, V> toCacheEntry(GridCacheEntryEx entry,
         boolean deserializeBinary)
-        throws IgniteCheckedException, GridCacheEntryRemovedException
-    {
+        throws IgniteCheckedException, GridCacheEntryRemovedException {
         CacheObject val = entry.innerGet(
             null,
             null,
@@ -5497,7 +5507,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
          * @param loadArgs Arguments.
          * @param plc Policy.
          */
-        private LoadCacheJob(String cacheName, AffinityTopologyVersion topVer, IgniteBiPredicate<K, V> p, Object[] loadArgs,
+        private LoadCacheJob(String cacheName, AffinityTopologyVersion topVer, IgniteBiPredicate<K, V> p,
+            Object[] loadArgs,
             ExpiryPolicy plc) {
             super(cacheName, topVer);
 
@@ -5710,7 +5721,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
     /**
      *
      */
-    static class LoadKeysCallable<K, V> implements IgniteCallable<Void>, Externalizable{
+    static class LoadKeysCallable<K, V> implements IgniteCallable<Void>, Externalizable {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -5831,8 +5842,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
 
         /** {@inheritDoc} */
         @Override public void applyx(KeyCacheObject key, Object val, GridCacheVersion ver)
-            throws IgniteCheckedException
-        {
+            throws IgniteCheckedException {
             assert ver != null;
 
             if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V)val))
@@ -5914,8 +5924,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
         private LoadCacheClosure(String cacheName,
             IgniteBiPredicate<K, V> p,
             Object[] args,
-            @Nullable ExpiryPolicy plc)
-        {
+            @Nullable ExpiryPolicy plc) {
             this.cacheName = cacheName;
             this.p = p;
             this.args = args;
@@ -6380,4 +6389,173 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
             return null;
         }
     }
+
+    /**
+     * Iterator implementation for KeySet.
+     */
+    private final class KeySetIterator implements Iterator<K> {
+        /** Internal map entry iterator. */
+        private final Iterator<GridCacheMapEntry> internalIterator;
+
+        /** Keep binary flag. */
+        private final boolean keepBinary;
+
+        /** Current entry. */
+        private GridCacheMapEntry current;
+
+        /**
+         * Constructor.
+         * @param internalIterator Internal iterator.
+         * @param keepBinary Keep binary flag.
+         */
+        private KeySetIterator(Iterator<GridCacheMapEntry> internalIterator, boolean keepBinary) {
+            this.internalIterator = internalIterator;
+            this.keepBinary = keepBinary;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            return internalIterator.hasNext();
+        }
+
+        /** {@inheritDoc} */
+        @Override public K next() {
+            current = internalIterator.next();
+
+            return (K)ctx.unwrapBinaryIfNeeded(current.key(), keepBinary, true);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void remove() {
+            if (current == null)
+                throw new IllegalStateException();
+
+            try {
+                GridCacheAdapter.this.getAndRemove((K)current.key());
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException(e);
+            }
+
+            current = null;
+        }
+    }
+
+    /**
+     * A wrapper over internal map that provides set semantics and constant-time contains() check.
+     */
+    private final class KeySet extends AbstractSet<K> {
+        /** Internal entry set. */
+        private final Set<GridCacheMapEntry> internalSet;
+
+        /** Keep binary flag. */
+        private final boolean keepBinary;
+
+        /**
+         * Constructor
+         * @param internalSet Internal set.
+         */
+        private KeySet(Set<GridCacheMapEntry> internalSet) {
+            this.internalSet = internalSet;
+
+            CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+            keepBinary = opCtx != null && opCtx.isKeepBinary();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<K> iterator() {
+            return new KeySetIterator(internalSet.iterator(), keepBinary);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int size() {
+            return F.size(iterator());
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean contains(Object o) {
+            GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o));
+
+            return entry != null && internalSet.contains(entry);
+        }
+    }
+
+    /**
+     * Iterator implementation for EntrySet.
+     */
+    private final class EntryIterator implements Iterator<Cache.Entry<K, V>> {
+
+        /** Internal iterator. */
+        private final Iterator<GridCacheMapEntry> internalIterator;
+
+        /** Current entry. */
+        private GridCacheMapEntry current;
+
+        /**
+         * Constructor.
+         * @param internalIterator Internal iterator.
+         */
+        private EntryIterator(Iterator<GridCacheMapEntry> internalIterator) {
+            this.internalIterator = internalIterator;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            return internalIterator.hasNext();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Cache.Entry<K, V> next() {
+            current = internalIterator.next();
+
+            return current.wrapLazyValue();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void remove() {
+            if (current == null)
+                throw new IllegalStateException();
+
+            try {
+                GridCacheAdapter.this.getAndRemove((K)current.wrapLazyValue().getKey());
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException(e);
+            }
+
+            current = null;
+        }
+    }
+
+    /**
+     * A wrapper over internal map that provides set semantics and constant-time contains() check.
+     */
+    private final class EntrySet extends AbstractSet<Cache.Entry<K, V>> {
+
+        /** Internal set. */
+        private final Set<GridCacheMapEntry> internalSet;
+
+        /** Constructor. */
+        private EntrySet(Set<GridCacheMapEntry> internalSet) {
+            this.internalSet = internalSet;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<Cache.Entry<K, V>> iterator() {
+            return new EntryIterator(internalSet.iterator());
+        }
+
+        /** {@inheritDoc} */
+        @Override public int size() {
+            return F.size(iterator());
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean contains(Object o) {
+            GridCacheMapEntry entry = map.getEntry(ctx.toCacheKeyObject(o));
+
+            return entry != null && internalSet.contains(entry);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
index f1767e0..5e843dc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
@@ -197,10 +197,18 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter {
     public int partition(Object key) {
         GridAffinityAssignmentCache aff0 = aff;
 
+        if (key instanceof KeyCacheObject && ((KeyCacheObject)key).partition() != -1)
+            return ((KeyCacheObject)key).partition();
+
         if (aff0 == null)
             throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
 
-        return affFunction.partition(affinityKey(key));
+        int p = affFunction.partition(affinityKey(key));
+
+        if (key instanceof KeyCacheObject)
+            ((KeyCacheObject)key).partition(p);
+
+        return p;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b7470b3/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
index ffce82d..4f97e7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllRunnable.java
@@ -79,7 +79,7 @@ public class GridCacheClearAllRunnable<K, V> implements Runnable {
 
     /** {@inheritDoc} */
     @Override public void run() {
-        Iterator<GridCacheEntryEx> iter = cache.map().stripedEntryIterator(id, totalCnt);
+        Iterator<? extends GridCacheEntryEx> iter = cache.entries().iterator();
 
         while (iter.hasNext())
             clearEntry(iter.next());


[39/50] [abbrv] ignite git commit: IGNITE-2996 .NET: Added IgniteConfiguration.isLateAffinityAssignment method.

Posted by sh...@apache.org.
IGNITE-2996 .NET: Added IgniteConfiguration.isLateAffinityAssignment method.


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

Branch: refs/heads/ignite-2788
Commit: 03b776fac8d3334074a9916fa8b67d1c376d3d97
Parents: f8bf93a
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Thu Apr 28 10:25:11 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../utils/PlatformConfigurationUtils.java       |  2 ++
 .../IgniteConfigurationSerializerTest.cs        |  3 +-
 .../IgniteConfigurationTest.cs                  |  2 ++
 .../Apache.Ignite.Core/IgniteConfiguration.cs   | 34 ++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/03b776fa/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 898bcf9..5ee19c1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -345,6 +345,7 @@ public class PlatformConfigurationUtils {
         cfg.setWorkDirectory(in.readString());
         cfg.setLocalHost(in.readString());
         cfg.setDaemon(in.readBoolean());
+        cfg.setLateAffinityAssignment(in.readBoolean());
 
         readCacheConfigurations(in, cfg);
         readDiscoveryConfiguration(in, cfg);
@@ -671,6 +672,7 @@ public class PlatformConfigurationUtils {
         w.writeString(cfg.getWorkDirectory());
         w.writeString(cfg.getLocalHost());
         w.writeBoolean(cfg.isDaemon());
+        w.writeBoolean(cfg.isLateAffinityAssignment());
 
         CacheConfiguration[] cacheCfg = cfg.getCacheConfiguration();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/03b776fa/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
index ae48e71..36bda2e 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
@@ -54,7 +54,7 @@ namespace Apache.Ignite.Core.Tests
         [Test]
         public void TestPredefinedXml()
         {
-            var xml = @"<igniteConfig workDirectory='c:' JvmMaxMemoryMb='1024' MetricsLogFrequency='0:0:10' isDaemon='true'>
+            var xml = @"<igniteConfig workDirectory='c:' JvmMaxMemoryMb='1024' MetricsLogFrequency='0:0:10' isDaemon='true' isLateAffinityAssignment='false'>
                             <localhost>127.1.1.1</localhost>
                             <binaryConfiguration compactFooter='false'>
                                 <defaultNameMapper type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+NameMapper, Apache.Ignite.Core.Tests' bar='testBar' />
@@ -107,6 +107,7 @@ namespace Apache.Ignite.Core.Tests
             Assert.AreEqual("c:", cfg.WorkDirectory);
             Assert.AreEqual("127.1.1.1", cfg.Localhost);
             Assert.IsTrue(cfg.IsDaemon);
+            Assert.IsFalse(cfg.IsLateAffinityAssignment);
             Assert.AreEqual(1024, cfg.JvmMaxMemoryMb);
             Assert.AreEqual(TimeSpan.FromSeconds(10), cfg.MetricsLogFrequency);
             Assert.AreEqual(TimeSpan.FromMinutes(1), ((TcpDiscoverySpi)cfg.DiscoverySpi).JoinTimeout);

http://git-wip-us.apache.org/repos/asf/ignite/blob/03b776fa/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
index c6a1cab..45b9a05 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs
@@ -111,6 +111,7 @@ namespace Apache.Ignite.Core.Tests
                 Assert.IsTrue(File.Exists(resCfg.JvmDllPath));
                 Assert.AreEqual(cfg.Localhost, resCfg.Localhost);
                 Assert.AreEqual(cfg.IsDaemon, resCfg.IsDaemon);
+                Assert.AreEqual(cfg.IsLateAffinityAssignment, resCfg.IsLateAffinityAssignment);
                 Assert.AreEqual(cfg.UserAttributes, resCfg.UserAttributes);
 
                 var atm = cfg.AtomicConfiguration;
@@ -369,6 +370,7 @@ namespace Apache.Ignite.Core.Tests
                 JvmClasspath = TestUtils.CreateTestClasspath(),
                 Localhost = "127.0.0.1",
                 IsDaemon = true,
+                IsLateAffinityAssignment = false,
                 UserAttributes = Enumerable.Range(1, 10).ToDictionary(x => x.ToString(), x => (object) x),
                 AtomicConfiguration = new AtomicConfiguration
                 {

http://git-wip-us.apache.org/repos/asf/ignite/blob/03b776fa/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
index e5f6a83..e14c15b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs
@@ -26,6 +26,7 @@
     using System.IO;
     using System.Linq;
     using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Configuration;
     using Apache.Ignite.Core.Cluster;
     using Apache.Ignite.Core.DataStructures.Configuration;
@@ -91,6 +92,11 @@
         public const int DefaultNetworkSendRetryCount = 3;
 
         /// <summary>
+        /// Default late affinity assignment mode.
+        /// </summary>
+        public const bool DefaultIsLateAffinityAssignment = true;
+
+        /// <summary>
         /// Initializes a new instance of the <see cref="IgniteConfiguration"/> class.
         /// </summary>
         public IgniteConfiguration()
@@ -105,6 +111,7 @@
             NetworkTimeout = DefaultNetworkTimeout;
             NetworkSendRetryCount = DefaultNetworkSendRetryCount;
             NetworkSendRetryDelay = DefaultNetworkSendRetryDelay;
+            IsLateAffinityAssignment = DefaultIsLateAffinityAssignment;
         }
 
         /// <summary>
@@ -181,6 +188,7 @@
             writer.WriteString(WorkDirectory);
             writer.WriteString(Localhost);
             writer.WriteBoolean(IsDaemon);
+            writer.WriteBoolean(IsLateAffinityAssignment);
 
             // Cache config
             var caches = CacheConfiguration;
@@ -283,6 +291,7 @@
             WorkDirectory = r.ReadString();
             Localhost = r.ReadString();
             IsDaemon = r.ReadBoolean();
+            IsLateAffinityAssignment = r.ReadBoolean();
 
             // Cache config
             var cacheCfgCount = r.ReadInt();
@@ -573,5 +582,30 @@
         /// Gets or sets the transaction configuration.
         /// </summary>
         public TransactionConfiguration TransactionConfiguration { get; set; }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether late affinity assignment mode should be used.
+        /// <para />
+        /// On each topology change, for each started cache, partition-to-node mapping is
+        /// calculated using AffinityFunction for cache. When late
+        /// affinity assignment mode is disabled then new affinity mapping is applied immediately.
+        /// <para />
+        /// With late affinity assignment mode, if primary node was changed for some partition, but data for this
+        /// partition is not rebalanced yet on this node, then current primary is not changed and new primary 
+        /// is temporary assigned as backup. This nodes becomes primary only when rebalancing for all assigned primary 
+        /// partitions is finished. This mode can show better performance for cache operations, since when cache 
+        /// primary node executes some operation and data is not rebalanced yet, then it sends additional message 
+        /// to force rebalancing from other nodes.
+        /// <para />
+        /// Note, that <see cref="ICacheAffinity"/> interface provides assignment information taking late assignment
+        /// into account, so while rebalancing for new primary nodes is not finished it can return assignment 
+        /// which differs from assignment calculated by AffinityFunction.
+        /// <para />
+        /// This property should have the same value for all nodes in cluster.
+        /// <para />
+        /// If not provided, default value is <see cref="DefaultIsLateAffinityAssignment"/>.
+        /// </summary>
+        [DefaultValue(DefaultIsLateAffinityAssignment)]
+        public bool IsLateAffinityAssignment { get; set; }
     }
 }


[47/50] [abbrv] ignite git commit: Fixed JavaDoc.

Posted by sh...@apache.org.
Fixed JavaDoc.


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

Branch: refs/heads/ignite-2788
Commit: 3624e183505465915fe59e4683ad2f02ccde7c9b
Parents: 6d75fe6
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Apr 29 16:19:11 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:17 2016 +0900

----------------------------------------------------------------------
 .../internal/processors/datastructures/GridCacheLockState.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3624e183/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
index 3feb9bf..675286d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheLockState.java
@@ -140,7 +140,7 @@ public final class GridCacheLockState implements GridCacheInternal, Externalizab
     }
 
     /**
-     * @return New owner node ID.
+     * @param id New owner node ID.
      */
     public void setId(UUID id) {
         this.id = id;


[33/50] [abbrv] ignite git commit: IGNITE-642 Implement IgniteReentrantLock data structure

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteLockAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteLockAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteLockAbstractSelfTest.java
new file mode 100644
index 0000000..8fb9049
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteLockAbstractSelfTest.java
@@ -0,0 +1,1629 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteCondition;
+import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.IgniteLock;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.GridConcurrentHashSet;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+
+import static java.util.concurrent.TimeUnit.MICROSECONDS;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+
+/**
+ * Cache reentrant lock self test.
+ */
+public abstract class IgniteLockAbstractSelfTest extends IgniteAtomicsAbstractTest
+    implements Externalizable {
+    /** */
+    private static final int NODES_CNT = 4;
+
+    /** */
+    protected static final int THREADS_CNT = 5;
+
+    /** */
+    private static final Random RND = new Random();
+
+    /** */
+    @Rule
+    public final ExpectedException exception = ExpectedException.none();
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return NODES_CNT;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLock() throws Exception {
+        checkReentrantLock(false);
+
+        checkReentrantLock(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFailover() throws Exception {
+        if (atomicsCacheMode() == LOCAL)
+            return;
+
+        checkFailover(true, false);
+
+        checkFailover(false, false);
+
+        checkFailover(true, true);
+
+        checkFailover(false, true);
+    }
+
+    /**
+     * @param failoverSafe Failover safe flag.
+     * @throws Exception
+     */
+    private void checkFailover(final boolean failoverSafe, final boolean fair) throws Exception {
+        IgniteEx g = startGrid(NODES_CNT + 1);
+
+        // For vars locality.
+        {
+            // Ensure not exists.
+            assert g.reentrantLock("lock", failoverSafe, fair, false) == null;
+
+            IgniteLock lock  = g.reentrantLock("lock", failoverSafe, fair, true);
+
+            lock.lock();
+
+            assert lock.tryLock();
+
+            assertEquals(2, lock.getHoldCount());
+        }
+
+        Ignite g0 = grid(0);
+
+        final IgniteLock lock0 = g0.reentrantLock("lock", false, fair, false);
+
+        assert !lock0.tryLock();
+
+        assertEquals(0, lock0.getHoldCount());
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    try {
+                        lock0.lock();
+
+                        info("Acquired in separate thread.");
+
+                        // Lock is acquired silently only in failoverSafe mode.
+                        assertTrue(failoverSafe);
+
+                        lock0.unlock();
+
+                        info("Released lock in separate thread.");
+                    }
+                    catch (IgniteException e) {
+                        if (!failoverSafe)
+                            info("Ignored expected exception: " + e);
+                        else
+                            throw e;
+                    }
+                    return null;
+                }
+            },
+            1);
+
+        Thread.sleep(100);
+
+        g.close();
+
+        fut.get(500);
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkReentrantLock(final boolean fair) throws Exception {
+        // Test API.
+        checkLock(fair);
+
+        checkFailoverSafe(fair);
+
+        // Test main functionality.
+        IgniteLock lock1 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertFalse(lock1.isLocked());
+
+        lock1.lock();
+
+        IgniteCompute comp = grid(0).compute().withAsync();
+
+        comp.call(new IgniteCallable<Object>() {
+            @IgniteInstanceResource
+            private Ignite ignite;
+
+            @LoggerResource
+            private IgniteLogger log;
+
+            @Nullable @Override public Object call() throws Exception {
+                // Test reentrant lock in multiple threads on each node.
+                IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(
+                    new Callable<Object>() {
+                        @Nullable @Override public Object call() throws Exception {
+                            IgniteLock lock = ignite.reentrantLock("lock", true, fair, true);
+
+                            assert lock != null;
+
+                            log.info("Thread is going to wait on reentrant lock: " + Thread.currentThread().getName());
+
+                            assert lock.tryLock(1, MINUTES);
+
+                            log.info("Thread is again runnable: " + Thread.currentThread().getName());
+
+                            lock.unlock();
+
+                            return null;
+                        }
+                    },
+                    5,
+                    "test-thread"
+                );
+
+                fut.get();
+
+                return null;
+            }
+        });
+
+        IgniteFuture<Object> fut = comp.future();
+
+        Thread.sleep(3000);
+
+        assert lock1.isHeldByCurrentThread();
+
+        assert lock1.getHoldCount() == 1;
+
+        lock1.lock();
+
+        assert lock1.isHeldByCurrentThread();
+
+        assert lock1.getHoldCount() == 2;
+
+        lock1.unlock();
+
+        lock1.unlock();
+
+        // Ensure there are no hangs.
+        fut.get();
+
+        // Test operations on removed lock.
+        lock1.close();
+
+        checkRemovedReentrantLock(lock1);
+    }
+
+    /**
+     * @param lock IgniteLock.
+     * @throws Exception If failed.
+     */
+    protected void checkRemovedReentrantLock(final IgniteLock lock) throws Exception {
+        assert GridTestUtils.waitForCondition(new PA() {
+            @Override public boolean apply() {
+                return lock.removed();
+            }
+        }, 5000);
+
+        assert lock.removed();
+    }
+
+    /**
+     * This method only checks if parameter of new reentrant lock is initialized properly.
+     * For tests considering failure recovery see @GridCachePartitionedNodeFailureSelfTest.
+     *
+     * @throws Exception Exception.
+     */
+    private void checkFailoverSafe(final boolean fair) throws Exception {
+        // Checks only if reentrant lock is initialized properly
+        IgniteLock lock = createReentrantLock("rmv", true, fair);
+
+        assert lock.isFailoverSafe();
+
+        removeReentrantLock("rmv", fair);
+
+        IgniteLock lock1 = createReentrantLock("rmv1", false, fair);
+
+        assert !lock1.isFailoverSafe();
+
+        removeReentrantLock("rmv1", fair);
+    }
+
+    /**
+     * @throws Exception Exception.
+     */
+    private void checkLock(final boolean fair) throws Exception {
+        // Check only 'false' cases here. Successful lock is tested over the grid.
+        final IgniteLock lock = createReentrantLock("acquire", false, fair);
+
+        lock.lock();
+
+        IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                assertNotNull(lock);
+
+                assert !lock.tryLock();
+
+                assert !lock.tryLock(10, MICROSECONDS);
+
+                return null;
+            }
+        });
+
+        fut.get();
+
+        lock.unlock();
+
+        removeReentrantLock("acquire", fair);
+    }
+
+    /**
+     * @param lockName Reentrant lock name.
+     * @param failoverSafe FailoverSafe flag.
+     * @param fair Fairness flag.
+     * @return New distributed reentrant lock.
+     * @throws Exception If failed.
+     */
+    private IgniteLock createReentrantLock(String lockName, boolean failoverSafe, boolean fair)
+        throws Exception {
+        IgniteLock lock = grid(RND.nextInt(NODES_CNT)).reentrantLock(lockName, failoverSafe, fair, true);
+
+        // Test initialization.
+        assert lockName.equals(lock.name());
+        assert !lock.isLocked();
+        assert lock.isFailoverSafe() == failoverSafe;
+        assert lock.isFair() == fair;
+
+        return lock;
+    }
+
+    /**
+     * @param lockName Reentrant lock name.
+     * @throws Exception If failed.
+     */
+    private void removeReentrantLock(String lockName, final boolean fair)
+        throws Exception {
+        IgniteLock lock = grid(RND.nextInt(NODES_CNT)).reentrantLock(lockName, false, fair, true);
+
+        assert lock != null;
+
+        // Remove lock on random node.
+        IgniteLock lock0 = grid(RND.nextInt(NODES_CNT)).reentrantLock(lockName, false, fair, true);
+
+        assertNotNull(lock0);
+
+        lock0.close();
+
+        // Ensure reentrant lock is removed on all nodes.
+        for (Ignite g : G.allGrids())
+            assertNull(((IgniteKernal)g).context().dataStructures().reentrantLock(lockName, false, fair, false));
+
+        checkRemovedReentrantLock(lock);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLockSerialization() throws Exception {
+        final IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+        info("Lock created: " + lock);
+
+        lock.isFailoverSafe();
+        lock.isFair();
+
+        grid(ThreadLocalRandom.current().nextInt(G.allGrids().size())).compute().broadcast(new IgniteCallable<Object>() {
+            @Nullable @Override public Object call() throws Exception {
+                Thread.sleep(1000);
+
+                lock.lock();
+
+                try {
+                    info("Inside lock: " + lock.getHoldCount());
+                }
+                finally {
+                    lock.unlock();
+                }
+
+                return null;
+            }
+        });
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInitialization() throws Exception {
+        // Test #name() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertEquals("lock", lock.name());
+
+            lock.close();
+        }
+
+        // Test #isFailoverSafe() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            info("Lock created: " + lock);
+
+            assertTrue(lock.isFailoverSafe());
+
+            lock.close();
+        }
+
+        // Test #isFair() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertTrue(lock.isFair());
+
+            lock.close();
+        }
+
+        // Test #isBroken() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.isBroken());
+
+            lock.close();
+        }
+
+        // Test #getOrCreateCondition(String ) method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertNotNull(lock.getOrCreateCondition("condition"));
+
+            lock.close();
+        }
+
+        // Test #getHoldCount() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertEquals(0, lock.getHoldCount());
+
+            lock.close();
+        }
+
+        // Test #isHeldByCurrentThread() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.isHeldByCurrentThread());
+
+            lock.close();
+        }
+
+        // Test #isLocked() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.isLocked());
+
+            lock.close();
+        }
+
+        // Test #hasQueuedThreads() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.hasQueuedThreads());
+
+            lock.close();
+        }
+
+        // Test #hasQueuedThread(Thread ) method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.hasQueuedThread(Thread.currentThread()));
+
+            lock.close();
+        }
+
+        // Test #hasWaiters(IgniteCondition ) method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            try {
+                IgniteCondition cond = grid(0).reentrantLock("lock2", true, true, true).getOrCreateCondition("cond");
+
+                lock.hasWaiters(cond);
+
+                fail("Condition not associated with this lock passed as argument.");
+            }
+            catch (IllegalArgumentException e) {
+                info("IllegalArgumentException thrown as it should be.");
+            }
+
+            try {
+                IgniteCondition cond = lock.getOrCreateCondition("condition");
+
+                lock.hasWaiters(cond);
+
+                fail("This method should throw exception when lock is not held.");
+            }
+            catch (IllegalMonitorStateException e) {
+                info("IllegalMonitorStateException thrown as it should be.");
+            }
+
+            lock.close();
+        }
+
+        // Test #getWaitQueueLength(IgniteCondition ) method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            try {
+                IgniteCondition cond = grid(0).reentrantLock("lock2", true, true, true).getOrCreateCondition("cond");
+
+                lock.getWaitQueueLength(cond);
+
+                fail("Condition not associated with this lock passed as argument.");
+            }
+            catch (IllegalArgumentException e) {
+                info("IllegalArgumentException thrown as it should be.");
+            }
+
+            try {
+                IgniteCondition cond = lock.getOrCreateCondition("condition");
+
+                lock.getWaitQueueLength(cond);
+
+                fail("This method should throw exception when lock is not held.");
+            }
+            catch (IllegalMonitorStateException e) {
+                info("IllegalMonitorStateException thrown as it should be.");
+            }
+
+            lock.close();
+        }
+
+        // Test #lock() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            lock.lock();
+
+            lock.unlock();
+
+            lock.close();
+        }
+
+        // Test #lockInterruptibly() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            lock.lockInterruptibly();
+
+            lock.unlock();
+
+            lock.close();
+        }
+
+        // Test #tryLock() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            boolean success = lock.tryLock();
+
+            assertTrue(success);
+
+            lock.unlock();
+
+            lock.close();
+        }
+
+        // Test #tryLock(long, TimeUnit) method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            boolean success = lock.tryLock(1, MILLISECONDS);
+
+            assertTrue(success);
+
+            lock.unlock();
+
+            lock.close();
+        }
+
+        // Test #unlock() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            try {
+                lock.unlock();
+
+                fail("This method should throw exception when lock is not held.");
+            }
+            catch (IllegalMonitorStateException e) {
+                info("IllegalMonitorStateException thrown as it should be.");
+            }
+
+            lock.close();
+        }
+
+        // Test #removed() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            assertFalse(lock.removed());
+
+            lock.close();
+
+            assertTrue(lock.removed());
+        }
+
+        // Test #close() method.
+        {
+            IgniteLock lock = grid(0).reentrantLock("lock", true, true, true);
+
+            lock.close();
+
+            assertTrue(lock.removed());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReentrantLockMultinode1() throws Exception {
+        testReentrantLockMultinode1(false);
+
+        testReentrantLockMultinode1(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testReentrantLockMultinode1(final boolean fair) throws Exception {
+        if (gridCount() == 1)
+            return;
+
+        IgniteLock lock = grid(0).reentrantLock("s1", true, fair, true);
+
+        List<IgniteInternalFuture<?>> futs = new ArrayList<>();
+
+        for (int i = 0; i < gridCount(); i++) {
+            final Ignite ignite = grid(i);
+
+            futs.add(GridTestUtils.runAsync(new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    IgniteLock lock = ignite.reentrantLock("s1", true, fair, false);
+
+                    assertNotNull(lock);
+
+                    IgniteCondition cond1 = lock.getOrCreateCondition("c1");
+
+                    IgniteCondition cond2 = lock.getOrCreateCondition("c2");
+
+                    try {
+                        boolean wait = lock.tryLock(30_000, MILLISECONDS);
+
+                        assertTrue(wait);
+
+                        cond2.signal();
+
+                        cond1.await();
+                    }
+                    finally {
+                        lock.unlock();
+                    }
+
+                    return null;
+                }
+            }));
+        }
+
+        boolean done = false;
+
+        while(!done) {
+            done = true;
+
+            for (IgniteInternalFuture<?> fut : futs){
+                if(!fut.isDone())
+                    done = false;
+            }
+
+            try{
+                lock.lock();
+
+                lock.getOrCreateCondition("c1").signal();
+
+                lock.getOrCreateCondition("c2").await(10,MILLISECONDS);
+            }
+            finally {
+                lock.unlock();
+            }
+        }
+
+        for (IgniteInternalFuture<?> fut : futs)
+            fut.get(30_000);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLockInterruptibly() throws Exception {
+        testLockInterruptibly(false);
+
+        testLockInterruptibly(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testLockInterruptibly(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        lock0.lock();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    try {
+                        lock0.lockInterruptibly();
+                    }
+                    catch (IgniteInterruptedException e) {
+                        assertFalse(Thread.currentThread().isInterrupted());
+
+                        isInterrupted = true;
+                    }
+                    finally {
+                        // Assert that thread was interrupted.
+                        assertTrue(isInterrupted);
+
+                        // Assert that locked is still owned by main thread.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread doesn't own the lock.
+                        assertFalse(lock0.isHeldByCurrentThread());
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        // Wait for all threads to attempt to acquire lock.
+        while (startedThreads.size() != totalThreads) {
+            Thread.sleep(1000);
+        }
+
+        for (Thread t : startedThreads)
+            t.interrupt();
+
+        fut.get();
+
+        lock0.unlock();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLockInterruptiblyMultinode() throws Exception {
+        testLockInterruptiblyMultinode(false);
+
+        testLockInterruptiblyMultinode(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testLockInterruptiblyMultinode(final boolean fair) throws Exception {
+        if (gridCount() == 1)
+            return;
+
+        // Initialize reentrant lock.
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        lock0.lock();
+
+        // Number of threads, one per node.
+        final int threadCount = gridCount();
+
+        final AtomicLong threadCounter = new AtomicLong(0);
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    final int localNodeId = (int)threadCounter.getAndIncrement();
+
+                    final Ignite grid = grid(localNodeId);
+
+                    IgniteClosure<Ignite, Void> closure = new IgniteClosure<Ignite, Void>() {
+                        @Override public Void apply(Ignite ignite) {
+                            final IgniteLock l = ignite.reentrantLock("lock", true, true, true);
+
+                            final AtomicReference<Thread> thread = new AtomicReference<>();
+
+                            final AtomicBoolean done = new AtomicBoolean(false);
+
+                            final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
+
+                            final IgniteCountDownLatch latch = ignite.countDownLatch("latch", threadCount, false, true);
+
+                            IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
+                                @Override public Void call() throws Exception {
+                                    try{
+                                        thread.set(Thread.currentThread());
+
+                                        l.lockInterruptibly();
+                                    }
+                                    catch(IgniteInterruptedException e){
+                                        exceptionThrown.set(true);
+                                    }
+                                    finally {
+                                        done.set(true);
+                                    }
+
+                                    return null;
+                                }
+                            });
+
+                            // Wait until l.lock() has been called.
+                            while(!l.hasQueuedThreads()){
+                                // No-op.
+                            }
+
+                            latch.countDown();
+
+                            latch.await();
+
+                            thread.get().interrupt();
+
+                            while(!done.get()){
+                                // No-op.
+                            }
+
+                            try {
+                                fut.get();
+                            }
+                            catch (IgniteCheckedException e) {
+                                fail(e.getMessage());
+
+                                throw new RuntimeException(e);
+                            }
+
+                            assertTrue(exceptionThrown.get());
+
+                            return null;
+                        }
+                    };
+
+                    closure.apply(grid);
+
+                    return null;
+                }
+            }, threadCount);
+
+        fut.get();
+
+        lock0.unlock();
+
+        info("Checking if interrupted threads are removed from global waiting queue...");
+
+        // Check if interrupted threads are removed from global waiting queue.
+        boolean locked = lock0.tryLock(1000, MILLISECONDS);
+
+        info("Interrupted threads successfully removed from global waiting queue. ");
+
+        assertTrue(locked);
+
+        lock0.unlock();
+
+        assertFalse(lock0.isLocked());
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLock() throws Exception {
+        testLock(false);
+
+        testLock(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testLock(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        lock0.lock();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    try {
+                        lock0.lock();
+                    }
+                    catch (IgniteInterruptedException e) {
+                        isInterrupted = true;
+
+                        fail("Lock() method is uninterruptible.");
+                    }
+                    finally {
+                        // Assert that thread was not interrupted.
+                        assertFalse(isInterrupted);
+
+                        // Assert that interrupted flag is set and clear it in order to call unlock().
+                        assertTrue(Thread.interrupted());
+
+                        // Assert that lock is still owned by this thread.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread does own the lock.
+                        assertTrue(lock0.isHeldByCurrentThread());
+
+                        // Release lock.
+                        lock0.unlock();
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        // Wait for all threads to attempt to acquire lock.
+        while (startedThreads.size() != totalThreads) {
+            Thread.sleep(500);
+        }
+
+        for (Thread t : startedThreads)
+            t.interrupt();
+
+        lock0.unlock();
+
+        fut.get();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTryLock() throws Exception {
+        testTryLock(false);
+
+        testTryLock(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testTryLock(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        lock0.lock();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    boolean locked = false;
+
+                    try {
+                        locked = lock0.tryLock();
+                    }
+                    catch (IgniteInterruptedException e) {
+                        isInterrupted = true;
+
+                        fail("tryLock() method is uninterruptible.");
+                    }
+                    finally {
+                        // Assert that thread was not interrupted.
+                        assertFalse(isInterrupted);
+
+                        // Assert that lock is locked.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread does own the lock.
+                        assertEquals(locked, lock0.isHeldByCurrentThread());
+
+                        // Release lock.
+                        if (locked)
+                            lock0.unlock();
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        // Wait for all threads to attempt to acquire lock.
+        while (startedThreads.size() != totalThreads) {
+            Thread.sleep(500);
+        }
+
+        for (Thread t : startedThreads)
+            t.interrupt();
+
+        fut.get();
+
+        lock0.unlock();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTryLockTimed() throws Exception {
+        testTryLockTimed(false);
+
+        testTryLockTimed(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testTryLockTimed(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        lock0.lock();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    boolean locked = false;
+
+                    try {
+                        locked = lock0.tryLock(100, TimeUnit.MILLISECONDS);
+                    }
+                    catch (IgniteInterruptedException e) {
+                        isInterrupted = true;
+                    }
+                    finally {
+                        // Assert that thread was not interrupted.
+                        assertFalse(isInterrupted);
+
+                        // Assert that tryLock returned false.
+                        assertFalse(locked);
+
+                        // Assert that lock is still owned by main thread.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread doesn't own the lock.
+                        assertFalse(lock0.isHeldByCurrentThread());
+
+                        // Release lock.
+                        if (locked)
+                            lock0.unlock();
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        fut.get();
+
+        lock0.unlock();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConditionAwaitUninterruptibly() throws Exception {
+        testConditionAwaitUninterruptibly(false);
+
+        testConditionAwaitUninterruptibly(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testConditionAwaitUninterruptibly(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    lock0.lock();
+
+                    IgniteCondition cond = lock0.getOrCreateCondition("cond");
+
+                    try {
+                        cond.awaitUninterruptibly();
+                    }
+                    catch (IgniteInterruptedException e) {
+                        isInterrupted = true;
+                    }
+                    finally {
+                        // Assert that thread was not interrupted.
+                        assertFalse(isInterrupted);
+
+                        // Assert that lock is still locked.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread does own the lock.
+                        assertTrue(lock0.isHeldByCurrentThread());
+
+                        // Clear interrupt flag.
+                        assertTrue(Thread.interrupted());
+
+                        // Release lock.
+                        if (lock0.isHeldByCurrentThread())
+                            lock0.unlock();
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        // Wait for all threads to attempt to acquire lock.
+        while (startedThreads.size() != totalThreads) {
+            Thread.sleep(500);
+        }
+
+        lock0.lock();
+
+        for (Thread t : startedThreads) {
+            t.interrupt();
+
+            lock0.getOrCreateCondition("cond").signal();
+        }
+
+        lock0.unlock();
+
+        fut.get();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConditionInterruptAwait() throws Exception {
+        testConditionInterruptAwait(false);
+
+        testConditionInterruptAwait(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testConditionInterruptAwait(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 2;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    boolean isInterrupted = false;
+
+                    lock0.lock();
+
+                    IgniteCondition cond = lock0.getOrCreateCondition("cond");
+
+                    try {
+                        cond.await();
+                    }
+                    catch (IgniteInterruptedException e) {
+                        isInterrupted = true;
+                    }
+                    finally {
+                        // Assert that thread was interrupted.
+                        assertTrue(isInterrupted);
+
+                        // Assert that lock is still locked.
+                        assertTrue(lock0.isLocked());
+
+                        // Assert that this thread does own the lock.
+                        assertTrue(lock0.isHeldByCurrentThread());
+
+                        // Release lock.
+                        if (lock0.isHeldByCurrentThread())
+                            lock0.unlock();
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        // Wait for all threads to attempt to acquire lock.
+        while (startedThreads.size() != totalThreads) {
+            Thread.sleep(500);
+        }
+
+        for (Thread t : startedThreads)
+            t.interrupt();
+
+        fut.get();
+
+        assertFalse(lock0.isLocked());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHasQueuedThreads() throws Exception {
+        testHasQueuedThreads(false);
+
+        testHasQueuedThreads(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testHasQueuedThreads(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 5;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        final Set<Thread> finishedThreads = new GridConcurrentHashSet<>();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    startedThreads.add(Thread.currentThread());
+
+                    lock0.lock();
+
+                    // Wait until every thread tries to lock.
+                    do {
+                        Thread.sleep(1000);
+                    }
+                    while (startedThreads.size() != totalThreads);
+
+                    try {
+                        info("Acquired in separate thread. ");
+
+                        assertTrue(lock0.isHeldByCurrentThread());
+
+                        assertFalse(lock0.hasQueuedThread(Thread.currentThread()));
+
+                        finishedThreads.add(Thread.currentThread());
+
+                        if (startedThreads.size() != finishedThreads.size()) {
+                            assertTrue(lock0.hasQueuedThreads());
+                        }
+
+                        for (Thread t : startedThreads) {
+                            assertTrue(lock0.hasQueuedThread(t) != finishedThreads.contains(t));
+                        }
+                    }
+                    finally {
+                        lock0.unlock();
+
+                        assertFalse(lock0.isHeldByCurrentThread());
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        fut.get();
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHasConditionQueuedThreads() throws Exception {
+        testHasConditionQueuedThreads(false);
+
+        testHasConditionQueuedThreads(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testHasConditionQueuedThreads(final boolean fair) throws Exception {
+        final IgniteLock lock0 = grid(0).reentrantLock("lock", true, fair, true);
+
+        assertEquals(0, lock0.getHoldCount());
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        final int totalThreads = 5;
+
+        final Set<Thread> startedThreads = new GridConcurrentHashSet<>();
+
+        final Set<Thread> finishedThreads = new GridConcurrentHashSet<>();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    assertFalse(lock0.isHeldByCurrentThread());
+
+                    IgniteCondition cond = lock0.getOrCreateCondition("cond");
+
+                    lock0.lock();
+
+                    startedThreads.add(Thread.currentThread());
+
+                    // Wait until every thread tries to lock.
+                    do {
+                        cond.await();
+
+                        Thread.sleep(1000);
+                    }
+                    while (startedThreads.size() != totalThreads);
+
+                    try {
+                        info("Acquired in separate thread. Number of threads waiting on condition: "
+                            + lock0.getWaitQueueLength(cond));
+
+                        assertTrue(lock0.isHeldByCurrentThread());
+
+                        assertFalse(lock0.hasQueuedThread(Thread.currentThread()));
+
+                        finishedThreads.add(Thread.currentThread());
+
+                        if (startedThreads.size() != finishedThreads.size()) {
+                            assertTrue(lock0.hasWaiters(cond));
+                        }
+
+                        for (Thread t : startedThreads) {
+                            if (!finishedThreads.contains(t))
+                                assertTrue(lock0.hasWaiters(cond));
+                        }
+
+                        assertTrue(lock0.getWaitQueueLength(cond) == (startedThreads.size() - finishedThreads.size()));
+                    }
+                    finally {
+                        cond.signal();
+
+                        lock0.unlock();
+
+                        assertFalse(lock0.isHeldByCurrentThread());
+                    }
+
+                    return null;
+                }
+            }, totalThreads);
+
+        IgniteCondition cond = lock0.getOrCreateCondition("cond");
+
+        lock0.lock();
+
+        try {
+            // Wait until all threads are waiting on condition.
+            while (lock0.getWaitQueueLength(cond) != totalThreads) {
+                lock0.unlock();
+
+                Thread.sleep(1000);
+
+                lock0.lock();
+            }
+
+            // Signal once to get things started.
+            cond.signal();
+        }
+        finally {
+            lock0.unlock();
+        }
+
+        fut.get();
+
+        assertFalse(lock0.hasQueuedThreads());
+
+        for (Thread t : startedThreads)
+            assertFalse(lock0.hasQueuedThread(t));
+
+        lock0.close();
+    }
+
+    /**
+     * Tests if lock is evenly acquired among nodes when fair flag is set on.
+     * Since exact ordering of lock acquisitions cannot be guaranteed because it also depends
+     * on the OS thread scheduling, certain deviation from uniform distribution is tolerated.
+     * @throws Exception If failed.
+     */
+    public void testFairness() throws Exception {
+        if (gridCount() == 1)
+            return;
+
+        // Total number of ops.
+        final long opsCount = 10000;
+
+        // Allowed deviation from uniform distribution.
+        final double tolerance = 0.05;
+
+        // Shared counter.
+        final String OPS_COUNTER = "ops_counter";
+
+        // Number of threads, one per node.
+        final int threadCount = gridCount();
+
+        final AtomicLong threadCounter = new AtomicLong(0);
+
+        Ignite ignite = startGrid(gridCount());
+
+        // Initialize reentrant lock.
+        IgniteLock l = ignite.reentrantLock("lock", true, true, true);
+
+        // Initialize OPS_COUNTER.
+        ignite.getOrCreateCache(OPS_COUNTER).put(OPS_COUNTER, (long)0);
+
+        final Map<Integer, Long> counts = new ConcurrentHashMap<>();
+
+        IgniteInternalFuture<?> fut = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    final int localNodeId = (int)threadCounter.getAndIncrement();
+
+                    final Ignite grid = grid(localNodeId);
+
+                    IgniteClosure<Ignite, Long> closure = new IgniteClosure<Ignite, Long>() {
+                        @Override public Long apply(Ignite ignite) {
+                            IgniteLock l = ignite.reentrantLock("lock", true, true, true);
+
+                            long localCount = 0;
+
+                            IgniteCountDownLatch latch = ignite.countDownLatch("latch", threadCount, false, true);
+
+                            latch.countDown();
+
+                            latch.await();
+
+                            while(true){
+                                l.lock();
+
+                                try {
+                                    long opsCounter = (long) ignite.getOrCreateCache(OPS_COUNTER).get(OPS_COUNTER);
+
+                                    if(opsCounter == opsCount)
+                                        break;
+
+                                    ignite.getOrCreateCache(OPS_COUNTER).put(OPS_COUNTER, ++opsCounter);
+
+                                    localCount++;
+
+                                    if(localCount > 1000){
+                                        assertTrue(localCount < (1 + tolerance) * opsCounter / threadCount);
+
+                                        assertTrue(localCount > (1 - tolerance) * opsCounter / threadCount);
+                                    }
+
+                                    if(localCount % 100 == 0) {
+                                        info("Node [id=" +ignite.cluster().localNode().id() + "] acquired " +
+                                            localCount + " times. " + "Total ops count: " +
+                                            opsCounter + "/" + opsCount +"]");
+                                    }
+                                }
+                                finally {
+                                    l.unlock();
+                                }
+                            }
+
+                            return localCount;
+                        }
+                    };
+
+                    long localCount = closure.apply(grid);
+
+                    counts.put(localNodeId, localCount);
+
+                    return null;
+                }
+            }, threadCount);
+
+        fut.get();
+
+        long totalSum = 0;
+
+        for(int i=0; i<gridCount(); i++){
+
+            totalSum += counts.get(i);
+
+            info("Node " + grid(i).localNode().id() + " acquired the lock " + counts.get(i) + " times. ");
+        }
+
+        assertEquals(totalSum, opsCount);
+
+        l.close();
+
+        ignite.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
index e60aed3..200e276 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSemaphoreAbstractSelfTest.java
@@ -77,6 +77,7 @@ public abstract class IgniteSemaphoreAbstractSelfTest extends IgniteAtomicsAbstr
      */
     public void testSemaphore() throws Exception {
         checkSemaphore();
+        checkSemaphoreSerialization();
     }
 
     /**
@@ -231,6 +232,36 @@ public abstract class IgniteSemaphoreAbstractSelfTest extends IgniteAtomicsAbstr
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    private void checkSemaphoreSerialization() throws Exception {
+        final IgniteSemaphore sem = grid(0).semaphore("semaphore", -gridCount() + 1, true, true);
+
+        assertEquals(-gridCount() + 1, sem.availablePermits());
+
+        grid(0).compute().broadcast(new IgniteCallable<Object>() {
+            @Nullable @Override public Object call() throws Exception {
+                sem.release();
+
+                return null;
+            }
+        });
+
+        assert sem.availablePermits() == 1;
+
+        sem.acquire();
+
+        assert sem.availablePermits() == 0;
+
+        sem.release();
+
+        // Test operations on removed semaphore.
+        sem.close();
+
+        checkRemovedSemaphore(sem);
+    }
+
+    /**
      * @param semaphore Semaphore.
      * @throws Exception If failed.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/local/IgniteLocalLockSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/local/IgniteLocalLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/local/IgniteLocalLockSelfTest.java
new file mode 100644
index 0000000..7e1a11c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/local/IgniteLocalLockSelfTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures.local;
+
+import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteLock;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteLockAbstractSelfTest;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+
+/**
+ *
+ */
+public class IgniteLocalLockSelfTest extends IgniteLockAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode atomicsCacheMode() {
+        return LOCAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testReentrantLock() throws Exception {
+        // Test main functionality.
+        IgniteLock lock = grid(0).reentrantLock("lock", true, false, true);
+
+        assertNotNull(lock);
+
+        assertEquals(0, lock.getHoldCount());
+
+        lock.lock();
+
+        IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(
+            new Callable<Object>() {
+                @Nullable @Override public Object call() throws Exception {
+                    IgniteLock lock = grid(0).reentrantLock("lock", true, false, true);
+
+                    assert lock != null;
+
+                    info("Thread is going to wait on lock: " + Thread.currentThread().getName());
+
+                    assert lock.tryLock(1, MINUTES);
+
+                    info("Thread is again runnable: " + Thread.currentThread().getName());
+
+                    lock.unlock();
+
+                    return null;
+                }
+            },
+            THREADS_CNT,
+            "test-thread"
+        );
+
+        Thread.sleep(3000);
+
+        assert lock.isLocked();
+
+        assert lock.getHoldCount() == 1;
+
+        lock.lock();
+
+        assert lock.isLocked();
+
+        assert lock.getHoldCount() == 2;
+
+        lock.unlock();
+
+        assert lock.isLocked();
+
+        assert lock.getHoldCount() == 1;
+
+        lock.unlock();
+
+        // Ensure there are no hangs.
+        fut.get();
+
+        // Test operations on removed lock.
+        IgniteLock lock0 = grid(0).reentrantLock("lock", true, false, false);
+
+        assertNotNull(lock0);
+
+        lock0.close();
+
+        checkRemovedReentrantLock(lock0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedLockSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedLockSelfTest.java
new file mode 100644
index 0000000..787f1e3
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/partitioned/IgnitePartitionedLockSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures.partitioned;
+
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteLockAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class IgnitePartitionedLockSelfTest extends IgniteLockAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode atomicsCacheMode() {
+        return PARTITIONED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/replicated/IgniteReplicatedLockSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/replicated/IgniteReplicatedLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/replicated/IgniteReplicatedLockSelfTest.java
new file mode 100644
index 0000000..00bb0fa
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/replicated/IgniteReplicatedLockSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures.replicated;
+
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteLockAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ *
+ */
+public class IgniteReplicatedLockSelfTest extends IgniteLockAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode atomicsCacheMode() {
+        return REPLICATED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
index ae591bd..43acc41 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
@@ -573,4 +573,4 @@ public abstract class GridCacheLockAbstractTest extends GridCommonAbstractTest {
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java
index d4ca9a5..18537c5 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.IgniteAtomicStamped;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteQueue;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteSystemProperties;
@@ -64,6 +65,9 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad
     /** Semaphore name. */
     private static final String TEST_SEMAPHORE_NAME = "test-semaphore";
 
+    /** Reentrant lock name. */
+    private static final String TEST_REENTRANT_LOCK_NAME = "test-reentrant-lock";
+
     /** */
     private static final CollectionConfiguration colCfg = new CollectionConfiguration();
 
@@ -98,6 +102,9 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad
     private static final boolean SEMAPHORE = true;
 
     /** */
+    private static final boolean REENTRANTLOCK = true;
+
+    /** */
     private GridCacheDataStructuresLoadTest() {
         // No-op
     }
@@ -347,6 +354,44 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad
             }
         };
 
+
+    /** Reentrant lock read closure. */
+    private final CIX1<Ignite> reentrantLockReadClos =
+        new CIX1<Ignite>() {
+            @Override public void applyx(Ignite ignite) {
+                IgniteLock r = ignite.reentrantLock(TEST_REENTRANT_LOCK_NAME, true, false, true);
+
+                for (int i = 0; i < operationsPerTx; i++) {
+                    r.isLocked();
+
+                    long cnt = reads.incrementAndGet();
+
+                    if (cnt % READ_LOG_MOD == 0)
+                        info("Performed " + cnt + " reads.");
+                }
+            }
+        };
+
+    /** Reentrant lock write closure. */
+    private final CIX1<Ignite> reentrantLockWriteClos =
+        new CIX1<Ignite>() {
+            @Override public void applyx(Ignite ignite) {
+                IgniteLock r = ignite.reentrantLock(TEST_REENTRANT_LOCK_NAME, true, false, true);
+
+                for (int i = 0; i < operationsPerTx; i++) {
+                    if ((i % 2) == 0)
+                        r.lock();
+                    else
+                        r.unlock();
+
+                    long cnt = writes.incrementAndGet();
+
+                    if (cnt % WRITE_LOG_MOD == 0)
+                        info("Performed " + cnt + " writes.");
+                }
+            }
+        };
+
     /**
      * @param args Arguments.
      * @throws IgniteCheckedException In case of error.
@@ -417,6 +462,14 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad
 
                 test.loadTestIgnite(test.semaphoreWriteClos, test.semaphoreReadClos);
             }
+
+            System.gc();
+
+            if (REENTRANTLOCK) {
+                info("Testing reentrant lock...");
+
+                test.loadTestIgnite(test.reentrantLockWriteClos, test.reentrantLockReadClos);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index c49c730..c9859fc 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -30,6 +30,7 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCluster;
 import org.apache.ignite.IgniteCompute;
 import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteEvents;
@@ -367,6 +368,15 @@ public class IgniteMock implements Ignite {
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public IgniteLock reentrantLock(String name,
+        boolean failoverSafe,
+        boolean fair,
+        boolean create)
+    {
+        return null;
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public <T> IgniteQueue<T> queue(String name,
         int cap,
         CollectionConfiguration cfg)

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index a2e0d5a..2598bc5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -42,6 +42,7 @@ import org.apache.ignite.IgniteIllegalStateException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteMessaging;
 import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteLock;
 import org.apache.ignite.IgniteScheduler;
 import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteServices;
@@ -545,6 +546,12 @@ public class IgniteProcessProxy implements IgniteEx {
     }
 
     /** {@inheritDoc} */
+    @Override public IgniteLock reentrantLock(String name, boolean failoverSafe,
+        boolean fair, boolean create) throws IgniteException {
+        throw new UnsupportedOperationException("Operation isn't supported yet.");
+    }
+
+    /** {@inheritDoc} */
     @Override public <T> IgniteQueue<T> queue(String name, int cap,
         @Nullable CollectionConfiguration cfg) throws IgniteException {
         throw new UnsupportedOperationException("Operation isn't supported yet.");

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
index e663a99..59a18e5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.processors.cache.datastructures.local.GridCach
 import org.apache.ignite.internal.processors.cache.datastructures.local.GridCacheLocalSetSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.local.IgniteLocalAtomicLongApiSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.local.IgniteLocalCountDownLatchSelfTest;
+import org.apache.ignite.internal.processors.cache.datastructures.local.IgniteLocalLockSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.local.IgniteLocalSemaphoreSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.GridCachePartitionedAtomicOffheapQueueApiSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.GridCachePartitionedAtomicOffheapQueueCreateMultiNodeSelfTest;
@@ -66,6 +67,7 @@ import org.apache.ignite.internal.processors.cache.datastructures.partitioned.Gr
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.GridCachePartitionedSetSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedAtomicLongApiSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedCountDownLatchSelfTest;
+import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedLockSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedQueueNoBackupsTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedSemaphoreSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.partitioned.IgnitePartitionedSetNoBackupsSelfTest;
@@ -80,6 +82,7 @@ import org.apache.ignite.internal.processors.cache.datastructures.replicated.Gri
 import org.apache.ignite.internal.processors.cache.datastructures.replicated.GridCacheReplicatedSetSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.replicated.IgniteReplicatedAtomicLongApiSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.replicated.IgniteReplicatedCountDownLatchSelfTest;
+import org.apache.ignite.internal.processors.cache.datastructures.replicated.IgniteReplicatedLockSelfTest;
 import org.apache.ignite.internal.processors.cache.datastructures.replicated.IgniteReplicatedSemaphoreSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheAtomicReplicatedNodeRestartSelfTest;
 
@@ -107,6 +110,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheLocalAtomicQueueApiSelfTest.class));
         suite.addTest(new TestSuite(IgniteLocalCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteLocalSemaphoreSelfTest.class));
+        suite.addTest(new TestSuite(IgniteLocalLockSelfTest.class));
 
         suite.addTest(new TestSuite(GridCacheReplicatedSequenceApiSelfTest.class));
         suite.addTest(new TestSuite(GridCacheReplicatedSequenceMultiNodeSelfTest.class));
@@ -117,6 +121,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridCacheReplicatedDataStructuresFailoverSelfTest.class));
         suite.addTest(new TestSuite(IgniteReplicatedCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteReplicatedSemaphoreSelfTest.class));
+        suite.addTest(new TestSuite(IgniteReplicatedLockSelfTest.class));
         suite.addTest(new TestSuite(IgniteCacheAtomicReplicatedNodeRestartSelfTest.class));
 
         suite.addTest(new TestSuite(GridCachePartitionedSequenceApiSelfTest.class));
@@ -139,6 +144,7 @@ public class IgniteCacheDataStructuresSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(IgnitePartitionedCountDownLatchSelfTest.class));
         suite.addTest(new TestSuite(IgniteDataStructureWithJobTest.class));
         suite.addTest(new TestSuite(IgnitePartitionedSemaphoreSelfTest.class));
+        suite.addTest(new TestSuite(IgnitePartitionedLockSelfTest.class));
 
         suite.addTest(new TestSuite(GridCachePartitionedSetFailoverSelfTest.class));
         suite.addTest(new TestSuite(GridCachePartitionedOffheapSetFailoverSelfTest.class));

http://git-wip-us.apache.org/repos/asf/ignite/blob/f8bf93a7/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
index 92d8c1d..03c7b0e 100644
--- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
+++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
@@ -425,6 +425,17 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     }
 
     /** {@inheritDoc} */
+    @Nullable @Override public IgniteLock reentrantLock(String name,
+        boolean failoverSafe,
+        boolean fair,
+        boolean create)
+    {
+        assert g != null;
+
+        return g.reentrantLock(name, failoverSafe, create, fair);
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public <T> IgniteQueue<T> queue(String name,
         int cap,
         CollectionConfiguration cfg)


[15/50] [abbrv] ignite git commit: IGNITE-2404: TcpDiscoverySpi.setLocalPortRange set 0 doesn't work. This closes #549 Reviewed and merged by Denis Magda (dmagda@gridgain.com)

Posted by sh...@apache.org.
IGNITE-2404: TcpDiscoverySpi.setLocalPortRange set 0 doesn't work. This closes #549
Reviewed and merged by Denis Magda (dmagda@gridgain.com)


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

Branch: refs/heads/ignite-2788
Commit: a8b1caf0bde32629c8bb60f75e76ad0652a7be8f
Parents: efe76f1
Author: Ryan Zhao <ry...@gmail.com>
Authored: Tue Apr 19 07:27:11 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../configuration/ConnectorConfiguration.java   |  3 ++
 .../configuration/IgniteConfiguration.java      |  3 ++
 .../processors/clock/GridClockServer.java       |  3 +-
 .../rest/protocols/tcp/GridTcpRestProtocol.java |  7 +++--
 .../communication/tcp/TcpCommunicationSpi.java  |  4 ++-
 .../ignite/spi/discovery/tcp/ServerImpl.java    | 32 ++++++++++----------
 .../spi/discovery/tcp/TcpDiscoverySpi.java      |  2 ++
 .../GridTcpCommunicationSpiConfigSelfTest.java  | 22 ++++++++++++++
 .../tcp/TcpDiscoverySpiConfigSelfTest.java      | 22 ++++++++++++++
 .../http/jetty/GridJettyRestProtocol.java       |  4 +--
 10 files changed, 79 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
index 1bfcbe4..0ef5f86 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/ConnectorConfiguration.java
@@ -492,6 +492,9 @@ public class ConnectorConfiguration {
     /**
      * Gets number of ports to try if configured port is already in use.
      *
+     * If port range value is <tt>0</tt>, then implementation will try bind only to the port provided by
+     * {@link #setPort(int)} method and fail if binding to this port did not succeed.
+     *
      * @return Number of ports to try.
      */
     public int getPortRange() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index 486a554..ca112c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -2178,6 +2178,9 @@ public class IgniteConfiguration {
     /**
      * Defines port range to try for time server start.
      *
+     * If port range value is <tt>0</tt>, then implementation will try bind only to the port provided by
+     * {@link #setTimeServerPortBase(int)} method and fail if binding to this port did not succeed.
+     *
      * @return Number of ports to try before server initialization fails.
      */
     public int getTimeServerPortRange() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
index b357e65..a1900c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/clock/GridClockServer.java
@@ -64,7 +64,8 @@ public class GridClockServer {
 
         try {
             int startPort = ctx.config().getTimeServerPortBase();
-            int endPort = startPort + ctx.config().getTimeServerPortRange() - 1;
+            int portRange = ctx.config().getTimeServerPortRange();
+            int endPort = portRange == 0 ? startPort : startPort + portRange - 1;
 
             InetAddress locHost;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
index 8e08481..a4a51ea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
@@ -134,10 +134,11 @@ public class GridTcpRestProtocol extends GridRestProtocolAdapter {
                 else
                     sslCtx = igniteFactory.create();
             }
+            int startPort = cfg.getPort();
+            int portRange = cfg.getPortRange();
+            int lastPort = portRange == 0 ? startPort : startPort + portRange - 1;
 
-            int lastPort = cfg.getPort() + cfg.getPortRange() - 1;
-
-            for (int port0 = cfg.getPort(); port0 <= lastPort; port0++) {
+            for (int port0 = startPort; port0 <= lastPort; port0++) {
                 if (startTcpServer(host, port0, lsnr, parser, sslCtx, cfg)) {
                     port = port0;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index c0982bf..080437d 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -1591,7 +1591,9 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
         IgniteCheckedException lastEx = null;
 
         // If configured TCP port is busy, find first available in range.
-        for (int port = locPort; port < locPort + locPortRange; port++) {
+        int lastPort = locPortRange == 0 ? locPort : locPort + locPortRange - 1;
+
+        for (int port = locPort; port <= lastPort; port++) {
             try {
                 MessageFactory msgFactory = new MessageFactory() {
                     private MessageFactory impl;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 75430c6..572f540 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -4904,34 +4904,34 @@ class ServerImpl extends TcpDiscoveryImpl {
 
             setPriority(spi.threadPri);
 
-            for (port = spi.locPort; port < spi.locPort + spi.locPortRange; port++) {
+            int lastPort = spi.locPortRange == 0 ? spi.locPort : spi.locPort + spi.locPortRange - 1;
+
+            for (port = spi.locPort; port <= lastPort; port++) {
                 try {
                     if (spi.isSslEnabled())
                         srvrSock = spi.sslSrvSockFactory.createServerSocket(port, 0, spi.locHost);
                     else
                         srvrSock = new ServerSocket(port, 0, spi.locHost);
 
-                    break;
+                    if (log.isInfoEnabled())
+                        log.info("Successfully bound to TCP port [port=" + port + ", localHost=" + spi.locHost + ']');
+
+                    return;
                 }
                 catch (IOException e) {
-                    if (port < spi.locPort + spi.locPortRange - 1) {
-                        if (log.isDebugEnabled())
-                            log.debug("Failed to bind to local port (will try next port within range) " +
-                                "[port=" + port + ", localHost=" + spi.locHost + ']');
+                    if (log.isDebugEnabled())
+                        log.debug("Failed to bind to local port (will try next port within range) " +
+                            "[port=" + port + ", localHost=" + spi.locHost + ']');
 
-                        onException("Failed to bind to local port. " +
-                            "[port=" + port + ", localHost=" + spi.locHost + ']', e);
-                    }
-                    else {
-                        throw new IgniteSpiException("Failed to bind TCP server socket (possibly all ports in range " +
-                            "are in use) [firstPort=" + spi.locPort + ", lastPort=" + (spi.locPort + spi.locPortRange - 1) +
-                            ", addr=" + spi.locHost + ']', e);
-                    }
+                    onException("Failed to bind to local port. " +
+                        "[port=" + port + ", localHost=" + spi.locHost + ']', e);
                 }
             }
 
-            if (log.isInfoEnabled())
-                log.info("Successfully bound to TCP port [port=" + port + ", localHost=" + spi.locHost + ']');
+            // If free port wasn't found.
+            throw new IgniteSpiException("Failed to bind TCP server socket (possibly all ports in range " +
+                "are in use) [firstPort=" + spi.locPort + ", lastPort=" + lastPort +
+                ", addr=" + spi.locHost + ']');
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index d981609..4351c64 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -676,6 +676,8 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T
      * Range for local ports. Local node will try to bind on first available port
      * starting from {@link #getLocalPort()} up until
      * <tt>{@link #getLocalPort()} {@code + locPortRange}</tt>.
+     * If port range value is <tt>0</tt>, then implementation will try bind only to the port provided by
+     * {@link #setLocalPort(int)} method and fail if binding to this port did not succeed.
      * <p>
      * If not specified, default is {@link #DFLT_PORT_RANGE}.
      * <p>

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
index 33944e4..b0353a6 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.ignite.spi.communication.tcp;
 
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest;
 import org.apache.ignite.testframework.junits.spi.GridSpiTest;
 
@@ -45,4 +48,23 @@ public class GridTcpCommunicationSpiConfigSelfTest extends GridSpiAbstractConfig
         checkNegativeSpiProperty(new TcpCommunicationSpi(), "ackSendThreshold", -1);
         checkNegativeSpiProperty(new TcpCommunicationSpi(), "unacknowledgedMessagesBufferSize", -1);
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalPortRange() throws Exception {
+        try {
+            IgniteConfiguration cfg = getConfiguration();
+
+            TcpCommunicationSpi spi = new TcpCommunicationSpi();
+
+            spi.setLocalPortRange(0);
+            cfg.setCommunicationSpi(spi);
+
+            startGrid(cfg.getGridName(), cfg);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
index bb5af60..24f47c9 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiConfigSelfTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.spi.discovery.tcp;
 
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest;
 import org.apache.ignite.testframework.junits.spi.GridSpiTest;
 
@@ -43,4 +45,24 @@ public class TcpDiscoverySpiConfigSelfTest extends GridSpiAbstractConfigTest<Tcp
         checkNegativeSpiProperty(new TcpDiscoverySpi(), "maxMissedHeartbeats", 0);
         checkNegativeSpiProperty(new TcpDiscoverySpi(), "statisticsPrintFrequency", 0);
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLocalPortRange() throws Exception {
+        try {
+            IgniteConfiguration cfg = getConfiguration();
+
+            TcpDiscoverySpi spi = new TcpDiscoverySpi();
+
+            spi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+            spi.setLocalPortRange(0);
+            cfg.setDiscoverySpi(spi);
+
+            startGrid(cfg.getGridName(), cfg);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8b1caf0/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
index ac49ef6..0440783 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
@@ -168,8 +168,8 @@ public class GridJettyRestProtocol extends GridRestProtocolAdapter {
         }
 
         int initPort = connector.getPort();
-
-        int lastPort = initPort + config().getPortRange() - 1;
+        int portRange = config().getPortRange();
+        int lastPort = portRange == 0 ? initPort : initPort + portRange - 1;
 
         for (port = initPort; port <= lastPort; port++) {
             connector.setPort(port);


[40/50] [abbrv] ignite git commit: IGNITE-3068: GridDhtPartitionTopology.nodes() now returns List instead of Collection.

Posted by sh...@apache.org.
IGNITE-3068: GridDhtPartitionTopology.nodes() now returns List instead of Collection.


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

Branch: refs/heads/ignite-2788
Commit: f900f3a1e802c10e1c1cc2a8b4bfedf83121fe3f
Parents: 3adc493
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Apr 28 16:32:54 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../distributed/dht/GridClientPartitionTopology.java      |  6 +++---
 .../cache/distributed/dht/GridDhtPartitionTopology.java   |  2 +-
 .../distributed/dht/GridDhtPartitionTopologyImpl.java     |  6 +++---
 .../distributed/dht/GridDhtTransactionalCacheAdapter.java |  4 ++--
 .../distributed/dht/atomic/GridDhtAtomicUpdateFuture.java |  8 ++++++--
 .../dht/atomic/GridNearAtomicUpdateFuture.java            | 10 +++++++---
 6 files changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index 4635cad..58933b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -395,14 +395,14 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
-    @Override public Collection<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
+    @Override public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
         lock.readLock().lock();
 
         try {
             assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer +
                 ", node2part=" + node2part + ']';
 
-            Collection<ClusterNode> nodes = null;
+            List<ClusterNode> nodes = null;
 
             Collection<UUID> nodeIds = part2node.get(p);
 
@@ -412,7 +412,7 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
 
                     if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) {
                         if (nodes == null)
-                            nodes = new ArrayList<>();
+                            nodes = new ArrayList<>(nodeIds.size());
 
                         nodes.add(n);
                     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
index 2c483a1..6e9b907 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopology.java
@@ -167,7 +167,7 @@ public interface GridDhtPartitionTopology {
      * @param topVer Topology version.
      * @return Collection of all nodes responsible for this partition with primary node being first.
      */
-    public Collection<ClusterNode> nodes(int p, AffinityTopologyVersion topVer);
+    public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer);
 
     /**
      * @param p Partition ID.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 9f5fbfb..4be0acb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -821,10 +821,10 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
     }
 
     /** {@inheritDoc} */
-    @Override public Collection<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
+    @Override public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
         GridAffinityAssignment affAssignment = cctx.affinity().assignment(topVer);
 
-        Collection<ClusterNode> affNodes = affAssignment.get(p);
+        List<ClusterNode> affNodes = affAssignment.get(p);
 
         lock.readLock().lock();
 
@@ -835,7 +835,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
                 ", cache=" + cctx.name() +
                 ", node2part=" + node2part + ']';
 
-            Collection<ClusterNode> nodes = null;
+            List<ClusterNode> nodes = null;
 
             Collection<UUID> nodeIds = part2node.get(p);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
index 9d277b9..7bace73 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
@@ -1367,9 +1367,9 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
         Map<ClusterNode, List<KeyCacheObject>> dhtMap,
         Map<ClusterNode, List<KeyCacheObject>> nearMap)
         throws IgniteCheckedException {
-        Collection<ClusterNode> dhtNodes = ctx.dht().topology().nodes(cached.partition(), topVer);
+        List<ClusterNode> dhtNodes = ctx.dht().topology().nodes(cached.partition(), topVer);
 
-        ClusterNode primary = F.first(dhtNodes);
+        ClusterNode primary = dhtNodes.get(0);
 
         assert primary != null;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
index 5760596..fa69f10 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.distributed.dht.atomic;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicReference;
@@ -216,6 +217,7 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
      * @param prevVal Previous value.
      * @param updateCntr Partition update counter.
      */
+    @SuppressWarnings("ForLoopReplaceableByForEach")
     public void addWriteEntry(GridDhtCacheEntry entry,
         @Nullable CacheObject val,
         EntryProcessor<Object, Object, Object> entryProcessor,
@@ -227,7 +229,7 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
         long updateCntr) {
         AffinityTopologyVersion topVer = updateReq.topologyVersion();
 
-        Collection<ClusterNode> dhtNodes = cctx.dht().topology().nodes(entry.partition(), topVer);
+        List<ClusterNode> dhtNodes = cctx.dht().topology().nodes(entry.partition(), topVer);
 
         if (log.isDebugEnabled())
             log.debug("Mapping entry to DHT nodes [nodes=" + U.nodeIds(dhtNodes) + ", entry=" + entry + ']');
@@ -236,7 +238,9 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
 
         keys.add(entry.key());
 
-        for (ClusterNode node : dhtNodes) {
+        for (int i = 0; i < dhtNodes.size(); i++) {
+            ClusterNode node = dhtNodes.get(i);
+
             UUID nodeId = node.id();
 
             if (!nodeId.equals(cctx.localNodeId())) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f900f3a1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index dfdf1a5..cc0427c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.cache.expiry.ExpiryPolicy;
@@ -789,6 +790,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
      * @return Mapping.
      * @throws Exception If failed.
      */
+    @SuppressWarnings("ForLoopReplaceableByForEach")
     private Map<UUID, GridNearAtomicUpdateRequest> mapUpdate(Collection<ClusterNode> topNodes,
         AffinityTopologyVersion topVer,
         GridCacheVersion futVer,
@@ -862,7 +864,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
             if (op != TRANSFORM)
                 val = cctx.toCacheObject(val);
 
-            Collection<ClusterNode> affNodes = mapKey(cacheKey, topVer);
+            List<ClusterNode> affNodes = mapKey(cacheKey, topVer);
 
             if (affNodes.isEmpty())
                 throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
@@ -870,7 +872,9 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
 
             int i = 0;
 
-            for (ClusterNode affNode : affNodes) {
+            for (int n = 0; n < affNodes.size(); n++) {
+                ClusterNode affNode = affNodes.get(n);
+
                 if (affNode == null)
                     throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
                         "(all partition nodes left the grid).");
@@ -1020,7 +1024,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
      * @param topVer Topology version to map.
      * @return Collection of nodes to which key is mapped.
      */
-    private Collection<ClusterNode> mapKey(KeyCacheObject key, AffinityTopologyVersion topVer) {
+    private List<ClusterNode> mapKey(KeyCacheObject key, AffinityTopologyVersion topVer) {
         GridCacheAffinityManager affMgr = cctx.affinity();
 
         // If we can send updates in parallel - do it.


[46/50] [abbrv] ignite git commit: IGNITE-3041: Implement config variations test for IgniteServices

Posted by sh...@apache.org.
IGNITE-3041: Implement config variations test for IgniteServices


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

Branch: refs/heads/ignite-2788
Commit: 6e1d45e83b91b9dda78c5f6ac6ed4f2726aba787
Parents: 2699235
Author: sboikov <sb...@gridgain.com>
Authored: Fri Apr 29 12:21:02 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 ...gniteServiceConfigVariationsFullApiTest.java | 350 +++++++++++++++++++
 .../configvariations/VariationsTestsConfig.java |   2 +-
 .../IgniteConfigVariationsAbstractTest.java     |  72 +++-
 ...ServiceConfigVariationsFullApiTestSuite.java |  92 +++++
 4 files changed, 507 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6e1d45e8/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceConfigVariationsFullApiTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceConfigVariationsFullApiTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceConfigVariationsFullApiTest.java
new file mode 100644
index 0000000..4e6d1e6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/IgniteServiceConfigVariationsFullApiTest.java
@@ -0,0 +1,350 @@
+/*
+ * 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.service;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.util.concurrent.ThreadLocalRandom;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteServices;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceConfiguration;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.testframework.configvariations.Parameters;
+import org.apache.ignite.testframework.junits.IgniteConfigVariationsAbstractTest;
+
+/**
+ * Full API services test.
+ */
+public class IgniteServiceConfigVariationsFullApiTest extends IgniteConfigVariationsAbstractTest {
+    /** Test service name. */
+    private static final String SERVICE_NAME = "testService";
+
+    /** Test service name. */
+    private static final String CACHE_NAME = "testCache";
+
+    /** */
+    protected static final int CLIENT_NODE_IDX_2 = 4;
+
+    /** Test object id counter. */
+    private static int cntr;
+
+    /** Callable factories. */
+    @SuppressWarnings("unchecked")
+    private static final Factory[] serviceFactories = new Factory[] {
+        Parameters.factory(TestServiceImpl.class),
+        Parameters.factory(TestServiceImplExternalizable.class),
+        Parameters.factory(TestServiceImplBinarylizable.class)
+    };
+
+    /** {@inheritDoc} */
+    @Override protected boolean expectedClient(String testGridName) {
+        int i = testsCfg.gridCount();
+
+        if (i < 5)
+            return super.expectedClient(testGridName);
+
+        // Use two client nodes if grid index 5 or greater.
+        return getTestGridName(CLIENT_NODE_IDX).equals(testGridName)
+            || getTestGridName(CLIENT_NODE_IDX_2).equals(testGridName);
+    }
+
+    /**
+     * Test node singleton deployment
+     *
+     * @throws Exception If failed.
+     */
+    public void testNodeSingletonDeploy() throws Exception {
+        runInAllDataModes(new ServiceTestRunnable(true, new DeployClosure() {
+            @Override public void run(IgniteServices services, String svcName, TestService svc) {
+                services.deployNodeSingleton(svcName, (Service)svc);
+            }
+        }));
+    }
+
+    /**
+     * Test cluster singleton deployment
+     *
+     * @throws Exception If failed.
+     */
+    public void testClusterSingletonDeploy() throws Exception {
+        runInAllDataModes(new ServiceTestRunnable(false, new DeployClosure() {
+            @Override public void run(IgniteServices services, String svcName, TestService svc) {
+                services.deployClusterSingleton(svcName, (Service)svc);
+            }
+        }));
+    }
+
+    /**
+     * Test key affinity deployment
+     *
+     * @throws Exception If failed.
+     */
+    public void testKeyAffinityDeploy() throws Exception {
+        runInAllDataModes(new ServiceTestRunnable(false, new DeployClosure() {
+            @Override public void run(IgniteServices services, String svcName, TestService svc) {
+                IgniteCache<Object, Object> cache = grid(testedNodeIdx).getOrCreateCache(CACHE_NAME);
+
+                services.deployKeyAffinitySingleton(svcName, (Service)svc, cache.getName(), "1");
+            }
+        }));
+    }
+
+    /**
+     * Tests multiple deployment
+     *
+     * @throws Exception If failed.
+     */
+    public void testMultipleDeploy() throws Exception {
+        runInAllDataModes(new ServiceTestRunnable(true, new DeployClosure() {
+            @Override public void run(IgniteServices services, String svcName, TestService svc) {
+                services.deployMultiple(svcName, (Service)svc, 0, 1);
+            }
+        }));
+    }
+
+    /**
+     * Tests deployment.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDeploy() throws Exception {
+        runInAllDataModes(new ServiceTestRunnable(false, new DeployClosure() {
+            @Override public void run(IgniteServices services, String svcName, TestService svc) {
+                services.deployClusterSingleton(svcName, (Service)svc);
+
+                ServiceConfiguration cfg = new ServiceConfiguration();
+
+                cfg.setName(svcName);
+
+                cfg.setService((Service)svc);
+
+                cfg.setTotalCount(1);
+
+                cfg.setMaxPerNodeCount(1);
+
+                cfg.setNodeFilter(services.clusterGroup().predicate());
+
+                services.deploy(cfg);
+            }
+        }));
+    }
+
+    /**
+     * Service test closure
+     */
+    private class ServiceTestRunnable implements TestRunnable {
+        /** Sticky. */
+        private final boolean sticky;
+
+        /** Deploy closure */
+        private final DeployClosure deployC;
+
+        /**
+         * Default constructor.
+         *
+         * @param sticky Sticky flag.
+         * @param deployC Closure.
+         */
+        public ServiceTestRunnable(boolean sticky, DeployClosure deployC) {
+            this.sticky = sticky;
+
+            this.deployC = deployC;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() throws Exception {
+            for (Factory factory : serviceFactories)
+                testService((TestService)factory.create(), sticky, deployC);
+        }
+    }
+
+    /**
+     *
+     */
+    interface DeployClosure {
+        /**
+         * @param services Services.
+         * @param svcName Service name.
+         * @param svc Service.
+         */
+        void run(IgniteServices services, String svcName, TestService svc);
+    }
+
+    /**
+     * Tests deployment and contract.
+     *
+     * @param svc Service.
+     * @param sticky Sticky.
+     * @param deployC Closure.
+     * @throws Exception If failed.
+     */
+    protected void testService(TestService svc, boolean sticky, DeployClosure deployC) throws Exception {
+        IgniteEx ignite = testedGrid();
+
+        IgniteServices services = ignite.services();
+
+        Object expected = value(++cntr);
+
+        // Put value for testing Service instance serialization.
+        svc.setValue(expected);
+
+        deployC.run(services, SERVICE_NAME, svc);
+
+        // Expect correct value from local instance.
+        assertEquals(expected, svc.getValue());
+
+        // Use stickiness to make sure data will be fetched from the same instance.
+        TestService proxy = services.serviceProxy(SERVICE_NAME, TestService.class, sticky);
+
+        // Expect that correct value is returned from deployed instance.
+        assertEquals(expected, proxy.getValue());
+
+        expected = value(++cntr);
+
+        // Change value.
+        proxy.setValue(expected);
+
+        // Expect correct value after being read back.
+        int r = 1000;
+
+        while(r-- > 0)
+            assertEquals(expected, proxy.getValue());
+
+        assertEquals("Expected 1 deployed service", 1, services.serviceDescriptors().size());
+
+        // Randomize stop method invocation
+        boolean tmp = ThreadLocalRandom.current().nextBoolean();
+
+        if (tmp)
+            services.cancelAll();
+        else
+            services.cancel(SERVICE_NAME);
+    }
+
+    /**
+     * Test service
+     */
+    public interface TestService {
+        /**
+         * @param o argument to set.
+         */
+        void setValue(Object o);
+
+        /**
+         * @return Argument
+         * @throws Exception If failed.
+         */
+        Object getValue() throws Exception;
+    }
+
+    /**
+     * Implementation for {@link TestService}
+     */
+    public static class TestServiceImpl implements Service, TestService, Serializable {
+        /** Test value. */
+        protected Object val;
+
+        /**
+         * Default constructor.
+         */
+        public TestServiceImpl() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object getValue() throws Exception {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void cancel(ServiceContext ctx) {
+            // No-op
+        }
+
+        /** {@inheritDoc} */
+        @Override public void init(ServiceContext ctx) throws Exception {
+            // No-op
+        }
+
+        /** {@inheritDoc} */
+        @Override public void execute(ServiceContext ctx) throws Exception {
+            // No-op
+        }
+
+        /** {@inheritDoc} */
+        public void setValue(Object val) {
+            this.val = val;
+        }
+    }
+
+    /**
+     * Echo service, externalizable object
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestServiceImplExternalizable extends TestServiceImpl implements Externalizable {
+        /**
+         * Default constructor.
+         */
+        public TestServiceImplExternalizable() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            val = in.readObject();
+        }
+    }
+
+    /**
+     * Echo service, binarylizable object
+     */
+    @SuppressWarnings({"PublicInnerClass"})
+    public static class TestServiceImplBinarylizable extends TestServiceImpl implements Binarylizable {
+        /**
+         * Default constructor.
+         */
+        public TestServiceImplBinarylizable() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeObject("arg", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readObject("arg");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6e1d45e8/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java
index 7bcfc7f..929b0c8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/configvariations/VariationsTestsConfig.java
@@ -70,7 +70,7 @@ public class VariationsTestsConfig {
      * @param factory Factory.
      * @param desc Config description.
      * @param stopNodes Stope nodes.
-     * @param gridCnt Grdi count.
+     * @param gridCnt Grid count.
      */
     public VariationsTestsConfig(
         ConfigFactory factory,

http://git-wip-us.apache.org/repos/asf/ignite/blob/6e1d45e8/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
index 258eba8..3b8c046 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteConfigVariationsAbstractTest.java
@@ -27,6 +27,10 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import org.apache.commons.io.FileUtils;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -200,12 +204,12 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         for (int i = 0; i < DataMode.values().length; i++) {
             dataMode = DataMode.values()[i];
 
-            if ((getConfiguration().getMarshaller() instanceof JdkMarshaller)
-                && (dataMode == DataMode.PLANE_OBJECT)) {
-                info("Skip test for JdkMarshaller & PLANE_OBJECT data mode");
+            if (!isCompatible()) {
+                info("Skipping test in data mode: " + dataMode);
+
                 continue;
             }
-
+            
             info("Running test in data mode: " + dataMode);
 
             if (i != 0)
@@ -250,6 +254,8 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
                 return new ExternalizableObject(keyId);
             case PLANE_OBJECT:
                 return new TestObject(keyId);
+            case BINARILIZABLE:
+                return new BinarylizableObject(keyId);
             default:
                 throw new IllegalArgumentException("mode: " + mode);
         }
@@ -279,6 +285,8 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
                 return new ExternalizableObject(idx);
             case PLANE_OBJECT:
                 return new TestObject(idx);
+            case BINARILIZABLE:
+                return new BinarylizableObject(idx);
             default:
                 throw new IllegalArgumentException("mode: " + mode);
         }
@@ -395,7 +403,7 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         /**
          * Default constructor.
          */
-        public ExternalizableObject() {
+        ExternalizableObject() {
             super(-1);
         }
 
@@ -422,6 +430,37 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
     }
 
     /**
+     *
+     */
+    public static class BinarylizableObject extends TestObject implements Binarylizable {
+        /**
+         * Default constructor.
+         */
+        public BinarylizableObject() {
+            super(-1);
+        }
+
+        /**
+         * @param val Value.
+         */
+        public BinarylizableObject(int val) {
+            super(val);
+        }
+
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+            writer.writeString("strVal", strVal);
+            writer.writeEnum("enumVal", enumVal);
+        }
+
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+            strVal = reader.readString("strVal");
+            enumVal = reader.readEnum("enumVal");
+        }
+    }
+
+    /**
      * Data mode.
      */
     public enum DataMode {
@@ -432,7 +471,10 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
         EXTERNALIZABLE,
 
         /** Objects without Serializable and Externalizable. */
-        PLANE_OBJECT
+        PLANE_OBJECT,
+
+        /** Binarylizable objects. Compatible only with binary marshaller */
+        BINARILIZABLE
     }
 
     /**
@@ -452,10 +494,24 @@ public abstract class IgniteConfigVariationsAbstractTest extends GridCommonAbstr
     /**
      *
      */
-    public static interface TestRunnable {
+    public interface TestRunnable {
         /**
          * @throws Exception If failed.
          */
-        public void run() throws Exception;
+        void run() throws Exception;
+    }
+
+    /**
+     * Check test compatibility with current data mode
+     * @return true if incompatible
+     * @throws Exception
+     */
+    protected boolean isCompatible() throws Exception {
+        switch (dataMode) {
+            case BINARILIZABLE:
+            case PLANE_OBJECT:
+                return !(getConfiguration().getMarshaller() instanceof JdkMarshaller);
+        }
+        return false;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6e1d45e8/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceConfigVariationsFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceConfigVariationsFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceConfigVariationsFullApiTestSuite.java
new file mode 100644
index 0000000..328ae8d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceConfigVariationsFullApiTestSuite.java
@@ -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.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.service.IgniteServiceConfigVariationsFullApiTest;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+import org.apache.ignite.testframework.configvariations.ConfigParameter;
+import org.apache.ignite.testframework.configvariations.ConfigVariations;
+import org.apache.ignite.testframework.configvariations.ConfigVariationsTestSuiteBuilder;
+import org.apache.ignite.testframework.configvariations.Parameters;
+
+/**
+ * Full API service test suit.
+ */
+public class IgniteServiceConfigVariationsFullApiTestSuite extends TestSuite {
+    /** */
+    @SuppressWarnings("unchecked")
+    private static final ConfigParameter<IgniteConfiguration>[][] PARAMS = new ConfigParameter[][] {
+        Parameters.objectParameters("setMarshaller",
+            Parameters.factory(JdkMarshaller.class),
+            Parameters.factory(BinaryMarshaller.class),
+            ConfigVariations.optimizedMarshallerFactory()
+        ),
+
+        Parameters.booleanParameters("setPeerClassLoadingEnabled")
+    };
+
+    /**
+     * @return Compute API test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Service Deployment New Full API Test Suite");
+
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "Single server",
+            IgniteServiceConfigVariationsFullApiTest.class)
+            .igniteParams(PARAMS)
+            .gridsCount(1)
+            .build());
+
+        // Tests run on server (node#0) & client(node#1).
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "1 server, 1 client",
+            IgniteServiceConfigVariationsFullApiTest.class)
+            .igniteParams(PARAMS)
+            .gridsCount(2)
+            .testedNodesCount(2)
+            .withClients()
+            .build());
+
+        // Tests run on servers (node#0,node#2,node#3) & client(node#1).
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "3 servers, 1 client",
+            IgniteServiceConfigVariationsFullApiTest.class)
+            .igniteParams(PARAMS)
+            .gridsCount(4)
+            .testedNodesCount(2)
+            .withClients()
+            .build());
+
+        // Tests run on servers (node#0,node#2,node#3) & client(node#1,node#4).
+        suite.addTest(new ConfigVariationsTestSuiteBuilder(
+            "3 servers, 2 clients",
+            IgniteServiceConfigVariationsFullApiTest.class)
+            .igniteParams(PARAMS)
+            .gridsCount(5)
+            .testedNodesCount(2)
+            .withClients()
+            .build());
+
+        return suite;
+    }
+}
\ No newline at end of file


[13/50] [abbrv] ignite git commit: Fixed imports.

Posted by sh...@apache.org.
Fixed imports.


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

Branch: refs/heads/ignite-2788
Commit: f6232b31e56933b8a4a456054e5a84bc4cffbbc8
Parents: a8b1caf
Author: sboikov <sb...@gridgain.com>
Authored: Tue Apr 19 08:31:47 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../ignite/internal/GridGetOrStartSelfTest.java      |  9 ++++++---
 .../ignite/testsuites/IgniteBasicTestSuite.java      | 15 ++++++++++++++-
 2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f6232b31/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
index 9b3985e..211d413 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridGetOrStartSelfTest.java
@@ -18,11 +18,14 @@
 package org.apache.ignite.internal;
 
 import java.util.concurrent.atomic.AtomicReference;
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.*;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
 
 /**
  * The GridGetOrStartSelfTest tests get or start semantics.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6232b31/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index bb4b0f0..a4be2de 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -20,7 +20,20 @@ package org.apache.ignite.testsuites;
 import java.util.Set;
 import junit.framework.TestSuite;
 import org.apache.ignite.GridSuppressedExceptionSelfTest;
-import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.ClusterGroupHostsSelfTest;
+import org.apache.ignite.internal.ClusterGroupSelfTest;
+import org.apache.ignite.internal.GridFailFastNodeFailureDetectionSelfTest;
+import org.apache.ignite.internal.GridGetOrStartSelfTest;
+import org.apache.ignite.internal.GridLifecycleAwareSelfTest;
+import org.apache.ignite.internal.GridLifecycleBeanSelfTest;
+import org.apache.ignite.internal.GridNodeMetricsLogSelfTest;
+import org.apache.ignite.internal.GridProjectionForCachesSelfTest;
+import org.apache.ignite.internal.GridReduceSelfTest;
+import org.apache.ignite.internal.GridReleaseTypeSelfTest;
+import org.apache.ignite.internal.GridSelfTest;
+import org.apache.ignite.internal.GridStartStopSelfTest;
+import org.apache.ignite.internal.GridStopWithCancelSelfTest;
+import org.apache.ignite.internal.IgniteSlowClientDetectionSelfTest;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorRendezvousSelfTest;
 import org.apache.ignite.internal.processors.cache.GridProjectionForCachesOnDaemonNodeSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteDaemonNodeMarshallerCacheTest;


[43/50] [abbrv] ignite git commit: .NET: Fix outdated LINQ NuGet package description

Posted by sh...@apache.org.
.NET: Fix outdated LINQ NuGet package description


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

Branch: refs/heads/ignite-2788
Commit: 1beea53556b904e7fc50af59acae2c2fe3a266e3
Parents: 90df322
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Thu Apr 28 15:21:16 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec         | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1beea535/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec b/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec
index 7654dac..334fb9c 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.nuspec
@@ -40,10 +40,11 @@ Creating NuGet package:
         <requireLicenseAcceptance>false</requireLicenseAcceptance>
         <description>
 LINQ Provider for Apache Ignite
+
+Query distributed in-memory data in a strongly-typed manner and with IDE support!
+All Ignite SQL features are supported: distributed joins, groupings, aggregates, field queries, and more.
             
 More info: https://apacheignite-net.readme.io/
-            
-WARNING: this only works with x64 build targets.
         </description>
         <summary>
             LINQ Provider for Apache Ignite


[20/50] [abbrv] ignite git commit: IGNITE-2977: .NET: Added ability to use Java filter in .NET continuous queries. This closes #668.

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/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 24ccad2..19d370a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj
@@ -115,6 +115,7 @@
     <Compile Include="Cache\IMutableCacheEntry.cs" />
     <Compile Include="Cache\Package-Info.cs" />
     <Compile Include="Cache\Query\Continuous\ContinuousQuery.cs" />
+    <Compile Include="Cache\Query\Continuous\ContinuousQueryExtensions.cs" />
     <Compile Include="Cache\Query\Continuous\IContinuousQueryHandle.cs" />
     <Compile Include="Cache\Query\Continuous\Package-Info.cs" />
     <Compile Include="Cache\Query\IQueryCursor.cs" />
@@ -145,6 +146,8 @@
     <Compile Include="Common\IgniteGuid.cs" />
     <Compile Include="Common\Package-Info.cs" />
     <Compile Include="Impl\Common\Platform.cs" />
+    <Compile Include="Impl\Cache\Event\JavaCacheEntryEventFilter.cs" />
+    <Compile Include="Impl\Common\PlatformJavaObjectFactoryProxy.cs" />
     <Compile Include="Compute\ComputeExecutionRejectedException.cs" />
     <Compile Include="Compute\ComputeJobAdapter.cs" />
     <Compile Include="Compute\ComputeJobFailoverException.cs" />
@@ -394,6 +397,7 @@
     <Compile Include="Impl\Unmanaged\UnmanagedNonReleaseableTarget.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedTarget.cs" />
     <Compile Include="Impl\Unmanaged\UnmanagedUtils.cs" />
+    <Compile Include="Interop\JavaObject.cs" />
     <Compile Include="Lifecycle\Package-Info.cs" />
     <Compile Include="Messaging\Package-Info.cs" />
     <Compile Include="Package-Info.cs" />
@@ -488,6 +492,9 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Impl\Common\JavaObjects\" />
+  </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup Condition="'$(Platform)' == 'AnyCPU'">
@@ -495,11 +502,11 @@
 	set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=$(ProjectDir)
 	PowerShell.exe -executionpolicy remotesigned -File build-common.ps1 -Configuration $(ConfigurationName) -msbuildexe "$(MSBuildBinPath)\msbuild.exe"</PreBuildEvent>
   </PropertyGroup>
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
   </Target>
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
\ No newline at end of file
+</Project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/Continuous/ContinuousQueryExtensions.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/Continuous/ContinuousQueryExtensions.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/Continuous/ContinuousQueryExtensions.cs
new file mode 100644
index 0000000..8aa5e42
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Query/Continuous/ContinuousQueryExtensions.cs
@@ -0,0 +1,42 @@
+\ufeff/*
+ * 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.Cache.Query.Continuous
+{
+    using Apache.Ignite.Core.Cache.Event;
+    using Apache.Ignite.Core.Impl.Cache.Event;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Interop;
+
+    /// <summary>
+    /// Extensions for continuous queries.
+    /// </summary>
+    public static class ContinuousQueryExtensions
+    {
+        /// <summary>
+        /// Creates the cache event filter that delegates to the corresponding Java object.
+        /// </summary>
+        /// <typeparam name="TK">Key type.</typeparam>
+        /// <typeparam name="TV">Value type.</typeparam>
+        public static ICacheEntryEventFilter<TK, TV> ToCacheEntryEventFilter<TK, TV>(this JavaObject javaObject)
+        {
+            IgniteArgumentCheck.NotNull(javaObject, "javaObject");
+
+            return new JavaCacheEntryEventFilter<TK, TV>(javaObject.ClassName, javaObject.Properties);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs
index 4142d60..0bdbdf9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs
@@ -187,6 +187,9 @@ namespace Apache.Ignite.Core.Impl.Binary
         /** Type: stream receiver holder. */
         public const byte TypeStreamReceiverHolder = 94;
 
+        /** Type: platform object proxy. */
+        public const byte TypePlatformJavaObjectFactoryProxy = 99;
+
         /** Collection: custom. */
         public const byte CollectionCustom = 0;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
index 1a01f2c..aa881bb 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs
@@ -27,6 +27,7 @@ namespace Apache.Ignite.Core.Impl.Binary
     using Apache.Ignite.Core.Impl.Binary.Metadata;
     using Apache.Ignite.Core.Impl.Cache;
     using Apache.Ignite.Core.Impl.Cache.Query.Continuous;
+    using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Compute;
     using Apache.Ignite.Core.Impl.Compute.Closure;
     using Apache.Ignite.Core.Impl.Datastream;
@@ -574,6 +575,7 @@ namespace Apache.Ignite.Core.Impl.Binary
             AddSystemType(BinaryUtils.TypeMessageListenerHolder, w => new MessageListenerHolder(w));
             AddSystemType(BinaryUtils.TypeStreamReceiverHolder, w => new StreamReceiverHolder(w));
             AddSystemType(0, w => new AffinityKey(w), "affKey");
+            AddSystemType(BinaryUtils.TypePlatformJavaObjectFactoryProxy, w => new PlatformJavaObjectFactoryProxy());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Event/JavaCacheEntryEventFilter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Event/JavaCacheEntryEventFilter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Event/JavaCacheEntryEventFilter.cs
new file mode 100644
index 0000000..b5c2ece
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Event/JavaCacheEntryEventFilter.cs
@@ -0,0 +1,49 @@
+\ufeff/*
+ * 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.Cache.Event
+{
+    using System;
+    using System.Collections.Generic;
+    using Apache.Ignite.Core.Cache.Event;
+    using Apache.Ignite.Core.Impl.Common;
+
+    /// <summary>
+    /// Cache entry event filter that delegates to Java.
+    /// </summary>
+    /// <typeparam name="TK">Key type.</typeparam>
+    /// <typeparam name="TV">Value type.</typeparam>
+    internal class JavaCacheEntryEventFilter<TK, TV> : PlatformJavaObjectFactoryProxy, ICacheEntryEventFilter<TK, TV>
+    {
+        /** <inheritdoc /> */
+        public bool Evaluate(ICacheEntryEvent<TK, TV> evt)
+        {
+            throw new InvalidOperationException(GetType() + " cannot be invoked directly.");
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JavaCacheEntryEventFilter{TK, TV}"/> class.
+        /// </summary>
+        /// <param name="factoryClassName">Name of the factory class.</param>
+        /// <param name="properties">The properties.</param>
+        public JavaCacheEntryEventFilter(string factoryClassName, IDictionary<string, object> properties) 
+            : base(FactoryType.User, factoryClassName, null, properties)
+        {
+            // No-op.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/Continuous/ContinuousQueryHandleImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/Continuous/ContinuousQueryHandleImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/Continuous/ContinuousQueryHandleImpl.cs
index bbc2dbe..6cfbe92 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/Continuous/ContinuousQueryHandleImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/Continuous/ContinuousQueryHandleImpl.cs
@@ -26,6 +26,7 @@ namespace Apache.Ignite.Core.Impl.Cache.Query.Continuous
     using Apache.Ignite.Core.Cache.Query.Continuous;
     using Apache.Ignite.Core.Impl.Binary;
     using Apache.Ignite.Core.Impl.Binary.IO;
+    using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Core.Impl.Resource;
     using Apache.Ignite.Core.Impl.Unmanaged;
     using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
@@ -111,10 +112,20 @@ namespace Apache.Ignite.Core.Impl.Cache.Query.Continuous
             writer.WriteBoolean(qry.Local);
             writer.WriteBoolean(_filter != null);
 
-            var filterHolder = _filter == null || qry.Local ? null :
-                new ContinuousQueryFilterHolder(_filter, _keepBinary);
+            var javaFilter = _filter as PlatformJavaObjectFactoryProxy;
 
-            writer.WriteObject(filterHolder);
+            if (javaFilter != null)
+            {
+                writer.WriteObject(javaFilter.GetRawProxy());
+            }
+            else
+            {
+                var filterHolder = _filter == null || qry.Local
+                    ? null
+                    : new ContinuousQueryFilterHolder(_filter, _keepBinary);
+
+                writer.WriteObject(filterHolder);
+            }
 
             writer.WriteInt(qry.BufferSize);
             writer.WriteLong((long)qry.TimeInterval.TotalMilliseconds);

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs
new file mode 100644
index 0000000..89b2891
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Common/PlatformJavaObjectFactoryProxy.cs
@@ -0,0 +1,106 @@
+\ufeff/*
+ * 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.Generic;
+    using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Impl.Binary;
+
+    /// <summary>
+    /// Maps to PlatformJavaObjectFactoryProxy in Java.
+    /// </summary>
+    internal class PlatformJavaObjectFactoryProxy : IBinaryWriteAware
+    {
+        /// <summary>
+        /// Represents the factory type.
+        /// </summary>
+        internal enum FactoryType
+        {
+            User = 0,
+            Default = 1
+        }
+
+        /** Type code. */
+        private readonly FactoryType _factoryType;
+
+        /** Java class name */
+        private readonly string _factoryClassName;
+
+        /** Optional payload. */
+        private readonly object _payload;
+
+        /** Properties to set */
+        private readonly IDictionary<string, object> _properties;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="PlatformJavaObjectFactoryProxy" /> class.
+        /// </summary>
+        /// <param name="type">The type.</param>
+        /// <param name="factoryClassName">Name of the factory class.</param>
+        /// <param name="payload">The payload.</param>
+        /// <param name="properties">The properties.</param>
+        protected PlatformJavaObjectFactoryProxy(FactoryType type, string factoryClassName, object payload, 
+            IDictionary<string, object> properties)
+        {
+            _factoryType = type;
+            _factoryClassName = factoryClassName;
+            _payload = payload;
+            _properties = properties;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="PlatformJavaObjectFactoryProxy"/> class.
+        /// </summary>
+        public PlatformJavaObjectFactoryProxy()
+        {
+            throw new InvalidOperationException(GetType() + " should never be deserialized on .NET side.");
+        }
+
+        /** <inheritdoc /> */
+        public void WriteBinary(IBinaryWriter writer)
+        {
+            var w = writer.GetRawWriter();
+
+            w.WriteInt((int) _factoryType);
+            w.WriteString(_factoryClassName);
+            w.WriteObject(_payload);
+
+            if (_properties != null)
+            {
+                w.WriteInt(_properties.Count);
+
+                foreach (var pair in _properties)
+                {
+                    w.WriteString(pair.Key);
+                    w.WriteObject(pair.Value);
+                }
+            }
+            else
+                w.WriteInt(0);
+        }
+
+        /// <summary>
+        /// Gets the raw proxy (not the derived type) for serialization.
+        /// </summary>
+        public PlatformJavaObjectFactoryProxy GetRawProxy()
+        {
+            return new PlatformJavaObjectFactoryProxy(_factoryType, _factoryClassName, _payload, _properties);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/73948df8/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
new file mode 100644
index 0000000..98ef619
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Interop/JavaObject.cs
@@ -0,0 +1,80 @@
+\ufeff/*
+ * 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.Interop
+{
+    using System.Collections.Generic;
+    using Apache.Ignite.Core.Impl.Common;
+
+    /// <summary>
+    /// Represents a Java object wrapper.
+    /// <para />
+    /// <see cref="JavaObject"/> can be converted to Ignite filters and predicates 
+    /// which can be used on non-.NET Ignite nodes.
+    /// <para />
+    /// Workflow is as follows:
+    /// Instantiate specified Java class;
+    /// Set property values;
+    /// If the resulting object implements PlatformJavaObjectFactory, call create() method and use the result,
+    /// otherwise use the original object.
+    /// </summary>
+    public class JavaObject
+    {
+        /** Java class name. */
+        private readonly string _className;
+
+        /** Properties. */
+        private readonly IDictionary<string, object> _properties = new Dictionary<string, object>();
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JavaObject"/> class.
+        /// </summary>
+        /// <param name="className">Name of the Java class.</param>
+        public JavaObject(string className)
+        {
+            IgniteArgumentCheck.NotNullOrEmpty(className, "className");
+
+            _className = className;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JavaObject"/> class.
+        /// </summary>
+        /// <param name="className">Name of the Java class.</param>
+        /// <param name="properties">The properties to set on the Java object.</param>
+        public JavaObject(string className, IDictionary<string, object> properties) : this(className)
+        {
+            _properties = properties ?? _properties;
+        }
+
+        /// <summary>
+        /// Gets the Java class name.
+        /// </summary>
+        public string ClassName
+        {
+            get { return _className; }
+        }
+
+        /// <summary>
+        /// Gets the properties to be set on the Java object.
+        /// </summary>
+        public IDictionary<string, object> Properties
+        {
+            get { return _properties; }
+        }
+    }
+}


[37/50] [abbrv] ignite git commit: Fixed BinaryObjectOffheapUnswapTemporaryTest.

Posted by sh...@apache.org.
Fixed BinaryObjectOffheapUnswapTemporaryTest.


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

Branch: refs/heads/ignite-2788
Commit: ffbde0515a404d5135702771dc87bc183224c40a
Parents: f900f3a
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Apr 29 09:01:47 2016 +0300
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:16 2016 +0900

----------------------------------------------------------------------
 .../cache/BinaryObjectOffHeapUnswapTemporaryTest.java   | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ffbde051/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/BinaryObjectOffHeapUnswapTemporaryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/BinaryObjectOffHeapUnswapTemporaryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/BinaryObjectOffHeapUnswapTemporaryTest.java
index f26191f..824481b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/BinaryObjectOffHeapUnswapTemporaryTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/BinaryObjectOffHeapUnswapTemporaryTest.java
@@ -36,6 +36,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
 import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -53,6 +54,9 @@ public class BinaryObjectOffHeapUnswapTemporaryTest extends GridCommonAbstractTe
     /** */
     private static final int CNT = 20;
 
+    /** Cache name. */
+    private static final String CACHE_NAME = "cache";
+
     /** */
     @SuppressWarnings("serial")
     private static final CacheEntryProcessor PROC = new CacheEntryProcessor() {
@@ -69,6 +73,7 @@ public class BinaryObjectOffHeapUnswapTemporaryTest extends GridCommonAbstractTe
         IgniteConfiguration c = super.getConfiguration(gridName);
 
         c.setMarshaller(new BinaryMarshaller());
+        c.setSwapSpaceSpi(new FileSwapSpaceSpi());
 
         return c;
     }
@@ -82,8 +87,9 @@ public class BinaryObjectOffHeapUnswapTemporaryTest extends GridCommonAbstractTe
         CacheMemoryMode memoryMode) {
         this.atomicityMode = atomicityMode;
 
-        CacheConfiguration cfg = new CacheConfiguration();
+        CacheConfiguration<Object, Object>  cfg = new CacheConfiguration<>();
 
+        cfg.setName(CACHE_NAME);
         cfg.setCacheMode(CacheMode.PARTITIONED);
         cfg.setAtomicityMode(atomicityMode);
         cfg.setMemoryMode(memoryMode);
@@ -168,10 +174,10 @@ public class BinaryObjectOffHeapUnswapTemporaryTest extends GridCommonAbstractTe
      */
     @SuppressWarnings("serial")
     private void doTest() {
-        final IgniteCache<Integer, BinaryObject> cache = jcache(0).withKeepBinary();
+        final IgniteCache<Integer, BinaryObject> cache = jcache(0, CACHE_NAME).withKeepBinary();
 
         for (int key = 0; key < CNT; key++)
-            jcache(0).put(key, new TestObject(key));
+            jcache(0, CACHE_NAME).put(key, new TestObject(key));
 
         for (int key = CNT; key < 2 * CNT; key++) {
             BinaryObjectBuilder builder = ignite(0).binary().builder("SomeType");


[09/50] [abbrv] ignite git commit: IGNITE-3035 Updated the create table query in the TcpDiscoveryJdbcIpFinder class to maintain the original line breaks. - Fixes #660.

Posted by sh...@apache.org.
IGNITE-3035 Updated the create table query in the TcpDiscoveryJdbcIpFinder class to maintain the original line breaks. - Fixes #660.

Signed-off-by: Alexey Kuznetsov <ak...@apache.org>


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

Branch: refs/heads/ignite-2788
Commit: 7d4e22eca13995b9b953f0fccfbf5335e7390171
Parents: 73649cc
Author: Peter Griffiths <pe...@1spatial.com>
Authored: Tue Apr 26 09:30:09 2016 +0700
Committer: shtykh_roman <rs...@yahoo.com>
Committed: Fri May 13 16:11:14 2016 +0900

----------------------------------------------------------------------
 .../tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java    | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7d4e22ec/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
index 9d25931..24802f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/jdbc/TcpDiscoveryJdbcIpFinder.java
@@ -64,22 +64,25 @@ public class TcpDiscoveryJdbcIpFinder extends TcpDiscoveryIpFinderAdapter {
     public static final String ADDRS_TABLE_NAME = "TBL_ADDRS";
     
     /** Query to get addresses. */
-    public static final String GET_ADDRS_QRY = "select hostname, port from tbl_addrs";
+    public static final String GET_ADDRS_QRY = "select hostname, port from \"" + ADDRS_TABLE_NAME
+            + "\"";
 
     /** Query to register address. */
-    public static final String REG_ADDR_QRY = "insert into tbl_addrs values (?, ?)";
+    public static final String REG_ADDR_QRY = "insert into \"" + ADDRS_TABLE_NAME
+            + "\" values (?, ?)";
 
     /** Query to unregister address. */
-    public static final String UNREG_ADDR_QRY = "delete from tbl_addrs where hostname = ? and port = ?";
+    public static final String UNREG_ADDR_QRY = "delete from \"" + ADDRS_TABLE_NAME
+            + "\" where hostname = ? and port = ?";
 
     /** Query to create addresses table. */
     public static final String CREATE_ADDRS_TABLE_QRY =
-        "create table tbl_addrs (" +
+        "create table \"" + ADDRS_TABLE_NAME + "\" (" +
         "hostname VARCHAR(1024), " +
         "port INT)";
 
     /** Query to check database validity. */
-    public static final String CHK_QRY = "select count(*) from tbl_addrs";
+    public static final String CHK_QRY = "select count(*) from \"" + ADDRS_TABLE_NAME + "\"";
 
     /** Grid logger. */
     @LoggerResource


[02/50] [abbrv] ignite git commit: IGNITE-2004 Fixed "Asynchronous execution of ContinuousQuery's remote filter & local list".

Posted by sh...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOrderingEventTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOrderingEventTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOrderingEventTest.java
new file mode 100644
index 0000000..7d975f2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryOrderingEventTest.java
@@ -0,0 +1,722 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_VALUES;
+import static org.apache.ignite.cache.CacheMemoryMode.ONHEAP_TIERED;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ *
+ */
+public class CacheContinuousQueryOrderingEventTest extends GridCommonAbstractTest {
+    /** */
+    public static final int LISTENER_CNT = 3;
+
+    /** */
+    public static final int KEYS = 10;
+
+    /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int NODES = 5;
+
+    /** */
+    public static final int ITERATION_CNT = 100;
+
+    /** */
+    private boolean client;
+
+    /** */
+    private static volatile boolean fail;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+        ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
+
+        cfg.setClientMode(client);
+
+        MemoryEventStorageSpi storeSpi = new MemoryEventStorageSpi();
+        storeSpi.setExpireCount(100);
+
+        cfg.setEventStorageSpi(storeSpi);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGridsMultiThreaded(NODES - 1);
+
+        client = true;
+
+        startGrid(NODES - 1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        fail = false;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnheapTwoBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapTwoBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapValuesTwoBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_VALUES, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicReplicatedOffheap() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 0, ATOMIC,
+            OFFHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapTwoBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL,
+            ONHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapWithoutBackup() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 0, TRANSACTIONAL,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapWithoutBackupFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 0, TRANSACTIONAL,
+            ONHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, false);
+    }
+
+    // ASYNC
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnheapTwoBackupAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnheapTwoBackupAsyncFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            ONHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapTwoBackupAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapTwoBackupAsyncFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapValuesTwoBackupAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_VALUES, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOffheapValuesTwoBackupAsyncFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, ATOMIC,
+            OFFHEAP_VALUES, FULL_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicReplicatedAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 0, ATOMIC,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicReplicatedAsyncFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 0, ATOMIC,
+            ONHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicReplicatedOffheapAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(REPLICATED, 0, ATOMIC,
+            OFFHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicOnheapWithoutBackupAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 0, ATOMIC,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapTwoBackupAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 2, TRANSACTIONAL,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapAsync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 0, TRANSACTIONAL,
+            ONHEAP_TIERED, PRIMARY_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxOnheapAsyncFullSync() throws Exception {
+        CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 0, TRANSACTIONAL,
+            ONHEAP_TIERED, FULL_SYNC);
+
+        doOrderingTest(ccfg, true);
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     * @param async Async filter.
+     * @throws Exception If failed.
+     */
+    protected void doOrderingTest(
+        final CacheConfiguration ccfg,
+        final boolean async)
+        throws Exception {
+        ignite(0).createCache(ccfg);
+
+        List<QueryCursor<?>> qries = new ArrayList<>();
+
+        try {
+            List<BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>>> rcvdEvts =
+                new ArrayList<>(LISTENER_CNT * NODES);
+
+            final AtomicInteger qryCntr = new AtomicInteger(0);
+
+            final int threadCnt = 20;
+
+            for (int idx = 0; idx < NODES; idx++) {
+                for (int i = 0; i < LISTENER_CNT; i++) {
+                    BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue =
+                        new ArrayBlockingQueue<>(ITERATION_CNT * threadCnt);
+
+                    ContinuousQuery qry = new ContinuousQuery();
+
+                    if (async) {
+                        qry.setLocalListener(new TestCacheAsyncEventListener(queue, qryCntr));
+
+                        qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(
+                            new CacheTestRemoteFilterAsync(ccfg.getName())));
+                    }
+                    else {
+                        qry.setLocalListener(new TestCacheEventListener(queue, qryCntr));
+
+                        qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(
+                            new CacheTestRemoteFilter(ccfg.getName())));
+                    }
+
+                    rcvdEvts.add(queue);
+
+                    IgniteCache<Object, Object> cache = grid(idx).cache(ccfg.getName());
+
+                    QueryCursor qryCursor = cache.query(qry);
+
+                    qries.add(qryCursor);
+                }
+            }
+
+            IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {
+                @Override public void run() {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    for (int i = 0; i < ITERATION_CNT; i++) {
+                        IgniteCache<QueryTestKey, QueryTestValue> cache =
+                            grid(rnd.nextInt(NODES)).cache(ccfg.getName());
+
+                        QueryTestKey key = new QueryTestKey(rnd.nextInt(KEYS));
+
+                        boolean startTx = cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() ==
+                            TRANSACTIONAL && rnd.nextBoolean();
+
+                        Transaction tx = null;
+
+                        if (startTx)
+                            tx = cache.unwrap(Ignite.class).transactions().txStart();
+
+                        try {
+                            if ((cache.get(key) == null) || rnd.nextBoolean()) {
+                                cache.invoke(key, new CacheEntryProcessor<QueryTestKey, QueryTestValue, Object>() {
+                                    @Override public Object process(
+                                        MutableEntry<QueryTestKey, QueryTestValue> entry,
+                                        Object... arguments)
+                                        throws EntryProcessorException {
+                                        if (entry.exists())
+                                            entry.setValue(new QueryTestValue(entry.getValue().val1 + 1));
+                                        else
+                                            entry.setValue(new QueryTestValue(0));
+
+                                        return null;
+                                    }
+                                });
+                            }
+                            else {
+                                QueryTestValue val;
+                                QueryTestValue newVal;
+
+                                do {
+                                    val = cache.get(key);
+
+                                    newVal = val == null ?
+                                        new QueryTestValue(0) : new QueryTestValue(val.val1 + 1);
+                                }
+                                while (!cache.replace(key, val, newVal));
+                            }
+                        }
+                        finally {
+                            if (tx != null)
+                                tx.commit();
+                        }
+                    }
+                }
+            }, threadCnt, "put-thread");
+
+            f.get(15, TimeUnit.SECONDS);
+
+            GridTestUtils.waitForCondition(new PA() {
+                @Override public boolean apply() {
+                    return qryCntr.get() >= ITERATION_CNT * threadCnt * LISTENER_CNT * NODES;
+                }
+            }, 1000L);
+
+            for (BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue : rcvdEvts)
+                checkEvents(queue, ITERATION_CNT * threadCnt);
+
+            assertFalse("Ordering invocations of filter broken.", fail);
+        }
+        finally {
+            for (QueryCursor<?> qry : qries)
+                qry.close();
+
+            ignite(0).destroyCache(ccfg.getName());
+        }
+    }
+
+    /**
+     * @param queue Event queue.
+     * @throws Exception If failed.
+     */
+    private void checkEvents(BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue, int expCnt)
+        throws Exception {
+        CacheEntryEvent<QueryTestKey, QueryTestValue> evt;
+        int cnt = 0;
+        Map<QueryTestKey, Integer> vals = new HashMap<>();
+
+        while ((evt = queue.poll(100, TimeUnit.MILLISECONDS)) != null) {
+            assertNotNull(evt);
+            assertNotNull(evt.getKey());
+
+            Integer preVal = vals.get(evt.getKey());
+
+            if (preVal == null)
+                assertEquals(new QueryTestValue(0), evt.getValue());
+            else {
+                if (!new QueryTestValue(preVal + 1).equals(evt.getValue()))
+                    assertEquals("Key event: " + evt.getKey(), new QueryTestValue(preVal + 1), evt.getValue());
+            }
+
+            vals.put(evt.getKey(), evt.getValue().val1);
+
+            ++cnt;
+        }
+
+        assertEquals(expCnt, cnt);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return TimeUnit.MINUTES.toMillis(8);
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class CacheTestRemoteFilterAsync extends CacheTestRemoteFilter {
+        /**
+         * @param cacheName Cache name.
+         */
+        public CacheTestRemoteFilterAsync(String cacheName) {
+            super(cacheName);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class CacheTestRemoteFilter implements
+        CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> {
+        /** */
+        private Map<QueryTestKey, QueryTestValue> prevVals = new ConcurrentHashMap<>();
+
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        private String cacheName;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        public CacheTestRemoteFilter(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
+            if (affinity(ignite.cache(cacheName)).isPrimary(ignite.cluster().localNode(), e.getKey())) {
+                QueryTestValue prevVal = prevVals.put(e.getKey(), e.getValue());
+
+                if (prevVal != null) {
+                    if (!new QueryTestValue(prevVal.val1 + 1).equals(e.getValue()))
+                        fail = true;
+                }
+            }
+
+            return true;
+        }
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static class TestCacheAsyncEventListener extends TestCacheEventListener {
+        /**
+         * @param queue Queue.
+         * @param cntr Received events counter.
+         */
+        public TestCacheAsyncEventListener(BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue,
+            AtomicInteger cntr) {
+            super(queue, cntr);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestCacheEventListener implements CacheEntryUpdatedListener<QueryTestKey, QueryTestValue> {
+        /** */
+        private final BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue;
+
+        /** */
+        private final AtomicInteger cntr;
+
+        /**
+         * @param queue Queue.
+         * @param cntr Received events counter.
+         */
+        public TestCacheEventListener(BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue,
+            AtomicInteger cntr) {
+            this.queue = queue;
+            this.cntr = cntr;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
+            ? extends QueryTestValue>> evts) {
+            for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : evts) {
+                queue.add((CacheEntryEvent<QueryTestKey, QueryTestValue>)e);
+
+                cntr.incrementAndGet();
+            }
+        }
+    }
+
+    /**
+     * @param cacheMode Cache mode.
+     * @param backups Number of backups.
+     * @param atomicityMode Cache atomicity mode.
+     * @param memoryMode Cache memory mode.
+     * @param writeMode Cache write mode.
+     * @return Cache configuration.
+     */
+    protected CacheConfiguration<Object, Object> cacheConfiguration(
+        CacheMode cacheMode,
+        int backups,
+        CacheAtomicityMode atomicityMode,
+        CacheMemoryMode memoryMode,
+        CacheWriteSynchronizationMode writeMode) {
+        CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+        ccfg.setName("test-cache-" + atomicityMode + "-" + cacheMode + "-" + memoryMode + "-" + memoryMode + "-"
+            + backups);
+        ccfg.setAtomicityMode(atomicityMode);
+        ccfg.setCacheMode(cacheMode);
+        ccfg.setMemoryMode(memoryMode);
+        ccfg.setWriteSynchronizationMode(writeMode);
+        ccfg.setAtomicWriteOrderMode(PRIMARY);
+
+        if (cacheMode == PARTITIONED)
+            ccfg.setBackups(backups);
+
+        return ccfg;
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestKey implements Serializable, Comparable {
+        /** */
+        private final Integer key;
+
+        /**
+         * @param key Key.
+         */
+        public QueryTestKey(Integer key) {
+            this.key = key;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestKey that = (QueryTestKey)o;
+
+            return key.equals(that.key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return key.hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestKey.class, this);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int compareTo(Object o) {
+            return key - ((QueryTestKey)o).key;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class QueryTestValue implements Serializable {
+        /** */
+        @GridToStringInclude
+        protected final Integer val1;
+
+        /** */
+        @GridToStringInclude
+        protected final String val2;
+
+        /**
+         * @param val Value.
+         */
+        public QueryTestValue(Integer val) {
+            this.val1 = val;
+            this.val2 = String.valueOf(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            QueryTestValue that = (QueryTestValue) o;
+
+            return val1.equals(that.val1) && val2.equals(that.val2);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = val1.hashCode();
+
+            res = 31 * res + val2.hashCode();
+
+            return res;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(QueryTestValue.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRandomOperationsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRandomOperationsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRandomOperationsTest.java
index e9fbf70..a6c33bb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRandomOperationsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryRandomOperationsTest.java
@@ -62,6 +62,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.PA;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -118,6 +119,7 @@ public class CacheContinuousQueryRandomOperationsTest extends GridCommonAbstract
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+        ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
 
         cfg.setClientMode(client);
 
@@ -598,6 +600,9 @@ public class CacheContinuousQueryRandomOperationsTest extends GridCommonAbstract
             final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts =
                 new CopyOnWriteArrayList<>();
 
+            if (noOpFilterFactory() != null)
+                qry.setRemoteFilterFactory(noOpFilterFactory());
+
             qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
                 @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
                     ? extends QueryTestValue>> events) throws CacheEntryListenerException {
@@ -684,9 +689,17 @@ public class CacheContinuousQueryRandomOperationsTest extends GridCommonAbstract
                     checkSingleEvent(evts.get(7), CREATED, new QueryTestValue(5), null);
                     checkSingleEvent(evts.get(8), EventType.UPDATED, new QueryTestValue(6), new QueryTestValue(5));
 
+                    evts.clear();
+
                     cache.remove(key);
                     cache.remove(key);
 
+                    assert GridTestUtils.waitForCondition(new PA() {
+                        @Override public boolean apply() {
+                            return evts.size() == 1;
+                        }
+                    }, 5_000);
+
                     evts.clear();
 
                     log.info("Finish iteration: " + i);
@@ -699,6 +712,13 @@ public class CacheContinuousQueryRandomOperationsTest extends GridCommonAbstract
     }
 
     /**
+     * @return No-op filter factory for batch operations.
+     */
+    protected Factory<? extends CacheEntryEventFilter<QueryTestKey, QueryTestValue>> noOpFilterFactory() {
+        return null;
+    }
+
+    /**
      * @param ccfg Cache configuration.
      * @throws Exception If failed.
      */
@@ -711,6 +731,9 @@ public class CacheContinuousQueryRandomOperationsTest extends GridCommonAbstract
             final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts =
                 new CopyOnWriteArrayList<>();
 
+            if (noOpFilterFactory() != null)
+                qry.setRemoteFilterFactory(noOpFilterFactory());
+
             qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
                 @Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
                     ? extends QueryTestValue>> events) throws CacheEntryListenerException {

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
index b4c31be..e4afe73 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
@@ -60,6 +60,7 @@ public class GridTestKernalContext extends GridKernalContextImpl {
                 null,
                 null,
                 null,
+                null,
                 U.allPluginProviders());
 
         GridTestUtils.setFieldValue(grid(), "cfg", config());

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
index 30625fe..761d4bd 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -44,7 +44,6 @@ public class IgniteBinaryCacheQueryTestSuite extends TestSuite {
         suite.addTestSuite(BinarySerializationQuerySelfTest.class);
         suite.addTestSuite(BinarySerializationQueryWithReflectiveSerializerSelfTest.class);
         suite.addTestSuite(IgniteCacheBinaryObjectsScanSelfTest.class);
-        suite.addTestSuite(CacheContinuousQueryLostPartitionTest.class);
 
         //Should be adjusted. Not ready to be used with BinaryMarshaller.
         //suite.addTestSuite(GridCacheBinarySwapScanQuerySelfTest.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
index fbb3091..e0e81b7 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite3.java
@@ -20,9 +20,14 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchAckTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchForceServerModeAckTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryAsyncFilterListenerTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryExecuteInPrimaryTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryFilterTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryAsyncFilterRandomOperationTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFactoryFilterRandomOperationTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryLostPartitionTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryOperationFromCallbackTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryOperationP2PTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryOrderingEventTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTwoNodesTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
@@ -87,12 +92,17 @@ public class IgniteCacheQuerySelfTestSuite3 extends TestSuite {
         suite.addTestSuite(IgniteCacheContinuousQueryClientTxReconnectTest.class);
         suite.addTestSuite(CacheContinuousQueryRandomOperationsTest.class);
         suite.addTestSuite(CacheContinuousQueryRandomOperationsTwoNodesTest.class);
-        suite.addTestSuite(CacheContinuousQueryFactoryFilterTest.class);
         suite.addTestSuite(GridCacheContinuousQueryConcurrentTest.class);
+        suite.addTestSuite(CacheContinuousQueryAsyncFilterListenerTest.class);
+        suite.addTestSuite(CacheContinuousQueryFactoryFilterRandomOperationTest.class);
+        suite.addTestSuite(CacheContinuousQueryFactoryAsyncFilterRandomOperationTest.class);
+        suite.addTestSuite(CacheContinuousQueryOrderingEventTest.class);
+        suite.addTestSuite(CacheContinuousQueryOperationFromCallbackTest.class);
         suite.addTestSuite(CacheContinuousQueryOperationP2PTest.class);
         suite.addTestSuite(CacheContinuousBatchAckTest.class);
         suite.addTestSuite(CacheContinuousBatchForceServerModeAckTest.class);
         suite.addTestSuite(CacheContinuousQueryExecuteInPrimaryTest.class);
+        suite.addTestSuite(CacheContinuousQueryLostPartitionTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite4.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite4.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite4.java
index fa4e642..c4fcdac 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite4.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite4.java
@@ -18,6 +18,9 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryAsyncFailoverTxSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFailoverAtomicPrimaryWriteOrderOffheapTieredTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFailoverAtomicPrimaryWriteOrderSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryFailoverAtomicReplicatedSelfTest;
@@ -44,6 +47,10 @@ public class IgniteCacheQuerySelfTestSuite4 extends TestSuite {
         suite.addTestSuite(CacheContinuousQueryFailoverAtomicPrimaryWriteOrderOffheapTieredTest.class);
         suite.addTestSuite(CacheContinuousQueryFailoverTxOffheapTieredTest.class);
 
+        suite.addTestSuite(CacheContinuousQueryAsyncFailoverAtomicPrimaryWriteOrderSelfTest.class);
+        suite.addTestSuite(CacheContinuousQueryAsyncFailoverTxReplicatedSelfTest.class);
+        suite.addTestSuite(CacheContinuousQueryAsyncFailoverTxSelfTest.class);
+
         return suite;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventAsyncProbe.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventAsyncProbe.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventAsyncProbe.java
new file mode 100644
index 0000000..0ea66d4
--- /dev/null
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventAsyncProbe.java
@@ -0,0 +1,61 @@
+/*
+ * 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.yardstick.cache;
+
+import java.util.concurrent.atomic.AtomicLong;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.lang.IgniteAsyncCallback;
+
+/**
+ * Probe which calculate continuous query events.
+ */
+public class CacheEntryEventAsyncProbe extends CacheEntryEventProbe {
+    /** */
+    @Override protected CacheEntryUpdatedListener<Integer, Integer> localListener(AtomicLong cntr) {
+        return new CacheEntryEventListener(cntr);
+    }
+
+    /**
+     *
+     */
+    @IgniteAsyncCallback
+    private static final class CacheEntryEventListener implements CacheEntryUpdatedListener<Integer, Integer> {
+        /** */
+        private AtomicLong cnt;
+
+        /**
+         * @param cnt Counter.
+         */
+        public CacheEntryEventListener(AtomicLong cnt) {
+            this.cnt = cnt;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> events)
+        throws CacheEntryListenerException {
+            int size = 0;
+
+            for (CacheEntryEvent<? extends Integer, ? extends Integer> e : events)
+                ++size;
+
+            cnt.addAndGet(size);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/395f4738/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventProbe.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventProbe.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventProbe.java
index e42479a..a25f975 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventProbe.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/CacheEntryEventProbe.java
@@ -45,9 +45,6 @@ public class CacheEntryEventProbe implements BenchmarkProbe {
     /** */
     private BenchmarkConfiguration cfg;
 
-    /** Counter. */
-    private AtomicLong cnt = new AtomicLong(0);
-
     /** Collected points. */
     private Collection<BenchmarkProbePoint> collected = new ArrayList<>();
 
@@ -67,17 +64,9 @@ public class CacheEntryEventProbe implements BenchmarkProbe {
             if (drv0.cache() != null) {
                 ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
 
-                qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
-                    @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>>
-                        events) throws CacheEntryListenerException {
-                        int size = 0;
-
-                        for (CacheEntryEvent<? extends Integer, ? extends Integer> e : events)
-                            ++size;
+                final AtomicLong cnt = new AtomicLong();
 
-                        cnt.addAndGet(size);
-                    }
-                });
+                qry.setLocalListener(localListener(cnt));
 
                 qryCur = drv0.cache().query(qry);
 
@@ -113,6 +102,24 @@ public class CacheEntryEventProbe implements BenchmarkProbe {
                 + " probe. Probably, the driver doesn't provide \"cache()\" method.");
     }
 
+    /**
+     * @param cntr Received event counter.
+     * @return Local listener.
+     */
+    protected CacheEntryUpdatedListener<Integer, Integer> localListener(final AtomicLong cntr) {
+        return new CacheEntryUpdatedListener<Integer, Integer>() {
+            @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> events)
+                throws CacheEntryListenerException {
+                int size = 0;
+
+                for (CacheEntryEvent<? extends Integer, ? extends Integer> e : events)
+                    ++size;
+
+                cntr.addAndGet(size);
+            }
+        };
+    }
+
     /** {@inheritDoc} */
     @Override public void stop() throws Exception {
         if (qryCur != null) {