use of javax.cache.configuration.Factory in project ignite by apache.
the class CacheContinuousQueryOperationP2PTest method testContinuousQuery.
/**
* @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);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
QueryCursor<?> cur = null;
final Class<Factory<CacheEntryEventFilter>> evtFilterFactory = (Class<Factory<CacheEntryEventFilter>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
final CountDownLatch latch = new CountDownLatch(10);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
TestLocalListener localLsnr = new TestLocalListener() {
@Override
public void onEvent(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) {
latch.countDown();
log.info("Received event: " + evt);
}
}
};
MutableCacheEntryListenerConfiguration<Integer, Integer> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(new FactoryBuilder.SingletonFactory<>(localLsnr), (Factory<? extends CacheEntryEventFilter<? super Integer, ? super Integer>>) (Object) evtFilterFactory.newInstance(), true, true);
qry.setLocalListener(localLsnr);
qry.setRemoteFilterFactory((Factory<? extends CacheEntryEventFilter<Integer, Integer>>) (Object) evtFilterFactory.newInstance());
IgniteCache<Integer, Integer> cache = null;
try {
if (isClient)
cache = grid(NODES - 1).cache(ccfg.getName());
else
cache = grid(rnd.nextInt(NODES - 1)).cache(ccfg.getName());
cur = cache.query(qry);
cache.registerCacheEntryListener(lsnrCfg);
for (int i = 0; i < 10; i++) cache.put(i, i);
assertTrue(latch.await(3, TimeUnit.SECONDS));
} finally {
if (cur != null)
cur.close();
if (cache != null)
cache.deregisterCacheEntryListener(lsnrCfg);
}
}
use of javax.cache.configuration.Factory in project Payara by payara.
the class CompleteConfigurationProxy method proxyLoader.
private Factory<CacheLoader<K, V>> proxyLoader(final Factory<CacheLoader<K, V>> fact) {
return new Factory<CacheLoader<K, V>>() {
@Override
public CacheLoader<K, V> create() {
@Cleanup Context ctx = ctxUtil.pushContext();
final CacheLoader<K, V> loader = fact.create();
return new CacheLoaderImpl(loader);
}
class CacheLoaderImpl implements CacheLoader<K, V> {
public CacheLoaderImpl(CacheLoader<K, V> loader) {
this.loader = loader;
}
@Override
public V load(K k) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.load(k);
}
@Override
public Map<K, V> loadAll(Iterable<? extends K> itrbl) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.loadAll(itrbl);
}
private final CacheLoader<K, V> loader;
}
private static final long serialVersionUID = 1L;
};
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class UsingContinuousQueries method remoteFilterExample.
public static void remoteFilterExample() {
try (Ignite ignite = Ignition.start()) {
IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");
// tag::remoteFilter[]
ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
qry.setLocalListener(events -> events.forEach(event -> System.out.format("Entry: key=[%s] value=[%s]\n", event.getKey(), event.getValue())));
qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter<Integer, String>>() {
@Override
public CacheEntryEventFilter<Integer, String> create() {
return new CacheEntryEventFilter<Integer, String>() {
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e) {
System.out.format("the value for key [%s] was updated from [%s] to [%s]\n", e.getKey(), e.getOldValue(), e.getValue());
return true;
}
};
}
});
// end::remoteFilter[]
cache.query(qry);
cache.put(1, "1");
}
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class AbstractDataTypesCoverageTest method parameters.
/**
* @return Test parameters.
*/
@Parameterized.Parameters(name = "atomicityMode={1}, cacheMode={2}, ttlFactory={3}, backups={4}," + " evictionFactory={5}, onheapCacheEnabled={6}, writeSyncMode={7}, persistenceEnabled={8}, useBinaryArrays={9}")
public static Collection parameters() {
Set<Object[]> params = new HashSet<>();
Object[] baseParamLine = { null, CacheAtomicityMode.ATOMIC, CacheMode.PARTITIONED, null, 2, null, false, CacheWriteSynchronizationMode.FULL_SYNC, false, DFLT_IGNITE_USE_BINARY_ARRAYS };
Object[] paramLine = null;
for (CacheAtomicityMode atomicityMode : CacheAtomicityMode.values()) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[1] = atomicityMode;
params.add(paramLine);
}
for (CacheMode cacheMode : CacheMode.values()) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[2] = cacheMode;
params.add(paramLine);
}
assert paramLine != null;
if ((paramLine[1]) != CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
for (Factory ttlFactory : TTL_FACTORIES) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[3] = ttlFactory;
params.add(paramLine);
}
}
for (int backups : new int[] { 0, 1, 2 }) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[4] = backups;
params.add(paramLine);
}
for (Factory evictionFactory : EVICTION_FACTORIES) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[5] = evictionFactory;
params.add(paramLine);
}
for (Boolean onheapCacheEnabled : BOOLEANS) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[6] = onheapCacheEnabled;
params.add(paramLine);
}
for (CacheWriteSynchronizationMode writeSyncMode : CacheWriteSynchronizationMode.values()) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[7] = writeSyncMode;
params.add(paramLine);
}
for (boolean persistenceEnabled : BOOLEANS) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[8] = persistenceEnabled;
params.add(paramLine);
}
for (boolean useTypedArrays : BOOLEANS) {
paramLine = Arrays.copyOf(baseParamLine, baseParamLine.length);
paramLine[9] = useTypedArrays;
params.add(paramLine);
}
for (Object[] pLine : params) pLine[0] = UUID.randomUUID();
return params;
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class EntryVersionConsistencyReadThroughTest method createCacheConfiguration.
/**
* @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;
}
Aggregations