[jboss-svn-commits] JBL Code SVN: r25907 - labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Apr 1 15:33:19 EDT 2009
Author: salaboy21
Date: 2009-04-01 15:33:19 -0400 (Wed, 01 Apr 2009)
New Revision: 25907
Modified:
labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java
labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/ProcessInstanceMarshaller.java
Log:
refactor processInstanceMarshaller for include and exclude the variables from serialization process
Modified: labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java 2009-04-01 19:32:20 UTC (rev 25906)
+++ labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/AbstractProcessInstanceMarshaller.java 2009-04-01 19:33:19 UTC (rev 25907)
@@ -46,9 +46,12 @@
ProcessInstanceMarshaller {
// Output methods
-
+ public void writeProcessInstance(MarshallerWriteContext context,
+ ProcessInstance processInstance) throws IOException {
+ writeProcessInstance(context, processInstance, true);
+ }
public void writeProcessInstance(MarshallerWriteContext context,
- ProcessInstance processInstance) throws IOException {
+ ProcessInstance processInstance, boolean includeVariables) throws IOException {
WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
ObjectOutputStream stream = context.stream;
@@ -56,21 +59,22 @@
stream.writeUTF(workFlow.getProcessId());
stream.writeInt(workFlow.getState());
stream.writeLong(workFlow.getNodeInstanceCounter());
-
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance( VariableScope.VARIABLE_SCOPE );
- Map<String, Object> variables = variableScopeInstance.getVariables();
- List<String> keys = new ArrayList<String>( variables.keySet() );
- Collections.sort( keys,
- new Comparator<String>() {
- public int compare(String o1,
- String o2) {
- return o1.compareTo( o2 );
- }
- } );
- stream.writeInt( keys.size() );
- for ( String key : keys ) {
- stream.writeUTF( key );
- stream.writeObject( variables.get( key ) );
+ if(includeVariables){
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance( VariableScope.VARIABLE_SCOPE );
+ Map<String, Object> variables = variableScopeInstance.getVariables();
+ List<String> keys = new ArrayList<String>( variables.keySet() );
+ Collections.sort( keys,
+ new Comparator<String>() {
+ public int compare(String o1,
+ String o2) {
+ return o1.compareTo( o2 );
+ }
+ } );
+ stream.writeInt( keys.size() );
+ for ( String key : keys ) {
+ stream.writeUTF( key );
+ stream.writeObject( variables.get( key ) );
+ }
}
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance( SwimlaneContext.SWIMLANE_SCOPE );
@@ -212,8 +216,10 @@
}
// Input methods
-
- public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
+ return readProcessInstance(context, true);
+ }
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context, boolean readVariables) throws IOException {
ObjectInputStream stream = context.stream;
InternalRuleBase ruleBase = context.ruleBase;
InternalWorkingMemory wm = context.wm;
@@ -230,23 +236,25 @@
long nodeInstanceCounter = stream.readLong();
processInstance.setWorkingMemory(wm);
- int nbVariables = stream.readInt();
- if (nbVariables > 0) {
- Context variableScope = process
- .getDefaultContext(VariableScope.VARIABLE_SCOPE);
- VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
- processInstance.getContextInstance(variableScope);
- for (int i = 0; i < nbVariables; i++) {
- String name = stream.readUTF();
- try {
- Object value = stream.readObject();
- variableScopeInstance.setVariable(name, value);
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException(
- "Could not reload variable " + name);
- }
- }
- }
+ if(readVariables){
+ int nbVariables = stream.readInt();
+ if (nbVariables > 0) {
+ Context variableScope = process
+ .getDefaultContext(VariableScope.VARIABLE_SCOPE);
+ VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
+ processInstance.getContextInstance(variableScope);
+ for (int i = 0; i < nbVariables; i++) {
+ String name = stream.readUTF();
+ try {
+ Object value = stream.readObject();
+ variableScopeInstance.setVariable(name, value);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(
+ "Could not reload variable " + name);
+ }
+ }
+ }
+ }
int nbSwimlanes = stream.readInt();
if (nbSwimlanes > 0) {
Modified: labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/ProcessInstanceMarshaller.java
===================================================================
--- labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/ProcessInstanceMarshaller.java 2009-04-01 19:32:20 UTC (rev 25906)
+++ labs/jbossrules/branches/salaboy_VariablesPersistenceStrategy2/drools-core/src/main/java/org/drools/marshalling/impl/ProcessInstanceMarshaller.java 2009-04-01 19:33:19 UTC (rev 25907)
@@ -27,11 +27,16 @@
public void writeProcessInstance(MarshallerWriteContext context,
ProcessInstance processInstance) throws IOException;
+ public void writeProcessInstance(MarshallerWriteContext context,
+ ProcessInstance processInstance, boolean includeVariables) throws IOException;
+
public void writeNodeInstance(MarshallerWriteContext context,
NodeInstance nodeInstance) throws IOException;
- public ProcessInstance readProcessInstance(MarshallerReaderContext context)
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context)
throws IOException;
+ public ProcessInstance readProcessInstance(MarshallerReaderContext context, boolean readVariables)
+ throws IOException;
public NodeInstance readNodeInstance(MarshallerReaderContext context,
NodeInstanceContainer nodeInstanceContainer,
More information about the jboss-svn-commits
mailing list