ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [13/50] [abbrv] incubator-ignite git commit: # ignite-6 merge from sprint-1
Date Thu, 05 Feb 2015 11:50:24 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedValue.java
index 78018d1,0000000..0f4be1e
mode 100644,000000..100644
--- 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
@@@ -1,135 -1,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 org.apache.ignite.internal.util.typedef.*;
++import org.apache.ignite.lang.*;
 +
 +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/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchImpl.java
index d9b41a4,0000000..2add962
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheCountDownLatchImpl.java
@@@ -1,369 -1,0 +1,369 @@@
 +/*
 + * 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.internal.*;
 +import org.apache.ignite.internal.processors.cache.*;
- import org.apache.ignite.lang.*;
- import org.apache.ignite.transactions.*;
++import org.apache.ignite.internal.processors.cache.transactions.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +import org.jetbrains.annotations.*;
 +
 +import java.io.*;
 +import java.util.concurrent.*;
 +import java.util.concurrent.atomic.*;
 +
 +import static org.apache.ignite.transactions.IgniteTxConcurrency.*;
 +import static org.apache.ignite.transactions.IgniteTxIsolation.*;
 +
 +/**
 + * Cache count down latch implementation.
 + */
 +public final class GridCacheCountDownLatchImpl implements GridCacheCountDownLatchEx, Externalizable {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** Deserialization stash. */
 +    private static final ThreadLocal<IgniteBiTuple<GridKernalContext, String>> stash =
 +        new ThreadLocal<IgniteBiTuple<GridKernalContext, String>>() {
 +            @Override protected IgniteBiTuple<GridKernalContext, String> initialValue() {
 +                return F.t2();
 +            }
 +        };
 +
 +    /** Logger. */
 +    private IgniteLogger log;
 +
 +    /** Latch name. */
 +    private String name;
 +
 +    /** Removed flag.*/
 +    private volatile boolean rmvd;
 +
 +    /** Latch key. */
 +    private GridCacheInternalKey key;
 +
 +    /** Latch projection. */
 +    private CacheProjection<GridCacheInternalKey, GridCacheCountDownLatchValue> latchView;
 +
 +    /** Cache context. */
 +    private GridCacheContext ctx;
 +
 +    /** Current count. */
 +    private int cnt;
 +
 +    /** Initial count. */
 +    private int initCnt;
 +
 +    /** Auto delete flag. */
 +    private boolean autoDel;
 +
 +    /** Internal latch (transient). */
 +    private volatile CountDownLatch internalLatch;
 +
 +    /** Initialization guard. */
 +    private final AtomicBoolean initGuard = new AtomicBoolean();
 +
 +    /** Initialization latch. */
 +    private final CountDownLatch initLatch = new CountDownLatch(1);
 +
 +    /**
 +     * Empty constructor required by {@link Externalizable}.
 +     */
 +    public GridCacheCountDownLatchImpl() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * Constructor.
 +     *
 +     * @param name Latch name.
 +     * @param cnt Current count.
 +     * @param initCnt Initial count.
 +     * @param autoDel Auto delete flag.
 +     * @param key Latch key.
 +     * @param latchView Latch projection.
 +     * @param ctx Cache context.
 +     */
 +    public GridCacheCountDownLatchImpl(String name,
 +        int cnt,
 +        int initCnt,
 +        boolean autoDel,
 +        GridCacheInternalKey key,
 +        CacheProjection<GridCacheInternalKey, GridCacheCountDownLatchValue> latchView,
 +        GridCacheContext ctx)
 +    {
 +        assert name != null;
 +        assert cnt >= 0;
 +        assert initCnt >= 0;
 +        assert key != null;
 +        assert latchView != null;
 +        assert ctx != null;
 +
 +        this.name = name;
 +        this.cnt = cnt;
 +        this.initCnt = initCnt;
 +        this.autoDel = autoDel;
 +        this.key = key;
 +        this.latchView = latchView;
 +        this.ctx = ctx;
 +
 +        log = ctx.gridConfig().getGridLogger().getLogger(getClass());
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String name() {
 +        return name;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int count() {
 +        return cnt;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int initialCount() {
 +        return initCnt;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean autoDelete() {
 +        return autoDel;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void await() throws IgniteCheckedException {
 +        initializeLatch();
 +
 +        U.await(internalLatch);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean await(long timeout, TimeUnit unit) throws IgniteCheckedException {
 +        initializeLatch();
 +
 +        return U.await(internalLatch, timeout, unit);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean await(long timeout) throws IgniteCheckedException {
 +        return await(timeout, TimeUnit.MILLISECONDS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int countDown() throws IgniteCheckedException {
 +        return CU.outTx(new CountDownCallable(1), ctx);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int countDown(int val) throws IgniteCheckedException {
 +        A.ensure(val > 0, "val should be positive");
 +
 +        return CU.outTx(new CountDownCallable(val), ctx);
 +    }
 +
 +    /** {@inheritDoc}*/
 +    @Override public void countDownAll() throws IgniteCheckedException {
 +        CU.outTx(new CountDownCallable(0), ctx);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean onRemoved() {
 +        assert cnt == 0;
 +
 +        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;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void onUpdate(int cnt) {
 +        assert cnt >= 0;
 +
 +        this.cnt = cnt;
 +
 +        while (internalLatch != null && internalLatch.getCount() > cnt)
 +            internalLatch.countDown();
 +    }
 +
 +    /**
 +     * @throws IgniteCheckedException If operation failed.
 +     */
 +    private void initializeLatch() throws IgniteCheckedException {
 +        if (initGuard.compareAndSet(false, true)) {
 +            try {
 +                internalLatch = CU.outTx(
 +                    new Callable<CountDownLatch>() {
 +                        @Override public CountDownLatch call() throws Exception {
-                             try (IgniteTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ)) {
++                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ)) {
 +                                GridCacheCountDownLatchValue val = latchView.get(key);
 +
 +                                if (val == null) {
 +                                    if (log.isDebugEnabled())
 +                                        log.debug("Failed to find count down latch with given name: " + name);
 +
 +                                    assert cnt == 0;
 +
 +                                    return new CountDownLatch(cnt);
 +                                }
 +
 +                                tx.commit();
 +
 +                                return new CountDownLatch(val.get());
 +                            }
 +                        }
 +                    },
 +                    ctx
 +                );
 +
 +                if (log.isDebugEnabled())
 +                    log.debug("Initialized internal latch: " + internalLatch);
 +            }
 +            finally {
 +                initLatch.countDown();
 +            }
 +        }
 +        else {
 +            U.await(initLatch);
 +
 +            if (internalLatch == null)
 +                throw new IgniteCheckedException("Internal latch has not been properly initialized.");
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void close() {
 +        if (rmvd)
 +            return;
 +
 +        try {
 +            ctx.kernalContext().dataStructures().removeCountDownLatch(name);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        out.writeObject(ctx.kernalContext());
 +        out.writeUTF(name);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        IgniteBiTuple<GridKernalContext, String> t = stash.get();
 +
 +        t.set1((GridKernalContext)in.readObject());
 +        t.set2(in.readUTF());
 +    }
 +
 +    /**
 +     * Reconstructs object on unmarshalling.
 +     *
 +     * @return Reconstructed object.
 +     * @throws ObjectStreamException Thrown in case of unmarshalling error.
 +     */
 +    @SuppressWarnings({"ConstantConditions"})
 +    private Object readResolve() throws ObjectStreamException {
 +        try {
 +            IgniteBiTuple<GridKernalContext, String> t = stash.get();
 +
 +            return t.get1().dataStructures().countDownLatch(t.get2(), 0, false, false);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
 +        }
 +        finally {
 +            stash.remove();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheCountDownLatchImpl.class, this);
 +    }
 +
 +    /**
 +     *
 +     */
 +    private class CountDownCallable implements Callable<Integer> {
 +        /** Value to count down on (if 0 then latch is counted down to 0). */
 +        private final int val;
 +
 +        /**
 +         * @param val Value to count down on (if 0 is passed latch is counted down to 0).
 +         */
 +        private CountDownCallable(int val) {
 +            assert val >= 0;
 +
 +            this.val = val;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public Integer call() throws Exception {
-             try (IgniteTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ)) {
++            try (IgniteInternalTx tx = CU.txStartInternal(ctx, latchView, PESSIMISTIC, REPEATABLE_READ)) {
 +                GridCacheCountDownLatchValue latchVal = latchView.get(key);
 +
 +                if (latchVal == null) {
 +                    if (log.isDebugEnabled())
 +                        log.debug("Failed to find count down latch with given name: " + name);
 +
 +                    assert cnt == 0;
 +
 +                    return cnt;
 +                }
 +
 +                int retVal;
 +
 +                if (val > 0) {
 +                    retVal = latchVal.get() - val;
 +
 +                    if (retVal < 0)
 +                        retVal = 0;
 +                }
 +                else
 +                    retVal = 0;
 +
 +                latchVal.set(retVal);
 +
 +                latchView.put(key, latchVal);
 +
 +                tx.commit();
 +
 +                return retVal;
 +            }
 +        }
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheInternalKeyImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheInternalKeyImpl.java
index 21f8e47,0000000..2d3ba03
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheInternalKeyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheInternalKeyImpl.java
@@@ -1,89 -1,0 +1,89 @@@
 +/*
 + * 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.cache.affinity.CacheAffinityKeyMapped;
++import org.apache.ignite.cache.affinity.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
 +
 +import java.io.*;
 +
 +/**
 + * Key is used for caching cache data structures.
 + */
 +public class GridCacheInternalKeyImpl implements GridCacheInternalKey, Externalizable, Cloneable {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** Name of cache data structure. */
 +    private String name;
 +
 +    /**
 +     * Default constructor.
 +     *
 +     * @param name - Name of cache data structure.
 +     */
 +    public GridCacheInternalKeyImpl(String name) {
 +        assert !F.isEmpty(name);
 +
 +        this.name = name;
 +    }
 +
 +    /**
 +     * Empty constructor required for {@link Externalizable}.
 +     */
 +    public GridCacheInternalKeyImpl() {
 +        // No-op.
 +    }
 +
 +    /** {@inheritDoc} */
 +    @CacheAffinityKeyMapped
 +    @Override public String name() {
 +        return name;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        return name.hashCode();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean equals(Object obj) {
 +        return this == obj || (obj instanceof GridCacheInternalKey && name.equals(((GridCacheInternalKey)obj).name()));
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public Object clone() throws CloneNotSupportedException {
 +        return super.clone();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        U.writeString(out, name);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException {
 +        name = U.readString(in);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheInternalKeyImpl.class, this);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
index e87ac07,0000000..b490261
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
@@@ -1,1021 -1,0 +1,1043 @@@
 +/*
 + * 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.affinity.*;
 +import org.apache.ignite.cache.datastructures.*;
 +import org.apache.ignite.internal.processors.cache.*;
- import org.apache.ignite.lang.*;
 +import org.apache.ignite.internal.util.tostring.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +import org.jetbrains.annotations.*;
 +
 +import javax.cache.processor.*;
 +import java.io.*;
 +import java.util.*;
 +import java.util.concurrent.*;
 +
 +import static java.util.concurrent.TimeUnit.*;
 +
 +/**
 + * Common code for {@link org.apache.ignite.IgniteQueue} implementation.
 + */
 +public abstract class GridCacheQueueAdapter<T> extends AbstractCollection<T> implements IgniteQueue<T> {
 +    /** Value returned by closure updating queue header indicating that queue was removed. */
 +    protected static final long QUEUE_REMOVED_IDX = Long.MIN_VALUE;
 +
 +    /** */
 +    protected static final int MAX_UPDATE_RETRIES = 100;
 +
 +    /** */
 +    protected static final long RETRY_DELAY = 1;
 +
 +    /** */
 +    private static final int DFLT_CLEAR_BATCH_SIZE = 100;
 +
 +    /** Logger. */
 +    protected final IgniteLogger log;
 +
 +    /** Cache context. */
 +    protected final GridCacheContext<?, ?> cctx;
 +
 +    /** Cache. */
-     protected final IgniteCache cache;
++    protected final GridCacheAdapter cache;
 +
 +    /** Queue name. */
 +    protected final String queueName;
 +
 +    /** Queue header key. */
 +    protected final GridCacheQueueHeaderKey queueKey;
 +
 +    /** Queue unique ID. */
 +    protected final IgniteUuid id;
 +
 +    /** Queue capacity. */
 +    private final int cap;
 +
 +    /** Collocation flag. */
 +    private final boolean collocated;
 +
 +    /** Removed flag. */
 +    private volatile boolean rmvd;
 +
 +    /** Read blocking operations semaphore. */
 +    @GridToStringExclude
 +    private final Semaphore readSem;
 +
 +    /** Write blocking operations semaphore. */
 +    @GridToStringExclude
 +    private final Semaphore writeSem;
 +
 +    /**
 +     * @param queueName Queue name.
 +     * @param hdr Queue hdr.
 +     * @param cctx Cache context.
 +     */
 +    @SuppressWarnings("unchecked")
 +    protected GridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?, ?> cctx) {
 +        this.cctx = cctx;
 +        this.queueName = queueName;
 +        id = hdr.id();
 +        cap = hdr.capacity();
 +        collocated = hdr.collocated();
 +        queueKey = new GridCacheQueueHeaderKey(queueName);
-         cache = cctx.kernalContext().cache().jcache(cctx.name());
++        cache = cctx.kernalContext().cache().internalCache(cctx.name());
 +
 +        log = cctx.logger(getClass());
 +
 +        readSem = new Semaphore(hdr.size(), true);
 +
 +        writeSem = bounded() ? new Semaphore(hdr.capacity() - hdr.size(), true) : null;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String name() {
 +        return queueName;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean add(T item) {
 +        A.notNull(item, "item");
 +
 +        return offer(item);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean collocated() {
 +        return collocated;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int capacity() throws IgniteCheckedException {
 +        return cap;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean bounded() {
 +        return cap < Integer.MAX_VALUE;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Override public int size() {
-         GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey);
++        try {
++            GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey);
 +
-         checkRemoved(hdr);
++            checkRemoved(hdr);
 +
-         return hdr.size();
++            return hdr.size();
++        }
++        catch (IgniteCheckedException e) {
++            throw U.convertException(e);
++        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public T peek() throws IgniteException {
-         GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey);
++        try {
++            GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey);
 +
-         checkRemoved(hdr);
++            checkRemoved(hdr);
 +
-         if (hdr.empty())
-             return null;
++            if (hdr.empty())
++                return null;
 +
-         return (T)cache.get(itemKey(hdr.head()));
++            return (T)cache.get(itemKey(hdr.head()));
++        }
++        catch (IgniteCheckedException e) {
++            throw U.convertException(e);
++        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public T remove() {
 +        T res = poll();
 +
 +        if (res == null)
 +            throw new NoSuchElementException();
 +
 +        return res;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public T element() {
 +        T el = peek();
 +
 +        if (el == null)
 +            throw new NoSuchElementException();
 +
 +        return el;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Override public Iterator<T> iterator() {
 +        try {
 +            GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.get(queueKey);
 +
 +            checkRemoved(hdr);
 +
 +            return new QueueIterator(hdr);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void put(T item) throws IgniteException {
 +        A.notNull(item, "item");
 +
 +        if (!bounded()) {
 +            boolean offer = offer(item);
 +
 +            assert offer;
 +
 +            return;
 +        }
 +
 +        while (true) {
 +            try {
 +                writeSem.acquire();
 +            }
 +            catch (InterruptedException e) {
 +                Thread.currentThread().interrupt();
 +
 +                throw new IgniteException("Queue put interrupted.", e);
 +            }
 +
 +            checkStopping();
 +
 +            if (offer(item))
 +                return;
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException {
 +        A.notNull(item, "item");
 +        A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout);
 +
 +        if (!bounded()) {
 +            boolean offer = offer(item);
 +
 +            assert offer;
 +
 +            return true;
 +        }
 +
 +        long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit);
 +
 +        while (U.currentTimeMillis() < end) {
 +            boolean retVal = false;
 +
 +            try {
 +                if (writeSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) {
 +                    checkStopping();
 +
 +                    retVal = offer(item);
 +                }
 +            }
 +            catch (InterruptedException e) {
 +                Thread.currentThread().interrupt();
 +
 +                throw new IgniteException("Queue put interrupted.", e);
 +            }
 +
 +            if (retVal)
 +                return true;
 +        }
 +
 +        return false;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T take() throws IgniteException {
 +        while (true) {
 +            try {
 +                readSem.acquire();
 +            }
 +            catch (InterruptedException e) {
 +                Thread.currentThread().interrupt();
 +
 +                throw new IgniteException("Queue take interrupted.", e);
 +            }
 +
 +            checkStopping();
 +
 +            T e = poll();
 +
 +            if (e != null)
 +                return e;
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T poll(long timeout, TimeUnit unit) throws IgniteException {
 +        A.ensure(timeout >= 0, "Timeout cannot be negative: " + timeout);
 +
 +        long end = U.currentTimeMillis() + MILLISECONDS.convert(timeout, unit);
 +
 +        while (U.currentTimeMillis() < end) {
 +            T retVal = null;
 +
 +            try {
 +                if (readSem.tryAcquire(end - U.currentTimeMillis(), MILLISECONDS)) {
 +                    checkStopping();
 +
 +                    retVal = poll();
 +                }
 +            }
 +            catch (InterruptedException e) {
 +                Thread.currentThread().interrupt();
 +
 +                throw new IgniteException("Queue poll interrupted.", e);
 +            }
 +
 +            if (retVal != null)
 +                return retVal;
 +        }
 +
 +        return null;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int remainingCapacity() {
 +        if (!bounded())
 +            return Integer.MAX_VALUE;
 +
 +        int remaining = cap - size();
 +
 +        return remaining > 0 ? remaining : 0;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void clear() {
 +        clear(DFLT_CLEAR_BATCH_SIZE);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Override public void clear(int batchSize) throws IgniteException {
 +        A.ensure(batchSize >= 0, "Batch size cannot be negative: " + batchSize);
 +
-         IgniteBiTuple<Long, Long> t = (IgniteBiTuple<Long, Long>)cache.invoke(queueKey, new ClearProcessor(id));
++        try {
++            IgniteBiTuple<Long, Long> t = (IgniteBiTuple<Long, Long>)cache.invoke(queueKey, new ClearProcessor(id)).get();
 +
-         if (t == null)
-             return;
++            if (t == null)
++                return;
 +
-         checkRemoved(t.get1());
++            checkRemoved(t.get1());
 +
-         removeKeys(id, queueName, collocated, t.get1(), t.get2(), batchSize);
++            removeKeys(id, queueName, collocated, t.get1(), t.get2(), batchSize);
++        }
++        catch (IgniteCheckedException e) {
++            throw new IgniteException(e);
++        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int drainTo(Collection<? super T> c) {
 +        return drainTo(c, Integer.MAX_VALUE);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int drainTo(Collection<? super T> c, int maxElements) {
 +        int max = Math.min(maxElements, size());
 +
 +        for (int i = 0; i < max; i++) {
 +            T el = poll();
 +
 +            if (el == null)
 +                return i;
 +
 +            c.add(el);
 +        }
 +
 +        return max;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean removed() {
 +        return rmvd;
 +    }
 +
 +    /**
 +     * @param id Queue unique ID.
 +     * @param name Queue name.
 +     * @param collocated Collocation flag.
 +     * @param startIdx Start item index.
 +     * @param endIdx End item index.
 +     * @param batchSize Batch size.
++     * @throws IgniteCheckedException If failed.
 +     */
 +    @SuppressWarnings("unchecked")
 +    private void removeKeys(
 +        IgniteUuid id,
 +        String name,
 +        boolean collocated,
 +        long startIdx,
 +        long endIdx,
 +        int batchSize)
++        throws IgniteCheckedException
 +    {
 +        Set<GridCacheQueueItemKey> keys = new HashSet<>(batchSize > 0 ? batchSize : 10);
 +
 +        for (long idx = startIdx; idx < endIdx; idx++) {
 +            keys.add(itemKey(id, name, collocated, idx));
 +
 +            if (batchSize > 0 && keys.size() == batchSize) {
 +                cache.removeAll(keys);
 +
 +                keys.clear();
 +            }
 +        }
 +
 +        if (!keys.isEmpty())
 +            cache.removeAll(keys);
 +    }
 +
 +    /**
 +     * Checks result of closure modifying queue header, throws {@link org.apache.ignite.cache.datastructures.DataStructureRemovedException}
 +     * if queue was removed.
 +     *
 +     * @param idx Result of closure execution.
 +     */
 +    protected final void checkRemoved(Long idx) {
 +        if (idx == QUEUE_REMOVED_IDX)
 +            onRemoved(true);
 +    }
 +
 +    /**
 +     * Checks queue state, throws {@link org.apache.ignite.cache.datastructures.DataStructureRemovedException} if queue was removed.
 +     *
 +     * @param hdr Queue hdr.
 +     */
 +    protected final void checkRemoved(@Nullable GridCacheQueueHeader hdr) {
 +        if (queueRemoved(hdr, id))
 +            onRemoved(true);
 +    }
 +
 +    /**
 +     * Marks queue as removed.
 +     *
 +     * @param throw0 If {@code true} then throws {@link org.apache.ignite.cache.datastructures.DataStructureRemovedException}.
 +     */
 +    public void onRemoved(boolean throw0) {
 +        rmvd = true;
 +
 +        releaseSemaphores();
 +
 +        if (throw0)
 +            throw new DataStructureRemovedException("Queue has been removed from cache: " + this);
 +    }
 +
 +    /**
 +     * Release all semaphores used in blocking operations (used in case queue was removed or grid is stopping).
 +     */
 +    private void releaseSemaphores() {
 +        if (bounded()) {
 +            writeSem.drainPermits();
 +            writeSem.release(1_000_000); // Let all blocked threads to proceed (operation will fail with exception).
 +        }
 +
 +        readSem.drainPermits();
 +        readSem.release(1_000_000); // Let all blocked threads to proceed (operation will fail with exception).
 +    }
 +
 +    /**
 +     * @param hdr Queue header.
 +     */
 +    public void onHeaderChanged(GridCacheQueueHeader hdr) {
 +        if (!hdr.empty()) {
 +            readSem.drainPermits();
 +            readSem.release(hdr.size());
 +        }
 +
 +        if (bounded()) {
 +            writeSem.drainPermits();
 +
 +            if (!hdr.full())
 +                writeSem.release(hdr.capacity() - hdr.size());
 +        }
 +    }
 +
 +    /**
 +     * Grid stop callback.
 +     */
 +    public void onKernalStop() {
 +        releaseSemaphores();
 +    }
 +
 +    /**
 +     * Throws {@link IgniteException} in case if grid is stopping.
 +     */
 +    private void checkStopping() {
 +        if (cctx.kernalContext().isStopping())
 +            throw new IgniteException("Grid is stopping");
 +    }
 +
 +    /**
 +     * @return Queue unique ID.
 +     */
 +    public IgniteUuid id() {
 +        return id;
 +    }
 +
 +    /**
 +     * Removes item with given index from queue.
 +     *
 +     * @param rmvIdx Index of item to be removed.
 +     * @throws IgniteCheckedException If failed.
 +     */
 +    protected abstract void removeItem(long rmvIdx) throws IgniteCheckedException;
 +
 +
 +    /**
 +     * @param idx Item index.
 +     * @return Item key.
 +     */
 +    protected GridCacheQueueItemKey itemKey(Long idx) {
 +        return itemKey(id, queueName, collocated(), idx);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    public void close() {
 +        if (rmvd)
 +            return;
 +
 +        GridCacheQueueHeader hdr = (GridCacheQueueHeader)cache.getAndRemove(new GridCacheQueueHeaderKey(queueName));
 +
 +        rmvd = true;
 +
 +        if (hdr == null || hdr.empty())
 +            return;
 +
 +        removeKeys(hdr.id(),
 +            queueName,
 +            hdr.collocated(),
 +            hdr.head(),
 +            hdr.tail(),
 +            0);
 +    }
 +
 +    /**
 +     * @param id Queue unique ID.
 +     * @param queueName Queue name.
 +     * @param collocated Collocation flag.
 +     * @param idx Item index.
 +     * @return Item key.
 +     */
 +    private static GridCacheQueueItemKey itemKey(IgniteUuid id, String queueName, boolean collocated, long idx) {
 +        return collocated ? new CollocatedItemKey(id, queueName, idx) :
 +            new GridCacheQueueItemKey(id, queueName, idx);
 +    }
 +
 +    /**
 +     * @param hdr Queue header.
 +     * @param id Expected queue unique ID.
 +     * @return {@code True} if queue was removed.
 +     */
 +    private static boolean queueRemoved(@Nullable GridCacheQueueHeader hdr, IgniteUuid id) {
 +        return hdr == null || !id.equals(hdr.id());
 +    }
 +
 +    /**
 +     *
 +     */
 +    private class QueueIterator implements Iterator<T> {
 +        /** */
 +        private T next;
 +
 +        /** */
 +        private T cur;
 +
 +        /** */
 +        private long curIdx;
 +
 +        /** */
 +        private long idx;
 +
 +        /** */
 +        private long endIdx;
 +
 +        /** */
 +        private Set<Long> rmvIdxs;
 +
 +        /**
 +         * @param hdr Queue header.
 +         * @throws IgniteCheckedException If failed.
 +         */
 +        @SuppressWarnings("unchecked")
 +        private QueueIterator(GridCacheQueueHeader hdr) throws IgniteCheckedException {
 +            idx = hdr.head();
 +            endIdx = hdr.tail();
 +            rmvIdxs = hdr.removedIndexes();
 +
 +            assert !F.contains(rmvIdxs, idx) : idx;
 +
 +            if (idx < endIdx)
 +                next = (T)cache.get(itemKey(idx));
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public boolean hasNext() {
 +            return next != null;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @SuppressWarnings("unchecked")
 +        @Override public T next() {
 +            if (next == null)
 +                throw new NoSuchElementException();
 +
-             cur = next;
-             curIdx = idx;
++            try {
++                cur = next;
++                curIdx = idx;
 +
-             idx++;
++                idx++;
 +
-             if (rmvIdxs != null) {
-                 while (F.contains(rmvIdxs, idx) && idx < endIdx)
-                     idx++;
-             }
++                if (rmvIdxs != null) {
++                    while (F.contains(rmvIdxs, idx) && idx < endIdx)
++                        idx++;
++                }
 +
-             next = idx < endIdx ? (T)cache.get(itemKey(idx)) : null;
++                next = idx < endIdx ? (T)cache.get(itemKey(idx)) : null;
 +
-             return cur;
++                return cur;
++            }
++            catch (IgniteCheckedException e) {
++                throw U.convertException(e);
++            }
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void remove() {
 +            if (cur == null)
 +                throw new IllegalStateException();
 +
 +            try {
 +                removeItem(curIdx);
 +
 +                cur = null;
 +            }
 +            catch (IgniteCheckedException e) {
 +                throw new IgniteException(e);
 +            }
 +        }
 +    }
 +
 +    /**
 +     * Item key for collocated queue.
 +     */
 +    private static class CollocatedItemKey extends GridCacheQueueItemKey {
 +        /** */
 +        private static final long serialVersionUID = 0L;
 +
 +        /**
 +         * Required by {@link Externalizable}.
 +         */
 +        public CollocatedItemKey() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param id Queue unique ID.
 +         * @param queueName Queue name.
 +         * @param idx Item index.
 +         */
 +        private CollocatedItemKey(IgniteUuid id, String queueName, long idx) {
 +            super(id, queueName, idx);
 +        }
 +
 +        /**
 +         * @return Item affinity key.
 +         */
 +        @CacheAffinityKeyMapped
 +        public Object affinityKey() {
 +            return queueName();
 +        }
 +    }
 +
 +    /**
 +     */
 +    protected static class ClearProcessor implements
 +        EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, IgniteBiTuple<Long, Long>>, Externalizable {
 +        /** */
 +        private static final long serialVersionUID = 0L;
 +
 +        /** */
 +        private IgniteUuid id;
 +
 +        /**
 +         * Required by {@link Externalizable}.
 +         */
 +        public ClearProcessor() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param id Queue unique ID.
 +         */
 +        public ClearProcessor(IgniteUuid id) {
 +            this.id = id;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public IgniteBiTuple<Long, Long> process(
 +            MutableEntry<GridCacheQueueHeaderKey, GridCacheQueueHeader> e, Object... args) {
 +            GridCacheQueueHeader hdr = e.getValue();
 +
 +            boolean rmvd = queueRemoved(hdr, id);
 +
 +            if (rmvd)
 +                return new IgniteBiTuple<>(QUEUE_REMOVED_IDX, QUEUE_REMOVED_IDX);
 +            else if (hdr.empty())
 +                return null;
 +
 +            GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                hdr.capacity(),
 +                hdr.collocated(),
 +                hdr.tail(),
 +                hdr.tail(),
 +                null);
 +
 +            e.setValue(newHdr);
 +
 +            return new IgniteBiTuple<>(hdr.head(), hdr.tail());
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeExternal(ObjectOutput out) throws IOException {
 +            U.writeGridUuid(out, id);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +            id = U.readGridUuid(in);
 +        }
 +    }
 +
 +    /**
 +     */
 +    protected static class PollProcessor implements
 +        EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, Long>, Externalizable {
 +        /** */
 +        private static final long serialVersionUID = 0L;
 +
 +        /** */
 +        private IgniteUuid id;
 +
 +        /**
 +         * Required by {@link Externalizable}.
 +         */
 +        public PollProcessor() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param id Queue unique ID.
 +         */
 +        public PollProcessor(IgniteUuid id) {
 +            this.id = id;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public Long process(
 +            MutableEntry<GridCacheQueueHeaderKey, GridCacheQueueHeader> e, Object... args) {
 +            GridCacheQueueHeader hdr = e.getValue();
 +
 +            boolean rmvd = queueRemoved(hdr, id);
 +
 +            if (rmvd || hdr.empty())
 +                return rmvd ? QUEUE_REMOVED_IDX : null;
 +
 +            Set<Long> rmvdIdxs = hdr.removedIndexes();
 +
 +            if (rmvdIdxs == null) {
 +                GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                    hdr.capacity(),
 +                    hdr.collocated(),
 +                    hdr.head() + 1,
 +                    hdr.tail(),
 +                    rmvdIdxs);
 +
 +                e.setValue(newHdr);
 +
 +                return hdr.head();
 +            }
 +
 +            long next = hdr.head() + 1;
 +
 +            rmvdIdxs = new HashSet<>(rmvdIdxs);
 +
 +            do {
 +                if (!rmvdIdxs.remove(next)) {
 +                    GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                        hdr.capacity(),
 +                        hdr.collocated(),
 +                        next + 1,
 +                        hdr.tail(),
 +                        rmvdIdxs.isEmpty() ? null : rmvdIdxs);
 +
 +                    e.setValue(newHdr);
 +
 +                    return next;
 +                }
 +
 +                next++;
 +            } while (next != hdr.tail());
 +
 +            GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                hdr.capacity(),
 +                hdr.collocated(),
 +                next,
 +                hdr.tail(),
 +                rmvdIdxs.isEmpty() ? null : rmvdIdxs);
 +
 +            e.setValue(newHdr);
 +
 +            return null;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeExternal(ObjectOutput out) throws IOException {
 +            U.writeGridUuid(out, id);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +            id = U.readGridUuid(in);
 +        }
 +    }
 +
 +    /**
 +     */
 +    protected static class AddProcessor implements
 +        EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, Long>, Externalizable {
 +        /** */
 +        private static final long serialVersionUID = 0L;
 +
 +        /** */
 +        private IgniteUuid id;
 +
 +        /** */
 +        private int size;
 +
 +        /**
 +         * Required by {@link Externalizable}.
 +         */
 +        public AddProcessor() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param id Queue unique ID.
 +         * @param size Number of elements to add.
 +         */
 +        public AddProcessor(IgniteUuid id, int size) {
 +            this.id = id;
 +            this.size = size;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public Long process(MutableEntry<GridCacheQueueHeaderKey, GridCacheQueueHeader> e, Object... args) {
 +            GridCacheQueueHeader hdr = e.getValue();
 +
 +            boolean rmvd = queueRemoved(hdr, id);
 +
 +            if (rmvd || !spaceAvailable(hdr, size))
 +                return rmvd ? QUEUE_REMOVED_IDX : null;
 +
 +            GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                hdr.capacity(),
 +                hdr.collocated(),
 +                hdr.head(),
 +                hdr.tail() + size,
 +                hdr.removedIndexes());
 +
 +            e.setValue(newHdr);
 +
 +            return hdr.tail();
 +        }
 +
 +        /**
 +         * @param hdr Queue header.
 +         * @param size Number of elements to add.
 +         * @return {@code True} if new elements can be added.
 +         */
 +        private boolean spaceAvailable(GridCacheQueueHeader hdr, int size) {
 +            return !hdr.bounded() || (hdr.size() + size) <= hdr.capacity();
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeExternal(ObjectOutput out) throws IOException {
 +            U.writeGridUuid(out, id);
 +            out.writeInt(size);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +            id = U.readGridUuid(in);
 +            size = in.readInt();
 +        }
 +    }
 +
 +    /**
 +     */
 +    protected static class RemoveProcessor implements
 +        EntryProcessor<GridCacheQueueHeaderKey, GridCacheQueueHeader, Long>, Externalizable {
 +        /** */
 +        private static final long serialVersionUID = 0L;
 +
 +        /** */
 +        private IgniteUuid id;
 +
 +        /** */
 +        private Long idx;
 +
 +        /**
 +         * Required by {@link Externalizable}.
 +         */
 +        public RemoveProcessor() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param id Queue UUID.
 +         * @param idx Index of item to be removed.
 +         */
 +        public RemoveProcessor(IgniteUuid id, Long idx) {
 +            this.id = id;
 +            this.idx = idx;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public Long process(MutableEntry<GridCacheQueueHeaderKey, GridCacheQueueHeader> e, Object... args) {
 +            GridCacheQueueHeader hdr = e.getValue();
 +
 +            boolean rmvd = queueRemoved(hdr, id);
 +
 +            if (rmvd || hdr.empty() || idx < hdr.head())
 +                return rmvd ? QUEUE_REMOVED_IDX : null;
 +
 +            if (idx == hdr.head()) {
 +                Set<Long> rmvIdxs = hdr.removedIndexes();
 +
 +                long head = hdr.head() + 1;
 +
 +                if (!F.contains(rmvIdxs, head)) {
 +                    GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                        hdr.capacity(),
 +                        hdr.collocated(),
 +                        head,
 +                        hdr.tail(),
 +                        hdr.removedIndexes());
 +
 +                    e.setValue(newHdr);
 +
 +                    return idx;
 +                }
 +
 +                rmvIdxs = new HashSet<>(rmvIdxs);
 +
 +                while (rmvIdxs.remove(head))
 +                    head++;
 +
 +                GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                    hdr.capacity(),
 +                    hdr.collocated(),
 +                    head,
 +                    hdr.tail(),
 +                    rmvIdxs.isEmpty() ? null : rmvIdxs);
 +
 +                e.setValue(newHdr);
 +
 +                return null;
 +            }
 +
 +            Set<Long> rmvIdxs = hdr.removedIndexes();
 +
 +            if (rmvIdxs == null) {
 +                rmvIdxs = new HashSet<>();
 +
 +                rmvIdxs.add(idx);
 +            }
 +            else {
 +                if (!rmvIdxs.contains(idx)) {
 +                    rmvIdxs = new HashSet<>(rmvIdxs);
 +
 +                    rmvIdxs.add(idx);
 +                }
 +                else
 +                    idx = null;
 +            }
 +
 +            GridCacheQueueHeader newHdr = new GridCacheQueueHeader(hdr.id(),
 +                hdr.capacity(),
 +                hdr.collocated(),
 +                hdr.head(),
 +                hdr.tail(),
 +                rmvIdxs);
 +
 +            e.setValue(newHdr);
 +
 +            return idx;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeExternal(ObjectOutput out) throws IOException {
 +            U.writeGridUuid(out, id);
 +            out.writeLong(idx);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +            id = U.readGridUuid(in);
 +            idx = in.readLong();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean equals(Object o) {
 +        if (this == o)
 +            return true;
 +
 +        if (o == null || getClass() != o.getClass())
 +            return false;
 +
 +        GridCacheQueueAdapter that = (GridCacheQueueAdapter) o;
 +
 +        return id.equals(that.id);
 +
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        return id.hashCode();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheQueueAdapter.class, this);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueHeader.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueHeader.java
index cfb1985,0000000..4e51821
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueHeader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueHeader.java
@@@ -1,199 -1,0 +1,199 @@@
 +/*
 + * 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.tostring.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +import org.jetbrains.annotations.*;
 +
 +import java.io.*;
 +import java.util.*;
 +
 +/**
 + * Queue header.
 + */
 +public class GridCacheQueueHeader implements GridCacheInternal, Externalizable {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** */
 +    private IgniteUuid id;
 +
 +    /** */
 +    private long head;
 +
 +    /** */
 +    private long tail;
 +
 +    /** */
 +    private int cap;
 +
 +    /** */
 +    private boolean collocated;
 +
 +    /** */
 +    @GridToStringInclude
 +    private Set<Long> rmvIdxs;
 +
 +    /**
 +     * Required by {@link Externalizable}.
 +     */
 +    public GridCacheQueueHeader() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * @param id Queue unique ID.
 +     * @param cap Capacity.
 +     * @param collocated Collocation flag.
 +     * @param head Queue head index.
 +     * @param tail Queue tail index.
 +     * @param rmvIdxs Indexes of removed items.
 +     */
 +    public GridCacheQueueHeader(IgniteUuid id, int cap, boolean collocated, long head, long tail,
 +        @Nullable Set<Long> rmvIdxs) {
 +        assert id != null;
 +        assert head <= tail;
 +
 +        this.id = id;
 +        this.cap = cap;
 +        this.collocated = collocated;
 +        this.head = head;
 +        this.tail = tail;
 +        this.rmvIdxs = rmvIdxs;
 +    }
 +
 +    /**
 +     * @return Queue unique ID.
 +     */
 +    public IgniteUuid id() {
 +        return id;
 +    }
 +
 +    /**
 +     * @return Capacity.
 +     */
 +    public int capacity() {
 +        return cap;
 +    }
 +
 +    /**
 +     * @return Queue collocation flag.
 +     */
 +    public boolean collocated() {
 +        return collocated;
 +    }
 +
 +    /**
 +     * @return Head index.
 +     */
 +    public long head() {
 +        return head;
 +    }
 +
 +    /**
 +     * @return Tail index.
 +     */
 +    public long tail() {
 +        return tail;
 +    }
 +
 +    /**
 +     * @return {@code True} if queue is bounded.
 +     */
 +    public boolean bounded() {
 +        return cap < Integer.MAX_VALUE;
 +    }
 +
 +    /**
 +     * @return {@code True} if queue is empty.
 +     */
 +    public boolean empty() {
 +        return head == tail;
 +    }
 +
 +    /**
 +     * @return {@code True} if queue is full.
 +     */
 +    public boolean full() {
 +        return bounded() && size() == capacity();
 +    }
 +
 +    /**
 +     * @return Queue size.
 +     */
 +    public int size() {
 +        int rmvSize = F.isEmpty(removedIndexes()) ? 0 : removedIndexes().size();
 +
 +        int size = (int)(tail() - head() - rmvSize);
 +
 +        assert size >= 0 : size;
 +
 +        return size;
 +    }
 +
 +    /**
 +     * @return Indexes of removed items.
 +     */
 +    @Nullable public Set<Long> removedIndexes() {
 +        return rmvIdxs;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        U.writeGridUuid(out, id);
 +        out.writeInt(cap);
 +        out.writeBoolean(collocated);
 +        out.writeLong(head);
 +        out.writeLong(tail);
 +        out.writeBoolean(rmvIdxs != null);
 +
 +        if (rmvIdxs != null) {
 +            out.writeInt(rmvIdxs.size());
 +
 +            for (Long idx : rmvIdxs)
 +                out.writeLong(idx);
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        id = U.readGridUuid(in);
 +        cap = in.readInt();
 +        collocated = in.readBoolean();
 +        head = in.readLong();
 +        tail = in.readLong();
 +
 +        if (in.readBoolean()) {
 +            int size = in.readInt();
 +
 +            rmvIdxs = new HashSet<>();
 +
 +            for (int i = 0; i < size; i++)
 +                rmvIdxs.add(in.readLong());
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheQueueHeader.class, this);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueItemKey.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueItemKey.java
index c51031b,0000000..2b1d106
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueItemKey.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueItemKey.java
@@@ -1,121 -1,0 +1,121 @@@
 +/*
 + * 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.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +
 +import java.io.*;
 +
 +/**
 + * Queue item key.
 + */
 +class GridCacheQueueItemKey implements Externalizable, GridCacheInternal {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** */
 +    private IgniteUuid queueId;
 +
 +    /** */
 +    private String queueName;
 +
 +    /** */
 +    private long idx;
 +
 +    /**
 +     * Required by {@link Externalizable}.
 +     */
 +    public GridCacheQueueItemKey() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * @param queueId Queue unique ID.
 +     * @param queueName Queue name.
 +     * @param idx Item index.
 +     */
 +    GridCacheQueueItemKey(IgniteUuid queueId, String queueName, long idx) {
 +        this.queueId = queueId;
 +        this.queueName = queueName;
 +        this.idx = idx;
 +    }
 +
 +    /**
 +     * @return Item index.
 +     */
 +    public Long index() {
 +        return idx;
 +    }
 +
 +    /**
 +     * @return Queue UUID.
 +     */
 +    public IgniteUuid queueId() {
 +        return queueId;
 +    }
 +
 +    /**
 +     * @return Queue name.
 +     */
 +    public String queueName() {
 +        return queueName;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        U.writeGridUuid(out, queueId);
 +        U.writeString(out, queueName);
 +        out.writeLong(idx);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        queueId = U.readGridUuid(in);
 +        queueName = U.readString(in);
 +        idx = in.readLong();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean equals(Object o) {
 +        if (this == o)
 +            return true;
 +
 +        if (o == null || getClass() != o.getClass())
 +            return false;
 +
 +        GridCacheQueueItemKey itemKey = (GridCacheQueueItemKey)o;
 +
 +        return idx == itemKey.idx && queueId.equals(itemKey.queueId);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        int result = queueId.hashCode();
 +
 +        result = 31 * result + (int)(idx ^ (idx >>> 32));
 +
 +        return result;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheQueueItemKey.class, this);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueProxy.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueProxy.java
index 1f1c62a,0000000..7a5450c
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueProxy.java
@@@ -1,771 -1,0 +1,771 @@@
 +/*
 + * 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.internal.*;
 +import org.apache.ignite.internal.processors.cache.*;
- import org.apache.ignite.lang.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +import org.jetbrains.annotations.*;
 +
 +import java.io.*;
 +import java.util.*;
 +import java.util.concurrent.*;
 +
 +/**
 + * Cache queue proxy.
 + */
 +public class GridCacheQueueProxy<T> implements IgniteQueue<T>, Externalizable {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** Deserialization stash. */
 +    private static final ThreadLocal<IgniteBiTuple<GridKernalContext, String>> stash =
 +        new ThreadLocal<IgniteBiTuple<GridKernalContext, String>>() {
 +            @Override protected IgniteBiTuple<GridKernalContext, String> initialValue() {
 +                return F.t2();
 +            }
 +        };
 +
 +    /** Delegate queue. */
 +    private GridCacheQueueAdapter<T> delegate;
 +
 +    /** Cache context. */
 +    private GridCacheContext cctx;
 +
 +    /** Cache gateway. */
 +    private GridCacheGateway gate;
 +
 +    /**
 +     * Required by {@link Externalizable}.
 +     */
 +    public GridCacheQueueProxy() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * @param cctx Cache context.
 +     * @param delegate Delegate queue.
 +     */
 +    public GridCacheQueueProxy(GridCacheContext cctx, GridCacheQueueAdapter<T> delegate) {
 +        this.cctx = cctx;
 +        this.delegate = delegate;
 +
 +        gate = cctx.gate();
 +    }
 +
 +    /**
 +     * @return Delegate queue.
 +     */
 +    public GridCacheQueueAdapter<T> delegate() {
 +        return delegate;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean add(final T item) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.add(item);
 +                    }
 +                }, cctx);
 +
 +            return delegate.add(item);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean offer(final T item) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.offer(item);
 +                    }
 +                }, cctx);
 +
 +            return delegate.offer(item);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean addAll(final Collection<? extends T> items) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.addAll(items);
 +                    }
 +                }, cctx);
 +
 +            return delegate.addAll(items);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("SuspiciousMethodCalls")
 +    @Override public boolean contains(final Object item) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.contains(item);
 +                    }
 +                }, cctx);
 +
 +            return delegate.contains(item);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean containsAll(final Collection<?> items) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.containsAll(items);
 +                    }
 +                }, cctx);
 +
 +            return delegate.containsAll(items);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void clear() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional()) {
 +                CU.outTx(new Callable<Void>() {
 +                    @Override public Void call() throws Exception {
 +                        delegate.clear();
 +
 +                        return null;
 +                    }
 +                }, cctx);
 +            }
 +            else
 +                delegate.clear();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("SuspiciousMethodCalls")
 +    @Override public boolean remove(final Object item) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.remove(item);
 +                    }
 +                }, cctx);
 +
 +            return delegate.remove(item);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean removeAll(final Collection<?> items) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.removeAll(items);
 +                    }
 +                }, cctx);
 +
 +            return delegate.removeAll(items);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean isEmpty() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.isEmpty();
 +                    }
 +                }, cctx);
 +
 +            return delegate.isEmpty();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public Iterator<T> iterator() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Iterator<T>>() {
 +                    @Override public Iterator<T> call() throws Exception {
 +                        return delegate.iterator();
 +                    }
 +                }, cctx);
 +
 +            return delegate.iterator();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public Object[] toArray() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Object[]>() {
 +                    @Override public Object[] call() throws Exception {
 +                        return delegate.toArray();
 +                    }
 +                }, cctx);
 +
 +            return delegate.toArray();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("SuspiciousToArrayCall")
 +    @Override public <T1> T1[] toArray(final T1[] a) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T1[]>() {
 +                    @Override public T1[] call() throws Exception {
 +                        return delegate.toArray(a);
 +                    }
 +                }, cctx);
 +
 +            return delegate.toArray(a);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean retainAll(final Collection<?> items) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.retainAll(items);
 +                    }
 +                }, cctx);
 +
 +            return delegate.retainAll(items);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int size() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Integer>() {
 +                    @Override public Integer call() throws Exception {
 +                        return delegate.size();
 +                    }
 +                }, cctx);
 +
 +            return delegate.size();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T poll() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.poll();
 +                    }
 +                }, cctx);
 +
 +            return delegate.poll();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T peek() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.peek();
 +                    }
 +                }, cctx);
 +
 +            return delegate.peek();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void clear(final int batchSize) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional()) {
 +                CU.outTx(new Callable<Void>() {
 +                    @Override public Void call() throws Exception {
 +                        delegate.clear(batchSize);
 +
 +                        return null;
 +                    }
 +                }, cctx);
 +            }
 +            else
 +                delegate.clear(batchSize);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int remainingCapacity() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Integer>() {
 +                    @Override public Integer call() throws Exception {
 +                        return delegate.remainingCapacity();
 +                    }
 +                }, cctx);
 +
 +            return delegate.remainingCapacity();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int drainTo(final Collection<? super T> c) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Integer>() {
 +                    @Override public Integer call() throws Exception {
 +                        return delegate.drainTo(c);
 +                    }
 +                }, cctx);
 +
 +            return delegate.drainTo(c);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int drainTo(final Collection<? super T> c, final int maxElements) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Integer>() {
 +                    @Override public Integer call() throws Exception {
 +                        return delegate.drainTo(c, maxElements);
 +                    }
 +                }, cctx);
 +
 +            return delegate.drainTo(c, maxElements);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public T remove() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.remove();
 +                    }
 +                }, cctx);
 +
 +            return delegate.remove();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public T element() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.element();
 +                    }
 +                }, cctx);
 +
 +            return delegate.element();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void put(final T item) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional()) {
 +                CU.outTx(new Callable<Void>() {
 +                    @Override public Void call() throws Exception {
 +                        delegate.put(item);
 +
 +                        return null;
 +                    }
 +                }, cctx);
 +            }
 +            else
 +                delegate.put(item);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean offer(final T item, final long timeout, final TimeUnit unit) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<Boolean>() {
 +                    @Override public Boolean call() throws Exception {
 +                        return delegate.offer(item, timeout, unit);
 +                    }
 +                }, cctx);
 +
 +            return delegate.offer(item, timeout, unit);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T take() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.take();
 +                    }
 +                }, cctx);
 +
 +            return delegate.take();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public T poll(final long timeout, final TimeUnit unit) {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional())
 +                return CU.outTx(new Callable<T>() {
 +                    @Override public T call() throws Exception {
 +                        return delegate.poll(timeout, unit);
 +                    }
 +                }, cctx);
 +
 +            return delegate.poll(timeout, unit);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void close() {
 +        gate.enter();
 +
 +        try {
 +            if (cctx.transactional()) {
 +                CU.outTx(new Callable<Void>() {
 +                    @Override public Void call() throws Exception {
 +                        delegate.close();
 +
 +                        return null;
 +                    }
 +                }, cctx);
 +            }
 +            else
 +                delegate.close();
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw new IgniteException(e);
 +        }
 +        finally {
 +            gate.leave();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String name() {
 +        return delegate.name();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int capacity() throws IgniteCheckedException {
 +        return delegate.capacity();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean bounded() throws IgniteCheckedException {
 +        return delegate.bounded();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean collocated() throws IgniteCheckedException {
 +        return delegate.collocated();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean removed() {
 +        return delegate.removed();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        return delegate.hashCode();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean equals(Object o) {
 +        if (this == o)
 +            return true;
 +
 +        if (o == null || getClass() != o.getClass())
 +            return false;
 +
 +        GridCacheQueueProxy that = (GridCacheQueueProxy)o;
 +
 +        return delegate.equals(that.delegate);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        out.writeObject(cctx.kernalContext());
 +        U.writeString(out, name());
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        IgniteBiTuple<GridKernalContext, String> t = stash.get();
 +
 +        t.set1((GridKernalContext)in.readObject());
 +        t.set2(U.readString(in));
 +    }
 +
 +    /**
 +     * Reconstructs object on unmarshalling.
 +     *
 +     * @return Reconstructed object.
 +     * @throws ObjectStreamException Thrown in case of unmarshalling error.
 +     */
 +    protected Object readResolve() throws ObjectStreamException {
 +        try {
 +            IgniteBiTuple<GridKernalContext, String> t = stash.get();
 +
 +            return t.get1().dataStructures().queue(t.get2(), null, 0, false);
 +        }
 +        catch (IgniteCheckedException e) {
 +            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
 +        }
 +        finally {
 +            stash.remove();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return delegate.toString();
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c6ca063f/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSetHeader.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSetHeader.java
index c77fe7f,0000000..d91aa60
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSetHeader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSetHeader.java
@@@ -1,85 -1,0 +1,85 @@@
 +/*
 + * 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.typedef.internal.*;
++import org.apache.ignite.lang.*;
 +
 +import java.io.*;
 +
 +/**
 + * Cache set header.
 + */
 +public class GridCacheSetHeader implements GridCacheInternal, Externalizable {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** */
 +    private IgniteUuid id;
 +
 +    /** */
 +    private boolean collocated;
 +
 +    /**
 +     * Required by {@link Externalizable}.
 +     */
 +    public GridCacheSetHeader() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * @param id Set UUID.
 +     * @param collocated Collocation flag.
 +     */
 +    public GridCacheSetHeader(IgniteUuid id, boolean collocated) {
 +        this.id = id;
 +        this.collocated = collocated;
 +    }
 +
 +    /**
 +     * @return Set unique ID.
 +     */
 +    public IgniteUuid id() {
 +        return id;
 +    }
 +
 +    /**
 +     * @return Collocation flag.
 +     */
 +    public boolean collocated() {
 +        return collocated;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        U.writeGridUuid(out, id);
 +        out.writeBoolean(collocated);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        id = U.readGridUuid(in);
 +        collocated = in.readBoolean();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public String toString() {
 +        return S.toString(GridCacheSetHeader.class, this);
 +    }
 +}


Mime
View raw message