What should be the ProcessInstance prc variable in your code?
Also, did you have to create synchronized insert (and modify, update)
method in your
wrapper class?
This is beacuse the whole API has to be synchronized within one Object. This
means for me the KSession, the Process and WokItemManager. My object has a
filed what holds the KSession and has delegates for all the functions I use.
To synchronize the process and workitemmanager I do within the _same_ class:
public synchronized int getPrcState(ProcessInstance prc) {
return prc.getState();
}
so everthing is synchronized with the same class.
The class is:
public class DroolsWrapper {
private KnowledgeBase kbase;
public DroolsWrapper() throws FctyException {
kbase = .....
}
public StatefulKnowledgeSessionWrapper newStatefulKnowledgeSession() {
return new StatefulKnowledgeSessionWrapper();
}
public class StatefulKnowledgeSessionWrapper {
private StatefulKnowledgeSession kSession;
public StatefulKnowledgeSessionWrapper(KnowledgeBase kbase, String bcn,
FctyFrame fctyFrame) {
kSession = kbase.newStatefulKnowledgeSession();
}
public synchronized void dispose() {
kSession.dispose();
}
public synchronized WorkItemManager getWorkItemManager() {
return kSession.getWorkItemManager();
}
public synchronized void setGlobal(String string, Object obj) {
kSession.setGlobal(string, obj);
}
public synchronized ProcessInstance startProcess(String string) {
return kSession.startProcess(string);
}
public synchronized FactHandle insert(Object obj) {
logger.debug(obj.toString());
return kSession.insert(obj);
}
public synchronized int fireAllRules() {
return kSession.fireAllRules();
}
public synchronized QueryResults getQueryResults(String string) {
return kSession.getQueryResults(string);
}
public synchronized Object getGlobal(String string) {
return kSession.getGlobal(string);
}
public synchronized void completeWorkItem(WorkItem workItem, Map<String,
Object> results) {
kSession.getWorkItemManager().completeWorkItem(workItem.getId(),
results);
}
public synchronized void abortWorkItem(WorkItem workItem) {
kSession.getWorkItemManager().abortWorkItem(workItem.getId());
}
public synchronized int getPrcState(ProcessInstance prc) {
return prc.getState();
}
public synchronized void completeWorkItem(WorkItem workItem, Exception e)
{
// complete with a Exception
Map<String, Object> results = new HashMap<String, Object>();
results.put("Exception", e);
kSession.getWorkItemManager().completeWorkItem(workItem.getId(),
results);
}
}
}
juergen
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Is-drools-ksession-th...
Sent from the Drools - User mailing list archive at
Nabble.com.