Search in sources :

Example 31 with Environment

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

the class MarshallingTest method marsallStatefulKnowledgeSession.

private KieSession marsallStatefulKnowledgeSession(KieSession ksession) throws IOException, ClassNotFoundException {
    Globals globals = ksession.getGlobals();
    KieBase kbase = ksession.getKieBase();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    MarshallerFactory.newMarshaller(kbase).marshall(out, ksession);
    KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ksconf.setOption(TimerJobFactoryOption.get("trackable"));
    ksconf.setOption(ClockTypeOption.get("pseudo"));
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(EnvironmentName.GLOBALS, globals);
    ksession = MarshallerFactory.newMarshaller(kbase).unmarshall(new ByteArrayInputStream(out.toByteArray()), ksconf, env);
    return ksession;
}
Also used : Globals(org.kie.api.runtime.Globals) ByteArrayInputStream(java.io.ByteArrayInputStream) KieBase(org.kie.api.KieBase) Environment(org.kie.api.runtime.Environment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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