/** {@inheritDoc} */ @Override protected IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> getTransformer() { if (rmtTrans == null && rmtTransFactory != null) rmtTrans = rmtTransFactory.create(); return rmtTrans; }
/** {@inheritDoc} */ @Override public SSLSocketFactory create() { return getTestSslContextFactory().create().getSocketFactory(); } }
Builder(String cacheName, CaffeineConfiguration<K, V> config) { this.config = config; this.cacheName = cacheName; this.caffeine = Caffeine.newBuilder(); this.statistics = new JCacheStatisticsMXBean(); this.ticker = config.getTickerFactory().create(); this.executor = config.getExecutorFactory().create(); this.expiryPolicy = config.getExpiryPolicyFactory().create(); this.dispatcher = new EventDispatcher<>(executor); caffeine.executor(executor); config.getCacheEntryListenerConfigurations().forEach(dispatcher::register); }
/** @return a writer created by the configured factory or null if not set. */ public @Nullable CacheWriter<K , V> getCacheWriter() { if (hasCacheWriter()) { @SuppressWarnings("unchecked") CacheWriter<K , V> writer = (CacheWriter<K, V>) getCacheWriterFactory().create(); return writer; } return null; }
static void checkStoreByValue(CaffeineConfiguration<?, ?> config) { assertThat(config.isStoreByValue(), is(true)); assertThat(config.getCopierFactory().create(), instanceOf(JavaSerializationCopier.class)); }
static void checkListener(CaffeineConfiguration<?, ?> config) { CacheEntryListenerConfiguration<?, ?> listener = Iterables.getOnlyElement( config.getCacheEntryListenerConfigurations()); assertThat(listener.getCacheEntryListenerFactory().create(), instanceOf(TestCacheEntryListener.class)); assertThat(listener.getCacheEntryEventFilterFactory().create(), instanceOf(TestCacheEntryEventFilter.class)); assertThat(listener.isSynchronous(), is(true)); assertThat(listener.isOldValueRequired(), is(true)); }
static void checkLazyExpiration(CaffeineConfiguration<?, ?> config) { ExpiryPolicy expiry = config.getExpiryPolicyFactory().create(); assertThat(expiry.getExpiryForCreation(), is(Duration.ONE_MINUTE)); assertThat(expiry.getExpiryForUpdate(), is(Duration.FIVE_MINUTES)); assertThat(expiry.getExpiryForAccess(), is(Duration.TEN_MINUTES)); }
/** Creates a cache that reads through on a cache miss. */ private CacheProxy<K, V> newLoadingCacheProxy() { CacheLoader<K, V> cacheLoader = config.getCacheLoaderFactory().create(); JCacheLoaderAdapter<K, V> adapter = new JCacheLoaderAdapter<>( cacheLoader, dispatcher, expiryPolicy, ticker, statistics); CacheProxy<K, V> cache = new LoadingCacheProxy<>(cacheName, executor, cacheManager, config, caffeine.build(adapter), dispatcher, cacheLoader, expiryPolicy, ticker, statistics); adapter.setCache(cache); return cache; }
static void checkTestCache(CaffeineConfiguration<?, ?> config) { checkStoreByValue(config); checkListener(config); assertThat(config.getKeyType(), is(Object.class)); assertThat(config.getValueType(), is(Object.class)); assertThat(config.getCacheLoaderFactory().create(), instanceOf(TestCacheLoader.class)); assertThat(config.getCacheWriter(), instanceOf(TestCacheWriter.class)); assertThat(config.isStatisticsEnabled(), is(true)); assertThat(config.isManagementEnabled(), is(true)); checkSize(config); checkRefresh(config); checkLazyExpiration(config); checkEagerExpiration(config); }
@Override public void test(Factory factory, Ignite ignite) throws Exception { Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { EchoCallable job = (EchoCallable)factory.create(); job.setArg(value(i - 1)); jobs.add(job); } Collection<Object> results = ignite.compute().call(jobs); checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
@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); } });
public JCache(JCacheManager cacheManager, Redisson redisson, String name, JCacheConfiguration<K, V> config, boolean hasOwnRedisson) { super(redisson.getConfig().getCodec(), redisson.getCommandExecutor(), name); this.hasOwnRedisson = hasOwnRedisson; this.redisson = redisson; Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory(); if (cacheLoaderFactory != null) { cacheLoader = cacheLoaderFactory.create(); } Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory = config.getCacheWriterFactory(); if (config.getCacheWriterFactory() != null) { cacheWriter = (CacheWriter<K, V>) cacheWriterFactory.create(); } this.cacheManager = cacheManager; this.config = config; redisson.getEvictionScheduler().scheduleJCache(getName(), getTimeoutSetName(), getExpiredChannelName()); for (CacheEntryListenerConfiguration<K, V> listenerConfig : config.getCacheEntryListenerConfigurations()) { registerCacheEntryListener(listenerConfig, false); } }
public JCache(JCacheManager cacheManager, Redisson redisson, String name, JCacheConfiguration<K, V> config, boolean hasOwnRedisson) { super(redisson.getConfig().getCodec(), redisson.getCommandExecutor(), name); this.hasOwnRedisson = hasOwnRedisson; this.redisson = redisson; Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory(); if (cacheLoaderFactory != null) { cacheLoader = cacheLoaderFactory.create(); } Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory = config.getCacheWriterFactory(); if (config.getCacheWriterFactory() != null) { cacheWriter = (CacheWriter<K, V>) cacheWriterFactory.create(); } this.cacheManager = cacheManager; this.config = config; redisson.getEvictionScheduler().scheduleJCache(getName(), getTimeoutSetName(), getExpiredChannelName()); for (CacheEntryListenerConfiguration<K, V> listenerConfig : config.getCacheEntryListenerConfigurations()) { registerCacheEntryListener(listenerConfig, false); } }
@Override public void test(Factory factory, Ignite ignite) throws Exception { Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { EchoCallable job = (EchoCallable)factory.create(); job.setArg(value(i - 1)); jobs.add(job); } IgniteFuture<Collection<Object>> fut = ignite.compute().callAsync(jobs); checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get()); } });
@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"), 0, job); fut.get(); } } });
@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(); } } });
public JCacheConfiguration(Configuration<K, V> configuration) { if (configuration != null) { if (configuration instanceof RedissonConfiguration) { configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig(); } if (configuration instanceof CompleteConfiguration) { delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration); } else { delegate = new MutableConfiguration<K, V>(); delegate.setStoreByValue(configuration.isStoreByValue()); delegate.setTypes(configuration.getKeyType(), configuration.getValueType()); } } else { delegate = new MutableConfiguration<K, V>(); } this.expiryPolicy = delegate.getExpiryPolicyFactory().create(); }
public JCacheConfiguration(Configuration<K, V> configuration) { if (configuration != null) { if (configuration instanceof RedissonConfiguration) { configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig(); } if (configuration instanceof CompleteConfiguration) { delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration); } else { delegate = new MutableConfiguration<K, V>(); delegate.setStoreByValue(configuration.isStoreByValue()); delegate.setTypes(configuration.getKeyType(), configuration.getValueType()); } } else { delegate = new MutableConfiguration<K, V>(); } this.expiryPolicy = delegate.getExpiryPolicyFactory().create(); }
/** * @throws Exception if failed. */ @Test public void testWithExpiryPolicyUnsupported() throws Exception { checkOperationUnsupported("withExpiryPolicy", m("withExpiryPolicy"), t(ExpiryPolicy.class), EternalExpiryPolicy.factoryOf().create()); }