Skip to content

Commit 89f8ff6

Browse files
In progress functionality
1 parent d03fb46 commit 89f8ff6

File tree

18 files changed

+314
-71
lines changed

18 files changed

+314
-71
lines changed

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<properties>
1919
<bt.qa.skip>false</bt.qa.skip>
20-
<dependency-check.skip>true</dependency-check.skip>
2120
</properties>
2221

2322
<description>
@@ -99,7 +98,7 @@
9998
<dependency>
10099
<groupId>org.ehcache</groupId>
101100
<artifactId>ehcache</artifactId>
102-
<version>3.6.3</version>
101+
<version>3.8.0</version>
103102
</dependency>
104103

105104
<!-- Common Lang3 -->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public CachingHelperProviderEhCache() {
4040
}
4141

4242
@Override
43-
public <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
43+
public synchronized <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
4444
Cache<K, V> cache = super.getOrCreateCache(name, keyClass, valueClass);
4545
if (!caches.containsKey(name)) {
4646
configCachePropertyValues(name, cache);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface CachingHelperProvider {
2929
* @param <V> the cache entry value value
3030
* @return the cache instance
3131
*/
32-
<K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass);
32+
<K, V> Cache<K, V> getOrCreateCache(String name, Class<K> keyClass, Class<V> valueClass);
3333

3434
/**
3535
* Create a cache with the specified duration.
@@ -42,7 +42,7 @@ public interface CachingHelperProvider {
4242
* @param <V> the cache entry value value
4343
* @return the cache instance
4444
*/
45-
<K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass, final Duration duration);
45+
<K, V> Cache<K, V> getOrCreateCache(String name, Class<K> keyClass, Class<V> valueClass, Duration duration);
4646

4747
/**
4848
* Create a cache with the specified configuration.
@@ -55,6 +55,6 @@ public interface CachingHelperProvider {
5555
* @param config the cache configuration
5656
* @return the cache instance
5757
*/
58-
<K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass, final Configuration<K, V> config);
58+
<K, V> Cache<K, V> getOrCreateCache(String name, Class<K> keyClass, Class<V> valueClass, Configuration<K, V> config);
5959

6060
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class CachingHelperProviderDefault implements CachingHelperProvider {
2727

2828
// Get unit
2929
TimeUnit unit;
30-
switch (unitType.toLowerCase()) {
30+
switch (unitType) {
3131
case "d":
3232
unit = TimeUnit.DAYS;
3333
break;
@@ -52,7 +52,7 @@ public synchronized void closeCacheManager() {
5252
}
5353

5454
@Override
55-
public <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
55+
public synchronized <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
5656
return getOrCreateCache(name, keyClass, valueClass, getDefaultDuration());
5757
}
5858

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public synchronized void closeCacheManager() {
5252
}
5353

5454
@Override
55-
public <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
55+
public synchronized <K, V> Cache<K, V> getOrCreateCache(final String name, final Class<K> keyClass, final Class<V> valueClass) {
5656
// Return the pre configured cache
5757
return MANAGER.getCache(name, keyClass, valueClass);
5858
}

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/TaskFuture.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import java.util.concurrent.Future;
55

66
/**
7-
* Web applications require a {@link Future} implementation that can be serializable to allow the user session to be
8-
* serialized.
7+
* Web applications require a {@link Future} implementation that can be serializable to allow the user session to be serialized.
98
*
109
* @param <T> the future get result type
1110
* @author Jonathan Austin
1211
* @since 1.0.0
1312
*/
14-
public interface TaskFuture<T> extends Future<T>, Serializable {
13+
public interface TaskFuture<T extends Serializable> extends Future<T>, Serializable {
1514

1615
}

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/TaskMaster.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
import com.github.bordertech.didums.Didums;
44
import com.github.bordertech.taskmaster.exception.RejectedTaskException;
55
import com.github.bordertech.taskmaster.impl.TaskMasterProviderExecutorService;
6+
import java.io.Serializable;
67

78
/**
89
* TaskMaster helps projects run ASYNC tasks.
910
*
1011
* <p>
11-
* TaskMaster allows a Runnable task to be submitted for execution and returns a Future representing that task. The
12-
* Future's get method will return the given result upon successful completion.
12+
* TaskMaster allows a Runnable task to be submitted for execution and returns a Future representing that task. The Future's get method will return
13+
* the given result upon successful completion.
1314
* </p>
1415
* <p>
15-
* As Web applications require a Future implementation that can be serializable, the TaskMaster has a custom interface
16-
* TaskFuture that implements both Future and Serializable. It does not make sense for a Future to be Serializable as it
17-
* is running on a specific thread on a particular server. To allow a Web Application to keep a reference to the Future,
18-
* the default implementation of TaskFuture (ie TaskFutureWrapper) wraps the future by putting the Future on a cache and
19-
* holding onto the cache key that is serializable.
16+
* As Web applications require a Future implementation that can be serializable, the TaskMaster has a custom interface TaskFuture that implements both
17+
* Future and Serializable. It does not make sense for a Future to be Serializable as it is running on a specific thread on a particular server. To
18+
* allow a Web Application to keep a reference to the Future, the default implementation of TaskFuture (ie TaskFutureWrapper) wraps the future by
19+
* putting the Future on a cache and holding onto the cache key that is serializable.
2020
* </p>
2121
*
2222
* @author Jonathan Austin
@@ -40,11 +40,11 @@ public static TaskMasterProvider getProvider() {
4040
}
4141

4242
/**
43-
* Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be
44-
* accepted. Invocation has no additional effect if already shut down.
43+
* Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional
44+
* effect if already shut down.
4545
*
46-
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate
47-
* threads that the caller is not permitted to modify because it does not hold permission
46+
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not
47+
* permitted to modify because it does not hold permission
4848
*/
4949
public static void shutdown() {
5050
PROVIDER.shutdown();
@@ -53,8 +53,8 @@ public static void shutdown() {
5353
/**
5454
* Attempts to stop all actively executing tasks, halts the processing of waiting tasks.
5555
*
56-
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate
57-
* threads that the caller is not permitted to modify because it does not hold permission
56+
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not
57+
* permitted to modify because it does not hold permission
5858
*/
5959
public static void shutdownNow() {
6060
PROVIDER.shutdownNow();
@@ -73,7 +73,7 @@ public static void shutdownNow() {
7373
* @return a Future representing pending completion of the task
7474
* @throws RejectedTaskException if the task cannot be scheduled for execution
7575
*/
76-
public static <T> TaskFuture<T> submit(final Runnable task, final T result) throws RejectedTaskException {
76+
public static <T extends Serializable> TaskFuture<T> submit(final Runnable task, final T result) throws RejectedTaskException {
7777
return PROVIDER.submit(task, result);
7878
}
7979

@@ -88,7 +88,7 @@ public static <T> TaskFuture<T> submit(final Runnable task, final T result) thro
8888
* @return a Future representing pending completion of the task
8989
* @throws RejectedTaskException if the task cannot be scheduled for execution
9090
*/
91-
public static <T> TaskFuture<T> submit(final Runnable task, final T result, final String pool) throws RejectedTaskException {
91+
public static <T extends Serializable> TaskFuture<T> submit(final Runnable task, final T result, final String pool) throws RejectedTaskException {
9292
return PROVIDER.submit(task, result, pool);
9393
}
9494
}

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/TaskMasterProvider.java

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

33
import com.github.bordertech.taskmaster.exception.RejectedTaskException;
4+
import java.io.Serializable;
45

56
/**
67
* TaskMasterProvider helps projects run ASYNC tasks.
@@ -11,19 +12,19 @@
1112
public interface TaskMasterProvider {
1213

1314
/**
14-
* Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be
15-
* accepted. Invocation has no additional effect if already shut down.
15+
* Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional
16+
* effect if already shut down.
1617
*
17-
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate
18-
* threads that the caller is not permitted to modify because it does not hold permission
18+
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not
19+
* permitted to modify because it does not hold permission
1920
*/
2021
void shutdown();
2122

2223
/**
2324
* Attempts to stop all actively executing tasks, halts the processing of waiting tasks.
2425
*
25-
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate
26-
* threads that the caller is not permitted to modify because it does not hold permission
26+
* @throws SecurityException if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not
27+
* permitted to modify because it does not hold permission
2728
*/
2829
void shutdownNow();
2930

@@ -40,7 +41,7 @@ public interface TaskMasterProvider {
4041
* @return a Future representing pending completion of the task
4142
* @throws RejectedTaskException if the task cannot be scheduled for execution
4243
*/
43-
<T> TaskFuture<T> submit(final Runnable task, final T result) throws RejectedTaskException;
44+
<T extends Serializable> TaskFuture<T> submit(Runnable task, T result) throws RejectedTaskException;
4445

4546
/**
4647
* Submits a Runnable task for execution and returns a Future representing that task. The Future's <tt>get</tt>
@@ -53,6 +54,6 @@ public interface TaskMasterProvider {
5354
* @return a Future representing pending completion of the task
5455
* @throws RejectedTaskException if the task cannot be scheduled for execution
5556
*/
56-
<T> TaskFuture<T> submit(final Runnable task, final T result, final String pool) throws RejectedTaskException;
57+
<T extends Serializable> TaskFuture<T> submit(Runnable task, T result, String pool) throws RejectedTaskException;
5758

5859
}

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/impl/TaskFutureResult.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.bordertech.taskmaster.TaskFuture;
44
import com.github.bordertech.taskmaster.exception.TaskMasterException;
5+
import java.io.Serializable;
56
import java.util.concurrent.ExecutionException;
67
import java.util.concurrent.TimeUnit;
78
import java.util.concurrent.TimeoutException;
@@ -14,7 +15,7 @@
1415
* @author Jonathan Austin
1516
* @since 1.0.0
1617
*/
17-
public class TaskFutureResult<T> implements TaskFuture<T> {
18+
public class TaskFutureResult<T extends Serializable> implements TaskFuture<T> {
1819

1920
private final T result;
2021

@@ -42,16 +43,24 @@ public boolean isDone() {
4243

4344
@Override
4445
public T get() throws InterruptedException, ExecutionException {
45-
if (result instanceof TaskMasterException) {
46-
TaskMasterException excp = (TaskMasterException) result;
46+
T res = getResult();
47+
if (res instanceof TaskMasterException) {
48+
TaskMasterException excp = (TaskMasterException) res;
4749
throw new ExecutionException("Error processing future. " + excp.getMessage(), excp);
4850
}
49-
return result;
51+
return res;
5052
}
5153

5254
@Override
5355
public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
5456
return get();
5557
}
5658

59+
/**
60+
* @return the result
61+
*/
62+
protected T getResult() {
63+
return result;
64+
}
65+
5766
}

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/impl/TaskFutureWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.bordertech.taskmaster.TaskFuture;
55
import com.github.bordertech.taskmaster.cache.CachingHelper;
66
import com.github.bordertech.taskmaster.exception.TaskMasterException;
7+
import java.io.Serializable;
78
import java.util.UUID;
89
import java.util.concurrent.ExecutionException;
910
import java.util.concurrent.Future;
@@ -21,7 +22,7 @@
2122
* @author Jonathan Austin
2223
* @since 1.0.0
2324
*/
24-
public class TaskFutureWrapper<T> implements TaskFuture<T> {
25+
public class TaskFutureWrapper<T extends Serializable> implements TaskFuture<T> {
2526

2627
private static final Cache<String, Future> CACHE;
2728

0 commit comments

Comments
 (0)