javax.cache.configuration.Factory Java Examples

The following examples show how to use javax.cache.configuration.Factory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CacheContinuousQueryHandlerV2.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);

    boolean b = in.readBoolean();

    if (b) {
        rmtFilterFactoryDep = (CacheContinuousQueryDeployableObject)in.readObject();

        if (p2pUnmarshalFut.isDone())
            p2pUnmarshalFut = new GridFutureAdapter<>();
    } else
        rmtFilterFactory = (Factory)in.readObject();

    types = in.readByte();
}
 
Example #2
Source File: TypesafeConfigurator.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/** Adds the JCache specification's lazy expiration settings. */
public void addLazyExpiration() {
  Duration creation = getDurationFor("policy.lazy-expiration.creation");
  Duration update = getDurationFor("policy.lazy-expiration.update");
  Duration access = getDurationFor("policy.lazy-expiration.access");
  requireNonNull(creation, "policy.lazy-expiration.creation may not be null");

  boolean eternal = Objects.equals(creation, Duration.ETERNAL)
      && Objects.equals(update, Duration.ETERNAL)
      && Objects.equals(access, Duration.ETERNAL);
  @SuppressWarnings("NullAway")
  Factory<? extends ExpiryPolicy> factory = eternal
      ? EternalExpiryPolicy.factoryOf()
      : FactoryBuilder.factoryOf(new JCacheExpiryPolicy(creation, update, access));
  configuration.setExpiryPolicyFactory(factory);
}
 
Example #3
Source File: CacheHibernateStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
    return new Factory<CacheStoreSessionListener>() {
        @Override public CacheStoreSessionListener create() {
            CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();

            SessionFactory sesFactory = new Configuration().
                setProperty("hibernate.connection.url", URL).
                addAnnotatedClass(Table1.class).
                addAnnotatedClass(Table2.class).
                buildSessionFactory();

            lsnr.setSessionFactory(sesFactory);

            return lsnr;
        }
    };
}
 
Example #4
Source File: CacheHibernateStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
    return new Factory<CacheStoreSessionListener>() {
        @Override public CacheStoreSessionListener create() {
            CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();

            SessionFactory sesFactory = new Configuration().
                setProperty("hibernate.connection.url", URL).
                addAnnotatedClass(Table1.class).
                addAnnotatedClass(Table2.class).
                buildSessionFactory();

            lsnr.setSessionFactory(sesFactory);

            return lsnr;
        }
    };
}
 
Example #5
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCall() throws Exception {
    runTest(callableFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                EchoCallable job = (EchoCallable)factory.create();
                job.setArg(value(i - 1));
                results.add(ignite.compute().call(job));
            }

            checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
            assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
        }
    });
}
 
Example #6
Source File: EntryVersionConsistencyReadThroughTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param atomicityMode Atomicity mode.
 * @return Cache configuration.
 */
@SuppressWarnings({"rawtypes", "unchecked"})
private CacheConfiguration<String, List<Double>> createCacheConfiguration(CacheAtomicityMode atomicityMode) {
    CacheConfiguration<String, List<Double>> cc = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cc.setCacheMode(PARTITIONED);
    cc.setAtomicityMode(atomicityMode);
    cc.setWriteSynchronizationMode(FULL_SYNC);

    cc.setReadThrough(true);
    cc.setWriteThrough(true);

    Factory cacheStoreFactory = new FactoryBuilder.SingletonFactory(new DummyCacheStore());

    cc.setCacheStoreFactory(cacheStoreFactory);

    cc.setBackups(2);

    return cc;
}
 
Example #7
Source File: Builder.java    From triava with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the ExpiryPolicyFactory. It will overwrite any values set before via {@link #setMaxIdleTime(int, TimeUnit)}.
 * @param factory The factory
 * @return This Builder
 */
public Builder<K,V> setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory)
{
	if (expiryPolicyFactory == null)
	{
		this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
	}
	else
	{
		@SuppressWarnings("unchecked")
		Factory<ExpiryPolicy> factoryCasted = (Factory<ExpiryPolicy>) factory;
		this.expiryPolicyFactory = (factoryCasted);
	}
	
	return this;
}
 
Example #8
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testExecuteTaskClassAsync() throws Exception {
    runTest(jobFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            // Begin with negative to check 'null' value in the test.
            final int[] i = {-1};

            ComputeTaskFuture<List<Object>> fut = ignite.compute().executeAsync(
                TestTask.class,
                new T2<>((Factory<ComputeJobAdapter>)factory,
                    (Factory<Object>)new Factory<Object>() {
                        @Override public Object create() {
                            return value(i[0]++);
                        }
                    }));

            checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass());
            assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get());
        }
    });
}
 
Example #9
Source File: EvictionPolicyFailureHandlerTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setFailureHandler((ignite, failureCtx) -> {
        nodeFailure.set(true);

        return false;
    });

    SortedEvictionPolicyFactory plcFactory = new SortedEvictionPolicyFactory();
    plcFactory.setMaxSize(3);
    plcFactory.setBatchSize(10);
    plcFactory.setMaxMemorySize(10);

    cfg.setGridLogger(log);

    cfg.setCacheConfiguration(new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME)
        .setEvictionPolicyFactory(oom ? (Factory<ThrowableEvictionPolicy>)ThrowableEvictionPolicy::new : plcFactory)
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
        .setOnheapCacheEnabled(true));

    return cfg;
}
 
Example #10
Source File: ConfigurationMerger.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
private <K, V> Jsr107CacheLoaderWriter<K, V> initCacheLoaderWriter(CompleteConfiguration<K, V> config) {
  Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory();
  @SuppressWarnings("unchecked")
  Factory<CacheWriter<K, V>> cacheWriterFactory = (Factory<CacheWriter<K, V>>) (Object) config.getCacheWriterFactory();

  if (config.isReadThrough() && cacheLoaderFactory == null) {
    throw new IllegalArgumentException("read-through enabled without a CacheLoader factory provided");
  }
  if (config.isWriteThrough() && cacheWriterFactory == null) {
    throw new IllegalArgumentException("write-through enabled without a CacheWriter factory provided");
  }

  CacheLoader<K, V> cacheLoader = cacheLoaderFactory == null ? null : cacheLoaderFactory.create();
  CacheWriter<K, V> cacheWriter;
  try {
    cacheWriter = cacheWriterFactory == null ? null : cacheWriterFactory.create();
  } catch (Throwable t) {
    throw closeAllAfter(new CacheException(t), cacheLoader);
  }

  if (cacheLoader == null && cacheWriter == null) {
    return null;
  } else {
    return new Eh107CacheLoaderWriter<>(cacheLoader, config.isReadThrough(), cacheWriter, config.isWriteThrough());
  }
}
 
Example #11
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testApplyForCollection() throws Exception {
    runTest(closureFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            Collection params = new ArrayList<>(MAX_JOB_COUNT);

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                // value(i - 1): use negative argument of the value method to generate nullong value.
                params.add(value(i - 1));
            }

            IgniteClosure c = (IgniteClosure)factory.create();

            // Use type casting to avoid ambiguous for apply(Callable, Object) vs apply(Callable, Collection<Object>).
            Collection<Object> results = ignite.compute().apply((IgniteClosure<TestObject, Object>)c,
                (Collection<TestObject>)params);

            checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
            assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
        }
    });
}
 
Example #12
Source File: TypesafeConfigurator.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/** Adds the entry listeners settings. */
private void addListeners() {
  for (String path : merged.getStringList("listeners")) {
    Config listener = root.getConfig(path);

    Factory<? extends CacheEntryListener<? super K, ? super V>> listenerFactory =
        factoryCreator.factoryOf(listener.getString("class"));
    Factory<? extends CacheEntryEventFilter<? super K, ? super V>> filterFactory = null;
    if (listener.hasPath("filter")) {
      filterFactory = factoryCreator.factoryOf(listener.getString("filter"));
    }
    boolean oldValueRequired = listener.getBoolean("old-value-required");
    boolean synchronous = listener.getBoolean("synchronous");
    configuration.addCacheEntryListenerConfiguration(
        new MutableCacheEntryListenerConfiguration<>(
            listenerFactory, filterFactory, oldValueRequired, synchronous));
  }
}
 
Example #13
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMultiCacheAffinityRunAsync() throws Exception {
    runTest(runnableFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            ignite.getOrCreateCache("test0");
            ignite.getOrCreateCache("test1");

            final IgniteCompute comp = ignite.compute();

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                IgniteRunnable job = (IgniteRunnable)factory.create();

                IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), key(0), job);

                fut.get();
            }
        }
    });
}
 
Example #14
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testBroadcastClosureAsync() throws Exception {
    runTest(closureFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            final Collection<Object> resultsAllNull = ignite.compute()
                .broadcast((IgniteClosure<Object, Object>)factory.create(), null);

            assertEquals("Result's size mismatch: job must be run on all server nodes",
                gridCount() - clientsCount(), resultsAllNull.size());

            for (Object o : resultsAllNull)
                assertNull("All results must be null", o);

            IgniteFuture<Collection<Object>> fut = ignite.compute()
                .broadcastAsync((IgniteClosure<Object, Object>)factory.create(), value(0));

            checkResultsClassCount(gridCount() - clientsCount(), fut.get(), value(0).getClass());
        }
    });
}
 
Example #15
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testApplyForCollectionAsync() throws Exception {
    runTest(closureFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            Collection params = new ArrayList<>(MAX_JOB_COUNT);

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                // value(i - 1): use negative argument of the value method to generate nullong value.
                params.add(value(i - 1));
            }

            IgniteClosure c = (IgniteClosure)factory.create();

            // Use type casting to avoid ambiguous for apply(Callable, Object) vs apply(Callable, Collection<Object>).
            IgniteFuture<Collection<Object>> fut = ignite.compute().applyAsync(
                (IgniteClosure<TestObject, Object>)c,
                (Collection<TestObject>)params);

            checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass());
            assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get());
        }
    });
}
 
Example #16
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testBroadcastClosure() throws Exception {
    runTest(closureFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            final Collection<Object> resultsAllNull = ignite.compute()
                .broadcast((IgniteClosure<Object, Object>)factory.create(), null);

            assertEquals("Result's size mismatch: job must be run on all server nodes",
                gridCount() - clientsCount(), resultsAllNull.size());

            for (Object o : resultsAllNull)
                assertNull("All results must be null", o);

            Collection<Object> resultsNotNull = ignite.compute()
                .broadcast((IgniteClosure<Object, Object>)factory.create(), value(0));

            checkResultsClassCount(gridCount() - clientsCount(), resultsNotNull, value(0).getClass());
        }
    });
}
 
Example #17
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testBroadcastRunnableAsync() throws Exception {
    runTest(runnableFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            IgniteRunnable job = (IgniteRunnable)factory.create();

            IgniteFuture<Void> fut = ignite.compute().broadcastAsync(job);

            fut.get();
            // All checks are inside the run() method of the job.
        }
    });
}
 
Example #18
Source File: ConfigVariations.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Custom near cache config.
 */
private static Factory nearCacheConfigurationFactory() {
    return new Factory() {
        @Override public Object create() {
            NearCacheConfiguration cfg = new NearCacheConfiguration<>();

            cfg.setNearEvictionPolicy(new FifoEvictionPolicy());

            return cfg;
        }
    };
}
 
Example #19
Source File: GridCacheAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    if (storeStgy != null) {
        Factory<? extends CacheStore<Object, Object>> storeFactory = storeStgy.getStoreFactory();

        CacheStore<?, ?> store = storeFactory.create();

        if (store != null) {
            cfg.setCacheStoreFactory(storeFactory);
            cfg.setReadThrough(true);
            cfg.setWriteThrough(true);
            cfg.setLoadPreviousValue(true);
            storeStgy.updateCacheConfiguration(cfg);
        }
    }

    cfg.setCacheMode(cacheMode());
    cfg.setAtomicityMode(atomicityMode());
    cfg.setWriteSynchronizationMode(writeSynchronization());
    cfg.setNearConfiguration(nearConfiguration());
    cfg.setOnheapCacheEnabled(onheapCacheEnabled());

    Class<?>[] idxTypes = indexedTypes();

    if (!F.isEmpty(idxTypes))
        cfg.setIndexedTypes(idxTypes);

    if (cacheMode() == PARTITIONED)
        cfg.setBackups(backups());

    return cfg;
}
 
Example #20
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test(expected=UnsupportedOperationException.class)
public void no_online_listener_attachment_with_cache2k_defaults() {
  CachingProvider p = Caching.getCachingProvider();
  CacheManager cm = p.getCacheManager();
  MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>(){});
  Cache cache = cm.createCache("mute",  cfg);
  cache.registerCacheEntryListener(new CacheEntryListenerConfiguration() {
    @Override
    public Factory<CacheEntryListener> getCacheEntryListenerFactory() {
      fail("not expected to be called");
      return null;
    }

    @Override
    public boolean isOldValueRequired() {
      return false;
    }

    @Override
    public Factory<CacheEntryEventFilter> getCacheEntryEventFilterFactory() {
      return null;
    }

    @Override
    public boolean isSynchronous() {
      return false;
    }
  });
  cache.close();
}
 
Example #21
Source File: IgniteCacheEntryListenerAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testConcurrentRegisterDeregister() throws Exception {
    final int THREADS = 10;

    final CyclicBarrier barrier = new CyclicBarrier(THREADS);

    final IgniteCache<Object, Object> cache = jcache(0);

    GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
        @Override public Void call() throws Exception {
            CacheEntryListenerConfiguration<Object, Object> cfg = new MutableCacheEntryListenerConfiguration<>(
                new Factory<CacheEntryListener<Object, Object>>() {
                    @Override public CacheEntryListener<Object, Object> create() {
                        return new CreateUpdateRemoveExpireListener();
                    }
                },
                null,
                true,
                false
            );

            barrier.await();

            for (int i = 0; i < 100; i++) {
                cache.registerCacheEntryListener(cfg);

                cache.deregisterCacheEntryListener(cfg);
            }

            return null;
        }
    }, THREADS, "register-thread").get();
}
 
Example #22
Source File: CacheJdbcStoreSessionListenerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() {
    return new Factory<CacheStore<Integer, Integer>>() {
        @Override public CacheStore<Integer, Integer> create() {
            return new Store();
        }
    };
}
 
Example #23
Source File: JCacheStore.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
public JCacheStore(Factory<ExpiryPolicy> expiryPolicyFactory) {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<String, Serializable> config = new MutableConfiguration<String, Serializable>()
            .setTypes(String.class, Serializable.class);
    if (expiryPolicyFactory != null) {
        config.setExpiryPolicyFactory(expiryPolicyFactory);
    }
    cache = cacheManager.getCache("session", String.class, Serializable.class);
    if (cache == null)
        cache = cacheManager.createCache("session", config);
}
 
Example #24
Source File: CacheContinuousQueryOperationP2PTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 * @param isClient Client.
 * @throws Exception If failed.
 */
protected void testContinuousQuery(CacheConfiguration<Object, Object> ccfg, boolean isClient)
    throws Exception {

    ignite(0).createCache(ccfg);

    final Class<Factory<CacheEntryEventFilter>> evtFilterFactoryCls =
        (Class<Factory<CacheEntryEventFilter>>)getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");

    testContinuousQuery(ccfg, isClient, false, evtFilterFactoryCls);
    testContinuousQuery(ccfg, isClient, true, evtFilterFactoryCls);
}
 
Example #25
Source File: CacheContinuousQueryHandlerV3.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);

    boolean b = in.readBoolean();

    if (b) {
        rmtTransFactoryDep = (CacheContinuousQueryDeployableObject)in.readObject();

        if (p2pUnmarshalFut.isDone())
            p2pUnmarshalFut = new GridFutureAdapter<>();
    } else
        rmtTransFactory = (Factory<? extends IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?>>)in.readObject();
}
 
Example #26
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMultiCacheByPartIdAffinityCallAsync() throws Exception {
    runTest(callableFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            ignite.getOrCreateCache("test0");
            ignite.getOrCreateCache("test1");

            final IgniteCompute comp = ignite.compute();

            Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                EchoCallable job = (EchoCallable)factory.create();

                job.setArg(value(i - 1));

                IgniteFuture fut = comp.affinityCallAsync(Arrays.asList("test0", "test1"), 0, job);

                results.add(fut.get());
            }

            checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
            assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
        }
    });
}
 
Example #27
Source File: JdbcThinConnectionAdditionalSecurityTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Test SSL context factory.
 */
private static Factory<SSLContext> getTestSslContextFactory() {
    SslContextFactory factory = new SslContextFactory();

    factory.setKeyStoreFilePath(SRV_KEY_STORE_PATH);
    factory.setKeyStorePassword("123456".toCharArray());
    factory.setTrustStoreFilePath(TRUST_KEY_STORE_PATH);
    factory.setTrustStorePassword("123456".toCharArray());

    return factory;
}
 
Example #28
Source File: ClientAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@SuppressWarnings("unchecked")
private static CacheConfiguration cacheConfiguration(@NotNull final String cacheName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(DEFAULT_CACHE_NAME.equals(cacheName) || CACHE_NAME.equals(cacheName) ? LOCAL : "replicated".equals(cacheName) ?
        REPLICATED : PARTITIONED);
    cfg.setName(cacheName);
    cfg.setWriteSynchronizationMode(FULL_SYNC);

    cfg.setCacheStoreFactory(new Factory<CacheStore>() {
        @Override public CacheStore create() {
            synchronized (cacheStores) {
                HashMapStore cacheStore = cacheStores.get(cacheName);

                if (cacheStore == null)
                    cacheStores.put(cacheName, cacheStore = new HashMapStore());

                return cacheStore;
            }
        }
    });

    cfg.setWriteThrough(true);
    cfg.setReadThrough(true);
    cfg.setLoadPreviousValue(true);

    if (cfg.getCacheMode() == PARTITIONED)
        cfg.setBackups(1);

    return cfg;
}
 
Example #29
Source File: JmhWaitStategyBenchmark.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** @param rate duration will decrease with */
private static Factory<ExpiryPolicy> getExpiryPolicyFactoryWithDecreasingRate(final double rate) {
    return new Factory<ExpiryPolicy>() {
        @Override public ExpiryPolicy create() {
            return new RandomExpiryPolicy(rate);
        }
    };
}
 
Example #30
Source File: GridCacheLoaderWriterStoreFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ldrFactory Loader factory.
 * @param writerFactory Writer factory.
 */
GridCacheLoaderWriterStoreFactory(@Nullable Factory<CacheLoader<K, V>> ldrFactory,
    @Nullable Factory<CacheWriter<K, V>> writerFactory) {
    this.ldrFactory = ldrFactory;
    this.writerFactory = writerFactory;

    assert ldrFactory != null || writerFactory != null;
}