Search in sources :

Example 11 with JavaDialectRuntimeData

use of org.drools.core.rule.JavaDialectRuntimeData in project drools by kiegroup.

the class JavaRuleBuilderHelper method registerInvokerBytecode.

public static void registerInvokerBytecode(RuleBuildContext context, Map<String, Object> vars, byte[] bytecode, Object invokerLookup) {
    String packageName = (String) vars.get("package");
    String invokerClassName = (String) vars.get("invokerClassName");
    String className = packageName + "." + invokerClassName;
    String resourceName = className.replace('.', '/') + ".class";
    JavaDialectRuntimeData data = (JavaDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData("java");
    data.write(resourceName, bytecode);
    data.putInvoker(className, (Wireable) invokerLookup);
}
Also used : JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData)

Example 12 with JavaDialectRuntimeData

use of org.drools.core.rule.JavaDialectRuntimeData in project drools by kiegroup.

the class InstancesHashcodedTest method build.

/*
        <dimension name="bck_cycle_dm"  item-expression="cycleDimension"
                   mode="ignore" cache="10" export-to="cycle_id">
            <id    name="objid"            type="long"             generator-sql="select bck_dimensions_uid.nextval from dual"/>
            <field name="cut_date"         type="java.util.Date"   value="cutDate"     key="true"/>
            <field name="due_date"         type="java.util.Date"   value="dueDate"     key="true"/>
            <field name="cycle_code"       type="java.lang.String" value="cycleCode"/>
            <field name="issue_date"       type="java.util.Date"   value="issueDate"/>
        </dimension>
 */
private Class build(ClassBuilder builder, ClassDefinition classDef) throws Exception {
    ProjectClassLoader prjClassLoader = ProjectClassLoader.createProjectClassLoader();
    byte[] d = builder.buildClass(classDef, prjClassLoader);
    JavaDialectRuntimeData data = new JavaDialectRuntimeData();
    data.write(convertClassToResourcePath(classDef.getClassName()), d);
    ClassLoader classLoader = new PackageClassLoader(data, prjClassLoader);
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(classLoader));
    store.setEagerWire(true);
    Class clazz = classLoader.loadClass(classDef.getClassName());
    classDef.setDefinedClass(clazz);
    return clazz;
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) PackageClassLoader(org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) PackageClassLoader(org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader)

Example 13 with JavaDialectRuntimeData

use of org.drools.core.rule.JavaDialectRuntimeData in project drools by kiegroup.

the class ReteooRuleBaseMultiThreadedTest method setUp.

@Before
public void setUp() {
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    pkg = new KnowledgePackageImpl("org.droos.test");
    pkg.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    JavaDialectRuntimeData data = new JavaDialectRuntimeData();
    data.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
    pkg.getDialectRuntimeRegistry().setDialectData("java", data);
    // we need to add one rule to the package because the previous deadlock was encountered
    // while removing rules from a package when said package is removed from the rulebase
    rule = new RuleImpl("Test");
    rule.setDialect("java");
    rule.setConsequence(new Consequence() {

        public void evaluate(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory) throws Exception {
        }

        public String getName() {
            return "default";
        }
    });
    pkg.addRule(rule);
    kBase.addPackage(pkg);
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) WorkingMemory(org.drools.core.WorkingMemory) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) Before(org.junit.Before)

Aggregations

JavaDialectRuntimeData (org.drools.core.rule.JavaDialectRuntimeData)13 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)5 HashMap (java.util.HashMap)4 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)3 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)3 TypeDeclaration (org.drools.core.rule.TypeDeclaration)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 WorkingMemory (org.drools.core.WorkingMemory)2 ClassDefinition (org.drools.core.factmodel.ClassDefinition)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 Consequence (org.drools.core.spi.Consequence)2 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)2 Test (org.junit.Test)2 Rule (org.kie.api.definition.rule.Rule)2 KieSession (org.kie.api.runtime.KieSession)2 ByteString (com.google.protobuf.ByteString)1