Java Code Examples for javax.cache.configuration.CompleteConfiguration#getExpiryPolicyFactory()
The following examples show how to use
javax.cache.configuration.CompleteConfiguration#getExpiryPolicyFactory() .
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: JCSConfiguration.java From commons-jcs with Apache License 2.0 | 5 votes |
public JCSConfiguration(final Configuration<K, V> configuration, final Class<K> keyType, final Class<V> valueType) { this.keyType = keyType; this.valueType = valueType; if (configuration instanceof CompleteConfiguration) { final CompleteConfiguration<K, V> cConfiguration = (CompleteConfiguration<K, V>) configuration; storeByValue = configuration.isStoreByValue(); readThrough = cConfiguration.isReadThrough(); writeThrough = cConfiguration.isWriteThrough(); statisticsEnabled = cConfiguration.isStatisticsEnabled(); managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<>(); final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations = cConfiguration .getCacheEntryListenerConfigurations(); if (entryListenerConfigurations != null) { for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration : entryListenerConfigurations) { cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration); } } } else { expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); storeByValue = true; readThrough = false; writeThrough = false; statisticsEnabled = false; managementEnabled = false; cacheLoaderFactory = null; cacheWristerFactory = null; cacheEntryListenerConfigurations = new HashSet<>(); } }
Example 2
Source File: Builder.java From triava with Apache License 2.0 | 4 votes |
/** * Copies the configuration to the target Builder. If the source (configuration) * is also a Builder, its fields also get copied. Any null-value in the * configuration is ignored in the copying process, leaving the corresponding * target value unchanged. The CacheWriteMode can be * defined in two ways: If configuration is a Builder it is copied plainly, * otherwise it is derived from configuration.isStoreByValue(). * * @param configuration The source builder * @param target The target builder */ private void copyBuilder(Configuration<K, V> configuration, Builder<K, V> target) { CacheWriteMode tcacheWriteMode = null; if (configuration instanceof Builder) { Builder<K, V> sourceB = (Builder<K, V>)configuration; // tCache native configuration if (sourceB.id != null) target.id = sourceB.id; target.strictJSR107 = sourceB.strictJSR107; target.maxCacheTime = sourceB.maxCacheTime; target.maxCacheTimeSpread = sourceB.maxCacheTimeSpread; this.cleanUpIntervalMillis = sourceB.cleanUpIntervalMillis; target.expectedMapSize = sourceB.expectedMapSize; target.concurrencyLevel = sourceB.concurrencyLevel; if (sourceB.evictionPolicy != null) target.evictionPolicy = sourceB.evictionPolicy; if (sourceB.evictionClass != null) target.evictionClass = sourceB.evictionClass; if (sourceB.hashImplementation != null) target.hashImplementation = sourceB.hashImplementation; if (sourceB.jamPolicy != null) target.jamPolicy = sourceB.jamPolicy; if (sourceB.loader != null) target.loader = sourceB.loader; // loader vs loaderFactory tcacheWriteMode = sourceB.writeMode; } if (configuration instanceof CompleteConfiguration) { CompleteConfiguration<K,V> cc = (CompleteConfiguration<K,V>)configuration; target.statistics = cc.isStatisticsEnabled(); target.management = cc.isManagementEnabled(); target.expiryPolicyFactory = cc.getExpiryPolicyFactory(); target.writerFactory = cc.getCacheWriterFactory(); Factory<javax.cache.integration.CacheLoader<K, V>> lf = cc.getCacheLoaderFactory(); if (lf != null) { target.loader = null; // loader vs loaderFactory target.loaderFactory = lf; } Collection<CacheEntryListenerConfiguration<K, V>> listenerConfsCopy = new ArrayList<>(0); for (CacheEntryListenerConfiguration<K, V> entry : cc.getCacheEntryListenerConfigurations()) { listenerConfsCopy.add(entry); } target.listenerConfigurations = listenerConfsCopy; target.writeThrough = cc.isWriteThrough(); target.readThrough = cc.isReadThrough(); } // JSR107 configuration follows if (tcacheWriteMode != null) target.writeMode = tcacheWriteMode; else target.writeMode = CacheWriteMode.fromStoreByValue(configuration.isStoreByValue()); target.keyType = configuration.getKeyType(); target.valueType = configuration.getValueType(); }
Example 3
Source File: BlazingCacheCache.java From blazingcache with Apache License 2.0 | 4 votes |
public BlazingCacheCache(String cacheName, CacheClient client, CacheManager cacheManager, Serializer<K, String, String> keysSerializer, Serializer<V, InputStream, byte[]> valuesSerializer, boolean usefetch, Configuration<K, V> configuration) { this.cacheName = cacheName; this.cacheManager = cacheManager; this.client = client; this.keysSerializer = keysSerializer; this.valuesSerializer = valuesSerializer; this.valueType = configuration.getValueType(); this.keyType = configuration.getKeyType(); this.usefetch = usefetch; this.configurationMXBean = new BlazingCacheConfigurationMXBean<>(this); this.statisticsMXBean = new BlazingCacheStatisticsMXBean<>(this); this.storeByReference = !configuration.isStoreByValue(); if (configuration instanceof CompleteConfiguration) { this.configuration = new MutableConfiguration<>((CompleteConfiguration<K, V>) configuration); CompleteConfiguration<K, V> cc = (CompleteConfiguration<K, V>) configuration; if (cc.getExpiryPolicyFactory() == null) { throw new IllegalArgumentException("ExpiryPolicyFactory cannot be null"); } else { ExpiryPolicy _policy = cc.getExpiryPolicyFactory().create();; if (_policy == null) { throw new IllegalArgumentException("ExpiryPolicy cannot be null"); } if (_policy instanceof EternalExpiryPolicy) { this.policy = null; // shortcut for the most common case } else { this.policy = _policy; } } if (cc.getCacheLoaderFactory() != null) { cacheLoader = (CacheLoader) cc.getCacheLoaderFactory().create(); } else { cacheLoader = null; } if (cc.getCacheWriterFactory() != null) { cacheWriter = (CacheWriter<K, V>) cc.getCacheWriterFactory().create(); } else { cacheWriter = null; } isReadThrough = cc.isReadThrough(); isWriteThrough = cc.isWriteThrough(); needPreviuosValueForListeners = policy != null; if (cc.getCacheEntryListenerConfigurations() != null) { for (CacheEntryListenerConfiguration<K, V> listenerConfig : cc.getCacheEntryListenerConfigurations()) { configureListener(listenerConfig); } } } else { this.configuration = new MutableConfiguration<K, V>() .setTypes(configuration.getKeyType(), configuration.getValueType()) .setStoreByValue(configuration.isStoreByValue()); this.policy = null; // means "eternal" cacheLoader = null; needPreviuosValueForListeners = false; cacheWriter = null; isReadThrough = false; isWriteThrough = false; } if (isReadThrough && cacheLoader == null) { throw new IllegalArgumentException("cache isReadThrough=" + isReadThrough + " cacheLoader=" + cacheLoader); } if (isWriteThrough && cacheWriter == null) { throw new IllegalArgumentException("cache isWriteThrough=" + isWriteThrough + " cacheWriter=" + cacheWriter); } if (this.configuration.isManagementEnabled()) { setManagementEnabled(true); } if (this.configuration.isStatisticsEnabled()) { setStatisticsEnabled(true); } }
Example 4
Source File: Eh107CompleteConfiguration.java From ehcache3 with Apache License 2.0 | 4 votes |
public Eh107CompleteConfiguration(Configuration<K, V> config, final CacheConfiguration<K, V> ehcacheConfig, boolean useEhcacheExpiry, boolean useEhcacheLoaderWriter) { this.ehcacheConfig = ehcacheConfig; this.keyType = config.getKeyType(); this.valueType = config.getValueType(); this.isStoreByValue = isStoreByValue(config, ehcacheConfig); Factory<ExpiryPolicy> tempExpiryPolicyFactory = EternalExpiryPolicy.factoryOf(); if (config instanceof CompleteConfiguration) { CompleteConfiguration<K, V> completeConfig = (CompleteConfiguration<K, V>) config; this.isReadThrough = completeConfig.isReadThrough(); this.isWriteThrough = completeConfig.isWriteThrough(); this.isStatisticsEnabled = completeConfig.isStatisticsEnabled(); this.isManagementEnabled = completeConfig.isManagementEnabled(); if (useEhcacheLoaderWriter) { this.cacheLoaderFactory = createThrowingFactory(); this.cacheWriterFactory = createThrowingFactory(); } else { this.cacheLoaderFactory = completeConfig.getCacheLoaderFactory(); this.cacheWriterFactory = completeConfig.getCacheWriterFactory(); } tempExpiryPolicyFactory = completeConfig.getExpiryPolicyFactory(); for (CacheEntryListenerConfiguration<K, V> listenerConfig : completeConfig.getCacheEntryListenerConfigurations()) { cacheEntryListenerConfigs.add(listenerConfig); } } else { this.isReadThrough = false; this.isWriteThrough = false; this.isStatisticsEnabled = false; this.isManagementEnabled = false; this.cacheLoaderFactory = null; this.cacheWriterFactory = null; } if (useEhcacheExpiry) { tempExpiryPolicyFactory = createThrowingFactory(); } this.expiryPolicyFactory = tempExpiryPolicyFactory; }
Example 5
Source File: EhCache107ConfigurationIntegrationDocTest.java From ehcache3 with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testWithoutEhcacheExplicitDependencyAndNoCodeChanges() throws Exception { CacheManager manager = cachingProvider.getCacheManager( getClass().getResource("/org/ehcache/docs/ehcache-jsr107-template-override.xml").toURI(), getClass().getClassLoader()); // tag::jsr107SupplementWithTemplatesExample[] MutableConfiguration<Long, Client> mutableConfiguration = new MutableConfiguration<>(); mutableConfiguration.setTypes(Long.class, Client.class); // <1> Cache<Long, Client> anyCache = manager.createCache("anyCache", mutableConfiguration); // <2> CacheRuntimeConfiguration<Long, Client> ehcacheConfig = (CacheRuntimeConfiguration<Long, Client>)anyCache.getConfiguration( Eh107Configuration.class).unwrap(CacheRuntimeConfiguration.class); // <3> ehcacheConfig.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize(); // <4> Cache<Long, Client> anotherCache = manager.createCache("byRefCache", mutableConfiguration); assertFalse(anotherCache.getConfiguration(Configuration.class).isStoreByValue()); // <5> MutableConfiguration<String, Client> otherConfiguration = new MutableConfiguration<>(); otherConfiguration.setTypes(String.class, Client.class); otherConfiguration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // <6> Cache<String, Client> foosCache = manager.createCache("foos", otherConfiguration);// <7> CacheRuntimeConfiguration<Long, Client> foosEhcacheConfig = (CacheRuntimeConfiguration<Long, Client>)foosCache.getConfiguration( Eh107Configuration.class).unwrap(CacheRuntimeConfiguration.class); Client client1 = new Client("client1", 1); foosEhcacheConfig.getExpiryPolicy().getExpiryForCreation(42L, client1).toMinutes(); // <8> CompleteConfiguration<String, String> foosConfig = foosCache.getConfiguration(CompleteConfiguration.class); try { final Factory<ExpiryPolicy> expiryPolicyFactory = foosConfig.getExpiryPolicyFactory(); ExpiryPolicy expiryPolicy = expiryPolicyFactory.create(); // <9> throw new AssertionError("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // Expected } // end::jsr107SupplementWithTemplatesExample[] assertThat(ehcacheConfig.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L)); assertThat(foosEhcacheConfig.getExpiryPolicy().getExpiryForCreation(42L, client1), is(java.time.Duration.ofMinutes(2))); }
Example 6
Source File: CopyCacheProxy.java From cache2k with Apache License 2.0 | 4 votes |
/** * Delegates to the wrapped cache. Wrap configuration and return true on store by value */ @SuppressWarnings("unchecked") @Override public <C extends Configuration<K, T>> C getConfiguration(Class<C> clazz) { final C c = cache.getConfiguration(clazz); if (c instanceof CompleteConfiguration) { final CompleteConfiguration<K, T> cc = (CompleteConfiguration<K,T>) c; return (C) new CompleteConfiguration<K, T>() { @Override public Iterable<CacheEntryListenerConfiguration<K, T>> getCacheEntryListenerConfigurations() { return cc.getCacheEntryListenerConfigurations(); } @Override public boolean isReadThrough() { return cc.isReadThrough(); } @Override public boolean isWriteThrough() { return cc.isWriteThrough(); } @Override public boolean isStatisticsEnabled() { return cc.isStatisticsEnabled(); } @Override public boolean isManagementEnabled() { return cc.isManagementEnabled(); } @Override public Factory<CacheLoader<K, T>> getCacheLoaderFactory() { return cc.getCacheLoaderFactory(); } @Override public Factory<CacheWriter<? super K, ? super T>> getCacheWriterFactory() { return cc.getCacheWriterFactory(); } @Override public Factory<ExpiryPolicy> getExpiryPolicyFactory() { return cc.getExpiryPolicyFactory(); } @Override public Class<K> getKeyType() { return cc.getKeyType(); } @Override public Class<T> getValueType() { return cc.getValueType(); } @Override public boolean isStoreByValue() { return true; } }; } else if (c instanceof Configuration) { return (C) new Configuration<K, T>() { @Override public Class<K> getKeyType() { return c.getKeyType(); } @Override public Class<T> getValueType() { return c.getValueType(); } @Override public boolean isStoreByValue() { return true; } }; } return c; }