Search in sources :

Example 1 with CacheWriter

use of javax.cache.integration.CacheWriter in project hazelcast by hazelcast.

the class CacheConfigTest method testCacheConfigLoaderWriter.

@Test
public void testCacheConfigLoaderWriter() throws Exception {
    CacheSimpleConfig simpleConfig = new CacheSimpleConfig();
    simpleConfig.setCacheLoader(MyCacheLoader.class.getName());
    simpleConfig.setCacheWriter(EmptyCacheWriter.class.getName());
    CacheConfig cacheConfig = new CacheConfig(simpleConfig);
    CacheLoader loader = (CacheLoader) cacheConfig.getCacheLoaderFactory().create();
    CacheWriter writer = (CacheWriter) cacheConfig.getCacheWriterFactory().create();
    assertTrue(loader instanceof MyCacheLoader);
    assertTrue(writer instanceof EmptyCacheWriter);
}
Also used : CacheWriter(javax.cache.integration.CacheWriter) CacheLoader(javax.cache.integration.CacheLoader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CacheWriter

use of javax.cache.integration.CacheWriter in project hazelcast by hazelcast.

the class CacheConfigTest method testCacheConfigLoaderWriterXml.

@Test
public void testCacheConfigLoaderWriterXml() throws Exception {
    Config config = new XmlConfigBuilder(configUrl2).build();
    CacheSimpleConfig simpleConfig = config.getCacheConfig("cache3");
    CacheConfig<Object, String> cacheConfig = new CacheConfig<Object, String>(simpleConfig);
    Factory<CacheWriter<? super Object, ? super String>> writerFactory = cacheConfig.getCacheWriterFactory();
    CacheWriter<? super Object, ? super String> cacheWriter = writerFactory.create();
    assertTrue(cacheWriter instanceof EmptyCacheWriter);
    Factory<CacheLoader<Object, String>> loaderFactory = cacheConfig.getCacheLoaderFactory();
    CacheLoader<Object, String> cacheLoader = loaderFactory.create();
    assertTrue(cacheLoader instanceof MyCacheLoader);
}
Also used : TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) CacheWriter(javax.cache.integration.CacheWriter) CacheLoader(javax.cache.integration.CacheLoader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with CacheWriter

use of javax.cache.integration.CacheWriter in project hazelcast by hazelcast.

the class LatencyTrackingCacheWriterTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    HazelcastInstance hz = createHazelcastInstance();
    plugin = new StoreLatencyPlugin(getNodeEngineImpl(hz));
    delegate = mock(CacheWriter.class);
    cacheWriter = new LatencyTrackingCacheWriter<Integer, String>(delegate, plugin, NAME);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) StoreLatencyPlugin(com.hazelcast.internal.diagnostics.StoreLatencyPlugin) CacheWriter(javax.cache.integration.CacheWriter) Before(org.junit.Before)

Example 4 with CacheWriter

use of javax.cache.integration.CacheWriter in project ignite by apache.

the class GridCacheProcessor method initialize.

/**
     * @param cfg Initializes cache configuration with proper defaults.
     * @param cacheObjCtx Cache object context.
     * @throws IgniteCheckedException If configuration is not valid.
     */
private void initialize(CacheConfiguration cfg, CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
    if (cfg.getCacheMode() == null)
        cfg.setCacheMode(DFLT_CACHE_MODE);
    if (cfg.getNodeFilter() == null)
        cfg.setNodeFilter(CacheConfiguration.ALL_NODES);
    if (cfg.getAffinity() == null) {
        if (cfg.getCacheMode() == PARTITIONED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction();
            cfg.setAffinity(aff);
        } else if (cfg.getCacheMode() == REPLICATED) {
            RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 512);
            cfg.setAffinity(aff);
            cfg.setBackups(Integer.MAX_VALUE);
        } else
            cfg.setAffinity(new LocalAffinityFunction());
    } else {
        if (cfg.getCacheMode() == LOCAL && !(cfg.getAffinity() instanceof LocalAffinityFunction)) {
            cfg.setAffinity(new LocalAffinityFunction());
            U.warn(log, "AffinityFunction configuration parameter will be ignored for local cache" + " [cacheName=" + U.maskName(cfg.getName()) + ']');
        }
    }
    if (cfg.getCacheMode() == REPLICATED)
        cfg.setBackups(Integer.MAX_VALUE);
    if (cfg.getQueryParallelism() > 1 && cfg.getCacheMode() != PARTITIONED)
        throw new IgniteCheckedException("Segmented indices are supported for PARTITIONED mode only.");
    if (cfg.getAffinityMapper() == null)
        cfg.setAffinityMapper(cacheObjCtx.defaultAffMapper());
    ctx.igfsHelper().preProcessCacheConfiguration(cfg);
    if (cfg.getRebalanceMode() == null)
        cfg.setRebalanceMode(ASYNC);
    if (cfg.getAtomicityMode() == null)
        cfg.setAtomicityMode(CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
    if (cfg.getWriteSynchronizationMode() == null)
        cfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    assert cfg.getWriteSynchronizationMode() != null;
    if (cfg.getCacheStoreFactory() == null) {
        Factory<CacheLoader> ldrFactory = cfg.getCacheLoaderFactory();
        Factory<CacheWriter> writerFactory = cfg.isWriteThrough() ? cfg.getCacheWriterFactory() : null;
        if (ldrFactory != null || writerFactory != null)
            cfg.setCacheStoreFactory(new GridCacheLoaderWriterStoreFactory(ldrFactory, writerFactory));
    } else {
        if (cfg.getCacheLoaderFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache loaded factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
        if (cfg.getCacheWriterFactory() != null)
            throw new IgniteCheckedException("Cannot set both cache writer factory and cache store factory " + "for cache: " + U.maskName(cfg.getName()));
    }
    Collection<QueryEntity> entities = cfg.getQueryEntities();
    if (!F.isEmpty(entities)) {
        Collection<QueryEntity> normalEntities = new ArrayList<>(entities.size());
        for (QueryEntity entity : entities) normalEntities.add(QueryUtils.normalizeQueryEntity(entity, cfg.isSqlEscapeAll()));
        cfg.clearQueryEntities().setQueryEntities(normalEntities);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheWriter(javax.cache.integration.CacheWriter) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheLoader(javax.cache.integration.CacheLoader) QueryEntity(org.apache.ignite.cache.QueryEntity)

Aggregations

CacheWriter (javax.cache.integration.CacheWriter)4 CacheLoader (javax.cache.integration.CacheLoader)3 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 ExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig)1 DurationConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig)1 TimedExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 StoreLatencyPlugin (com.hazelcast.internal.diagnostics.StoreLatencyPlugin)1 ArrayList (java.util.ArrayList)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 Before (org.junit.Before)1