[rules-dev] Ruleflow ActionNodes

Mark Proctor mproctor at codehaus.org
Wed Nov 21 01:20:53 EST 2007


Kris,

ActionNodeInstanceImpl is a stateless representation of a node in a 
process, and the ActionNode it references is also stateless. So why do 
you accesss it indirectly?

    protected ActionNode getActionNode() {
        return (ActionNode) getNode();
    }

    protected Node getNode() {
        return this.processInstance.getRuleFlowProcess().getNode( 
this.nodeId );
    }
--------------------
    private Map                nodes;
    final Long idLong = new Long( id );

Look at PrimitiveLongMap and how its used, means no ObjectWrappers and 
uses up a lot less memory than HashMap - as well as being marginally 
faster. It is meant for situations where you no the keys are issued 
incrementally, we use a key recycling class PrimitiveLongStack to ensure 
we don't end up with gaps.

--------------------
I have MVELAction working now in the build framework. I don't really 
like actionNode.getAction() which returns an Object, the execution 
implemtentation is encapsulated so just actoinNode.execute( wm ) should 
be fine, which then delegates to the MVELAction.

    public void testSimpleAction() throws Exception {
        final Package pkg = new Package( "pkg1" );
 
        ActionDescr actionDescr = new ActionDescr();
        actionDescr.setText( "list.add( 'hello world' )" );       
 
        PackageBuilder pkgBuilder = new PackageBuilder( pkg );
        final PackageBuilderConfiguration conf = pkgBuilder.getPackageBuilderConfiguration();
        MVELDialect mvelDialect = ( MVELDialect ) pkgBuilder.getDialectRegistry().getDialect( "mvel" );
 
        PackageBuildContext context = new PackageBuildContext();
        context.init( conf, pkg, null, pkgBuilder.getDialectRegistry(), mvelDialect, null);
 
        pkgBuilder.addPackageFromDrl( new StringReader("package pkg1;\nglobal java.util.List list;\n") );        
 
        ActionNodeImpl actionNode = new ActionNodeImpl();
 
        final MVELActionBuilder builder = new MVELActionBuilder();
        builder.build( context,
                       actionNode,
                       actionDescr );
 
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( pkgBuilder.getPackage() );
        final WorkingMemory wm = ruleBase.newStatefulSession();
 
        List list = new  ArrayList();
        wm.setGlobal( "list", list );        
 
        ((Action)actionNode.getAction()).execute( wm );
 
        assertEquals("hello world", list.get(0) );
    }



Mark







More information about the rules-dev mailing list