"true" );
aconf.setProperty( "drools.agent.scanResources",
"true" );
aconf.setProperty( "drools.agent.newInstance",
"true" );
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
kbase,
aconf );
kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
List list = new ArrayList();
ksession.setGlobal( "list",
list );
ksession.fireAllRules();
ksession.dispose();
assertEquals( 2,
list.size() );
assertTrue( list.contains( "rule1" ) );
assertTrue( list.contains( "rule2" ) );
list.clear();
// have to sleep here as linux lastModified does not do milliseconds http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=019789
Thread.sleep( 2000 );
rule1 = "";
rule1 += "package org.drools.test\n";
rule1 += "global java.util.List list\n";
rule1 += "rule rule3\n";
rule1 += "when\n";
rule1 += "then\n";
rule1 += "list.add( drools.getRule().getName() );\n";
rule1 += "end\n";
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( rule1.getBytes() ), ResourceType.DRL );
kbuilder.add( ResourceFactory.newByteArrayResource( rule2.getBytes() ), ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
fail( kbuilder.getErrors().toString() );
}
pkg = ( KnowledgePackage ) kbuilder.getKnowledgePackages().iterator().next();
writePackage( pkg, fileManager.newFile( "pkg1.pkg" ) );
//KnowledgePackage pkg2 = ( KnowledgePackage ) DroolsStreamUtils.streamIn( new FileInputStream( fileManager.newFile( "pkg1.pkg" ) ) );
Thread.sleep( 3000 );
ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
list = new ArrayList();
ksession.setGlobal( "list",
list );
ksession.fireAllRules();
ksession.dispose();
assertEquals( 2,
list.size() );
assertTrue( list.contains( "rule3" ) );
assertTrue( list.contains( "rule2" ) );
kagent.monitorResourceChangeEvents( false );
}