use of org.drools.core.marshalling.MarshallerReaderContext in project drools by kiegroup.
the class PersisterHelper method loadStrategiesIndex.
private static void loadStrategiesIndex(MarshallerReaderContext context, ProtobufMessages.Header _header) throws IOException, ClassNotFoundException {
for (ProtobufMessages.Header.StrategyIndex _entry : _header.getStrategyList()) {
ObjectMarshallingStrategy strategyObject = context.getResolverStrategyFactory().getStrategyObject(_entry.getName());
if (strategyObject == null) {
throw new IllegalStateException("No strategy of type " + _entry.getName() + " available.");
}
context.getUsedStrategies().put(_entry.getId(), strategyObject);
Context ctx = strategyObject.createContext();
context.getStrategyContexts().put(strategyObject, ctx);
if (_entry.hasData() && ctx != null) {
ClassLoader classLoader = null;
if (context.getClassLoader() != null) {
classLoader = context.getClassLoader();
} else if (context.getKnowledgeBase() != null) {
classLoader = context.getKnowledgeBase().getRootClassLoader();
}
if (classLoader instanceof ProjectClassLoader) {
readRuntimeDefinedClasses(_header, (ProjectClassLoader) classLoader);
}
ctx.read(new DroolsObjectInputStream(_entry.getData().newInput(), classLoader));
}
}
}
use of org.drools.core.marshalling.MarshallerReaderContext in project drools by kiegroup.
the class WorkItemInfo method getWorkItem.
public WorkItem getWorkItem(Environment env, InternalKnowledgeBase kBase) {
this.env = env;
if (workItem == null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(workItemByteArray);
MarshallerReaderContext context = new ProtobufMarshallerReaderContext(bais, kBase, null, null, null, env);
try {
workItem = ProtobufInputMarshaller.readWorkItem(context);
} catch (Exception e) {
// for backward compatibility to be able to restore 5.x data
try {
context.close();
bais = new ByteArrayInputStream(workItemByteArray);
context = new ProtobufMarshallerReaderContext(bais, kBase, null, null, null, env);
workItem = InputMarshaller.readWorkItem(context);
} catch (IOException e1) {
logger.error("Unable to read work item with InputMarshaller", e1);
// throw the original exception produced by failed protobuf op
throw new RuntimeException("Unable to read work item ", e);
}
}
context.close();
} catch (IOException e) {
e.printStackTrace();
throw new IllegalArgumentException("IOException while loading work item: " + e.getMessage());
}
}
return workItem;
}
Aggregations