Search in sources :

Example 1 with GridCacheQueueProxy

use of org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy in project ignite by apache.

the class CacheDataStructuresManager method onReconnected.

/**
     * @param clusterRestarted Cluster restarted flag.
     * @throws IgniteCheckedException If failed.
     */
public void onReconnected(boolean clusterRestarted) throws IgniteCheckedException {
    for (Map.Entry<IgniteUuid, GridCacheSetProxy> e : setsMap.entrySet()) {
        GridCacheSetProxy set = e.getValue();
        if (clusterRestarted) {
            set.blockOnRemove();
            setsMap.remove(e.getKey(), set);
        } else
            set.needCheckNotRemoved();
    }
    for (Map.Entry<IgniteUuid, GridCacheQueueProxy> e : queuesMap.entrySet()) {
        GridCacheQueueProxy queue = e.getValue();
        if (clusterRestarted) {
            queue.delegate().onRemoved(false);
            queuesMap.remove(e.getKey(), queue);
        }
    }
}
Also used : GridCacheSetProxy(org.apache.ignite.internal.processors.datastructures.GridCacheSetProxy) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheQueueProxy(org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with GridCacheQueueProxy

use of org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy in project ignite by apache.

the class CacheDataStructuresManager method queue0.

/**
     * @param name Queue name.
     * @param cap Capacity.
     * @param colloc Collocated flag.
     * @param create Create flag.
     * @return Queue header.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
@Nullable
public <T> GridCacheQueueProxy<T> queue0(final String name, final int cap, boolean colloc, final boolean create) throws IgniteCheckedException {
    cctx.gate().enter();
    try {
        GridCacheQueueHeaderKey key = new GridCacheQueueHeaderKey(name);
        GridCacheQueueHeader hdr;
        if (create) {
            hdr = new GridCacheQueueHeader(IgniteUuid.randomUuid(), cap, colloc, 0, 0, null);
            GridCacheQueueHeader old = queueHdrView.withNoRetries().getAndPutIfAbsent(key, hdr);
            if (old != null) {
                if (old.capacity() != cap || old.collocated() != colloc)
                    throw new IgniteCheckedException("Failed to create queue, queue with the same name but " + "different configuration already exists [name=" + name + ']');
                hdr = old;
            }
        } else
            hdr = queueHdrView.get(key);
        if (hdr == null)
            return null;
        if (queueQryGuard.compareAndSet(false, true)) {
            queueQryId = cctx.continuousQueries().executeInternalQuery(new CacheEntryUpdatedListener<Object, Object>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                    if (!busyLock.enterBusy())
                        return;
                    try {
                        for (CacheEntryEvent<?, ?> e : evts) {
                            GridCacheQueueHeaderKey key = (GridCacheQueueHeaderKey) e.getKey();
                            GridCacheQueueHeader hdr = (GridCacheQueueHeader) e.getValue();
                            for (final GridCacheQueueProxy queue : queuesMap.values()) {
                                if (queue.name().equals(key.queueName())) {
                                    if (hdr == null) {
                                        GridCacheQueueHeader oldHdr = (GridCacheQueueHeader) e.getOldValue();
                                        assert oldHdr != null;
                                        if (oldHdr.id().equals(queue.delegate().id())) {
                                            queue.delegate().onRemoved(false);
                                            queuesMap.remove(queue.delegate().id());
                                        }
                                    } else
                                        queue.delegate().onHeaderChanged(hdr);
                                }
                            }
                        }
                    } finally {
                        busyLock.leaveBusy();
                    }
                }
            }, new QueueHeaderPredicate(), cctx.isLocal() || (cctx.isReplicated() && cctx.affinityNode()), true, false);
        }
        GridCacheQueueProxy queue = queuesMap.get(hdr.id());
        if (queue == null) {
            queue = new GridCacheQueueProxy(cctx, cctx.atomic() ? new GridAtomicCacheQueueImpl<>(name, hdr, cctx) : new GridTransactionalCacheQueueImpl<>(name, hdr, cctx));
            GridCacheQueueProxy old = queuesMap.putIfAbsent(hdr.id(), queue);
            if (old != null)
                queue = old;
        }
        return queue;
    } finally {
        cctx.gate().leave();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) GridCacheQueueProxy(org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy) GridCacheQueueHeaderKey(org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey) GridCacheQueueHeader(org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeader) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GridCacheQueueProxy (org.apache.ignite.internal.processors.datastructures.GridCacheQueueProxy)2 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridCacheQueueHeader (org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeader)1 GridCacheQueueHeaderKey (org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey)1 GridCacheSetProxy (org.apache.ignite.internal.processors.datastructures.GridCacheSetProxy)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1 Nullable (org.jetbrains.annotations.Nullable)1