[jboss-svn-commits] JBL Code SVN: r19246 - in labs/jbossrules/branches/4.0.x: drools-core/src/main/java/org/drools/common and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 26 11:49:05 EDT 2008
Author: tirelli
Date: 2008-03-26 11:49:05 -0400 (Wed, 26 Mar 2008)
New Revision: 19246
Modified:
labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
Log:
JBRULES-1521: fixing serialization problem
Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2008-03-26 15:13:51 UTC (rev 19245)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2008-03-26 15:49:05 UTC (rev 19246)
@@ -846,7 +846,7 @@
* session.fireAllRules() is throwing NoClassDefFoundError
*
*/
- public void FIXME_testSerializeAddRemove_NoClassDefFoundError() throws Exception {
+ public void testSerializeAddRemove_NoClassDefFoundError() throws Exception {
//Create a rulebase, a session, and test it
RuleBase ruleBase = RuleBaseFactory.newRuleBase( );
@@ -956,11 +956,13 @@
serializedSession = null;
serializedRulebase = null;
+ // Now serialize rulebase and session again
+ serializedRulebase = serializeOut( ruleBase );
serializedSession = serializeOut( session );
- serializedRulebase = serializeOut( ruleBase );
session.dispose();
-
+
+ // Deserialize the rulebase and the session
ruleBase = (RuleBase) serializeIn( serializedRulebase );
session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) ); // throws java.lang.ClassNotFoundException Exception
results = (List) session.getGlobal( "results" );
@@ -973,9 +975,9 @@
assertEquals( 8,
results.size() );
+ assertEquals( bob8.getObject(),
+ results.get( 6 ) );
assertEquals( bob7.getObject(),
- results.get( 6 ) );
- assertEquals( bob8.getObject(),
results.get( 7 ) );
serializedSession = null;
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2008-03-26 15:13:51 UTC (rev 19245)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2008-03-26 15:49:05 UTC (rev 19246)
@@ -116,5 +116,5 @@
public void setExtractorFactory(ClassFieldExtractorCache extractorFactory) {
this.extractorFactory = extractorFactory;
}
-
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-03-26 15:13:51 UTC (rev 19245)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2008-03-26 15:49:05 UTC (rev 19246)
@@ -16,10 +16,13 @@
* limitations under the License.
*/
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.Serializable;
import org.drools.RuleBaseConfiguration;
import org.drools.common.BaseNode;
+import org.drools.common.DroolsObjectInputStream;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.NodeMemory;
@@ -72,7 +75,7 @@
private final ObjectType objectType;
/** The parent Rete node */
- private final Rete rete;
+ private transient Rete rete;
private boolean skipOnModify = false;
@@ -98,6 +101,12 @@
setObjectMemoryEnabled( context.isObjectTypeNodeMemoryEnabled() );
}
+ private void readObject(ObjectInputStream stream) throws IOException,
+ ClassNotFoundException {
+ stream.defaultReadObject();
+ this.rete = ((DroolsObjectInputStream) stream).getRuleBase().getRete();
+ }
+
/**
* Retrieve the semantic <code>ObjectType</code> differentiator.
*
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java 2008-03-26 15:13:51 UTC (rev 19245)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/Rete.java 2008-03-26 15:49:05 UTC (rev 19246)
@@ -428,14 +428,15 @@
protected Class shadowClass;
protected transient ObjectInstantiator instantiator;
- private ObjectTypeNode concreteObjectTypeNode;
+ private transient ObjectTypeNode concreteObjectTypeNode;
+ private ObjectType objectType;
public ClassObjectTypeConf(Class clazz,
InternalRuleBase ruleBase) {
this.cls = clazz;
this.ruleBase = ruleBase;
- ObjectType objectType = new ClassObjectType( clazz );
+ objectType = new ClassObjectType( clazz );
this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
// JBRULES-1315: do not add OTN dynamically anymore
@@ -599,6 +600,7 @@
ClassNotFoundException {
stream.defaultReadObject();
this.ruleBase = ((DroolsObjectInputStream) stream).getRuleBase();
+ this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
}
/**
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2008-03-26 15:13:51 UTC (rev 19245)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2008-03-26 15:49:05 UTC (rev 19246)
@@ -16,13 +16,13 @@
* limitations under the License.
*/
+import java.io.IOException;
import java.io.Serializable;
-import org.drools.common.EventSupport;
import org.drools.RuleBaseConfiguration;
-import org.drools.common.BinaryHeapQueueAgendaGroup;
import org.drools.common.AgendaItem;
import org.drools.common.BaseNode;
+import org.drools.common.EventSupport;
import org.drools.common.InternalAgenda;
import org.drools.common.InternalAgendaGroup;
import org.drools.common.InternalFactHandle;
@@ -62,8 +62,8 @@
// Instance members
// ------------------------------------------------------------
- private int sequence;
-
+ private int sequence;
+
/**
*
*/
@@ -79,9 +79,9 @@
private TupleSinkNode previousTupleSinkNode;
private TupleSinkNode nextTupleSinkNode;
-
- protected boolean tupleMemoryEnabled;
+ protected boolean tupleMemoryEnabled;
+
// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
@@ -118,7 +118,7 @@
public Rule getRule() {
return this.rule;
}
-
+
public void setSequence(int seq) {
this.sequence = seq;
}
@@ -126,7 +126,7 @@
public int getSequence() {
return this.sequence;
}
-
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// org.drools.impl.TupleSink
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -195,14 +195,14 @@
agenda.scheduleItem( item );
tuple.setActivation( item );
-
+
if ( this.tupleMemoryEnabled ) {
memory.getTupleMemory().add( tuple );
}
item.setActivated( true );
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
- workingMemory );
+ workingMemory );
} else {
// -----------------
// Lazy instantiation and addition to the Agenda of AgendGroup
@@ -232,11 +232,12 @@
final AgendaItem item = new AgendaItem( context.getPropagationNumber(),
cloned,
- rule.getSalience().getValue( tuple, workingMemory ),
+ rule.getSalience().getValue( tuple,
+ workingMemory ),
context,
this.rule,
this.subrule );
-
+
if ( this.tupleMemoryEnabled ) {
item.setSequenence( this.sequence );
}
@@ -328,8 +329,8 @@
// We only want to fire an event on a truly new Activation and not on an Activation as a result of a modify
if ( fireActivationCreated ) {
- ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
- workingMemory );
+ ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
+ workingMemory );
}
}
@@ -393,7 +394,7 @@
}
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
- workingMemory );
+ workingMemory );
((InternalAgenda) workingMemory.getAgenda()).decreaseActiveActivations();
} else {
((InternalAgenda) workingMemory.getAgenda()).decreaseDormantActivations();
@@ -446,7 +447,7 @@
if ( activation.isActivated() ) {
activation.remove();
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
- workingMemory );
+ workingMemory );
}
final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
@@ -455,15 +456,15 @@
null );
workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
propagationContext,
- this.rule );
+ this.rule );
}
workingMemory.executeQueuedActions();
workingMemory.clearNodeMemory( this );
}
- if( !context.alreadyVisited( this.tupleSource ) ) {
- this.tupleSource.remove( context,
+ if ( !context.alreadyVisited( this.tupleSource ) ) {
+ this.tupleSource.remove( context,
this,
workingMemories );
}
@@ -474,16 +475,16 @@
}
public Object createMemory(final RuleBaseConfiguration config) {
- return new TerminalNodeMemory();
+ return new TerminalNodeMemory( );
}
-
+
public boolean isTupleMemoryEnabled() {
return tupleMemoryEnabled;
}
public void setTupleMemoryEnabled(boolean tupleMemoryEnabled) {
this.tupleMemoryEnabled = tupleMemoryEnabled;
- }
+ }
/**
* Returns the next node
@@ -538,19 +539,19 @@
return this.rule.equals( other.rule );
}
- class TerminalNodeMemory
+ static class TerminalNodeMemory
implements
Serializable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private InternalAgendaGroup agendaGroup;
+ private InternalAgendaGroup agendaGroup;
- private ActivationGroup activationGroup;
+ private ActivationGroup activationGroup;
- private RuleFlowGroup ruleFlowGroup;
+ private RuleFlowGroup ruleFlowGroup;
- private TupleHashTable tupleMemory;
-
+ private TupleHashTable tupleMemory;
+
public TerminalNodeMemory() {
this.tupleMemory = new TupleHashTable();
}
@@ -582,5 +583,6 @@
public void setRuleFlowGroup(final RuleFlowGroup ruleFlowGroup) {
this.ruleFlowGroup = ruleFlowGroup;
}
+
}
}
More information about the jboss-svn-commits
mailing list