Search in sources :

Example 1 with ProtobufRuleFlowProcessInstanceMarshaller

use of io.automatiko.engine.workflow.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller in project automatiko-engine by automatiko-io.

the class ProcessInstanceMarshaller method marhsallProcessInstance.

public byte[] marhsallProcessInstance(ProcessInstance<?> processInstance) {
    io.automatiko.engine.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
    if (pi == null) {
        return null;
    }
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(baos, ((io.automatiko.engine.workflow.base.instance.ProcessInstance) pi).getProcessRuntime(), null, env);
        context.setProcessInstanceId(pi.getId());
        context.setState(pi.getState());
        String processType = pi.getProcess().getType();
        context.stream.writeUTF(processType);
        io.automatiko.engine.workflow.marshalling.impl.ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType);
        Object result = marshaller.writeProcessInstance(context, pi);
        if (marshaller instanceof ProtobufRuleFlowProcessInstanceMarshaller && result != null) {
            AutomatikoMessages.ProcessInstance _instance = (AutomatikoMessages.ProcessInstance) result;
            PersisterHelper.writeToStreamWithHeader(context, _instance);
        }
        context.close();
        ((WorkflowProcessInstanceImpl) pi).disconnect();
        return baos.toByteArray();
    } catch (Exception e) {
        throw new RuntimeException("Error while marshalling process instance", e);
    }
}
Also used : AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) ProtobufRuleFlowProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) StringExportedProcessInstance(io.automatiko.engine.workflow.StringExportedProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) AutomatikoMessages(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages)

Aggregations

WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 StringExportedProcessInstance (io.automatiko.engine.workflow.StringExportedProcessInstance)1 AutomatikoMessages (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages)1 ProtobufRuleFlowProcessInstanceMarshaller (io.automatiko.engine.workflow.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller)1 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 StreamCorruptedException (java.io.StreamCorruptedException)1