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