Skip to content

Commit

Permalink
JBPM-4112 - Clean up and migrate ProtobufProcessMarshaller fully to P…
Browse files Browse the repository at this point in the history
…rotoBuf
  • Loading branch information
mswiderski committed Sep 5, 2013
1 parent 6d8af76 commit 797f7bf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.kie.api.runtime.process.ProcessInstance;
import org.drools.core.process.instance.WorkItem;

public interface ProcessMarshaller {

Expand All @@ -21,4 +22,8 @@ public interface ProcessMarshaller {

void init(MarshallerReaderContext context);

void writeWorkItem( MarshallerWriteContext context, WorkItem workItem);

WorkItem readWorkItem(MarshallerReaderContext context);

}
Expand Up @@ -59,6 +59,7 @@
import org.drools.core.phreak.RuleAgendaItem;
import org.drools.core.phreak.RuleExecutor;
import org.drools.core.phreak.StackEntry;
import org.drools.core.process.instance.WorkItem;
import org.drools.core.reteoo.InitialFactImpl;
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.ObjectTypeConf;
Expand Down Expand Up @@ -724,6 +725,10 @@ public static Trigger readTrigger(MarshallerReaderContext inCtx,

}

public static WorkItem readWorkItem( MarshallerReaderContext context ) {
return processMarshaller.readWorkItem( context );
}

public static class PBActivationsFilter
implements
ActivationsFilter,
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.drools.core.marshalling.impl.ProtobufMessages.Timers.Timer;
import org.drools.core.marshalling.impl.ProtobufMessages.Tuple;
import org.drools.core.phreak.RuleAgendaItem;
import org.drools.core.process.instance.WorkItem;
import org.drools.core.reteoo.AccumulateNode.AccumulateContext;
import org.drools.core.reteoo.AccumulateNode.AccumulateMemory;
import org.drools.core.reteoo.BetaMemory;
Expand Down Expand Up @@ -900,4 +901,8 @@ public static ProtobufMessages.Trigger writeTrigger(Trigger trigger,
throw new RuntimeException( "Unable to serialize Trigger for type: " + trigger.getClass() );
}

public static void writeWorkItem( MarshallerWriteContext context, WorkItem workItem ) {
processMarshaller.writeWorkItem( context, workItem );
}

}
Expand Up @@ -21,13 +21,21 @@
import org.drools.core.marshalling.impl.MarshallerReaderContext;
import org.drools.core.marshalling.impl.MarshallerWriteContext;
import org.drools.core.marshalling.impl.OutputMarshaller;
import org.drools.core.marshalling.impl.ProcessMarshaller;
import org.drools.core.marshalling.impl.ProcessMarshallerFactory;
import org.drools.core.marshalling.impl.ProtobufInputMarshaller;
import org.drools.core.marshalling.impl.ProtobufOutputMarshaller;
import org.drools.core.process.instance.WorkItem;
import org.kie.api.runtime.Environment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Entity
@SequenceGenerator(name="workItemInfoIdSeq", sequenceName="WORKITEMINFO_ID_SEQ")
public class WorkItemInfo {


private static final Logger logger = LoggerFactory.getLogger(WorkItemInfo.class);

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="workItemInfoIdSeq")
private Long workItemId;
Expand Down Expand Up @@ -100,12 +108,33 @@ public WorkItem getWorkItem(Environment env, InternalRuleBase ruleBase) {
null,
null,
null,
env);
workItem = InputMarshaller.readWorkItem( context );
env);
try {
workItem = ProtobufInputMarshaller.readWorkItem(context);
} catch (Exception e) {
// for backward compatibility to be able to restore 5.x data
try {
context.close();
bais = new ByteArrayInputStream( workItemByteArray );
context = new MarshallerReaderContext( bais,
ruleBase,
null,
null,
null,
env);

workItem = InputMarshaller.readWorkItem( context );
} catch (IOException e1) {
logger.error("Unable to read work item with InputMarshaller", e1);
// throw the original exception produced by failed protobuf op
throw new RuntimeException("Unable to read work item ", e);
}
}

context.close();
} catch ( IOException e ) {
e.printStackTrace();
throw new IllegalArgumentException( "IOException while loading process instance: " + e.getMessage() );
throw new IllegalArgumentException( "IOException while loading work item: " + e.getMessage() );
}
}
return workItem;
Expand All @@ -116,6 +145,9 @@ public WorkItem getWorkItem(Environment env, InternalRuleBase ruleBase) {
@PreUpdate
public void update() {
this.state = workItem.getState();



ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
MarshallerWriteContext context = new MarshallerWriteContext( baos,
Expand All @@ -124,9 +156,7 @@ public void update() {
null,
null,
this.env);

OutputMarshaller.writeWorkItem( context,
workItem );
ProtobufOutputMarshaller.writeWorkItem(context, workItem);

context.close();
this.workItemByteArray = baos.toByteArray();
Expand All @@ -138,5 +168,6 @@ public void update() {
public void setId(Long id){
this.workItemId = id;
}



}

0 comments on commit 797f7bf

Please sign in to comment.