001: package org.drools.examples.manners;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.io.InputStream;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.drools.RuleBase;
024: import org.drools.RuleBaseFactory;
025: import org.drools.WorkingMemory;
026: import org.drools.event.AfterActivationFiredEvent;
027: import org.drools.event.DefaultAgendaEventListener;
028:
029: public class ReteooMannersTest extends BaseMannersTest {
030:
031: public void testManners() throws Exception {
032:
033: final RuleBase ruleBase = RuleBaseFactory
034: .newRuleBase(RuleBase.RETEOO);
035: ruleBase.addPackage(this .pkg);
036: final WorkingMemory workingMemory = ruleBase
037: .newStatefulSession();
038:
039: final DefaultAgendaEventListener listener = new DefaultAgendaEventListener() {
040: private int counter = 0;
041:
042: // public void activationCreated(ActivationCreatedEvent event) {
043: // super.activationCreated( event );
044: // System.out.println( event );
045: // }
046: //
047: // public void activationCancelled(ActivationCancelledEvent event) {
048: // super.activationCancelled( event );
049: // System.out.println( event );
050: // }
051: //
052: // public void beforeActivationFired(BeforeActivationFiredEvent event) {
053: // super.beforeActivationFired( event );
054: // System.out.println( event );
055: // }
056:
057: public void afterActivationFired(
058: AfterActivationFiredEvent event) {
059: this .counter++;
060: //super.afterActivationFired( event );
061: //System.out.println( event );
062: }
063:
064: public String toString() {
065: return "fired : " + this .counter;
066: }
067:
068: };
069:
070: //workingMemory.addEventListener(listener );
071: final InputStream is = getClass().getResourceAsStream(
072: "/manners64.dat");
073: final List list = getInputObjects(is);
074: for (final Iterator it = list.iterator(); it.hasNext();) {
075: final Object object = it.next();
076: workingMemory.insert(object);
077: }
078:
079: workingMemory.insert(new Count(1));
080:
081: final long start = System.currentTimeMillis();
082: workingMemory.fireAllRules();
083: System.err.println(System.currentTimeMillis() - start);
084:
085: //System.out.println( listener );
086:
087: // while (1==1){
088: // Thread.yield();
089: // Thread.sleep( 2000 );
090: // }
091:
092: // final MemoryVisitor visitor = new MemoryVisitor( (InternalWorkingMemory) workingMemory );
093: // visitor.visit( ruleBase );
094:
095: // final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase);
096: //
097: // javax.swing.SwingUtilities.invokeLater(new Runnable() {
098: // public void run() {
099: // viewer.showGUI();
100: // }
101: // });
102: //
103: // Thread.sleep( 10000 );
104: }
105: }
|