Search in sources :

Example 6 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class PlatformProcessorImpl method createNearCache.

/** {@inheritDoc} */
@Override
public PlatformTargetProxy createNearCache(@Nullable String cacheName, long memPtr) {
    NearCacheConfiguration cfg = getNearCacheConfiguration(memPtr);
    IgniteCacheProxy cache = (IgniteCacheProxy) ctx.grid().createNearCache(cacheName, cfg);
    return createPlatformCache(cache);
}
Also used : IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 7 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class VisorCacheConfigurationCollectorJob method run.

/** {@inheritDoc} */
@Override
protected Map<IgniteUuid, VisorCacheConfiguration> run(VisorCacheConfigurationCollectorTaskArg arg) {
    Collection<IgniteCacheProxy<?, ?>> caches = ignite.context().cache().jcaches();
    Collection<IgniteUuid> depIds = arg.getDeploymentIds();
    boolean all = depIds == null || depIds.isEmpty();
    Map<IgniteUuid, VisorCacheConfiguration> res = U.newHashMap(caches.size());
    for (IgniteCacheProxy<?, ?> cache : caches) {
        IgniteUuid deploymentId = cache.context().dynamicDeploymentId();
        if (all || depIds.contains(deploymentId))
            res.put(deploymentId, config(cache.getConfiguration(CacheConfiguration.class)));
    }
    return res;
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 8 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class BasicWarmupClosure method doWarmup.

/**
     * @param grids Grids to warmup.
     */
private void doWarmup(Iterable<Ignite> grids) throws Exception {
    Ignite first = F.first(grids);
    ExecutorService svc = Executors.newFixedThreadPool(threadCnt);
    try {
        for (IgniteCacheProxy cache : ((IgniteKernal) first).caches()) {
            if (!cache.context().userCache())
                continue;
            IgniteInternalCache<Object, Object> cache0 = cache.context().cache();
            for (String warmupMethod : warmupMethods) {
                Collection<Future> futs = new ArrayList<>(threadCnt);
                for (int i = 0; i < threadCnt; i++) {
                    Callable call;
                    switch(warmupMethod) {
                        case "get":
                            {
                                call = new GetCallable(cache0);
                                break;
                            }
                        case "put":
                            {
                                call = new PutCallable(cache0);
                                break;
                            }
                        case "putx":
                            {
                                call = new PutxCallable(cache0);
                                break;
                            }
                        case "remove":
                            {
                                call = new RemoveCallable(cache0);
                                break;
                            }
                        case "removex":
                            {
                                call = new RemovexCallable(cache0);
                                break;
                            }
                        case "putIfAbsent":
                            {
                                call = new PutIfAbsentCallable(cache0);
                                break;
                            }
                        case "replace":
                            {
                                call = new ReplaceCallable(cache0);
                                break;
                            }
                        default:
                            throw new IgniteCheckedException("Unsupported warmup method: " + warmupMethod);
                    }
                    futs.add(svc.submit(call));
                }
                out("Running warmup [cacheName=" + U.maskName(cache.getName()) + ", method=" + warmupMethod + ']');
                for (Future fut : futs) fut.get();
                for (int key = 0; key < keyRange; key++) cache0.getAndRemove(key);
            }
        }
    } finally {
        svc.shutdownNow();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) Callable(java.util.concurrent.Callable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Ignite(org.apache.ignite.Ignite)

Example 9 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class IgniteCacheClientNearCacheExpiryTest method testExpirationOnClient.

/**
     * @throws Exception If failed.
     */
public void testExpirationOnClient() throws Exception {
    Ignite ignite = grid(NODES - 1);
    assertTrue(ignite.configuration().isClientMode());
    IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
    assertTrue(((IgniteCacheProxy) cache).context().isNear());
    for (int i = 0; i < KEYS_COUNT; i++) cache.put(i, i);
    CreatedExpiryPolicy plc = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 500));
    IgniteCache<Object, Object> cacheWithExpiry = cache.withExpiryPolicy(plc);
    for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) {
        cacheWithExpiry.put(i, i);
        assertEquals(i, cacheWithExpiry.localPeek(i));
    }
    U.sleep(1000);
    // Check size of near entries via reflection because entries is filtered for size() API call.
    IgniteEx igniteEx = (IgniteEx) ignite;
    GridCacheConcurrentMap map = GridTestUtils.getFieldValue(((GridCacheProxyImpl) igniteEx.cachex(DEFAULT_CACHE_NAME)).delegate(), GridCacheAdapter.class, "map");
    assertEquals(KEYS_COUNT, map.publicSize());
    assertEquals(KEYS_COUNT, cache.size());
    for (int i = 0; i < KEYS_COUNT; i++) assertEquals(i, cacheWithExpiry.localPeek(i));
    for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) assertNull(cache.localPeek(i));
}
Also used : GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Duration(javax.cache.expiry.Duration) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy)

Example 10 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class CacheManager method createCache.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C cacheCfg) throws IllegalArgumentException {
    kernalGateway.readLock();
    try {
        if (cacheCfg == null)
            throw new NullPointerException();
        if (cacheName == null)
            throw new NullPointerException();
        CacheConfiguration<K, V> igniteCacheCfg;
        if (cacheCfg instanceof CompleteConfiguration)
            igniteCacheCfg = new CacheConfiguration<>((CompleteConfiguration<K, V>) cacheCfg);
        else {
            igniteCacheCfg = new CacheConfiguration<>();
            igniteCacheCfg.setTypes(cacheCfg.getKeyType(), cacheCfg.getValueType());
        }
        igniteCacheCfg.setName(cacheName);
        IgniteCache<K, V> res = ignite.createCache(igniteCacheCfg);
        if (res == null)
            throw new CacheException();
        ((IgniteCacheProxy<K, V>) res).setCacheManager(this);
        if (igniteCacheCfg.isManagementEnabled())
            enableManagement(cacheName, true);
        if (igniteCacheCfg.isStatisticsEnabled())
            enableStatistics(cacheName, true);
        return res;
    } finally {
        kernalGateway.readUnlock();
    }
}
Also used : CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheException(javax.cache.CacheException) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)17 Ignite (org.apache.ignite.Ignite)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1