use of org.kie.api.marshalling.ObjectMarshallingStrategy in project opennms by OpenNMS.
the class DroolsCorrelationEngine method marshallStateToDisk.
private void marshallStateToDisk(boolean serialize) {
final File stateFile = getPathToState().toFile();
LOG.debug("Saving state for engine {} in {} ...", m_name, stateFile);
final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
final ObjectMarshallingStrategy oms = serialize ? kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
final Marshaller marshaller = kMarshallers.newMarshaller(m_kieBase, new ObjectMarshallingStrategy[] { oms });
try (FileOutputStream fos = new FileOutputStream(stateFile)) {
m_kieSession.halt();
marshaller.marshall(fos, m_kieSession);
m_kieSession.dispose();
m_kieSession.destroy();
LOG.info("Sucessfully save state for engine {} in {}.", m_name, stateFile);
} catch (IOException e) {
LOG.error("Failed to save state for engine {} in {}.", m_name, stateFile, e);
}
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project opennms by OpenNMS.
the class DroolsCorrelationEngine method unmarshallStateFromDisk.
private void unmarshallStateFromDisk(boolean serialize) {
final File stateFile = getPathToState().toFile();
if (!stateFile.exists()) {
LOG.error("Can't restore state from {} because the file doesn't exist", stateFile);
return;
}
LOG.debug("Restoring state for engine {} from {} ...", m_name, stateFile);
final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
final ObjectMarshallingStrategy oms = serialize ? kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
final Marshaller marshaller = kMarshallers.newMarshaller(m_kieBase, new ObjectMarshallingStrategy[] { oms });
try (FileInputStream fin = new FileInputStream(stateFile)) {
marshaller.unmarshall(fin, m_kieSession);
stateFile.delete();
LOG.info("Sucessfully restored state for engine {} from {}.", m_name, stateFile);
} catch (IOException | ClassNotFoundException e) {
LOG.error("Failed to restore state for engine {} from {}.", m_name, stateFile, e);
}
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project opennms by OpenNMS.
the class DroolsNorthbounder method marshallStateToDisk.
/**
* Marshall state to disk.
*
* @param serialize the serialize
*/
private void marshallStateToDisk(boolean serialize) {
final File stateFile = getPathToState().toFile();
LOG.debug("Saving state for engine {} in {} ...", getName(), stateFile);
final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
final ObjectMarshallingStrategy oms = serialize ? kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
final Marshaller marshaller = kMarshallers.newMarshaller(m_kieBase, new ObjectMarshallingStrategy[] { oms });
try (FileOutputStream fos = new FileOutputStream(stateFile)) {
m_kieSession.halt();
marshaller.marshall(fos, m_kieSession);
m_kieSession.dispose();
m_kieSession.destroy();
LOG.info("Sucessfully save state for engine {} in {}. There are {} elements on the working memory.", getName(), stateFile, m_kieSession.getObjects().size());
} catch (IOException e) {
LOG.error("Failed to save state for engine {} in {}.", getName(), stateFile, e);
}
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project jbpm by kiegroup.
the class CaseFileInstanceMarshallingStrategy method unmarshal.
@SuppressWarnings("unchecked")
@Override
public Object unmarshal(Context context, ObjectInputStream is, byte[] object, ClassLoader classloader) throws IOException, ClassNotFoundException {
logger.debug("About to read {} bytes to unmarshal CaseFileInstance", (object == null ? 0 : object.length));
Map<String, Object> caseFileContent = (Map<String, Object>) caseFileMarshaller.unmarshal(context, is, object, classloader);
CaseFileInstanceImpl caseFileInstance = new CaseFileInstanceImpl();
caseFileInstance.setCaseId((String) caseFileContent.get(CASE_ID_KEY));
caseFileInstance.setDefinitionId((String) caseFileContent.get(CASE_DEF_ID_KEY));
caseFileInstance.setCaseStartDate((Date) caseFileContent.get(CASE_START_KEY));
caseFileInstance.setCaseEndDate((Date) caseFileContent.get(CASE_END_KEY));
caseFileInstance.setCaseReopenDate((Date) caseFileContent.get(CASE_REOPEN_KEY));
caseFileInstance.setRolesAssignments((Map<String, CaseRoleInstance>) caseFileContent.get(CASE_ROLE_ASSIGNMENTS_KEY));
caseFileInstance.setComments((List<CommentInstance>) caseFileContent.get(CASE_COMMENTS_KEY));
logger.debug("CaseFileInstance meta data unmarshalled properly into {}", caseFileInstance);
List<SerializedContent> caseDataContent = (List<SerializedContent>) caseFileContent.get(CASE_DATA_KEY);
logger.debug("About to read serialized content {}", caseDataContent);
for (SerializedContent serializedContent : caseDataContent) {
ObjectMarshallingStrategy marshaller = marshallersByName.get(serializedContent.getMarshaller());
logger.debug("Marshaller for {} is of type {}", serializedContent, marshaller);
Object value = marshaller.unmarshal(context, is, serializedContent.getContent(), classloader);
caseFileInstance.add(serializedContent.getName(), value);
logger.debug("Data unmarshalled into {} and put into case file under '{}' name", value, serializedContent.getName());
}
caseFileInstance.setAccessRestrictions((Map<String, List<String>>) caseFileContent.get(CASE_DATA_RESTRICTIONS_KEY));
caseFileInstance.setParentInstanceId((Long) caseFileContent.get(CASE_PARENT_INSTANCE_ID_KEY));
caseFileInstance.setParentWorkItemId((Long) caseFileContent.get(CASE_PARENT_WORK_ITEM_ID_KEY));
logger.debug("Unmarshal of CaseFileInstance completed - result {}", caseFileInstance);
return caseFileInstance;
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project jbpm by kiegroup.
the class MarshalVariablesProcessEventListener method afterProcessCompleted.
public void afterProcessCompleted(ProcessCompletedEvent event) {
ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) event.getKieRuntime().getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
VariableScopeInstance variableScope = (VariableScopeInstance) ((WorkflowProcessInstance) event.getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
Map<String, Object> variables = variableScope.getVariables();
for (Map.Entry<String, Object> variable : variables.entrySet()) {
logger.debug("Searching for applicable strategy to handle variable name '{}' value '{}'", variable.getKey(), variable.getValue());
for (ObjectMarshallingStrategy strategy : strategies) {
// are removed together with process instance
if (strategy instanceof SerializablePlaceholderResolverStrategy) {
continue;
}
if (strategy.accept(variable.getValue())) {
logger.debug("Strategy of type {} found to handle variable '{}'", strategy, variable.getKey());
try {
ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(new ByteArrayOutputStream(), null, null, null, null, event.getKieRuntime().getEnvironment());
context.setProcessInstanceId(event.getProcessInstance().getId());
context.setState(ProcessMarshallerWriteContext.STATE_COMPLETED);
strategy.marshal(null, context, variable.getValue());
logger.debug("Variable '{}' successfully persisted by strategy {}", variable.getKey(), strategy);
break;
} catch (Exception e) {
logger.warn("Errer while storing process variable {} due to {}", variable.getKey(), e.getMessage());
logger.debug("Variable marshal error:", e);
}
}
}
}
}
Aggregations