[jboss-svn-commits] JBL Code SVN: r13830 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: ruleflow/core and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 29 19:24:41 EDT 2007


Author: KrisVerlaenen
Date: 2007-07-29 19:24:41 -0400 (Sun, 29 Jul 2007)
New Revision: 13830

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/SubFlowNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/SubFlowNodeImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/SubFlowNodeInstanceImpl.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   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/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/impl/MilestoneNodeInstanceImpl.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
Log:
JBRULES-1043: Enhanced Java completion proposals
 - reuse of standard Java completion proposals
JBRULES-981: Milestone
 - end of impl. in core + integrated into Eclipse IDE
JBRULES-1041: Subflow
 - impl. in core + eclipse IDE
JBRULES-1038: addRuleFlow throws Exceptions
 - ruleflows are checking before parsing
JBRULES-1042: Integrate ruleflows in drools build

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-07-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -144,6 +144,8 @@
     protected boolean                      firing;
 
     protected boolean                      halt;
+    
+    private int 						   processCounter;
 
     // ------------------------------------------------------------
     // Constructors
@@ -1350,11 +1352,12 @@
             final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstanceImpl();
             processInstance.setWorkingMemory( this );
             processInstance.setProcess( process );
+            processInstance.setId(++processCounter);
             processInstance.start();
-
-            getRuleFlowEventSupport().fireRuleFlowProcessStarted( processInstance,
-                                                                  this );
-
+            
+            getRuleFlowEventSupport().fireRuleFlowProcessStarted(
+            		processInstance, this );
+                
             return processInstance;
         } else {
             throw new IllegalArgumentException( "Unknown process type: " + process.getClass() );

Modified: 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	2007-07-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/MilestoneNode.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -52,7 +52,6 @@
      * 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-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/RuleFlowProcessValidationError.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -44,6 +44,9 @@
     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 SUBFLOW_NODE_WITHOUT_INCOMING_CONNECTIONS    = "SubFlow node has no incoming connection.";
+    String SUBFLOW_NODE_WITHOUT_OUTGOING_CONNECTIONS    = "SubFlow node has no outgoing connection.";
+    String SUBFLOW_WITHOUT_PROCESS_ID                   = "A SubFlow node has no process id.";
 
     String getType();
 }

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/SubFlowNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/SubFlowNode.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/SubFlowNode.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -0,0 +1,56 @@
+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 sub-flow in a RuleFlow.
+ * The node will continue if the sub-flow has ended.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface SubFlowNode
+    extends
+    Node {
+
+    /**
+     * Returns the incoming connection of the SubFlowNode.
+     * 
+     * @return the incoming connection of the SubFlowNode.
+     */
+    Connection getFrom();
+
+    /**
+     * Returns the outgoing connection of the SubFlowNode.
+     * 
+     * @return the outgoing connection of the SubFlowNode.
+     */
+    Connection getTo();
+
+    /**
+     * Returns the process id of the SubFlowNode.
+     * 
+     * @return the process id of the SubFlowNode.
+     */
+    String getProcessId();
+
+    /**
+     * Sets the process id of the SubFlowNode.
+     * 
+     * @param processId	The process id of the SubFlowNode
+     */
+    void setProcessId(String processId);
+}

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-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/RuleFlowProcessValidatorImpl.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -33,6 +33,7 @@
 import org.drools.ruleflow.core.RuleSetNode;
 import org.drools.ruleflow.core.Split;
 import org.drools.ruleflow.core.StartNode;
+import org.drools.ruleflow.core.SubFlowNode;
 import org.drools.ruleflow.core.Variable;
 
 /**
@@ -144,6 +145,18 @@
                 if ( milestone.getConstraint() == null ) {
                     errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.MILESTONE_WITHOUT_CONSTRAINT ) );
                 }
+            } else if ( node instanceof SubFlowNode ) {
+                final SubFlowNode subFlow = (SubFlowNode) node;
+                if ( subFlow.getFrom() == null ) {
+                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SUBFLOW_NODE_WITHOUT_INCOMING_CONNECTIONS ) );
+                }
+
+                if ( subFlow.getTo() == null ) {
+                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SUBFLOW_NODE_WITHOUT_OUTGOING_CONNECTIONS ) );
+                }
+                if ( subFlow.getProcessId() == null ) {
+                   errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SUBFLOW_WITHOUT_PROCESS_ID ) );
+                }
             }
         }
         if ( !startNodeFound ) {

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/SubFlowNodeImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/SubFlowNodeImpl.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/core/impl/SubFlowNodeImpl.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -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.SubFlowNode;
+
+/**
+ * Default implementation of a sub-flow node.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class SubFlowNodeImpl extends NodeImpl
+    implements
+    SubFlowNode {
+
+	private static final long serialVersionUID = -6120950606595743908L;
+	
+	private String            processId;
+
+    public void setProcessId(final String processId) {
+        this.processId = processId;
+    }
+
+    public String getProcessId() {
+        return this.processId;
+    }
+
+    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/instance/impl/MilestoneNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java	2007-07-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/MilestoneNodeInstanceImpl.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -25,7 +25,7 @@
 import org.drools.spi.RuleFlowGroup;
 
 /**
- * Runtime counterpart of a ruleset node.
+ * Runtime counterpart of a milestone node.
  * 
  * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */

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-29 23:24:33 UTC (rev 13829)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -23,8 +23,8 @@
 import java.util.List;
 
 import org.drools.Agenda;
+import org.drools.WorkingMemory;
 import org.drools.common.EventSupport;
-import org.drools.WorkingMemory;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.event.ActivationCancelledEvent;
 import org.drools.event.ActivationCreatedEvent;
@@ -33,6 +33,11 @@
 import org.drools.event.AgendaGroupPoppedEvent;
 import org.drools.event.AgendaGroupPushedEvent;
 import org.drools.event.BeforeActivationFiredEvent;
+import org.drools.event.RuleFlowCompletedEvent;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.RuleFlowGroupActivatedEvent;
+import org.drools.event.RuleFlowGroupDeactivatedEvent;
+import org.drools.event.RuleFlowStartedEvent;
 import org.drools.ruleflow.common.instance.impl.ProcessInstanceImpl;
 import org.drools.ruleflow.core.EndNode;
 import org.drools.ruleflow.core.Join;
@@ -42,6 +47,7 @@
 import org.drools.ruleflow.core.RuleSetNode;
 import org.drools.ruleflow.core.Split;
 import org.drools.ruleflow.core.StartNode;
+import org.drools.ruleflow.core.SubFlowNode;
 import org.drools.ruleflow.instance.RuleFlowNodeInstance;
 import org.drools.ruleflow.instance.RuleFlowProcessInstance;
 
@@ -52,7 +58,7 @@
  */
 public class RuleFlowProcessInstanceImpl extends ProcessInstanceImpl
     implements
-    RuleFlowProcessInstance, AgendaEventListener {
+    RuleFlowProcessInstance, AgendaEventListener, RuleFlowEventListener {
 
     private static final long serialVersionUID = -6760756665603399413L;
 
@@ -73,7 +79,7 @@
     }
 
     public Collection getNodeInstances() {
-        return Collections.unmodifiableCollection( this.nodeInstances );
+        return Collections.unmodifiableCollection( new ArrayList(this.nodeInstances) );
     }
 
     public RuleFlowNodeInstance getFirstNodeInstance(final long nodeId) {
@@ -98,7 +104,8 @@
     		throw new IllegalArgumentException("A working memory can only be set once.");
     	}
         this.workingMemory = workingMemory;
-        workingMemory.addEventListener(this);
+        workingMemory.addEventListener((AgendaEventListener) this);
+        workingMemory.addEventListener((RuleFlowEventListener) this);
     }
     
     public WorkingMemory getWorkingMemory() {
@@ -142,6 +149,11 @@
             result.setNodeId( node.getId() );
             addNodeInstance( result );
             return result;
+        } else if ( node instanceof SubFlowNode ) {
+            final RuleFlowNodeInstance result = new SubFlowNodeInstanceImpl();
+            result.setNodeId( node.getId() );
+            addNodeInstance( result );
+            return result;
         }
         throw new IllegalArgumentException( "Illegal node type: " + node.getClass() );
     }
@@ -156,13 +168,14 @@
     
     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) {
+            // deactivate all node instances of this process instance
+            while (!nodeInstances.isEmpty()) {
+            	RuleFlowNodeInstance nodeInstance = (RuleFlowNodeInstance) nodeInstances.get(0);
+            	nodeInstance.cancel();
+            }
+            workingMemory.removeEventListener((AgendaEventListener) this);
+            workingMemory.removeEventListener((RuleFlowEventListener) this);
         	((EventSupport) this.workingMemory).getRuleFlowEventSupport()
         		.fireRuleFlowProcessCompleted(this, this.workingMemory);
         }
@@ -220,4 +233,30 @@
 	public void beforeActivationFired(BeforeActivationFiredEvent event, WorkingMemory workingMemory) {
 		// Do nothing
 	}
+
+	public void ruleFlowGroupActivated(RuleFlowGroupActivatedEvent event, WorkingMemory workingMemory) {
+		// Do nothing
+	}
+
+	public void ruleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event, WorkingMemory workingMemory) {
+		// Do nothing
+	}
+
+	public void ruleFlowStarted(RuleFlowStartedEvent event, WorkingMemory workingMemory) {
+		// Do nothing
+	}
+
+	public void ruleFlowCompleted(RuleFlowCompletedEvent event, WorkingMemory workingMemory) {
+		// TODO group all subflow related code in subflow instance impl?
+		for (Iterator iterator = getNodeInstances().iterator(); iterator.hasNext(); ) {
+			RuleFlowNodeInstance nodeInstance = (RuleFlowNodeInstance) iterator.next();
+			if (nodeInstance instanceof SubFlowNodeInstanceImpl) {
+				SubFlowNodeInstanceImpl subFlowInstance = (SubFlowNodeInstanceImpl) nodeInstance;
+				if (event.getRuleFlowProcessInstance().getId() == subFlowInstance.getProcessInstanceId()) {
+					subFlowInstance.triggerCompleted();
+				}
+			}
+			
+		}
+	}
 }

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/SubFlowNodeInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/SubFlowNodeInstanceImpl.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/SubFlowNodeInstanceImpl.java	2007-07-29 23:24:41 UTC (rev 13830)
@@ -0,0 +1,51 @@
+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 org.drools.ruleflow.common.instance.ProcessInstance;
+import org.drools.ruleflow.core.SubFlowNode;
+import org.drools.ruleflow.instance.RuleFlowNodeInstance;
+
+/**
+ * Runtime counterpart of a SubFlow node.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class SubFlowNodeInstanceImpl extends RuleFlowNodeInstanceImpl {
+
+	private long processInstanceId;
+	
+    protected SubFlowNode getSubFlowNode() {
+        return (SubFlowNode) getNode();
+    }
+
+    public void trigger(final RuleFlowNodeInstance from) {
+    	ProcessInstance processInstance = 
+    		getProcessInstance().getWorkingMemory().startProcess(getSubFlowNode().getProcessId());
+    	this.processInstanceId = processInstance.getId();
+    }
+    
+    public long getProcessInstanceId() {
+    	return processInstanceId;
+    }
+
+    public void triggerCompleted() {
+        getProcessInstance().getNodeInstance( getSubFlowNode().getTo().getTo() ).trigger( this );
+        getProcessInstance().removeNodeInstance(this);
+    }
+
+}
\ No newline at end of file




More information about the jboss-svn-commits mailing list