Search in sources :

Example 1 with ProcessInstanceMarshaller

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

the class ProcessInstanceInfo method transform.

public void transform() {
    // if (processInstance == null) {
    // return;
    // }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    boolean variablesChanged = false;
    try {
        ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(baos, null, null, null, null, this.env);
        context.setProcessInstanceId(processInstance.getId());
        context.setState(processInstance.getState() == ProcessInstance.STATE_ACTIVE ? ProcessMarshallerWriteContext.STATE_ACTIVE : ProcessMarshallerWriteContext.STATE_COMPLETED);
        String processType = ((ProcessInstanceImpl) processInstance).getProcess().getType();
        saveProcessInstanceType(context, processInstance, processType);
        ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType);
        Object result = marshaller.writeProcessInstance(context, processInstance);
        if (marshaller instanceof ProtobufRuleFlowProcessInstanceMarshaller && result != null) {
            JBPMMessages.ProcessInstance _instance = (JBPMMessages.ProcessInstance) result;
            PersisterHelper.writeToStreamWithHeader(context, _instance);
        }
        context.close();
    } catch (IOException e) {
        throw new IllegalArgumentException("IOException while storing process instance " + processInstance.getId() + ": " + e.getMessage(), e);
    }
    byte[] newByteArray = baos.toByteArray();
    if (variablesChanged || !Arrays.equals(newByteArray, processInstanceByteArray)) {
        this.state = processInstance.getState();
        this.lastModificationDate = new Date();
        this.processInstanceByteArray = newByteArray;
        this.eventTypes.clear();
        for (String type : processInstance.getEventTypes()) {
            eventTypes.add(type);
        }
    }
    if (!processInstance.getProcessId().equals(this.processId)) {
        this.processId = processInstance.getProcessId();
    }
    ((WorkflowProcessInstanceImpl) processInstance).setPersisted(true);
}
Also used : ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProcessInstanceMarshaller) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) JBPMMessages(org.jbpm.marshalling.impl.JBPMMessages) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Date(java.util.Date) ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PersistentProcessInstance(org.jbpm.persistence.api.PersistentProcessInstance) ProcessMarshallerWriteContext(org.drools.core.marshalling.impl.ProcessMarshallerWriteContext)

Example 2 with ProcessInstanceMarshaller

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

the class ProcessInstanceInfo method getProcessInstance.

public ProcessInstance getProcessInstance(InternalKnowledgeRuntime kruntime, Environment env, boolean readOnly) {
    this.env = env;
    if (processInstance == null) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(processInstanceByteArray);
            MarshallerReaderContext context = new MarshallerReaderContext(bais, (InternalKnowledgeBase) kruntime.getKieBase(), null, null, ProtobufMarshaller.TIMER_READERS, this.env);
            ProcessInstanceMarshaller marshaller = getMarshallerFromContext(context);
            context.wm = ((StatefulKnowledgeSessionImpl) kruntime).getInternalWorkingMemory();
            processInstance = marshaller.readProcessInstance(context);
            ((WorkflowProcessInstanceImpl) processInstance).setPersisted(false);
            if (readOnly) {
                ((WorkflowProcessInstanceImpl) processInstance).disconnect();
            }
            context.close();
        } catch (IOException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("IOException while loading process instance: " + e.getMessage(), e);
        }
    }
    ((WorkflowProcessInstanceImpl) processInstance).internalSetStartDate(this.startDate);
    return processInstance;
}
Also used : ProtobufRuleFlowProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) ProcessInstanceMarshaller(org.jbpm.marshalling.impl.ProcessInstanceMarshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ProcessInstanceMarshaller (org.jbpm.marshalling.impl.ProcessInstanceMarshaller)2 ProtobufRuleFlowProcessInstanceMarshaller (org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 MarshallerReaderContext (org.drools.core.marshalling.impl.MarshallerReaderContext)1 ProcessMarshallerWriteContext (org.drools.core.marshalling.impl.ProcessMarshallerWriteContext)1 JBPMMessages (org.jbpm.marshalling.impl.JBPMMessages)1 PersistentProcessInstance (org.jbpm.persistence.api.PersistentProcessInstance)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1