org.drools.examples.troubleticket.TroubleTicketExample Maven / Gradle / Ivy
The newest version!
package org.drools.examples.troubleticket;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.rule.FactHandle;
public class TroubleTicketExample {
/**
* @param args
*/
public static void main(final String[] args) throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "TroubleTicket.drl",
TroubleTicketExample.class ),
ResourceType.DRL );
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "log/trouble_ticket");
final Customer a = new Customer( "A",
"Drools",
"Gold" );
final Customer b = new Customer( "B",
"Drools",
"Platinum" );
final Customer c = new Customer( "C",
"Drools",
"Silver" );
final Customer d = new Customer( "D",
"Drools",
"Silver" );
final Ticket t1 = new Ticket( a );
final Ticket t2 = new Ticket( b );
final Ticket t3 = new Ticket( c );
final Ticket t4 = new Ticket( d );
ksession.insert( a );
ksession.insert( b );
ksession.insert( c );
ksession.insert( d );
ksession.insert( t1 );
ksession.insert( t2 );
final FactHandle ft3 = ksession.insert( t3 );
ksession.insert( t4 );
ksession.fireAllRules();
t3.setStatus( "Done" );
ksession.update( ft3,
t3 );
try {
System.err.println( "[[ Sleeping 5 seconds ]]" );
Thread.sleep( 5000 );
} catch ( final InterruptedException e ) {
e.printStackTrace();
}
System.err.println( "[[ awake ]]" );
ksession.dispose();
logger.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy