ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [07/16] incubator-ignite git commit: # ignite-60
Date Mon, 26 Jan 2015 14:18:57 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongImpl.java
new file mode 100644
index 0000000..a918c18
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongImpl.java
@@ -0,0 +1,527 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.datastructures.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.transactions.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
+import static org.apache.ignite.transactions.IgniteTxIsolation.*;
+
+/**
+ * Cache atomic long implementation.
+ */
+public final class GridCacheAtomicLongImpl implements GridCacheAtomicLongEx, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Deserialization stash. */
+    private static final ThreadLocal<IgniteBiTuple<GridCacheContext, String>> stash =
+        new ThreadLocal<IgniteBiTuple<GridCacheContext, String>>() {
+            @Override protected IgniteBiTuple<GridCacheContext, String> initialValue() {
+                return F.t2();
+            }
+        };
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Atomic long name. */
+    private String name;
+
+    /** Removed flag.*/
+    private volatile boolean rmvd;
+
+    /** Atomic long key. */
+    private GridCacheInternalKey key;
+
+    /** Atomic long projection. */
+    private CacheProjection<GridCacheInternalKey, GridCacheAtomicLongValue> atomicView;
+
+    /** Cache context. */
+    private GridCacheContext ctx;
+
+    /** Callable for {@link #get()}. */
+    private final Callable<Long> getCall = new Callable<Long>() {
+        @Override public Long call() throws Exception {
+            GridCacheAtomicLongValue val = atomicView.get(key);
+
+            if (val == null)
+                throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+            return val.get();
+        }
+    };
+
+    /** Callable for {@link #incrementAndGet()}. */
+    private final Callable<Long> incAndGetCall = new Callable<Long>() {
+        @Override public Long call() throws Exception {
+            IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+            try {
+                GridCacheAtomicLongValue val = atomicView.get(key);
+
+                if (val == null)
+                    throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                long retVal = val.get() + 1;
+
+                val.set(retVal);
+
+                atomicView.put(key, val);
+
+                tx.commit();
+
+                return retVal;
+            }
+            catch (Error | Exception e) {
+                U.error(log, "Failed to increment and get: " + this, e);
+
+                throw e;
+            } finally {
+                tx.close();
+            }
+        }
+    };
+
+    /** Callable for {@link #getAndIncrement()}. */
+    private final Callable<Long> getAndIncCall = new Callable<Long>() {
+        @Override public Long call() throws Exception {
+            IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+            try {
+                GridCacheAtomicLongValue val = atomicView.get(key);
+
+                if (val == null)
+                    throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                long retVal = val.get();
+
+                val.set(retVal + 1);
+
+                atomicView.put(key, val);
+
+                tx.commit();
+
+                return retVal;
+            }
+            catch (Error | Exception e) {
+                U.error(log, "Failed to get and increment: " + this, e);
+
+                throw e;
+            } finally {
+                tx.close();
+            }
+        }
+    };
+
+    /** Callable for {@link #decrementAndGet()}. */
+    private final Callable<Long> decAndGetCall = new Callable<Long>() {
+        @Override public Long call() throws Exception {
+            IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+            try {
+                GridCacheAtomicLongValue val = atomicView.get(key);
+
+                if (val == null)
+                    throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                long retVal = val.get() - 1;
+
+                val.set(retVal);
+
+                atomicView.put(key, val);
+
+                tx.commit();
+
+                return retVal;
+            }
+            catch (Error | Exception e) {
+                U.error(log, "Failed to decrement and get: " + this, e);
+
+                throw e;
+            } finally {
+                tx.close();
+            }
+        }
+    };
+
+    /** Callable for {@link #getAndDecrement()}. */
+    private final Callable<Long> getAndDecCall = new Callable<Long>() {
+        @Override public Long call() throws Exception {
+            IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+            try {
+                GridCacheAtomicLongValue val = atomicView.get(key);
+
+                if (val == null)
+                    throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                long retVal = val.get();
+
+                val.set(retVal - 1);
+
+                atomicView.put(key, val);
+
+                tx.commit();
+
+                return retVal;
+            }
+            catch (Error | Exception e) {
+                U.error(log, "Failed to get and decrement and get: " + this, e);
+
+                throw e;
+            } finally {
+                tx.close();
+            }
+        }
+    };
+
+    /**
+     * Empty constructor required by {@link Externalizable}.
+     */
+    public GridCacheAtomicLongImpl() {
+        // No-op.
+    }
+
+    /**
+     * Default constructor.
+     *
+     * @param name Atomic long name.
+     * @param key Atomic long key.
+     * @param atomicView Atomic projection.
+     * @param ctx CacheContext.
+     */
+    public GridCacheAtomicLongImpl(String name, GridCacheInternalKey key,
+        CacheProjection<GridCacheInternalKey, GridCacheAtomicLongValue> atomicView, GridCacheContext ctx) {
+        assert key != null;
+        assert atomicView != null;
+        assert ctx != null;
+        assert name != null;
+
+        this.ctx = ctx;
+        this.key = key;
+        this.atomicView = atomicView;
+        this.name = name;
+
+        log = ctx.gridConfig().getGridLogger().getLogger(getClass());
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long get() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(getCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long incrementAndGet() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(incAndGetCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndIncrement() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(getAndIncCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long addAndGet(long l) throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(internalAddAndGet(l), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndAdd(long l) throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(internalGetAndAdd(l), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long decrementAndGet() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(decAndGetCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndDecrement() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(getAndDecCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndSet(long l) throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(internalGetAndSet(l), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean compareAndSet(long expVal, long newVal)
+        throws IgniteCheckedException {
+        checkRemoved();
+        return CU.outTx(internalCompareAndSet(expVal, newVal), ctx);
+    }
+
+    /**
+     * Check removed flag.
+     *
+     * @throws IgniteCheckedException If removed.
+     */
+    private void checkRemoved() throws IgniteCheckedException {
+        if (rmvd)
+            throw new CacheDataStructureRemovedException("Atomic long was removed from cache: " + name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onRemoved() {
+        return rmvd = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onInvalid(@Nullable Exception err) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheInternalKey key() {
+        return key;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removed() {
+        return rmvd;
+    }
+
+    /**
+     * Method returns callable for execution {@link #addAndGet(long)} operation in async and sync mode.
+     *
+     * @param l Value will be added to atomic long.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Long> internalAddAndGet(final long l) {
+        return new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicLongValue val = atomicView.get(key);
+
+                    if (val == null)
+                        throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                    long retVal = val.get() + l;
+
+                    val.set(retVal);
+
+                    atomicView.put(key, val);
+
+                    tx.commit();
+
+                    return retVal;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to add and get: " + this, e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Method returns callable for execution {@link #getAndAdd(long)} operation in async and sync mode.
+     *
+     * @param l Value will be added to atomic long.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Long> internalGetAndAdd(final long l) {
+        return new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicLongValue val = atomicView.get(key);
+
+                    if (val == null)
+                        throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                    long retVal = val.get();
+
+                    val.set(retVal + l);
+
+                    atomicView.put(key, val);
+
+                    tx.commit();
+
+                    return retVal;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to get and add: " + this, e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Method returns callable for execution {@link #getAndSet(long)} operation in async and sync mode.
+     *
+     * @param l Value will be added to atomic long.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Long> internalGetAndSet(final long l) {
+        return new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicLongValue val = atomicView.get(key);
+
+                    if (val == null)
+                        throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                    long retVal = val.get();
+
+                    val.set(l);
+
+                    atomicView.put(key, val);
+
+                    tx.commit();
+
+                    return retVal;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to get and set: " + this, e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Method returns callable for execution {@link #compareAndSet(long, long)}
+     * operation in async and sync mode.
+     *
+     * @param expVal Expected atomic long value.
+     * @param newVal New atomic long value.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Boolean> internalCompareAndSet(final long expVal, final long newVal) {
+        return new Callable<Boolean>() {
+            @Override public Boolean call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicLongValue val = atomicView.get(key);
+
+                    if (val == null)
+                        throw new IgniteCheckedException("Failed to find atomic long with given name: " + name);
+
+                    boolean retVal = val.get() == expVal;
+
+                    if (retVal) {
+                        val.set(newVal);
+
+                        atomicView.put(key, val);
+
+                        tx.commit();
+                    }
+
+                    return retVal;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to compare and set: " + this, e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+        out.writeUTF(name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+        t.set1((GridCacheContext)in.readObject());
+        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<GridCacheContext, String> t = stash.get();
+
+            return t.get1().dataStructures().atomicLong(t.get2(), 0L, false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicLongImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongValue.java
new file mode 100644
index 0000000..43c7856
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicLongValue.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.datastructures;
+
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+
+/**
+ * Atomic long value.
+ */
+public final class GridCacheAtomicLongValue implements GridCacheInternal, Externalizable, Cloneable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Value. */
+    private long val;
+
+    /**
+     * Constructor.
+     *
+     * @param val Initial value.
+     */
+    public GridCacheAtomicLongValue(long val) {
+        this.val = val;
+    }
+
+    /**
+     * Empty constructor required for {@link Externalizable}.
+     */
+    public GridCacheAtomicLongValue() {
+        // No-op.
+    }
+
+    /**
+     * @param val New value.
+     */
+    public void set(long val) {
+        this.val = val;
+    }
+
+    /**
+     * @return val Current value.
+     */
+    public long get() {
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeLong(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException {
+        val = in.readLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicLongValue.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceEx.java
new file mode 100644
index 0000000..5759217
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceEx.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.ignite.*;
+
+/**
+ * Atomic reference managed by cache ({@code 'Ex'} stands for external).
+ */
+public interface GridCacheAtomicReferenceEx<T> extends GridCacheRemovable, IgniteAtomicReference<T> {
+    /**
+     * Get current atomic reference key.
+     *
+     * @return Atomic reference key.
+     */
+    public GridCacheInternalKey key();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/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
new file mode 100644
index 0000000..f050faf
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceImpl.java
@@ -0,0 +1,320 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.datastructures.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.transactions.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
+import static org.apache.ignite.transactions.IgniteTxIsolation.*;
+
+/**
+ * Cache atomic reference implementation.
+ */
+public final class GridCacheAtomicReferenceImpl<T> implements GridCacheAtomicReferenceEx<T>, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Deserialization stash. */
+    private static final ThreadLocal<IgniteBiTuple<GridCacheContext, String>> stash =
+        new ThreadLocal<IgniteBiTuple<GridCacheContext, String>>() {
+            @Override protected IgniteBiTuple<GridCacheContext, String> initialValue() {
+                return F.t2();
+            }
+        };
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Atomic reference name. */
+    private String name;
+
+    /** Status.*/
+    private volatile boolean rmvd;
+
+    /** Atomic reference key. */
+    private GridCacheInternalKey key;
+
+    /** Atomic reference projection. */
+    private CacheProjection<GridCacheInternalKey, GridCacheAtomicReferenceValue<T>> atomicView;
+
+    /** Cache context. */
+    private GridCacheContext ctx;
+
+    /** Callable for {@link #get} operation */
+    private final Callable<T> getCall = new Callable<T>() {
+        @Override public T call() throws Exception {
+            GridCacheAtomicReferenceValue<T> ref = atomicView.get(key);
+
+            if (ref == null)
+                throw new IgniteCheckedException("Failed to find atomic reference with given name: " + name);
+
+            return ref.get();
+        }
+    };
+
+    /**
+     * Empty constructor required by {@link Externalizable}.
+     */
+    public GridCacheAtomicReferenceImpl() {
+        // No-op.
+    }
+
+    /**
+     * Default constructor.
+     *
+     * @param name Atomic reference name.
+     * @param key Atomic reference key.
+     * @param atomicView Atomic projection.
+     * @param ctx Cache context.
+     */
+    public GridCacheAtomicReferenceImpl(String name,
+        GridCacheInternalKey key,
+        CacheProjection<GridCacheInternalKey, GridCacheAtomicReferenceValue<T>> atomicView,
+        GridCacheContext ctx) {
+        assert key != null;
+        assert atomicView != null;
+        assert ctx != null;
+        assert name != null;
+
+        this.ctx = ctx;
+        this.key = key;
+        this.atomicView = atomicView;
+        this.name = name;
+
+        log = ctx.gridConfig().getGridLogger().getLogger(getClass());
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public T get() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(getCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(T val) throws IgniteCheckedException {
+        checkRemoved();
+
+        CU.outTx(internalSet(val), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean compareAndSet(T expVal, T newVal) throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(internalCompareAndSet(wrapperPredicate(expVal), wrapperClosure(newVal)), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onRemoved() {
+        return rmvd = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onInvalid(@Nullable Exception err) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheInternalKey key() {
+        return key;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removed() {
+        return rmvd;
+    }
+
+    /**
+     * Method make wrapper predicate for existing value.
+     *
+     * @param val Value.
+     * @return Predicate.
+     */
+    private IgnitePredicate<T> wrapperPredicate(final T val) {
+        return new IgnitePredicate<T>() {
+            @Override public boolean apply(T e) {
+                return val != null && val.equals(e);
+            }
+        };
+    }
+
+    /**
+     * Method make wrapper closure for existing value.
+     *
+     * @param val Value.
+     * @return Closure.
+     */
+    private IgniteClosure<T, T> wrapperClosure(final T val) {
+        return new IgniteClosure<T, T>() {
+            @Override public T apply(T e) {
+                return val;
+            }
+        };
+    }
+
+    /**
+     * Method returns callable for execution {@link #set(Object)} operation in async and sync mode.
+     *
+     * @param val Value will be set in reference .
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Boolean> internalSet(final T val) {
+        return new Callable<Boolean>() {
+            @Override public Boolean call() throws Exception {
+
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicReferenceValue<T> ref = atomicView.get(key);
+
+                    if (ref == null)
+                        throw new IgniteCheckedException("Failed to find atomic reference with given name: " + name);
+
+                    ref.set(val);
+
+                    atomicView.put(key, ref);
+
+                    tx.commit();
+
+                    return true;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to set value [val=" + val + ", atomicReference=" + this + ']', e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Conditionally sets the new value. It will be set if {@code expValPred} is
+     * evaluate to {@code true}.
+     *
+     * @param expValPred Predicate which should evaluate to {@code true} for value to be set.
+     * @param newValClos Closure which generates new value.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Boolean> internalCompareAndSet(final IgnitePredicate<T> expValPred,
+        final IgniteClosure<T, T> newValClos) {
+        return new Callable<Boolean>() {
+            @Override public Boolean call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicReferenceValue<T> ref = atomicView.get(key);
+
+                    if (ref == null)
+                        throw new IgniteCheckedException("Failed to find atomic reference with given name: " + name);
+
+                    if (!expValPred.apply(ref.get())) {
+                        tx.setRollbackOnly();
+
+                        return false;
+                    }
+                    else {
+                        ref.set(newValClos.apply(ref.get()));
+
+                        atomicView.put(key, ref);
+
+                        tx.commit();
+
+                        return true;
+                    }
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to compare and value [expValPred=" + expValPred + ", newValClos" +
+                        newValClos + ", atomicReference" + this + ']', e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Check removed status.
+     *
+     * @throws IgniteCheckedException If removed.
+     */
+    private void checkRemoved() throws IgniteCheckedException {
+        if (rmvd)
+            throw new CacheDataStructureRemovedException("Atomic reference was removed from cache: " + name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+        out.writeUTF(name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+        t.set1((GridCacheContext)in.readObject());
+        t.set2(in.readUTF());
+    }
+
+    /**
+     * Reconstructs object on unmarshalling.
+     *
+     * @return Reconstructed object.
+     * @throws ObjectStreamException Thrown in case of unmarshalling error.
+     */
+    @SuppressWarnings("unchecked")
+    private Object readResolve() throws ObjectStreamException {
+        try {
+            IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+            return t.get1().dataStructures().atomicReference(t.get2(), null, false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicReferenceImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceValue.java
new file mode 100644
index 0000000..ef2db3e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicReferenceValue.java
@@ -0,0 +1,106 @@
+/*
+ * 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 org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+
+/**
+ * Atomic reference value.
+ */
+public final class GridCacheAtomicReferenceValue<T> implements GridCacheInternal, GridPeerDeployAware,
+    Externalizable, Cloneable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Value. */
+    private T val;
+
+    /**
+     * Default constructor.
+     *
+     * @param val Initial value.
+     */
+    public GridCacheAtomicReferenceValue(T val) {
+        this.val = val;
+    }
+
+    /**
+     * Empty constructor required for {@link Externalizable}.
+     */
+    public GridCacheAtomicReferenceValue() {
+        // No-op.
+    }
+
+    /**
+     * @param val New value.
+     */
+    public void set(T val) {
+        this.val = val;
+    }
+
+    /**
+     * @return val Current value.
+     */
+    public T get() {
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings( {"unchecked"})
+    @Override public GridCacheAtomicReferenceValue<T> clone() throws CloneNotSupportedException {
+        GridCacheAtomicReferenceValue<T> obj = (GridCacheAtomicReferenceValue<T>)super.clone();
+
+        T locVal = X.cloneObject(val, false, true);
+
+        obj.set(locVal);
+
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(val);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings( {"unchecked"})
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        val = (T)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Class<?> deployClass() {
+        // First of all check classes that may be loaded by class loader other than application one.
+        return val != null ? val.getClass() : getClass();
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClassLoader classLoader() {
+        return deployClass().getClassLoader();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicReferenceValue.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceEx.java
new file mode 100644
index 0000000..732031e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceEx.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.ignite.*;
+
+/**
+ * Sequence managed by cache ({@code 'Ex'} stands for external.
+ */
+public interface GridCacheAtomicSequenceEx extends GridCacheRemovable, IgniteAtomicSequence {
+    /**
+     * Get current sequence key.
+     *
+     * @return Sequence key.
+     */
+    public GridCacheInternalKey key();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
new file mode 100644
index 0000000..ecf5bb2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
@@ -0,0 +1,516 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.datastructures.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.transactions.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.internal.util.future.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+import java.util.concurrent.locks.*;
+
+import static java.util.concurrent.TimeUnit.*;
+import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
+import static org.apache.ignite.transactions.IgniteTxIsolation.*;
+
+/**
+ * Cache sequence implementation.
+ */
+public final class GridCacheAtomicSequenceImpl implements GridCacheAtomicSequenceEx, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** De-serialization stash. */
+    private static final ThreadLocal<IgniteBiTuple<GridCacheContext, String>> stash =
+        new ThreadLocal<IgniteBiTuple<GridCacheContext, String>>() {
+            @Override protected IgniteBiTuple<GridCacheContext, String> initialValue() {
+                return F.t2();
+            }
+        };
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Sequence name. */
+    private String name;
+
+    /** Removed flag. */
+    private volatile boolean rmvd;
+
+    /** Sequence key. */
+    private GridCacheInternalKey key;
+
+    /** Sequence projection. */
+    private CacheProjection<GridCacheInternalKey, GridCacheAtomicSequenceValue> seqView;
+
+    /** Cache context. */
+    private volatile GridCacheContext ctx;
+
+    /** Local value of sequence. */
+    private long locVal;
+
+    /**  Upper bound of local counter. */
+    private long upBound;
+
+    /**  Sequence batch size */
+    private volatile int batchSize;
+
+    /** Synchronization lock. */
+    private final Lock lock = new ReentrantLock();
+
+    /** Await condition. */
+    private Condition cond = lock.newCondition();
+
+    /** Callable for execution {@link #incrementAndGet} operation in async and sync mode.  */
+    private final Callable<Long> incAndGetCall = internalUpdate(1, true);
+
+    /** Callable for execution {@link #getAndIncrement} operation in async and sync mode.  */
+    private final Callable<Long> getAndIncCall = internalUpdate(1, false);
+
+    /** Add and get cache call guard. */
+    private final AtomicBoolean updateGuard = new AtomicBoolean();
+
+    /**
+     * Empty constructor required by {@link Externalizable}.
+     */
+    public GridCacheAtomicSequenceImpl() {
+        // No-op.
+    }
+
+    /**
+     * Default constructor.
+     *
+     * @param name Sequence name.
+     * @param key Sequence key.
+     * @param seqView Sequence projection.
+     * @param ctx CacheContext.
+     * @param locVal Local counter.
+     * @param upBound Upper bound.
+     */
+    public GridCacheAtomicSequenceImpl(String name, GridCacheInternalKey key,
+        CacheProjection<GridCacheInternalKey, GridCacheAtomicSequenceValue> seqView,
+        GridCacheContext ctx, long locVal, long upBound) {
+        assert key != null;
+        assert seqView != null;
+        assert ctx != null;
+        assert locVal <= upBound;
+
+        batchSize = ctx.config().getAtomicSequenceReserveSize();
+        this.ctx = ctx;
+        this.key = key;
+        this.seqView = seqView;
+        this.upBound = upBound;
+        this.locVal = locVal;
+        this.name = name;
+
+        log = ctx.gridConfig().getGridLogger().getLogger(getClass());
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long get() throws IgniteCheckedException {
+        checkRemoved();
+
+        lock.lock();
+
+        try {
+            return locVal;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public long incrementAndGet() throws IgniteCheckedException {
+        return internalUpdate(1, incAndGetCall, true);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndIncrement() throws IgniteCheckedException {
+        return internalUpdate(1, getAndIncCall, false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long addAndGet(long l) throws IgniteCheckedException {
+        A.ensure(l > 0, " Parameter mustn't be less then 1: " + l);
+
+        return internalUpdate(l, null, true);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getAndAdd(long l) throws IgniteCheckedException {
+        A.ensure(l > 0, " Parameter mustn't be less then 1: " + l);
+
+        return internalUpdate(l, null, false);
+    }
+
+    /**
+     * Synchronous sequence update operation. Will add given amount to the sequence value.
+     *
+     * @param l Increment amount.
+     * @param updateCall Cache call that will update sequence reservation count in accordance with l.
+     * @param updated If {@code true}, will return sequence value after update, otherwise will return sequence value
+     *      prior to update.
+     * @return Sequence value.
+     * @throws IgniteCheckedException If update failed.
+     */
+    @SuppressWarnings("SignalWithoutCorrespondingAwait")
+    private long internalUpdate(long l, @Nullable Callable<Long> updateCall, boolean updated) throws IgniteCheckedException {
+        checkRemoved();
+
+        assert l > 0;
+
+        lock.lock();
+
+        try {
+            // If reserved range isn't exhausted.
+            if (locVal + l <= upBound) {
+                long curVal = locVal;
+
+                locVal += l;
+
+                return updated ? locVal : curVal;
+            }
+        }
+        finally {
+            lock.unlock();
+        }
+
+        if (updateCall == null)
+            updateCall = internalUpdate(l, updated);
+
+        while (true) {
+            if (updateGuard.compareAndSet(false, true)) {
+                try {
+                    // This call must be outside lock.
+                    return CU.outTx(updateCall, ctx);
+                }
+                finally {
+                    lock.lock();
+
+                    try {
+                        updateGuard.set(false);
+
+                        cond.signalAll();
+                    }
+                    finally {
+                        lock.unlock();
+                    }
+                }
+            }
+            else {
+                lock.lock();
+
+                try {
+                    while (locVal >= upBound && updateGuard.get())
+                        U.await(cond, 500, MILLISECONDS);
+
+                    checkRemoved();
+
+                    // If reserved range isn't exhausted.
+                    if (locVal + l <= upBound) {
+                        long curVal = locVal;
+
+                        locVal += l;
+
+                        return updated ? locVal : curVal;
+                    }
+                }
+                finally {
+                    lock.unlock();
+                }
+            }
+        }
+    }
+
+    /**
+     * Asynchronous sequence update operation. Will add given amount to the sequence value.
+     *
+     * @param l Increment amount.
+     * @param updateCall Cache call that will update sequence reservation count in accordance with l.
+     * @param updated If {@code true}, will return sequence value after update, otherwise will return sequence value
+     *      prior to update.
+     * @return Future indicating sequence value.
+     * @throws IgniteCheckedException If update failed.
+     */
+    @SuppressWarnings("SignalWithoutCorrespondingAwait")
+    private IgniteFuture<Long> internalUpdateAsync(long l, @Nullable Callable<Long> updateCall, boolean updated)
+        throws IgniteCheckedException {
+        checkRemoved();
+
+        A.ensure(l > 0, " Parameter mustn't be less then 1: " + l);
+
+        lock.lock();
+
+        try {
+            // If reserved range isn't exhausted.
+            if (locVal + l <= upBound) {
+                long curVal = locVal;
+
+                locVal += l;
+
+                return new GridFinishedFuture<>(ctx.kernalContext(), updated ? locVal : curVal);
+            }
+        }
+        finally {
+            lock.unlock();
+        }
+
+        if (updateCall == null)
+            updateCall = internalUpdate(l, updated);
+
+        while (true) {
+            if (updateGuard.compareAndSet(false, true)) {
+                try {
+                    // This call must be outside lock.
+                    return ctx.closures().callLocalSafe(updateCall, true);
+                }
+                finally {
+                    lock.lock();
+
+                    try {
+                        updateGuard.set(false);
+
+                        cond.signalAll();
+                    }
+                    finally {
+                        lock.unlock();
+                    }
+                }
+            }
+            else {
+                lock.lock();
+
+                try {
+                    while (locVal >= upBound && updateGuard.get())
+                        U.await(cond, 500, MILLISECONDS);
+
+                    checkRemoved();
+
+                    // If reserved range isn't exhausted.
+                    if (locVal + l <= upBound) {
+                        long curVal = locVal;
+
+                        locVal += l;
+
+                        return new GridFinishedFuture<>(ctx.kernalContext(), updated ? locVal : curVal);
+                    }
+                }
+                finally {
+                    lock.unlock();
+                }
+            }
+        }
+    }
+
+    /** Get local batch size for this sequences.
+     *
+     * @return Sequence batch size.
+     */
+    @Override public int batchSize() {
+        return batchSize;
+    }
+
+    /**
+     * Set local batch size for this sequences.
+     *
+     * @param size Sequence batch size. Must be more then 0.
+     */
+    @Override public void batchSize(int size) {
+        A.ensure(size > 0, " Batch size can't be less then 0: " + size);
+
+        lock.lock();
+
+        try {
+            batchSize = size;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Check removed status.
+     *
+     * @throws IgniteCheckedException If removed.
+     */
+    private void checkRemoved() throws IgniteCheckedException {
+        if (rmvd)
+            throw new CacheDataStructureRemovedException("Sequence was removed from cache: " + name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onRemoved() {
+        return rmvd = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onInvalid(@Nullable Exception err) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheInternalKey key() {
+        return key;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removed() {
+        return rmvd;
+    }
+
+    /**
+     * Method returns callable for execution all update operations in async and sync mode.
+     *
+     * @param l Value will be added to sequence.
+     * @param updated If {@code true}, will return updated value, if {@code false}, will return previous value.
+     * @return Callable for execution in async and sync mode.
+     */
+    @SuppressWarnings("TooBroadScope")
+    private Callable<Long> internalUpdate(final long l, final boolean updated) {
+        return new Callable<Long>() {
+            @Override public Long call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, seqView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicSequenceValue seq = seqView.get(key);
+
+                    checkRemoved();
+
+                    assert seq != null;
+
+                    long curLocVal;
+
+                    long newUpBound;
+
+                    lock.lock();
+
+                    try {
+                        curLocVal = locVal;
+
+                        // If local range was already reserved in another thread.
+                        if (locVal + l <= upBound) {
+                            long retVal = locVal;
+
+                            locVal += l;
+
+                            return updated ? locVal : retVal;
+                        }
+
+                        long curGlobalVal = seq.get();
+
+                        long newLocVal;
+
+                        /* We should use offset because we already reserved left side of range.*/
+                        long off = batchSize > 1 ? batchSize - 1 : 1;
+
+                        // Calculate new values for local counter, global counter and upper bound.
+                        if (curLocVal + l >= curGlobalVal) {
+                            newLocVal = curLocVal + l;
+
+                            newUpBound = newLocVal + off;
+                        }
+                        else {
+                            newLocVal = curGlobalVal;
+
+                            newUpBound = newLocVal + off;
+                        }
+
+                        locVal = newLocVal;
+                        upBound = newUpBound;
+
+                        if (updated)
+                            curLocVal = newLocVal;
+                    }
+                    finally {
+                        lock.unlock();
+                    }
+
+                    // Global counter must be more than reserved upper bound.
+                    seq.set(newUpBound + 1);
+
+                    seqView.put(key, seq);
+
+                    tx.commit();
+
+                    return curLocVal;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to get and add: " + this, e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+        out.writeUTF(name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+        t.set1((GridCacheContext)in.readObject());
+        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<GridCacheContext, String> t = stash.get();
+
+            return t.get1().dataStructures().sequence(t.get2(), 0L, false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicSequenceImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceValue.java
new file mode 100644
index 0000000..e6d6ceb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceValue.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.datastructures;
+
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+
+/**
+ * Sequence value.
+ */
+public final class GridCacheAtomicSequenceValue implements GridCacheInternal, Externalizable, Cloneable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Counter. */
+    private long val;
+
+    /**
+     * Empty constructor required for {@link Externalizable}.
+     */
+    public GridCacheAtomicSequenceValue() {
+        // No-op.
+    }
+
+    /**
+     * Default constructor.
+     *
+     * @param val Initial value.
+     */
+    public GridCacheAtomicSequenceValue(long val) {
+        this.val = val;
+    }
+
+    /**
+     * @param val New value.
+     */
+    public void set(long val) {
+        this.val = val;
+    }
+
+    /**
+     * @return val Current value.
+     */
+    public long get() {
+        return val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeLong(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException {
+        val = in.readLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridCacheAtomicSequenceValue.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedEx.java
new file mode 100644
index 0000000..eea2204
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedEx.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.ignite.*;
+
+/**
+ * Atomic stamped managed by cache ({@code 'Ex'} stands for external).
+ */
+public interface GridCacheAtomicStampedEx<T, S> extends GridCacheRemovable, IgniteAtomicStamped<T, S> {
+    /**
+     * Get current atomic stamped key.
+     *
+     * @return Atomic stamped key.
+     */
+    public GridCacheInternalKey key();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
new file mode 100644
index 0000000..2cf835e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.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.datastructures;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.datastructures.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.transactions.*;
+import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
+import static org.apache.ignite.transactions.IgniteTxIsolation.*;
+
+/**
+ * Cache atomic stamped implementation.
+ */
+public final class GridCacheAtomicStampedImpl<T, S> implements GridCacheAtomicStampedEx<T, S>, Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Deserialization stash. */
+    private static final ThreadLocal<IgniteBiTuple<GridCacheContext, String>> stash =
+        new ThreadLocal<IgniteBiTuple<GridCacheContext, String>>() {
+            @Override protected IgniteBiTuple<GridCacheContext, String> initialValue() {
+                return F.t2();
+            }
+        };
+
+    /** Logger. */
+    private IgniteLogger log;
+
+    /** Atomic stamped name. */
+    private String name;
+
+    /** Removed flag.*/
+    private volatile boolean rmvd;
+
+    /** Atomic stamped key. */
+    private GridCacheInternalKey key;
+
+    /** Atomic stamped projection. */
+    private CacheProjection<GridCacheInternalKey, GridCacheAtomicStampedValue<T, S>> atomicView;
+
+    /** Cache context. */
+    private GridCacheContext ctx;
+
+    /** Callable for {@link #get()} operation */
+    private final Callable<IgniteBiTuple<T, S>> getCall = new Callable<IgniteBiTuple<T, S>>() {
+        @Override public IgniteBiTuple<T, S> call() throws Exception {
+            GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key);
+
+            if (stmp == null)
+                throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
+
+            return stmp.get();
+        }
+    };
+
+    /** Callable for {@link #value()} operation */
+    private final Callable<T> valCall = new Callable<T>() {
+        @Override public T call() throws Exception {
+            GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key);
+
+            if (stmp == null)
+                throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
+
+            return stmp.value();
+        }
+    };
+
+    /** Callable for {@link #stamp()} operation */
+    private final Callable<S> stampCall = new Callable<S>() {
+        @Override public S call() throws Exception {
+            GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key);
+
+            if (stmp == null)
+                throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
+
+            return stmp.stamp();
+        }
+    };
+
+    /**
+     * Empty constructor required by {@link Externalizable}.
+     */
+    public GridCacheAtomicStampedImpl() {
+        // No-op.
+    }
+
+    /**
+     * Default constructor.
+     *
+     * @param name Atomic stamped name.
+     * @param key Atomic stamped key.
+     * @param atomicView Atomic projection.
+     * @param ctx Cache context.
+     */
+    public GridCacheAtomicStampedImpl(String name, GridCacheInternalKey key, CacheProjection<GridCacheInternalKey,
+            GridCacheAtomicStampedValue<T, S>> atomicView, GridCacheContext ctx) {
+        assert key != null;
+        assert atomicView != null;
+        assert ctx != null;
+        assert name != null;
+
+        this.ctx = ctx;
+        this.key = key;
+        this.atomicView = atomicView;
+        this.name = name;
+
+        log = ctx.gridConfig().getGridLogger().getLogger(getClass());
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteBiTuple<T, S> get() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(getCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void set(T val, S stamp) throws IgniteCheckedException {
+        checkRemoved();
+
+        CU.outTx(internalSet(val, stamp), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean compareAndSet(T expVal, T newVal, S expStamp, S newStamp) throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(internalCompareAndSet(F0.equalTo(expVal), wrapperClosure(newVal),
+            F0.equalTo(expStamp), wrapperClosure(newStamp)), ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public S stamp() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(stampCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public T value() throws IgniteCheckedException {
+        checkRemoved();
+
+        return CU.outTx(valCall, ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean onRemoved() {
+        return rmvd = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onInvalid(@Nullable Exception err) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheInternalKey key() {
+        return key;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean removed() {
+        return rmvd;
+    }
+
+    /**
+     * Method make wrapper closure for existing value.
+     *
+     * @param val Value.
+     * @return Closure.
+     */
+    private <N> IgniteClosure<N, N> wrapperClosure(final N val) {
+        return new IgniteClosure<N, N>() {
+            @Override public N apply(N e) {
+                return val;
+            }
+        };
+    }
+
+    /**
+     * Method returns callable for execution {@link #set(Object,Object)}} operation in async and sync mode.
+     *
+     * @param val Value will be set in the atomic stamped.
+     * @param stamp Stamp will be set in the atomic stamped.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Boolean> internalSet(final T val, final S stamp) {
+        return new Callable<Boolean>() {
+            @Override public Boolean call() throws Exception {
+
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key);
+
+                    if (stmp == null)
+                        throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
+
+                    stmp.set(val, stamp);
+
+                    atomicView.put(key, stmp);
+
+                    tx.commit();
+
+                    return true;
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to set [val=" + val + ", stamp=" + stamp + ", atomicStamped=" + this + ']', e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /**
+     * Conditionally asynchronously sets the new value and new stamp. They will be set if
+     * {@code expValPred} and {@code expStampPred} both evaluate to {@code true}.
+     *
+     * @param expValPred Predicate which should evaluate to {@code true} for value to be set
+     * @param newValClos Closure generates new value.
+     * @param expStampPred Predicate which should evaluate to {@code true} for value to be set
+     * @param newStampClos Closure generates new stamp value.
+     * @return Callable for execution in async and sync mode.
+     */
+    private Callable<Boolean> internalCompareAndSet(final IgnitePredicate<T> expValPred,
+        final IgniteClosure<T, T> newValClos, final IgnitePredicate<S> expStampPred,
+        final IgniteClosure<S, S> newStampClos) {
+        return new Callable<Boolean>() {
+            @Override public Boolean call() throws Exception {
+                IgniteTx tx = CU.txStartInternal(ctx, atomicView, PESSIMISTIC, REPEATABLE_READ);
+
+                try {
+                    GridCacheAtomicStampedValue<T, S> stmp = atomicView.get(key);
+
+                    if (stmp == null)
+                        throw new IgniteCheckedException("Failed to find atomic stamped with given name: " + name);
+
+                    if (!(expValPred.apply(stmp.value()) && expStampPred.apply(stmp.stamp()))) {
+                        tx.setRollbackOnly();
+
+                        return false;
+                    }
+                    else {
+                        stmp.set(newValClos.apply(stmp.value()), newStampClos.apply(stmp.stamp()));
+
+                        atomicView.put(key, stmp);
+
+                        tx.commit();
+
+                        return true;
+                    }
+                }
+                catch (Error | Exception e) {
+                    U.error(log, "Failed to compare and set [expValPred=" + expValPred + ", newValClos=" +
+                        newValClos + ", expStampPred=" + expStampPred + ", newStampClos=" + newStampClos +
+                        ", atomicStamped=" + this + ']', e);
+
+                    throw e;
+                } finally {
+                    tx.close();
+                }
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+        out.writeUTF(name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+        t.set1((GridCacheContext)in.readObject());
+        t.set2(in.readUTF());
+    }
+
+    /**
+     * Reconstructs object on unmarshalling.
+     *
+     * @return Reconstructed object.
+     * @throws ObjectStreamException Thrown in case of unmarshalling error.
+     */
+    @SuppressWarnings("unchecked")
+    private Object readResolve() throws ObjectStreamException {
+        try {
+            IgniteBiTuple<GridCacheContext, String> t = stash.get();
+
+            return t.get1().dataStructures().atomicStamped(t.get2(), null, null, false);
+        }
+        catch (IgniteCheckedException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+        finally {
+            stash.remove();
+        }
+    }
+
+    /**
+     * Check removed status.
+     *
+     * @throws IgniteCheckedException If removed.
+     */
+    private void checkRemoved() throws IgniteCheckedException {
+        if (rmvd)
+            throw new CacheDataStructureRemovedException("Atomic stamped was removed from cache: " + name);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return GridToStringBuilder.toString(GridCacheAtomicStampedImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java
new file mode 100644
index 0000000..78018d1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java
@@ -0,0 +1,135 @@
+/*
+ * 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 org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.tostring.*;
+
+import java.io.*;
+
+/**
+ * Atomic stamped value.
+ */
+
+public final class GridCacheAtomicStampedValue<T, S> implements GridCacheInternal, GridPeerDeployAware,
+    Externalizable, Cloneable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Value. */
+    private T val;
+
+    /** Stamp. */
+    private S stamp;
+
+    /**
+     * Constructor.
+     *
+     * @param val Initial value.
+     * @param stamp Initial stamp.
+     */
+    public GridCacheAtomicStampedValue(T val, S stamp) {
+        this.val = val;
+        this.stamp = stamp;
+    }
+
+    /**
+     * Empty constructor required for {@link Externalizable}.
+     */
+    public GridCacheAtomicStampedValue() {
+        // No-op.
+    }
+
+    /**
+     * @param val New value.
+     * @param stamp New stamp.
+     */
+    public void set(T val, S stamp) {
+        this.val = val;
+        this.stamp = stamp;
+    }
+
+    /**
+     * @return Current value and stamp.
+     */
+    public IgniteBiTuple<T, S> get() {
+        return F.t(val, stamp);
+    }
+
+    /**
+     * @return val Current value.
+     */
+    public T value() {
+        return val;
+    }
+
+    /**
+     * @return Current stamp.
+     */
+    public S stamp() {
+        return stamp;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings( {"unchecked"})
+    @Override public GridCacheAtomicStampedValue<T, S> clone() throws CloneNotSupportedException {
+        GridCacheAtomicStampedValue<T, S> obj = (GridCacheAtomicStampedValue<T, S>)super.clone();
+
+        T locVal = X.cloneObject(val, false, true);
+        S locStamp = X.cloneObject(stamp, false, true);
+
+        obj.set(locVal, locStamp);
+
+        return obj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(val);
+        out.writeObject(stamp);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings( {"unchecked"})
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        val = (T)in.readObject();
+        stamp = (S)in.readObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Class<?> deployClass() {
+        ClassLoader clsLdr = getClass().getClassLoader();
+
+        // First of all check classes that may be loaded by class loader other than application one.
+        return stamp != null && !clsLdr.equals(stamp.getClass().getClassLoader()) ?
+            stamp.getClass() : val != null ? val.getClass() : getClass();
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClassLoader classLoader() {
+        return deployClass().getClassLoader();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return GridToStringBuilder.toString(GridCacheAtomicStampedValue.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10a6c7d/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchEx.java
new file mode 100644
index 0000000..7cce308
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchEx.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.datastructures;
+
+import org.apache.ignite.*;
+
+/**
+ * Grid cache count down latch ({@code 'Ex'} stands for external).
+ */
+public interface GridCacheCountDownLatchEx extends IgniteCountDownLatch, GridCacheRemovable {
+    /**
+     * Get current count down latch key.
+     *
+     * @return Latch key.
+     */
+    public GridCacheInternalKey key();
+
+    /**
+     * Callback to notify latch on changes.
+     *
+     * @param count New count.
+     */
+    public void onUpdate(int count);
+}


Mime
View raw message