Search in sources :

Example 16 with Environment

use of org.kie.api.runtime.Environment in project drools by kiegroup.

the class TimerAndCalendarTest method createSession.

private KieSession createSession(KieBase kbase) {
    final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    Environment env = createEnvironment(context);
    if (locking) {
        env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
    }
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
    return ksession;
}
Also used : StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Environment(org.kie.api.runtime.Environment) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 17 with Environment

use of org.kie.api.runtime.Environment in project drools by kiegroup.

the class DynamicRulesTest method testDynamicNotNode.

@Test(timeout = 10000)
public void testDynamicNotNode() throws Exception {
    InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase("test_CollectDynamicRules1.drl");
    kbase = SerializationHelper.serializeObject(kbase);
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new IdentityPlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    KieSession ksession = kbase.newKieSession(null, env);
    List<?> results = new ArrayList<Object>();
    ksession.setGlobal("results", results);
    final Cheese a = new Cheese("stilton", 10);
    final Cheese b = new Cheese("stilton", 15);
    final Cheese c = new Cheese("stilton", 20);
    ksession.insert(a);
    ksession.insert(b);
    ksession.insert(c);
    Collection<KiePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_DynamicNotNode.drl"));
    kbase.addPackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, false);
    results = (List) ksession.getGlobal("results");
    ksession.fireAllRules();
    assertEquals(0, results.size());
    kbase.removeKiePackage("org.drools.compiler");
    ksession.retract(ksession.getFactHandle(b));
    kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_DynamicNotNode.drl"));
    kbase.addPackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, false);
    results = (List<?>) ksession.getGlobal("results");
    ksession.fireAllRules();
    assertEquals(1, results.size());
}
Also used : IdentityPlaceholderResolverStrategy(org.drools.core.marshalling.impl.IdentityPlaceholderResolverStrategy) KiePackage(org.kie.api.definition.KiePackage) ArrayList(java.util.ArrayList) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 18 with Environment

use of org.kie.api.runtime.Environment in project drools by kiegroup.

the class JPAWorkItemManager method internalGetWorkItem.

private WorkItem internalGetWorkItem(WorkItemInfo workItemInfo) {
    Environment env = kruntime.getEnvironment();
    WorkItem workItem = workItemInfo.getWorkItem(env, (InternalKnowledgeBase) kruntime.getKieBase());
    return workItem;
}
Also used : Environment(org.kie.api.runtime.Environment) WorkItem(org.drools.core.process.instance.WorkItem)

Example 19 with Environment

use of org.kie.api.runtime.Environment in project drools by kiegroup.

the class JPAWorkItemManager method retryWorkItemWithParams.

public void retryWorkItemWithParams(long workItemId, Map<String, Object> map) {
    Environment env = this.kruntime.getEnvironment();
    WorkItem workItem = getWorkItem(workItemId);
    if (workItem != null) {
        workItem.setParameters(map);
        WorkItemInfo workItemInfo = new WorkItemInfo(workItem, env);
        PersistenceContext context = getPersistenceContext();
        context.merge(workItemInfo);
        retryWorkItem(workItem);
    }
}
Also used : Environment(org.kie.api.runtime.Environment) PersistenceContext(org.drools.persistence.api.PersistenceContext) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemInfo(org.drools.persistence.info.WorkItemInfo)

Example 20 with Environment

use of org.kie.api.runtime.Environment in project drools by kiegroup.

the class SimpleBatchExecutionPersistenceTest method createKnowledgeSession.

protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase) {
    if (context == null) {
        context = DroolsPersistenceUtil.setupWithPoolingDataSource(DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME);
    }
    KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    Environment env = DroolsPersistenceUtil.createEnvironment(context);
    if (this.locking) {
        env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
    }
    return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, ksconf, env);
}
Also used : Environment(org.kie.api.runtime.Environment) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Aggregations

Environment (org.kie.api.runtime.Environment)31 Test (org.junit.Test)15 KieBase (org.kie.api.KieBase)9 KieSession (org.kie.api.runtime.KieSession)9 ArrayList (java.util.ArrayList)6 DroolsPersistenceUtil.createEnvironment (org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment)6 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)6 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 IdentityPlaceholderResolverStrategy (org.drools.core.marshalling.impl.IdentityPlaceholderResolverStrategy)4 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)4 Cheese (org.drools.compiler.Cheese)3 PersistenceContext (org.drools.persistence.api.PersistenceContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Collection (java.util.Collection)2 List (java.util.List)2 EntityManager (javax.persistence.EntityManager)2 UserTransaction (javax.transaction.UserTransaction)2 Person (org.drools.compiler.Person)2 IteratorToList (org.drools.compiler.integrationtests.IteratorToList)2