Search in sources :

Example 1 with ProcessInstanceResolverStrategy

use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method before.

@Before
public void before() {
    context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
    // load up the knowledge base
    Environment env = PersistenceUtil.createEnvironment(context);
    env.set(OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new ProcessInstanceResolverStrategy(), new JPAPlaceholderResolverStrategy(env), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    if (useLocking) {
        env.set(USE_PESSIMISTIC_LOCKING, true);
    }
    KieBase kbase = loadKnowledgeBase();
    // create session
    ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    Assert.assertTrue("Valid KnowledgeSession could not be created.", ksession != null && ksession.getIdentifier() > 0);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) KieBase(org.kie.api.KieBase) Environment(org.kie.api.runtime.Environment) Before(org.junit.Before)

Example 2 with ProcessInstanceResolverStrategy

use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.

the class SimpleRuntimeEnvironment method copyEnvironment.

protected Environment copyEnvironment() {
    Environment copy = EnvironmentFactory.newEnvironment();
    addIfPresent(EnvironmentName.ENTITY_MANAGER_FACTORY, copy);
    addIfPresent(EnvironmentName.CALENDARS, copy);
    addIfPresent(EnvironmentName.DATE_FORMATS, copy);
    addIfPresent(EnvironmentName.GLOBALS, copy);
    addIfPresent(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, copy);
    addIfPresent(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, copy);
    addIfPresent(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, copy);
    addIfPresent(EnvironmentName.TRANSACTION_MANAGER, copy);
    addIfPresent(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, copy);
    addIfPresent(EnvironmentName.TRANSACTION, copy);
    addIfPresent(EnvironmentName.USE_LOCAL_TRANSACTIONS, copy);
    addIfPresent(EnvironmentName.USE_PESSIMISTIC_LOCKING, copy);
    addIfPresent(EnvironmentName.EXEC_ERROR_MANAGER, copy);
    addIfPresent(EnvironmentName.DEPLOYMENT_ID, copy);
    if (usePersistence()) {
        ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) copy.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
        List<ObjectMarshallingStrategy> listStrategies = new ArrayList<ObjectMarshallingStrategy>(Arrays.asList(strategies));
        listStrategies.add(0, new ProcessInstanceResolverStrategy());
        strategies = new ObjectMarshallingStrategy[listStrategies.size()];
        copy.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, listStrategies.toArray(strategies));
    }
    // copy if present in environment template which in general should not be used
    // unless with some framework support to make EM thread safe - like spring
    addIfPresent(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, copy);
    addIfPresent(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, copy);
    addIfPresent("IS_JTA_TRANSACTION", copy);
    addIfPresent("IS_TIMER_CMT", copy);
    addIfPresent("IS_SHARED_ENTITY_MANAGER", copy);
    addIfPresent("TRANSACTION_LOCK_ENABLED", copy);
    addIfPresent("IdentityProvider", copy);
    addIfPresent("jbpm.business.calendar", copy);
    // handle for custom environment entries that might be required by non engine use cases
    if (!environmentEntries.isEmpty()) {
        for (Entry<String, Object> entry : environmentEntries.entrySet()) {
            // don't override
            if (copy.get(entry.getKey()) != null) {
                continue;
            }
            copy.set(entry.getKey(), entry.getValue());
        }
    }
    return copy;
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) ArrayList(java.util.ArrayList) RuntimeEnvironment(org.kie.internal.runtime.manager.RuntimeEnvironment) Environment(org.kie.api.runtime.Environment)

Example 3 with ProcessInstanceResolverStrategy

use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method testProcessInstanceResolverStrategy.

@Test
public void testProcessInstanceResolverStrategy() throws Exception {
    // Setup
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource(PROCESS_NAME, this.getClass()), ResourceType.DRF);
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    ProcessInstance processInstance = ksession.createProcessInstance("process name", new HashMap<String, Object>());
    ksession.insert(processInstance);
    // strategy setup
    ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
    ObjectMarshallingStrategy[] strategies = { strategy, MarshallerFactory.newSerializeMarshallingStrategy() };
    // Test strategy.write
    org.kie.api.marshalling.MarshallingConfiguration marshallingConfig = new MarshallingConfigurationImpl(strategies, true, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MarshallerWriteContext writerContext = new MarshallerWriteContext(baos, ((InternalKnowledgeBase) kbase), (InternalWorkingMemory) ((StatefulKnowledgeSessionImpl) ksession), RuleBaseNodes.getNodeMap(((InternalKnowledgeBase) kbase)), marshallingConfig.getObjectMarshallingStrategyStore(), marshallingConfig.isMarshallProcessInstances(), marshallingConfig.isMarshallWorkItems(), ksession.getEnvironment());
    strategy.write(writerContext, processInstance);
    baos.close();
    writerContext.close();
    byte[] bytes = baos.toByteArray();
    int numCorrectBytes = calculateNumBytesForLong(processInstance.getId());
    assertTrue("Expected " + numCorrectBytes + " bytes, not " + bytes.length, bytes.length == numCorrectBytes);
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    long serializedProcessInstanceId = ois.readLong();
    assertTrue("Expected " + processInstance.getId() + ", not " + serializedProcessInstanceId, processInstance.getId() == serializedProcessInstanceId);
    // Test other strategy stuff
    ProcessInstanceManager pim = ProcessInstanceResolverStrategy.retrieveProcessInstanceManager(writerContext);
    assertNotNull(pim);
    assertNotNull(ProcessInstanceResolverStrategy.retrieveKnowledgeRuntime(writerContext));
    assertTrue(processInstance == pim.getProcessInstance(serializedProcessInstanceId));
    // Test strategy.read
    bais = new ByteArrayInputStream(bytes);
    MarshallerReaderContext readerContext = new MarshallerReaderContext(bais, ((KnowledgeBaseImpl) kbase), RuleBaseNodes.getNodeMap(((KnowledgeBaseImpl) kbase)), marshallingConfig.getObjectMarshallingStrategyStore(), ProtobufMarshaller.TIMER_READERS, marshallingConfig.isMarshallProcessInstances(), marshallingConfig.isMarshallWorkItems(), EnvironmentFactory.newEnvironment());
    readerContext.wm = ((StatefulKnowledgeSessionImpl) ksession).getInternalWorkingMemory();
    Object procInstObject = strategy.read(readerContext);
    assertTrue(procInstObject != null && procInstObject instanceof ProcessInstance);
    assertTrue(processInstance == procInstObject);
}
Also used : ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) ProcessInstanceManager(org.jbpm.process.instance.ProcessInstanceManager) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBase(org.kie.api.KieBase) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) MarshallingConfigurationImpl(org.drools.core.marshalling.impl.MarshallingConfigurationImpl) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallerWriteContext(org.drools.core.marshalling.impl.MarshallerWriteContext) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with ProcessInstanceResolverStrategy

use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.

the class ProcessInstanceResolverStrategyTest method testAccept.

@Test
public void testAccept() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
    assertTrue(strategy.accept(processInstance));
    Object object = new Object();
    assertTrue(!strategy.accept(object));
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with ProcessInstanceResolverStrategy

use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.

the class JbpmBpmn2TestCase method createEnvironment.

protected Environment createEnvironment(EntityManagerFactory emf) {
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(ENTITY_MANAGER_FACTORY, emf);
    env.set(TRANSACTION_MANAGER, com.arjuna.ats.jta.TransactionManager.transactionManager());
    if (sessionPersistence) {
        ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) env.get(OBJECT_MARSHALLING_STRATEGIES);
        List<ObjectMarshallingStrategy> listStrategies = new ArrayList<ObjectMarshallingStrategy>(Arrays.asList(strategies));
        listStrategies.add(0, new ProcessInstanceResolverStrategy());
        strategies = new ObjectMarshallingStrategy[listStrategies.size()];
        env.set(OBJECT_MARSHALLING_STRATEGIES, listStrategies.toArray(strategies));
    }
    return env;
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) ArrayList(java.util.ArrayList) Environment(org.kie.api.runtime.Environment)

Aggregations

ProcessInstanceResolverStrategy (org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy)5 KieBase (org.kie.api.KieBase)3 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)3 Environment (org.kie.api.runtime.Environment)3 ArrayList (java.util.ArrayList)2 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)2 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 ClassPathResource (org.drools.core.io.impl.ClassPathResource)1 MarshallerReaderContext (org.drools.core.marshalling.impl.MarshallerReaderContext)1 MarshallerWriteContext (org.drools.core.marshalling.impl.MarshallerWriteContext)1 MarshallingConfigurationImpl (org.drools.core.marshalling.impl.MarshallingConfigurationImpl)1 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)1 JPAPlaceholderResolverStrategy (org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy)1