Revision 41466
Added by Sandro La Bruzzo about 8 years ago
AbstractObjectStoreAction.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.objectstore.modular; |
2 | 2 |
|
3 |
import java.util.concurrent.Executor; |
|
4 |
import java.util.concurrent.Executors; |
|
5 |
|
|
3 | 6 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
7 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
8 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
9 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerAction; |
|
10 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
4 | 13 |
|
5 | 14 |
/** |
6 | 15 |
* The Class AbstractObjectStoreAction. |
7 | 16 |
*/ |
8 |
public class AbstractObjectStoreAction {
|
|
17 |
public abstract class AbstractObjectStoreAction implements BlackboardServerAction<ObjectStoreActions> {
|
|
9 | 18 |
|
19 |
/** |
|
20 |
* Logger |
|
21 |
*/ |
|
22 |
private static final Log log = LogFactory.getLog(AbstractObjectStoreAction.class); |
|
23 |
private final Executor executor = Executors.newCachedThreadPool(); |
|
10 | 24 |
/** The object store dao. */ |
11 | 25 |
private ObjectStoreDao dao; |
12 | 26 |
|
27 |
protected abstract void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws ObjectStoreServiceException; |
|
28 |
|
|
29 |
@Override |
|
30 |
public void execute(final BlackboardServerHandler handler, final BlackboardJob job) { |
|
31 |
executor.execute(new Runnable() { |
|
32 |
|
|
33 |
@Override |
|
34 |
public void run() { |
|
35 |
try { |
|
36 |
handler.ongoing(job); |
|
37 |
executeAsync(handler, job); |
|
38 |
} catch (ObjectStoreServiceException e) { |
|
39 |
handler.failed(job, e); |
|
40 |
} |
|
41 |
} |
|
42 |
}); |
|
43 |
} |
|
44 |
|
|
45 |
protected void completeWithSuccess(final BlackboardServerHandler handler, final BlackboardJob job) { |
|
46 |
// Don't change this synchronization rule |
|
47 |
synchronized (this) { |
|
48 |
handler.done(job); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
protected void completeWithFail(final BlackboardServerHandler handler, final BlackboardJob job, final Throwable e) { |
|
53 |
// Don't change this synchronization rule |
|
54 |
synchronized (this) { |
|
55 |
handler.failed(job, e); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
13 | 59 |
/** |
14 | 60 |
* Gets the dao. |
15 | 61 |
* |
Also available in: Unified diff
implemented Drop content action