0

I have a drl file and a .class file in a folder. drl contains rule which is built on class attributes. Now through a java program i want to invoke this rule on some input. I am clueless here . please look at code below

class file

import java.io.Serializable;

public class Txn754909164
  implements Serializable
{
  String sequenceNo;
  String accountNumber;
  String customerNumber;

  // setter and getters

 }

drl file

import Txn754909164;
import java.util.*;
dialect  "mvel"

rule "rule6"
    when
        txn:Txn754909164(sequence == 10)
    then
        System.out.println( "invoking rule ***********************" );
end

client code

 public KieContainer kieContainer(String packageName) {
        KieServices kieServices = KieServices.Factory.get();
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();

        kieFileSystem.write(ResourceFactory.newUrlResource("drl resource url..."));
        KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem,MyInputClass.getClassLoader());
        KieModule kieModule = null;
        try {
            kieBuilder.buildAll();
            kieModule = kieBuilder.getKieModule();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId(),cls.getClassLoader());

    }

and finally

StatelessKieSession kieSession = container.getKieBase().newStatelessKieSession();
        kieSession.execute(obj);

logs

11:47:34.795 [http-nio-8282-exec-4] INFO  o.d.c.k.b.impl.KieRepositoryImpl - KieModule was added: MemoryKieModule[releaseId=org.default:artifact:1.0.0-SNAPSHOT]
11:47:34.803 [http-nio-8282-exec-4] TRACE org.drools.core.phreak.AddRemoveRule - Adding Rule rule6
11:47:45.994 [AsyncResolver-bootstrap-executor-0] INFO  c.n.d.s.r.aws.ConfigClusterResolver - Resolving eureka endpoints via configuration
11:47:49.899 [http-nio-8282-exec-4] TRACE o.drools.core.reteoo.EntryPointNode - Insert [fact 0:1:1764329060:1764329060:1:DEFAULT:NON_TRAIT:Txn754909164:Txn754909164@69298664]
11:47:52.953 [http-nio-8282-exec-4] INFO  o.k.a.e.r.DebugRuleRuntimeEventListener - ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:1:1764329060:1764329060:1:DEFAULT:NON_TRAIT:Txn754909164:Txn754909164@69298664], getObject()=Txn754909164@69298664, getKnowledgeRuntime()=KieSession[0], getPropagationContext()=PhreakPropagationContext [entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:1:1764329060:1764329060:1:DEFAULT:NON_TRAIT:Txn754909164:Txn754909164@69298664], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=INSERTION]]
11:48:41.571 [http-nio-8282-exec-4] DEBUG org.drools.core.common.DefaultAgenda - State was INACTIVE is now FIRING_ALL_RULES
11:48:41.572 [http-nio-8282-exec-4] TRACE org.drools.core.common.DefaultAgenda - Starting Fire All Rules
11:48:41.573 [http-nio-8282-exec-4] DEBUG org.drools.core.common.DefaultAgenda - State was FIRING_ALL_RULES is now HALTING
11:48:41.573 [http-nio-8282-exec-4] DEBUG org.drools.core.common.DefaultAgenda - State was HALTING is now INACTIVE
11:48:41.574 [http-nio-8282-exec-4] TRACE org.drools.core.common.DefaultAgenda - Ending Fire All Rules
11:48:41.575 [http-nio-8282-exec-4] DEBUG org.drools.core.common.DefaultAgenda - State was INACTIVE is now DISPOSED

It should print statement in then clause of drl rule

amarzeet
  • 63
  • 2
  • 11

1 Answers1

0

above mentioned question and explanation is answer in itself. Found it working perfectly fine from next day. I guess it was just a workspace issue.

amarzeet
  • 63
  • 2
  • 11