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;
}
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());
}
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;
}
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);
}
}
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);
}
Aggregations