[jboss-svn-commits] JBL Code SVN: r13175 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow: core/impl and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 6 13:52:23 EDT 2007
Author: KrisVerlaenen
Date: 2007-07-06 13:52:23 -0400 (Fri, 06 Jul 2007)
New Revision: 13175
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/MilestoneNodeImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessValidatorImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowNodeInstance.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/EndNodeInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowJoinInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowNodeInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSequenceNodeInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSplitInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/StartNodeInstanceImpl.java
Log:
JBRULES-979: Ruleflow should terminate all running node instances when ruleflow process is completed
JBRULES-981: Milestone
- initial start of milestone node
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -0,0 +1,58 @@
+package org.drools.ruleflow.core;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Represents a milestone in a RuleFlow.
+ * A milestone has an associated constraint.
+ * Flow will only continue if this constraint has been satisfied.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface MilestoneNode
+ extends
+ Node {
+
+ /**
+ * Returns the incoming connection of the MilestoneNode.
+ *
+ * @return the incoming connection of the MilestoneNode.
+ */
+ Connection getFrom();
+
+ /**
+ * Returns the outgoing connection of the MilestoneNode.
+ *
+ * @return the outgoing connection of the MilestoneNode.
+ */
+ Connection getTo();
+
+ /**
+ * Returns the constraint of the MilestoneNode.
+ *
+ * @return the constraint of the MilestoneNode.
+ */
+ String getConstraint();
+
+ /**
+ * Sets the ruleflow-group of the MilestoneNode.
+ *
+ * @param constraint The constraint of the MilestoneNode
+ * @throws IllegalArgumentException if constraint is null
+ */
+ void setConstraint(String constraint);
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -41,6 +41,9 @@
String JOIN_WITHOUT_OUTGOING_CONNECTION = "Join node has no outgoing connection.";
String VARIABLE_WITHOUT_TYPE = "A variable has no type.";
String ALL_NODES_CONNECTED_TO_START = "A node is not connected to the start node.";
+ String MILESTONE_NODE_WITHOUT_INCOMING_CONNECTIONS = "Milestone node has no incoming connection.";
+ String MILESTONE_NODE_WITHOUT_OUTGOING_CONNECTIONS = "Milestone node has no outgoing connection.";
+ String MILESTONE_WITHOUT_CONSTRAINT = "A milestone node has no constraint.";
String getType();
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/MilestoneNodeImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/MilestoneNodeImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/MilestoneNodeImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -0,0 +1,79 @@
+package org.drools.ruleflow.core.impl;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.ruleflow.core.Connection;
+import org.drools.ruleflow.core.MilestoneNode;
+
+/**
+ * Default implementation of a milestone node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class MilestoneNodeImpl extends NodeImpl
+ implements
+ MilestoneNode {
+
+ private static final long serialVersionUID = 8552568488755348247L;
+
+ private String constraint;
+
+ public void setConstraint(final String constraint) {
+ this.constraint = constraint;
+ }
+
+ public String getConstraint() {
+ return this.constraint;
+ }
+
+ public Connection getFrom() {
+ final List list = getIncomingConnections();
+ if ( list.size() > 0 ) {
+ return (Connection) list.get( 0 );
+ }
+ return null;
+ }
+
+ public Connection getTo() {
+ final List list = getOutgoingConnections();
+ if ( list.size() > 0 ) {
+ return (Connection) list.get( 0 );
+ }
+ return null;
+ }
+
+ protected void validateAddIncomingConnection(final Connection connection) {
+ super.validateAddIncomingConnection( connection );
+ if ( getIncomingConnections().size() > 0 ) {
+ throw new IllegalArgumentException( "A MilestoneNode cannot have more than one incoming node" );
+ }
+ }
+
+ protected void validateAddOutgoingConnection(final Connection connection) {
+ super.validateAddOutgoingConnection( connection );
+ for ( final Iterator it = getOutgoingConnections().iterator(); it.hasNext(); ) {
+ final Connection conn = (Connection) it.next();
+ if ( conn.getType() == connection.getType() ) {
+ throw new IllegalArgumentException( "A MilestoneNode can have at most one outgoing node" );
+ }
+ }
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessValidatorImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessValidatorImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessValidatorImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -25,6 +25,7 @@
import org.drools.ruleflow.core.Connection;
import org.drools.ruleflow.core.EndNode;
import org.drools.ruleflow.core.Join;
+import org.drools.ruleflow.core.MilestoneNode;
import org.drools.ruleflow.core.Node;
import org.drools.ruleflow.core.RuleFlowProcess;
import org.drools.ruleflow.core.RuleFlowProcessValidationError;
@@ -131,6 +132,18 @@
if ( join.getTo() == null ) {
errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.JOIN_WITHOUT_OUTGOING_CONNECTION ) );
}
+ } else if ( node instanceof MilestoneNode ) {
+ final MilestoneNode milestone = (MilestoneNode) node;
+ if ( milestone.getFrom() == null ) {
+ errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.MILESTONE_NODE_WITHOUT_INCOMING_CONNECTIONS ) );
+ }
+
+ if ( milestone.getTo() == null ) {
+ errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.MILESTONE_NODE_WITHOUT_OUTGOING_CONNECTIONS ) );
+ }
+ if ( milestone.getConstraint() == null ) {
+ errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.MILESTONE_WITHOUT_CONSTRAINT ) );
+ }
}
}
if ( !startNodeFound ) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowNodeInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowNodeInstance.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowNodeInstance.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -40,6 +40,6 @@
void trigger(RuleFlowNodeInstance from);
- void triggerCompleted();
+ void cancel();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/EndNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/EndNodeInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/EndNodeInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -30,8 +30,4 @@
getProcessInstance().setState( ProcessInstance.STATE_COMPLETED );
}
- public void triggerCompleted() {
- // this should never occur
- throw new IllegalArgumentException( "End nodes cannot be completed." );
- }
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -0,0 +1,56 @@
+package org.drools.ruleflow.instance.impl;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+
+import org.drools.common.RuleFlowGroupNode;
+import org.drools.ruleflow.core.MilestoneNode;
+import org.drools.ruleflow.instance.RuleFlowNodeInstance;
+import org.drools.spi.Activation;
+import org.drools.spi.RuleFlowGroup;
+
+/**
+ * Runtime counterpart of a ruleset node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class MilestoneNodeInstanceImpl extends RuleFlowNodeInstanceImpl {
+
+ protected MilestoneNode getMilestoneNode() {
+ return (MilestoneNode) getNode();
+ }
+
+ public void trigger(final RuleFlowNodeInstance from) {
+ RuleFlowGroup systemRuleFlowGroup = getProcessInstance().getAgenda().getRuleFlowGroup("DROOLS_SYSTEM");
+ String rule = "RuleFlow-" + getProcessInstance().getProcess().getId()
+ + "-" + getNode().getId();
+ for (Iterator activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
+ Activation activation = ((RuleFlowGroupNode) activations.next()).getActivation();
+ if (rule.equals(activation.getRule().getName())) {
+ triggerCompleted();
+ break;
+ }
+ }
+ }
+
+ public void triggerCompleted() {
+ getProcessInstance().getNodeInstance( getMilestoneNode().getTo().getTo() ).trigger( this );
+ getProcessInstance().removeNodeInstance(this);
+ }
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowJoinInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowJoinInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowJoinInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -88,5 +88,5 @@
public void triggerCompleted() {
getProcessInstance().getNodeInstance( getJoinNode().getTo().getTo() ).trigger( this );
}
-
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowNodeInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowNodeInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -60,4 +60,9 @@
protected Node getNode() {
return this.processInstance.getRuleFlowProcess().getNode( this.nodeId );
}
+
+ public void cancel() {
+ getProcessInstance().removeNodeInstance(this);
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -26,9 +26,17 @@
import org.drools.WorkingMemory;
import org.drools.common.EventSupport;
import org.drools.common.InternalWorkingMemory;
+import org.drools.event.ActivationCancelledEvent;
+import org.drools.event.ActivationCreatedEvent;
+import org.drools.event.AfterActivationFiredEvent;
+import org.drools.event.AgendaEventListener;
+import org.drools.event.AgendaGroupPoppedEvent;
+import org.drools.event.AgendaGroupPushedEvent;
+import org.drools.event.BeforeActivationFiredEvent;
import org.drools.ruleflow.common.instance.impl.ProcessInstanceImpl;
import org.drools.ruleflow.core.EndNode;
import org.drools.ruleflow.core.Join;
+import org.drools.ruleflow.core.MilestoneNode;
import org.drools.ruleflow.core.Node;
import org.drools.ruleflow.core.RuleFlowProcess;
import org.drools.ruleflow.core.RuleSetNode;
@@ -44,7 +52,7 @@
*/
public class RuleFlowProcessInstanceImpl extends ProcessInstanceImpl
implements
- RuleFlowProcessInstance {
+ RuleFlowProcessInstance, AgendaEventListener {
private static final long serialVersionUID = -6760756665603399413L;
@@ -90,6 +98,7 @@
throw new IllegalArgumentException("A working memory can only be set once.");
}
this.workingMemory = workingMemory;
+ workingMemory.addEventListener(this);
}
public WorkingMemory getWorkingMemory() {
@@ -128,6 +137,11 @@
result.setNodeId( node.getId() );
addNodeInstance( result );
return result;
+ } else if ( node instanceof MilestoneNode ) {
+ final RuleFlowNodeInstance result = new MilestoneNodeInstanceImpl();
+ result.setNodeId( node.getId() );
+ addNodeInstance( result );
+ return result;
}
throw new IllegalArgumentException( "Illegal node type: " + node.getClass() );
}
@@ -142,6 +156,12 @@
public void setState(final int state) {
super.setState(state);
+ // deactivate all node instances of this process instance
+ while (!nodeInstances.isEmpty()) {
+ RuleFlowNodeInstance nodeInstance = (RuleFlowNodeInstance) nodeInstances.get(0);
+ nodeInstance.cancel();
+ }
+ workingMemory.removeEventListener(this);
if (state == ProcessInstanceImpl.STATE_COMPLETED) {
((EventSupport) this.workingMemory).getRuleFlowEventSupport()
.fireRuleFlowProcessCompleted(this, this.workingMemory);
@@ -158,4 +178,46 @@
sb.append( "]" );
return sb.toString();
}
+
+ public void activationCreated(ActivationCreatedEvent event, WorkingMemory workingMemory) {
+ // TODO group all milestone related code in milestone instance impl?
+ // check whether this activation is from the DROOLS_SYSTEM agenda group
+ String ruleFlowGroup = event.getActivation().getRule().getRuleFlowGroup();
+ if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) {
+ // new activations of the rule associate with a milestone node
+ // trigger node instances of that milestone node
+ String ruleName = event.getActivation().getRule().getName();
+ for (Iterator iterator = getNodeInstances().iterator(); iterator.hasNext(); ) {
+ RuleFlowNodeInstance nodeInstance = (RuleFlowNodeInstance) iterator.next();
+ if (nodeInstance instanceof MilestoneNodeInstanceImpl) {
+ String milestoneName = "RuleFlow-" + getProcess().getId()
+ + "-" + nodeInstance.getNodeId();
+ if (milestoneName.equals(ruleName)) {
+ ((MilestoneNodeInstanceImpl) nodeInstance).triggerCompleted();
+ }
+ }
+
+ }
+ }
+ }
+
+ public void activationCancelled(ActivationCancelledEvent event, WorkingMemory workingMemory) {
+ // Do nothing
+ }
+
+ public void afterActivationFired(AfterActivationFiredEvent event, WorkingMemory workingMemory) {
+ // Do nothing
+ }
+
+ public void agendaGroupPopped(AgendaGroupPoppedEvent event, WorkingMemory workingMemory) {
+ // Do nothing
+ }
+
+ public void agendaGroupPushed(AgendaGroupPushedEvent event, WorkingMemory workingMemory) {
+ // Do nothing
+ }
+
+ public void beforeActivationFired(BeforeActivationFiredEvent event, WorkingMemory workingMemory) {
+ // Do nothing
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSequenceNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSequenceNodeInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSequenceNodeInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -36,6 +36,12 @@
public void triggerCompleted() {
getProcessInstance().getNodeInstance( getRuleSetNode().getTo().getTo() ).trigger( this );
+ getProcessInstance().removeNodeInstance(this);
}
+
+ public void cancel() {
+ getProcessInstance().getAgenda().deactivateRuleFlowGroup( getRuleSetNode().getRuleFlowGroup() );
+ super.cancel();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSplitInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSplitInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowSplitInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -105,9 +105,4 @@
}
}
- public void triggerCompleted() {
- // TODO Auto-generated method stub
-
- }
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/StartNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/StartNodeInstanceImpl.java 2007-07-06 17:52:05 UTC (rev 13174)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/StartNodeInstanceImpl.java 2007-07-06 17:52:23 UTC (rev 13175)
@@ -36,5 +36,7 @@
public void triggerCompleted() {
getProcessInstance().getNodeInstance( getStartNode().getTo().getTo() ).trigger( this );
+ getProcessInstance().removeNodeInstance(this);
}
+
}
More information about the jboss-svn-commits
mailing list