Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 5da22b1

Browse files
committed
Merge pull request #3 from emmartins/JBEE-122-sync-with-spec-final-release
JBEE-122: update to match spec's final release. No javadocs or cosmetic ...
2 parents 0cdd203 + e3bcc38 commit 5da22b1

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

src/main/java/javax/enterprise/concurrent/ManagedExecutors.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package javax.enterprise.concurrent;
22

3-
import java.util.Locale;
3+
import java.util.HashMap;
44
import java.util.Map;
55
import java.util.concurrent.Callable;
66

@@ -14,65 +14,80 @@ public static boolean isCurrentThreadShutdown() {
1414
return thread instanceof ManageableThread && ((ManageableThread)thread).isShutdown();
1515
}
1616

17-
public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) {
17+
public static <V> Callable<V> managedTask(Callable<V> task, ManagedTaskListener taskListener) throws IllegalArgumentException {
1818
return new ManagedCallable<V>(task, taskListener, null);
1919
}
2020

21-
public static <V> Callable<V> managedTask(Callable<V> task, Map<String, String> executionProperties, ManagedTaskListener taskListener) {
21+
public static <V> Callable<V> managedTask(Callable<V> task, Map<String, String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException {
2222
return new ManagedCallable<V>(task, taskListener, executionProperties);
2323
}
2424

25-
static class ManagedCallable<V> implements Callable<V>, ManagedTask {
25+
static class ManagedCallable<V> extends AbstractManagedTask implements Callable<V> {
2626
private final Callable<V> task;
27-
private final ManagedTaskListener taskListener;
28-
private final Map<String, String> executionProperties;
2927

3028
ManagedCallable(final Callable<V> task, final ManagedTaskListener taskListener, final Map<String, String> executionProperties) {
29+
super(task, taskListener, executionProperties);
3130
this.task = task;
32-
this.taskListener = taskListener;
33-
this.executionProperties = executionProperties;
3431
}
3532

3633
public V call() throws Exception {
3734
return task.call();
3835
}
39-
40-
public Map<String, String> getExecutionProperties() {
41-
return executionProperties;
42-
}
43-
44-
public ManagedTaskListener getManagedTaskListener() {
45-
return taskListener;
46-
}
4736
}
4837

49-
public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) {
38+
public static Runnable managedTask(Runnable task, ManagedTaskListener taskListener) throws IllegalArgumentException {
5039
return new ManagedRunnable(task, taskListener, null);
5140
}
5241

53-
public static Runnable managedTask(Runnable task, Map<String, String> executionProperties, ManagedTaskListener taskListener) {
42+
public static Runnable managedTask(Runnable task, Map<String, String> executionProperties, ManagedTaskListener taskListener) throws IllegalArgumentException {
5443
return new ManagedRunnable(task, taskListener, executionProperties);
5544
}
5645

57-
static class ManagedRunnable implements Runnable, ManagedTask {
46+
static class ManagedRunnable extends AbstractManagedTask implements Runnable {
5847
private final Runnable task;
59-
private final ManagedTaskListener taskListener;
60-
private final Map<String, String> executionProperties;
6148

6249
ManagedRunnable(final Runnable task, final ManagedTaskListener taskListener, final Map<String, String> executionProperties) {
50+
super(task, taskListener, executionProperties);
6351
this.task = task;
64-
this.taskListener = taskListener;
65-
this.executionProperties = executionProperties;
6652
}
6753

6854
public void run() {
6955
task.run();
7056
}
57+
}
58+
59+
abstract static class AbstractManagedTask implements ManagedTask {
60+
private final ManagedTaskListener taskListener;
61+
private Map<String, String> executionProperties = null;
62+
63+
AbstractManagedTask(Object task, ManagedTaskListener taskListener, Map<String, String> executionProperties) throws IllegalArgumentException {
64+
if (task == null) {
65+
throw new IllegalArgumentException("null task");
66+
}
67+
final ManagedTask managedTask = task instanceof ManagedTask ? (ManagedTask) task : null;
68+
if (taskListener != null) {
69+
this.taskListener = taskListener;
70+
} else {
71+
this.taskListener = managedTask != null ? managedTask.getManagedTaskListener() : null;
72+
}
73+
if (managedTask != null && managedTask.getExecutionProperties() != null) {
74+
this.executionProperties = new HashMap<String, String>(managedTask.getExecutionProperties());
75+
}
76+
if (executionProperties != null) {
77+
if (this.executionProperties == null) {
78+
this.executionProperties = new HashMap<String, String>(executionProperties);
79+
} else {
80+
this.executionProperties.putAll(executionProperties);
81+
}
82+
}
83+
}
7184

85+
@Override
7286
public Map<String, String> getExecutionProperties() {
7387
return executionProperties;
7488
}
7589

90+
@Override
7691
public ManagedTaskListener getManagedTaskListener() {
7792
return taskListener;
7893
}

src/main/java/javax/enterprise/concurrent/ManagedTaskListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
/**
66
*/
77
public interface ManagedTaskListener {
8-
void taskAborted(Future<?> future, ManagedExecutorService executor, Throwable exception);
8+
void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception);
99

10-
void taskDone(Future<?> future, ManagedExecutorService executor, Throwable exception);
10+
void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception);
1111

12-
void taskStarting(Future<?> future, ManagedExecutorService executor);
12+
void taskStarting(Future<?> future, ManagedExecutorService executor, Object task);
1313

14-
void taskSubmitted(Future<?> future, ManagedExecutorService executor);
14+
void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task);
1515
}

0 commit comments

Comments
 (0)