@SuppressWarnings({ "unchecked", "rawtypes" }) private static Object fallbackParse(MarshallerReaderContext context, Header header, ExtensionRegistry registry) throws Exception { Variable parseFrom = JBPMMessages.Variable.parseFrom(header.getPayload(), registry); Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, parseFrom); if (value instanceof Map) { Map result = new HashMap(); Map<String, Variable> variablesMap = (Map<String, Variable>) value; for (String key : variablesMap.keySet()) { result.put(key, ProtobufProcessMarshaller.unmarshallVariableValue(context, variablesMap.get(key))); } return result; } return value; } }
public static Variable marshallVariablesMap(MarshallerWriteContext context, Map<String, Object> variables) throws IOException{ Map<String, Variable> marshalledVariables = new HashMap<String, Variable>(); for(String key : variables.keySet()){ JBPMMessages.Variable.Builder builder = JBPMMessages.Variable.newBuilder().setName( key ); if(variables.get(key) != null){ ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject( variables.get(key) ); Integer index = context.getStrategyIndex( strategy ); builder.setStrategyIndex( index ) .setValue( ByteString.copyFrom( strategy.marshal( context.strategyContext.get( strategy ), context, variables.get(key) ) ) ); } marshalledVariables.put(key, builder.build()); } return marshallVariable(context, "variablesMap" ,marshalledVariables); }
public ProcessMarshaller newProcessMarshaller() { return new ProtobufProcessMarshaller(); }
Variable marshallVariable = null; if (o instanceof Map) { marshallVariable = ProtobufProcessMarshaller.marshallVariablesMap( context, (Map<String, Object>) o); } else { marshallVariable = ProtobufProcessMarshaller.marshallVariable( context, "results",
public static WorkItem readWorkItem(MarshallerReaderContext context, JBPMMessages.WorkItem _workItem ) throws IOException { return readWorkItem( context, _workItem, true ); }
public Timer serialize(JobContext jobCtx, MarshallerWriteContext outputCtx) { // do not store StartProcess timers as they are registered whenever session starts if (jobCtx instanceof StartProcessJobContext) { return null; } ProcessJobContext pctx = (ProcessJobContext) jobCtx; return ProtobufMessages.Timers.Timer .newBuilder() .setType(ProtobufMessages.Timers.TimerType.PROCESS) .setExtension( JBPMMessages.procTimer, JBPMMessages.ProcessTimer.newBuilder() .setTimer(ProtobufProcessMarshaller.writeTimer(outputCtx, pctx.getTimer())) .setTrigger(ProtobufOutputMarshaller.writeTrigger(pctx.getTrigger(), outputCtx)).build()) .build(); } }
public void deserialize(MarshallerReaderContext inCtx, Timer timer) throws ClassNotFoundException { JBPMMessages.ProcessTimer ptimer = timer.getExtension(JBPMMessages.procTimer); TimerService ts = inCtx.wm.getTimerService(); long processInstanceId = ptimer.getTimer().getProcessInstanceId(); Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, ptimer.getTrigger()); TimerInstance timerInstance = ProtobufProcessMarshaller.readTimer(inCtx, ptimer.getTimer()); TimerManager tm = ((InternalProcessRuntime) inCtx.wm.getProcessRuntime()).getTimerManager(); // check if the timer instance is not already registered to avoid duplicated timers if (!tm.getTimerMap().containsKey(timerInstance.getId())) { ProcessJobContext pctx = new ProcessJobContext(timerInstance, trigger, processInstanceId, inCtx.wm.getKnowledgeRuntime(), false); Date date = trigger.hasNextFireTime(); if (date != null) { long then = date.getTime(); long now = pctx.getKnowledgeRuntime().getSessionClock().getCurrentTime(); // overdue timer if (then < now) { trigger = new OverdueTrigger(trigger, pctx.getKnowledgeRuntime()); } } JobHandle jobHandle = ts.scheduleJob(processJob, pctx, trigger); timerInstance.setJobHandle(jobHandle); pctx.setJobHandle(jobHandle); tm.getTimerMap().put(timerInstance.getId(), timerInstance); } } }
Map<String, Object> value = ProtobufProcessMarshaller.unmarshallVariableContainerValue(context, parseFrom);
input.put(SINGLE_VAR_KEY, o); Message marshallVariable = ProtobufProcessMarshaller.marshallVariablesContainer(context, input); PersisterHelper.writeToStreamWithHeader(context, marshallVariable);
@Override public org.drools.core.process.instance.WorkItem readWorkItem(MarshallerReaderContext context) { try { ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null); Header _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry); JBPMMessages.WorkItem _workItem = JBPMMessages.WorkItem.parseFrom(_header.getPayload(), registry); return (org.drools.core.process.instance.WorkItem) readWorkItem(context, _workItem, persistWorkItemVars); } catch (IOException e) { throw new IllegalArgumentException( "IOException while fetching work item instance : " + e.getMessage(), e ); } catch (ClassNotFoundException e) { throw new IllegalArgumentException( "ClassNotFoundException while fetching work item instance : " + e.getMessage(), e ); } }
public Timer serialize(JobContext jobCtx, MarshallerWriteContext outputCtx) { // do not store StartProcess timers as they are registered whenever session starts if (jobCtx instanceof StartProcessJobContext) { return null; } ProcessJobContext pctx = (ProcessJobContext) jobCtx; return ProtobufMessages.Timers.Timer .newBuilder() .setType(ProtobufMessages.Timers.TimerType.PROCESS) .setExtension( JBPMMessages.procTimer, JBPMMessages.ProcessTimer.newBuilder() .setTimer(ProtobufProcessMarshaller.writeTimer(outputCtx, pctx.getTimer())) .setTrigger(ProtobufOutputMarshaller.writeTrigger(pctx.getTrigger(), outputCtx)).build()) .build(); } }
public void deserialize(MarshallerReaderContext inCtx, Timer timer) throws ClassNotFoundException { JBPMMessages.ProcessTimer ptimer = timer.getExtension(JBPMMessages.procTimer); TimerService ts = inCtx.wm.getTimerService(); long processInstanceId = ptimer.getTimer().getProcessInstanceId(); Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, ptimer.getTrigger()); TimerInstance timerInstance = ProtobufProcessMarshaller.readTimer(inCtx, ptimer.getTimer()); TimerManager tm = ((InternalProcessRuntime) inCtx.wm.getProcessRuntime()).getTimerManager(); // check if the timer instance is not already registered to avoid duplicated timers if (!tm.getTimerMap().containsKey(timerInstance.getId())) { ProcessJobContext pctx = new ProcessJobContext(timerInstance, trigger, processInstanceId, inCtx.wm.getKnowledgeRuntime(), false); Date date = trigger.hasNextFireTime(); if (date != null) { long then = date.getTime(); long now = pctx.getKnowledgeRuntime().getSessionClock().getCurrentTime(); // overdue timer if (then < now) { trigger = new OverdueTrigger(trigger, pctx.getKnowledgeRuntime()); } } JobHandle jobHandle = ts.scheduleJob(processJob, pctx, trigger); timerInstance.setJobHandle(jobHandle); pctx.setJobHandle(jobHandle); tm.getTimerMap().put(timerInstance.getId(), timerInstance); } } }
public static Map<String, Object> unmarshallVariableContainerValue(MarshallerReaderContext context, JBPMMessages.VariableContainer _variableContiner) throws IOException, ClassNotFoundException { Map<String, Object> variables = new HashMap<String, Object>(); if (_variableContiner.getVariableCount() == 0) { return variables; } for (Variable _variable : _variableContiner.getVariableList()) { Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable); variables.put(_variable.getName(), value); } return variables; }
public static JBPMMessages.WorkItem writeWorkItem(MarshallerWriteContext context, WorkItem workItem, boolean includeVariables) throws IOException { JBPMMessages.WorkItem.Builder _workItem = JBPMMessages.WorkItem.newBuilder() .setId( workItem.getId() ) .setProcessInstancesId( workItem.getProcessInstanceId() ) .setName( workItem.getName() ) .setState( workItem.getState() ); if (workItem instanceof org.drools.core.process.instance.WorkItem) { if (((org.drools.core.process.instance.WorkItem)workItem).getDeploymentId() != null){ _workItem.setDeploymentId(((org.drools.core.process.instance.WorkItem)workItem).getDeploymentId()); } _workItem.setNodeId(((org.drools.core.process.instance.WorkItem)workItem).getNodeId()) .setNodeInstanceId(((org.drools.core.process.instance.WorkItem)workItem).getNodeInstanceId()); } if ( includeVariables ) { Map<String, Object> parameters = workItem.getParameters(); for ( Map.Entry<String, Object> entry : parameters.entrySet() ) { _workItem.addVariable( marshallVariable( context, entry.getKey(), entry.getValue() ) ); } } return _workItem.build(); }
public void readWorkItems(MarshallerReaderContext context) throws IOException { ProtobufMessages.ProcessData _pdata = (ProtobufMessages.ProcessData) context.parameterObject; InternalWorkingMemory wm = context.wm; for ( JBPMMessages.WorkItem _workItem : _pdata.getExtension( JBPMMessages.workItem ) ) { WorkItem workItem = readWorkItem( context, _workItem ); ((WorkItemManager) wm.getWorkItemManager()).internalAddWorkItem( (org.drools.core.process.instance.WorkItem) workItem ); } }
public ProcessMarshaller newProcessMarshaller() { return new ProtobufProcessMarshaller(); }
public static WorkItem readWorkItem(MarshallerReaderContext context, JBPMMessages.WorkItem _workItem, boolean includeVariables) throws IOException { WorkItemImpl workItem = new WorkItemImpl(); workItem.setId( _workItem.getId() ); workItem.setProcessInstanceId( _workItem.getProcessInstancesId() ); workItem.setName( _workItem.getName() ); workItem.setState( _workItem.getState() ); workItem.setDeploymentId(_workItem.getDeploymentId()); workItem.setNodeId(_workItem.getNodeId()); workItem.setNodeInstanceId(_workItem.getNodeInstanceId()); if ( includeVariables ) { for ( JBPMMessages.Variable _variable : _workItem.getVariableList() ) { try { Object value = unmarshallVariableValue( context, _variable ); workItem.setParameter( _variable.getName(), value ); } catch ( ClassNotFoundException e ) { throw new IllegalArgumentException( "Could not reload parameter " + _variable.getName() + " for work item " + _workItem ); } } } return workItem; }
_instance.addVariable( ProtobufProcessMarshaller.marshallVariable( context, variable.getKey(), variable.getValue() ) );
public static WorkItem readWorkItem(MarshallerReaderContext context, JBPMMessages.WorkItem _workItem ) throws IOException { return readWorkItem( context, _workItem, true ); }
for ( JBPMMessages.Variable _variable : _instance.getVariableList() ) { try { Object _value = ProtobufProcessMarshaller.unmarshallVariableValue( context, _variable ); variableScopeInstance.internalSetVariable( _variable.getName(), _value );