Package org.drools.examples.state

Source Code of org.drools.examples.state.StateExampleUsingAgendaGroup

/*
* Copyright 2010 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.
*/

package org.drools.examples.state;

import java.io.IOException;
import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
import org.drools.event.AfterActivationFiredEvent;
import org.drools.event.DefaultAgendaEventListener;

public class StateExampleUsingAgendaGroup {

    /**
     * @param args
     */
    public static void main(final String[] args) {

        final PackageBuilder builder = new PackageBuilder();
        try {
            builder.addPackageFromDrl( new InputStreamReader( StateExampleUsingAgendaGroup.class.getResourceAsStream( "StateExampleUsingAgendaGroup.drl" ) ) );
        } catch (DroolsParserException e) {
            throw new IllegalArgumentException("Invalid drl", e);
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not read drl", e);
        }

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( builder.getPackage() );

        final StatefulSession session = ruleBase.newStatefulSession();

        session.addEventListener( new DefaultAgendaEventListener() {
            public void afterActivationFired(final AfterActivationFiredEvent arg0) {
                super.afterActivationFired( arg0,
                                            session );
            }
        } );

//        final WorkingMemoryFileLogger logger = new WorkingMemoryFileLogger( session );
//        logger.setFileName( "log/state.log" );

        final State a = new State( "A" );
        final State b = new State( "B" );
        final State c = new State( "C" );
        final State d = new State( "D" );

        // By setting dynamic to TRUE, Drools will use JavaBean
        // PropertyChangeListeners so you don't have to call update().
        final boolean dynamic = true;

        session.insert( a,
                        dynamic );
        session.insert( b,
                        dynamic );
        session.insert( c,
                        dynamic );
        session.insert( d,
                        dynamic );

        session.fireAllRules();
        session.dispose();

//        logger.writeToDisk();
    }

}
TOP

Related Classes of org.drools.examples.state.StateExampleUsingAgendaGroup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.