Skip to content

Commit

Permalink
Update to coffig
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Jan 3, 2017
1 parent 7d3045d commit 6b6cf17
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 142 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# Version 3.0.0 (2017-01-03)

* [brk] Update for new configuration system.

# Version 2.1.1 (2016-04-26)

* [chg] Update for SeedStack 16.4
Expand Down
17 changes: 8 additions & 9 deletions pom.xml
Expand Up @@ -15,18 +15,18 @@
<parent>
<groupId>org.seedstack.poms</groupId>
<artifactId>parent-internal</artifactId>
<version>2.4.0</version>
<version>3.0.0</version>
</parent>

<groupId>org.seedstack.addons.jcache</groupId>
<artifactId>jcache</artifactId>
<version>2.1.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>

<properties>
<seed.version>2.3.0</seed.version>
<seed.version>3.0.0</seed.version>
<jcache.version>1.0.0</jcache.version>

<compatibility.version>2.1.0</compatibility.version>
<compatibility.skip>true</compatibility.skip>

<bintray.package>jcache-addon</bintray.package>
</properties>
Expand Down Expand Up @@ -56,6 +56,10 @@
<licenseMerge>Apache 2|Apache License, Version 2.0</licenseMerge>
<licenseMerge>Apache 2|The Apache Software License, Version 2.0</licenseMerge>
<licenseMerge>Apache 2|Apache License 2.0</licenseMerge>
<licenseMerge>Apache 2|Apache License, version 2.0</licenseMerge>
<licenseMerge>Apache 2|Apache License Version 2.0</licenseMerge>
<licenseMerge>Apache 2|JSR-000107 JCACHE 2.9 Public Review - Updated Specification
License</licenseMerge>
<licenseMerge>BSD|The New BSD License</licenseMerge>
<licenseMerge>CDDL|CDDL + GPLv2 with classpath exception</licenseMerge>
<licenseMerge>LGPL 3.0|GNU Lesser Public License</licenseMerge>
Expand All @@ -77,7 +81,6 @@
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>${jcache.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsr107.ri</groupId>
Expand All @@ -88,10 +91,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
<exclusion>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Expand Up @@ -6,8 +6,11 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

[org.seedstack.jcache]
default-provider = org.jsr107.ri.spi.RICachingProvider
caches = testcache1, testcache2
cache.testcache1.expiry-policy-factory = org.seedstack.jcache.SampleExpiryPolicyFactory
cache.testcache1.provider = org.jsr107.ri.spi.RICachingProvider
jcache:
defaultProvider: org.jsr107.ri.spi.RICachingProvider
caches:
testcache1:
provider: org.jsr107.ri.spi.RICachingProvider
expiryPolicyFactory: org.seedstack.jcache.SampleExpiryPolicyFactory
testcache2:

20 changes: 0 additions & 20 deletions src/it/resources/logback-test.xml

This file was deleted.

152 changes: 152 additions & 0 deletions src/main/java/org/seedstack/jcache/JCacheConfig.java
@@ -0,0 +1,152 @@
/**
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.jcache;

import org.seedstack.coffig.Config;

import javax.cache.configuration.Factory;
import javax.cache.expiry.AccessedExpiryPolicy;
import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.Duration;
import javax.cache.expiry.EternalExpiryPolicy;
import javax.cache.expiry.ModifiedExpiryPolicy;
import javax.cache.expiry.TouchedExpiryPolicy;
import javax.cache.spi.CachingProvider;
import java.util.HashMap;
import java.util.Map;

@Config("jcache")
public class JCacheConfig {

private Class<? extends CachingProvider> defaultProvider;
private Map<String, CacheConfig> caches = new HashMap<>();

public Class<? extends CachingProvider> getDefaultProvider() {
return defaultProvider;
}

public JCacheConfig setDefaultProvider(Class<? extends CachingProvider> defaultProvider) {
this.defaultProvider = defaultProvider;
return this;
}

public Map<String, CacheConfig> getCaches() {
return caches;
}

public JCacheConfig addCache(String name, CacheConfig config) {
this.caches.put(name, config);
return this;
}

public static class CacheConfig {
private Class<? extends CachingProvider> provider;
private ExpiryPolicy expiryPolicy;
private long expiryDuration = 900;
private Class<? extends Factory<? extends javax.cache.expiry.ExpiryPolicy>> expiryPolicyFactory;

public Class<? extends CachingProvider> getProvider() {
return provider;
}

public CacheConfig setProvider(Class<? extends CachingProvider> provider) {
this.provider = provider;
return this;
}

public ExpiryPolicy getExpiryPolicy() {
return expiryPolicy;
}

public CacheConfig setExpiryPolicy(ExpiryPolicy expiryPolicy) {
this.expiryPolicy = expiryPolicy;
return this;
}

public long getExpiryDuration() {
return expiryDuration;
}

public CacheConfig setExpiryDuration(long expiryDuration) {
this.expiryDuration = expiryDuration;
return this;
}

public Class<? extends Factory<? extends javax.cache.expiry.ExpiryPolicy>> getExpiryPolicyFactory() {
return expiryPolicyFactory;
}

public CacheConfig setExpiryPolicyFactory(Class<? extends Factory<? extends javax.cache.expiry.ExpiryPolicy>> expiryPolicyFactory) {
this.expiryPolicyFactory = expiryPolicyFactory;
return this;
}
}

/**
* Enumerates all built-in expiry policies.
*/
public enum ExpiryPolicy {
/**
* An {@link javax.cache.expiry.ExpiryPolicy} that defines the expiry {@link Duration}
* of a Cache Entry based on when it was last touched. A touch includes
* creation, update or access.
*/
TOUCHED(TouchedExpiryPolicy.class, true),

/**
* An {@link javax.cache.expiry.ExpiryPolicy} that defines the expiry {@link Duration}
* of a Cache Entry based on the last time it was accessed. Accessed
* does not include a cache update.
*/
ACCESSED(AccessedExpiryPolicy.class, true),

/**
* An {@link javax.cache.expiry.ExpiryPolicy} that defines the expiry {@link Duration}
* of a Cache Entry based on when it was created. An update does not reset
* the expiry time.
*/
CREATED(CreatedExpiryPolicy.class, true),

/**
* An eternal {@link javax.cache.expiry.ExpiryPolicy} specifies that Cache Entries
* won't expire. This however doesn't mean they won't be evicted if an
* underlying implementation needs to free-up resources where by it may
* choose to evict entries that are not due to expire.
*/
ETERNAL(EternalExpiryPolicy.class, false),

/**
* An {@link javax.cache.expiry.ExpiryPolicy} that defines the expiry {@link Duration}
* of a Cache Entry based on the last time it was updated. Updating
* includes created and changing (updating) an entry.
*/
MODIFIED(ModifiedExpiryPolicy.class, true);

private static final String FACTORY_OF = "factoryOf";
private final Class<? extends javax.cache.expiry.ExpiryPolicy> expiryPolicyClass;
private final boolean hasDuration;

ExpiryPolicy(Class<? extends javax.cache.expiry.ExpiryPolicy> expiryPolicyClass, boolean hasDuration) {
this.expiryPolicyClass = expiryPolicyClass;
this.hasDuration = hasDuration;
}

@SuppressWarnings("unchecked")
public Factory<javax.cache.expiry.ExpiryPolicy> getFactory(Duration duration) {
try {
if (hasDuration) {
return (Factory<javax.cache.expiry.ExpiryPolicy>) this.expiryPolicyClass.getDeclaredMethod(FACTORY_OF, Duration.class).invoke(null, duration);
} else {
return (Factory<javax.cache.expiry.ExpiryPolicy>) this.expiryPolicyClass.getDeclaredMethod(FACTORY_OF).invoke(null);
}
} catch (Exception e) {
throw new RuntimeException("Unable to create expiry policy " + expiryPolicyClass.getCanonicalName(), e);
}
}
}
}

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/java/org/seedstack/jcache/internal/CacheConcern.java
Expand Up @@ -15,8 +15,6 @@

/**
* Nuun concern for ordering jcache operations.
*
* @author adrien.lauer@mpsa.com
*/
@Retention(RetentionPolicy.RUNTIME)
@Concern(name="jcache-concern", priority= Concern.Priority.HIGH)
Expand Down

0 comments on commit 6b6cf17

Please sign in to comment.