Search in sources :

Example 1 with MarshallerReaderContext

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));
        }
    }
}
Also used : Context(org.kie.api.marshalling.ObjectMarshallingStrategy.Context) MarshallerReaderContext(org.drools.core.marshalling.MarshallerReaderContext) MarshallerWriteContext(org.drools.core.marshalling.MarshallerWriteContext) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) Header(org.drools.serialization.protobuf.ProtobufMessages.Header) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader)

Example 2 with MarshallerReaderContext

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;
}
Also used : ProtobufMarshallerReaderContext(org.drools.serialization.protobuf.ProtobufMarshallerReaderContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtobufMarshallerReaderContext(org.drools.serialization.protobuf.ProtobufMarshallerReaderContext) MarshallerReaderContext(org.drools.core.marshalling.MarshallerReaderContext) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

MarshallerReaderContext (org.drools.core.marshalling.MarshallerReaderContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)1 MarshallerWriteContext (org.drools.core.marshalling.MarshallerWriteContext)1 ProtobufMarshallerReaderContext (org.drools.serialization.protobuf.ProtobufMarshallerReaderContext)1 Header (org.drools.serialization.protobuf.ProtobufMessages.Header)1 ProjectClassLoader (org.drools.wiring.api.classloader.ProjectClassLoader)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 Context (org.kie.api.marshalling.ObjectMarshallingStrategy.Context)1