Search in sources :

Example 1 with GridCacheSetHeaderKey

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

the class CacheDataStructuresManager method set0.

/**
     * @param name Name of set.
     * @param collocated Collocation flag.
     * @param create If {@code true} set will be created in case it is not in cache.
     * @return Set.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
@Nullable
private <T> IgniteSet<T> set0(String name, boolean collocated, boolean create) throws IgniteCheckedException {
    cctx.gate().enter();
    try {
        GridCacheSetHeaderKey key = new GridCacheSetHeaderKey(name);
        GridCacheSetHeader hdr;
        IgniteInternalCache cache = cctx.cache().withNoRetries();
        if (create) {
            hdr = new GridCacheSetHeader(IgniteUuid.randomUuid(), collocated);
            GridCacheSetHeader old = (GridCacheSetHeader) cache.getAndPutIfAbsent(key, hdr);
            if (old != null)
                hdr = old;
        } else
            hdr = (GridCacheSetHeader) cache.get(key);
        if (hdr == null)
            return null;
        GridCacheSetProxy<T> set = setsMap.get(hdr.id());
        if (set == null) {
            GridCacheSetProxy<T> old = setsMap.putIfAbsent(hdr.id(), set = new GridCacheSetProxy<>(cctx, new GridCacheSetImpl<T>(cctx, name, hdr)));
            if (old != null)
                set = old;
        }
        return set;
    } finally {
        cctx.gate().leave();
    }
}
Also used : GridCacheSetProxy(org.apache.ignite.internal.processors.datastructures.GridCacheSetProxy) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCacheSetHeaderKey(org.apache.ignite.internal.processors.datastructures.GridCacheSetHeaderKey) GridCacheSetHeader(org.apache.ignite.internal.processors.datastructures.GridCacheSetHeader) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BROADCAST (org.apache.ignite.internal.GridClosureCallMode.BROADCAST)1 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)1 GridCacheSetHeader (org.apache.ignite.internal.processors.datastructures.GridCacheSetHeader)1 GridCacheSetHeaderKey (org.apache.ignite.internal.processors.datastructures.GridCacheSetHeaderKey)1 GridCacheSetProxy (org.apache.ignite.internal.processors.datastructures.GridCacheSetProxy)1 Nullable (org.jetbrains.annotations.Nullable)1