Skip to content

Commit

Permalink
JBRULES-3304: ensuring that the work item unmarshaller uses the ruleb…
Browse files Browse the repository at this point in the history
…ase classloader
  • Loading branch information
Marco Rietveld authored and etirelli committed Jan 30, 2012
1 parent cbdd2f1 commit 81a6d76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.persistence.Transient;
import javax.persistence.Version;

import org.drools.common.InternalRuleBase;
import org.drools.marshalling.impl.InputMarshaller;
import org.drools.marshalling.impl.MarshallerReaderContext;
import org.drools.marshalling.impl.MarshallerWriteContext;
Expand Down Expand Up @@ -86,13 +87,13 @@ public long getState() {
return workItemByteArray;
}

public WorkItem getWorkItem(Environment env) {
public WorkItem getWorkItem(Environment env, InternalRuleBase ruleBase) {
this.env = env;
if ( workItem == null ) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream( workItemByteArray );
MarshallerReaderContext context = new MarshallerReaderContext( bais,
null,
ruleBase,
null,
null,
env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import org.drools.WorkItemHandlerNotFoundException;
import org.drools.common.InternalKnowledgeRuntime;
import org.drools.common.InternalRuleBase;
import org.drools.impl.KnowledgeBaseImpl;
import org.drools.persistence.PersistenceContext;
import org.drools.persistence.PersistenceContextManager;
import org.drools.persistence.info.WorkItemInfo;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void internalAbortWorkItem(long id) {
WorkItemInfo workItemInfo = context.findWorkItemInfo( id );
// work item may have been aborted
if (workItemInfo != null) {
WorkItemImpl workItem = (WorkItemImpl) workItemInfo.getWorkItem(env);
WorkItemImpl workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
WorkItemHandler handler = (WorkItemHandler) this.workItemHandlers.get(workItem.getName());
if (handler != null) {
handler.abortWorkItem(workItem, this);
Expand Down Expand Up @@ -110,7 +112,7 @@ public void completeWorkItem(long id, Map<String, Object> results) {

// work item may have been aborted
if (workItemInfo != null) {
WorkItem workItem = (WorkItemImpl) workItemInfo.getWorkItem(env);
WorkItem workItem = internalGetWorkItem(workItemInfo);
workItem.setResults(results);
ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
workItem.setState(WorkItem.COMPLETED);
Expand Down Expand Up @@ -144,7 +146,7 @@ public void abortWorkItem(long id) {

// work item may have been aborted
if (workItemInfo != null) {
WorkItem workItem = (WorkItemImpl) workItemInfo.getWorkItem(env);
WorkItem workItem = (WorkItemImpl) internalGetWorkItem(workItemInfo);
ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
workItem.setState(WorkItem.ABORTED);
// process instance may have finished already
Expand Down Expand Up @@ -176,9 +178,16 @@ public WorkItem getWorkItem(long id) {
if (workItemInfo == null) {
return null;
}
return workItemInfo.getWorkItem(env);
return internalGetWorkItem(workItemInfo);
}

private WorkItem internalGetWorkItem(WorkItemInfo workItemInfo) {
Environment env = kruntime.getEnvironment();
InternalRuleBase ruleBase = (InternalRuleBase) ((KnowledgeBaseImpl) kruntime.getKnowledgeBase()).getRuleBase();
WorkItem workItem = workItemInfo.getWorkItem(env, ruleBase);
return workItem;
}

public Set<WorkItem> getWorkItems() {
return new HashSet<WorkItem>();
}
Expand Down

0 comments on commit 81a6d76

Please sign in to comment.