1
|
package eu.dnetlib.data.objectstore.modular;
|
2
|
|
3
|
import java.util.concurrent.Executor;
|
4
|
import java.util.concurrent.Executors;
|
5
|
|
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;
|
13
|
|
14
|
/**
|
15
|
* The Class AbstractObjectStoreAction.
|
16
|
*/
|
17
|
public abstract class AbstractObjectStoreAction implements BlackboardServerAction<ObjectStoreActions> {
|
18
|
|
19
|
/**
|
20
|
* Logger
|
21
|
*/
|
22
|
private static final Log log = LogFactory.getLog(AbstractObjectStoreAction.class);
|
23
|
private final Executor executor = Executors.newCachedThreadPool();
|
24
|
/** The object store dao. */
|
25
|
private ObjectStoreDao dao;
|
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
|
|
59
|
/**
|
60
|
* Gets the dao.
|
61
|
*
|
62
|
* @return the dao
|
63
|
*/
|
64
|
public ObjectStoreDao getDao() {
|
65
|
return dao;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* Sets the dao.
|
70
|
*
|
71
|
* @param dao the new dao
|
72
|
*/
|
73
|
public void setDao(ObjectStoreDao dao) {
|
74
|
this.dao = dao;
|
75
|
}
|
76
|
|
77
|
}
|