Skip to content

Commit 01c7401

Browse files
Merge pull request #23 from BorderTech/refactor-submodules
Refactor CacheHelper, TaskMaster, ServiceHelper to the Provider Pattern
2 parents 8c35bc8 + a9c1eed commit 01c7401

File tree

29 files changed

+337
-233
lines changed

29 files changed

+337
-233
lines changed

taskmaster-cache-ehcache/src/main/java/com/github/bordertech/taskmaster/ehcache/CacheHelperEhCachePropertiesConfig.java renamed to taskmaster-cache-ehcache/src/main/java/com/github/bordertech/taskmaster/ehcache/CachingHelperProviderEhCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.bordertech.taskmaster.ehcache;
22

33
import com.github.bordertech.config.Config;
4-
import com.github.bordertech.taskmaster.cache.impl.CacheHelperXmlConfig;
4+
import com.github.bordertech.taskmaster.cache.impl.CachingHelperProviderXmlConfig;
55
import java.beans.PropertyChangeEvent;
66
import java.beans.PropertyChangeListener;
77
import java.util.HashMap;
@@ -21,19 +21,19 @@
2121
import org.ehcache.jsr107.Eh107Configuration;
2222

2323
/**
24-
* Cache Helper that configures ehcache with properties and wraps the cache with JSR107 interface.
24+
* CachingHelperProvider that configures ehcache with properties and wraps the cache with JSR107 interface.
2525
*/
2626
@Singleton
27-
public class CacheHelperEhCachePropertiesConfig extends CacheHelperXmlConfig {
27+
public class CachingHelperProviderEhCache extends CachingHelperProviderXmlConfig {
2828

29-
private static final Log LOGGER = LogFactory.getLog(CacheHelperEhCachePropertiesConfig.class);
29+
private static final Log LOGGER = LogFactory.getLog(CachingHelperProviderEhCache.class);
3030
private static final String CACHE_PREFIX = "Cache [";
3131
private final Map<String, Triple<String, Class, Class>> caches = new HashMap<>();
3232

3333
/**
3434
* Construct Helper.
3535
*/
36-
public CacheHelperEhCachePropertiesConfig() {
36+
public CachingHelperProviderEhCache() {
3737
// Add property change listener
3838
PropertyChangeListener listener = new RefreshCachePropertyChangeListener();
3939
Config.addPropertyChangeListener(listener);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* CacheHelper that can configure ehcache.
2+
* CachingHelperProvider that can configure ehcache.
33
*/
44
package com.github.bordertech.taskmaster.ehcache;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## EHACHE CachingHelperProvider
2+
bordertech.factory.impl.com.github.bordertech.taskmaster.cache.CachingHelperProvider=com.github.bordertech.taskmaster.ehcache.CachingHelperProviderEhCache

taskmaster-cache-helper/pom.xml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,10 @@
3838
<artifactId>cache-api</artifactId>
3939
</dependency>
4040

41-
<!-- Config -->
41+
<!-- Didums Injection -->
4242
<dependency>
43-
<groupId>com.github.bordertech.config</groupId>
44-
<artifactId>config</artifactId>
45-
</dependency>
46-
47-
<!-- Injection interface. JSR 330 -->
48-
<dependency>
49-
<groupId>javax.inject</groupId>
50-
<artifactId>javax.inject</artifactId>
51-
<scope>provided</scope>
43+
<groupId>com.github.bordertech.didums</groupId>
44+
<artifactId>didums-core</artifactId>
5245
</dependency>
5346

5447
<!-- Servlet Interface -->
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.github.bordertech.taskmaster.cache;
2+
3+
import com.github.bordertech.didums.Didums;
4+
import com.github.bordertech.taskmaster.cache.impl.CachingHelperProviderDefault;
5+
6+
/**
7+
* Caching helper based on JSR 107.
8+
* <p>
9+
* Allows projects to provide a different mechanism for creating their cache requirements.
10+
* </p>
11+
*
12+
* @author jonathan
13+
*/
14+
public final class CachingHelper {
15+
16+
private static final CachingHelperProvider PROVIDER;
17+
18+
static {
19+
// Check if instance defined
20+
if (Didums.hasService(CachingHelperProvider.class)) {
21+
PROVIDER = Didums.getService(CachingHelperProvider.class);
22+
} else {
23+
// Default Implementation
24+
PROVIDER = new CachingHelperProviderDefault();
25+
}
26+
}
27+
28+
/**
29+
* Private constructor.
30+
*/
31+
private CachingHelper() {
32+
}
33+
34+
/**
35+
* @return the CachingHelper Provider
36+
*/
37+
public static CachingHelperProvider getProvider() {
38+
return PROVIDER;
39+
}
40+
41+
}

taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/CacheHelper.java renamed to taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/CachingHelperProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import javax.cache.expiry.Duration;
66

77
/**
8-
* Create Cache helper based on JSR 107.
8+
* Caching helper provider based on JSR 107.
99
* <p>
1010
* Allows projects to provide a different mechanism for creating their cache requirements.
1111
* </p>
1212
*
1313
* @author jonathan
1414
*/
15-
public interface CacheHelper {
15+
public interface CachingHelperProvider {
1616

1717
/**
1818
* Create a cache with the specified duration.

taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/impl/CacheHelperDefault.java renamed to taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/impl/CachingHelperProviderDefault.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.bordertech.taskmaster.cache.impl;
22

3-
import com.github.bordertech.taskmaster.cache.CacheHelper;
3+
import com.github.bordertech.taskmaster.cache.CachingHelperProvider;
44
import javax.cache.Cache;
55
import javax.cache.CacheManager;
66
import javax.cache.Caching;
@@ -10,11 +10,11 @@
1010
import javax.cache.expiry.Duration;
1111

1212
/**
13-
* Create Cache helper implementation using JSR107 provider.
13+
* Default CachingHelperProvider implementation using JSR107 provider.
1414
*
1515
* @author jonathan
1616
*/
17-
public class CacheHelperDefault implements CacheHelper {
17+
public class CachingHelperProviderDefault implements CachingHelperProvider {
1818

1919
@Override
2020
public synchronized <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass,

taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/impl/CacheHelperXmlConfig.java renamed to taskmaster-cache-helper/src/main/java/com/github/bordertech/taskmaster/cache/impl/CachingHelperProviderXmlConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.bordertech.taskmaster.cache.impl;
22

33
import com.github.bordertech.config.Config;
4-
import com.github.bordertech.taskmaster.cache.CacheHelper;
4+
import com.github.bordertech.taskmaster.cache.CachingHelperProvider;
55
import java.net.URI;
66
import java.net.URISyntaxException;
77
import javax.cache.Cache;
@@ -15,12 +15,12 @@
1515
import org.apache.commons.logging.LogFactory;
1616

1717
/**
18-
* Cache Helper that relies on the cache config in a xml file.
18+
* CachingHelperProvider that relies on the cache config in a xml file.
1919
*/
2020
@Singleton
21-
public class CacheHelperXmlConfig implements CacheHelper {
21+
public class CachingHelperProviderXmlConfig implements CachingHelperProvider {
2222

23-
private static final Log LOGGER = LogFactory.getLog(CacheHelperXmlConfig.class);
23+
private static final Log LOGGER = LogFactory.getLog(CachingHelperProviderXmlConfig.class);
2424

2525
private static final CacheManager MANAGER;
2626

@@ -30,12 +30,12 @@ public class CacheHelperXmlConfig implements CacheHelper {
3030
LOGGER.info("Loading cache config [" + config + "].");
3131
URI uri;
3232
try {
33-
uri = CacheHelperXmlConfig.class.getResource(config).toURI();
33+
uri = CachingHelperProviderXmlConfig.class.getResource(config).toURI();
3434
} catch (URISyntaxException e) {
3535
throw new IllegalStateException("Could not load cache config [" + config + "]." + e.getMessage(), e);
3636
}
3737
CachingProvider cachingProvider = Caching.getCachingProvider();
38-
MANAGER = cachingProvider.getCacheManager(uri, CacheHelperXmlConfig.class.getClassLoader());
38+
MANAGER = cachingProvider.getCacheManager(uri, CachingHelperProviderXmlConfig.class.getClassLoader());
3939
}
4040

4141
@Override
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* CacheHelper implementations.
2+
* CachingHelperProvider default implementations.
33
*/
44
package com.github.bordertech.taskmaster.cache.impl;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* CacheHelper based on JSR 107.
2+
* CachingHelper based on JSR 107.
33
*/
44
package com.github.bordertech.taskmaster.cache;

0 commit comments

Comments
 (0)