Package org.gridgain.grid.cache

Examples of org.gridgain.grid.cache.GridCacheConfiguration


     *
     * @param gridName Grid name.
     * @return Cache configuration.
     */
    protected GridCacheConfiguration cacheConfiguration(String gridName) {
        GridCacheConfiguration cacheCfg = defaultCacheConfiguration();

        cacheCfg.setCacheMode(PARTITIONED);
        cacheCfg.setPreloadBatchSize(preloadBatchSize);
        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
        cacheCfg.setPreloadMode(preloadMode);
        cacheCfg.setAffinity(new GridCacheConsistentHashAffinityFunction(false, partitions));
        cacheCfg.setBackups(backups);

        return cacheCfg;
    }
View Full Code Here


        disco.setIpFinder(ipFinder);
        c.setDiscoverySpi(disco);
        c.setDeploymentMode(CONTINUOUS);

        // Cache.
        GridCacheConfiguration cc = defaultCacheConfiguration();

        cc.setName(CACHE_NAME);
        cc.setCacheMode(PARTITIONED);
        cc.setWriteSynchronizationMode(FULL_SYNC);
        cc.setStartSize(20);
        cc.setPreloadMode(preloadMode);
        cc.setPreloadBatchSize(preloadBatchSize);
        cc.setAffinity(new GridCacheConsistentHashAffinityFunction(false, partitions));
        cc.setBackups(backups);
        cc.setAtomicityMode(TRANSACTIONAL);

        cc.setDistributionMode(nearEnabled() ? NEAR_PARTITIONED : PARTITIONED_ONLY);

        c.setCacheConfiguration(cc);

        return c;
    }
View Full Code Here

        GridConfiguration cfg = super.getConfiguration(gridName);

        GridCacheConfiguration[] cacheCfgs = new GridCacheConfiguration[cacheCnt];

        for (int i = 0; i < cacheCnt; i++) {
            GridCacheConfiguration cacheCfg = defaultCacheConfiguration();

            cacheCfg.setName("partitioned-" + i);

            cacheCfg.setCacheMode(PARTITIONED);
            cacheCfg.setPreloadBatchSize(preloadBatchSize);
            cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC);
            cacheCfg.setPreloadMode(preloadMode);
            cacheCfg.setAffinity(new GridCacheConsistentHashAffinityFunction(false, partitions));
            cacheCfg.setBackups(backups);
            cacheCfg.setAtomicityMode(TRANSACTIONAL);

            cacheCfgs[i] = cacheCfg;
        }

        GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();
View Full Code Here

    /** {@inheritDoc} */
    @Override protected GridConfiguration getConfiguration(String gridName) throws Exception {
        GridConfiguration c = super.getConfiguration(gridName);

        GridCacheConfiguration cc = defaultCacheConfiguration();

        cc.setCacheMode(PARTITIONED);
        cc.setPreloadBatchSize(preloadBatchSize);
        cc.setWriteSynchronizationMode(FULL_SYNC);
        cc.setPreloadMode(preloadMode);
        cc.setAffinity(new GridCacheConsistentHashAffinityFunction(false, partitions));
        cc.setBackups(backups);

        GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();

        disco.setIpFinder(ipFinder);

View Full Code Here

    /** {@inheritDoc} */
    @Override protected GridConfiguration getConfiguration(String gridName) throws Exception {
        GridConfiguration c = super.getConfiguration(gridName);

        GridCacheConfiguration cc = defaultCacheConfiguration();

        cc.setCacheMode(PARTITIONED);
        cc.setPreloadBatchSize(preloadBatchSize);
        cc.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC);
        cc.setPreloadMode(preloadMode);
        cc.setAffinity(new GridCacheConsistentHashAffinityFunction(false, partitions));
        cc.setBackups(backups);
        cc.setAtomicityMode(TRANSACTIONAL);

        GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi();

        disco.setIpFinder(ipFinder);

View Full Code Here

    /**
     * @param cctx Cache context.
     */
    private void cleanup(GridCacheContext cctx) {
        GridCacheConfiguration cfg = cctx.config();

        cleanup(cfg, cfg.getEvictionPolicy(), false);
        cleanup(cfg, cfg.getNearEvictionPolicy(), true);
        cleanup(cfg, cfg.getAffinity(), false);
        cleanup(cfg, cfg.getAffinityMapper(), false);
        cleanup(cfg, cctx.jta().tmLookup(), false);
        cleanup(cfg, cfg.getCloner(), false);
        cleanup(cfg, cfg.getStore(), false);

        cctx.cleanup();
    }
View Full Code Here

        sysCaches.add(CU.UTILITY_CACHE_NAME);

        GridCacheConfiguration[] cfgs = ctx.config().getCacheConfiguration();

        for (int i = 0; i < cfgs.length; i++) {
            GridCacheConfiguration cfg = new GridCacheConfiguration(cfgs[i]);

            // Initialize defaults.
            initialize(cfg);

            // Skip suggestions for system caches.
            if (!sysCaches.contains(cfg.getName()))
                suggestOptimizations(cfg);

            validate(ctx.config(), cfg);

            GridCacheJtaManagerAdapter jta = JTA.create(cfg.getTransactionManagerLookupClassName() == null);

            jta.createTmLookup(cfg);

            prepare(cfg, jta.tmLookup());

            U.startLifecycleAware(lifecycleAwares(cfg, jta.tmLookup()));

            cfgs[i] = cfg; // Replace original configuration value.

            GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
            GridCacheTxManager tm = new GridCacheTxManager();
            GridCacheAffinityManager affMgr = new GridCacheAffinityManager();
            GridCacheVersionManager verMgr = new GridCacheVersionManager();
            GridCacheEventManager evtMgr = new GridCacheEventManager();
            GridCacheSwapManager swapMgr = new GridCacheSwapManager(cfg.getCacheMode() == LOCAL || !isNearEnabled(cfg));
            GridCacheDgcManager dgcMgr = new GridCacheDgcManager();
            GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
            GridCacheEvictionManager evictMgr = new GridCacheEvictionManager();
            GridCacheQueryManager qryMgr = queryManager(cfg);
            GridCacheContinuousQueryManager contQryMgr = new GridCacheContinuousQueryManager();
            GridCacheIoManager ioMgr = new GridCacheIoManager();
            GridCacheDataStructuresManager dataStructuresMgr = new GridCacheDataStructuresManager();
            GridCacheTtlManager ttlMgr = new GridCacheTtlManager();
            GridCacheDrManager drMgr = createComponent(GridCacheDrManager.class);

            GridCacheStore nearStore = cacheStore(ctx.gridName(), cfg, isNearEnabled(cfg));
            GridCacheStoreManager storeMgr = new GridCacheStoreManager(nearStore);

            GridCacheContext<?, ?> cacheCtx = new GridCacheContext(
                ctx,
                cfg,

                /*
                 * Managers in starting order!
                 * ===========================
                 */
                mvccMgr,
                verMgr,
                evtMgr,
                swapMgr,
                storeMgr,
                depMgr,
                evictMgr,
                ioMgr,
                qryMgr,
                contQryMgr,
                dgcMgr,
                affMgr,
                tm,
                dataStructuresMgr,
                ttlMgr,
                drMgr,
                jta);

            GridCacheAdapter cache = null;

            switch (cfg.getCacheMode()) {
                case LOCAL: {
                    switch (cfg.getAtomicityMode()) {
                        case TRANSACTIONAL: {
                            cache = new GridLocalCache(cacheCtx);

                            break;
                        }
                        case ATOMIC: {
                            cache = new GridLocalAtomicCache(cacheCtx);

                            break;
                        }

                        default: {
                            assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
                        }
                    }

                    break;
                }
                case PARTITIONED:
                case REPLICATED: {
                    if (isNearEnabled(cfg)) {
                        switch (cfg.getAtomicityMode()) {
                            case TRANSACTIONAL: {
                                cache = new GridNearTransactionalCache(cacheCtx);

                                break;
                            }
                            case ATOMIC: {
                                cache = new GridNearAtomicCache(cacheCtx);

                                break;
                            }

                            default: {
                                assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
                            }
                        }
                    }
                    else {
                        switch (cfg.getAtomicityMode()) {
                            case TRANSACTIONAL: {
                                cache = isAffinityNode(cfg) ? new GridDhtColocatedCache(cacheCtx) :
                                    new GridDhtColocatedCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));

                                break;
                            }
                            case ATOMIC: {
                                cache = isAffinityNode(cfg) ? new GridDhtAtomicCache(cacheCtx) :
                                    new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));

                                break;
                            }

                            default: {
                                assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
                            }
                        }
                    }

                    break;
                }

                default: {
                    assert false : "Invalid cache mode: " + cfg.getCacheMode();
                }
            }

            cacheCtx.cache(cache);

            if (caches.containsKey(cfg.getName())) {
                String cacheName = cfg.getName();

                if (cacheName != null)
                    throw new GridException("Duplicate cache name found (check configuration and " +
                        "assign unique name to each cache): " + cacheName);
                else
                    throw new GridException("Default cache has already been configured (check configuration and " +
                        "assign unique name to each cache).");
            }

            caches.put(cfg.getName(), cache);

            if (sysCaches.contains(cfg.getName()))
                stopSeq.addLast(cache);
            else
                stopSeq.addFirst(cache);

            // Start managers.
            for (GridCacheManager mgr : F.view(cacheCtx.managers(), F.notContains(dhtExcludes(cacheCtx))))
                mgr.start(cacheCtx);

            /*
             * Start DHT cache.
             * ================
             */
            if (cfg.getCacheMode() != LOCAL && isNearEnabled(cfg)) {
                /*
                 * Specifically don't create the following managers
                 * here and reuse the one from Near cache:
                 * 1. GridCacheVersionManager
                 * 2. GridCacheIoManager
                 * 3. GridCacheDeploymentManager
                 * 4. GridCacheQueryManager (note, that we start it for DHT cache though).
                 * 5. GridCacheContinuousQueryManager (note, that we start it for DHT cache though).
                 * 6. GridCacheDgcManager
                 * 7. GridCacheTtlManager.
                 * ===============================================
                 */
                mvccMgr = new GridCacheMvccManager();
                tm = new GridCacheTxManager();
                swapMgr = new GridCacheSwapManager(true);
                evictMgr = new GridCacheEvictionManager();
                evtMgr = new GridCacheEventManager();
                drMgr = createComponent(GridCacheDrManager.class);

                GridCacheStore dhtStore = cacheStore(ctx.gridName(), cfg, false);

                storeMgr = new GridCacheStoreManager(dhtStore);

                cacheCtx = new GridCacheContext(
                    ctx,
                    cfg,

                    /*
                     * Managers in starting order!
                     * ===========================
                     */
                    mvccMgr,
                    verMgr,
                    evtMgr,
                    swapMgr,
                    storeMgr,
                    depMgr,
                    evictMgr,
                    ioMgr,
                    qryMgr,
                    contQryMgr,
                    dgcMgr,
                    affMgr,
                    tm,
                    dataStructuresMgr,
                    ttlMgr,
                    drMgr,
                    jta);

                GridDhtCacheAdapter dht = null;

                switch (cfg.getAtomicityMode()) {
                    case TRANSACTIONAL: {
                        assert cache instanceof GridNearTransactionalCache;

                        GridNearTransactionalCache near = (GridNearTransactionalCache)cache;

                        GridDhtCache dhtCache = !isAffinityNode(cfg) ?
                            new GridDhtCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx)) :
                            new GridDhtCache(cacheCtx);

                        dhtCache.near(near);

                        near.dht(dhtCache);

                        dht = dhtCache;

                        break;
                    }
                    case ATOMIC: {
                        assert cache instanceof GridNearAtomicCache;

                        GridNearAtomicCache near = (GridNearAtomicCache)cache;

                        GridDhtAtomicCache dhtCache = isAffinityNode(cfg) ? new GridDhtAtomicCache(cacheCtx) :
                            new GridDhtAtomicCache(cacheCtx, new GridNoStorageCacheMap(cacheCtx));

                        dhtCache.near(near);

                        near.dht(dhtCache);

                        dht = dhtCache;

                        break;
                    }

                    default: {
                        assert false : "Invalid cache atomicity mode: " + cfg.getAtomicityMode();
                    }
                }

                cacheCtx.cache(dht);

                // Start managers.
                for (GridCacheManager mgr : dhtManagers(cacheCtx))
                    mgr.start(cacheCtx);

                dht.start();

                if (log.isDebugEnabled())
                    log.debug("Started DHT cache: " + dht.name());
            }

            cache.start();

            if (log.isInfoEnabled())
                log.info("Started cache [name=" + cfg.getName() + ", mode=" + cfg.getCacheMode() + ']');
        }

        for (Map.Entry<String, GridCacheAdapter<?, ?>> e : caches.entrySet()) {
            GridCacheAdapter cache = e.getValue();

View Full Code Here

     * @param node Joining node.
     * @return Validation result or {@code null} in case of success.
     */
    @Nullable private GridNodeValidationResult validateHashIdResolvers(GridNode node) {
        for (GridCacheAdapter cache : ctx.cache().internalCaches()) {
            GridCacheConfiguration cfg = cache.configuration();

            if (cfg.getAffinity() instanceof GridCacheConsistentHashAffinityFunction) {
                GridCacheConsistentHashAffinityFunction aff = (GridCacheConsistentHashAffinityFunction)cfg.getAffinity();

                GridCacheAffinityNodeHashResolver hashIdRslvr = aff.getHashIdResolver();

                assert hashIdRslvr != null;

View Full Code Here

        for (Map.Entry<String, GridCacheAdapter<?, ?>> e : caches.entrySet()) {
            GridCacheAdapter cache = e.getValue();

            if (maxPreloadOrder > 0) {
                GridCacheConfiguration cfg = cache.configuration();

                int order = cfg.getPreloadOrder();

                if (order > 0 && order != maxPreloadOrder && cfg.getCacheMode() != LOCAL) {
                    GridCompoundFuture<Object, Object> fut = (GridCompoundFuture<Object, Object>)preloadFuts
                        .get(order);

                    if (fut == null) {
                        fut = new GridCompoundFuture<>(ctx);

                        preloadFuts.put(order, fut);
                    }

                    fut.add(cache.preloader().syncFuture());
                }
            }
        }

        for (GridFuture<?> fut : preloadFuts.values())
            ((GridCompoundFuture<Object, Object>)fut).markInitialized();

        for (GridCacheAdapter<?, ?> cache : caches.values())
            onKernalStart(cache);

        // Wait for caches in SYNC preload mode.
        for (GridCacheAdapter<?, ?> cache : caches.values()) {
            GridCacheConfiguration cfg = cache.configuration();

            if (cfg.getPreloadMode() == SYNC) {
                if (cfg.getCacheMode() == REPLICATED ||
                    (cfg.getCacheMode() == PARTITIONED && cfg.getPreloadPartitionedDelay() >= 0))
                    cache.preloader().syncFuture().get();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.gridgain.grid.cache.GridCacheConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.