Search in sources :

Example 1 with Context

use of org.kie.api.marshalling.ObjectMarshallingStrategy.Context 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.resolverStrategyFactory.getStrategyObject(_entry.getName());
        if (strategyObject == null) {
            throw new IllegalStateException("No strategy of type " + _entry.getName() + " available.");
        }
        context.usedStrategies.put(_entry.getId(), strategyObject);
        Context ctx = strategyObject.createContext();
        context.strategyContexts.put(strategyObject, ctx);
        if (_entry.hasData() && ctx != null) {
            ClassLoader classLoader = null;
            if (context.classLoader != null) {
                classLoader = context.classLoader;
            } else if (context.kBase != null) {
                classLoader = context.kBase.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) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) Header(org.drools.core.marshalling.impl.ProtobufMessages.Header) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ProjectClassLoader(org.drools.core.common.ProjectClassLoader)

Example 2 with Context

use of org.kie.api.marshalling.ObjectMarshallingStrategy.Context 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 3 with Context

use of org.kie.api.marshalling.ObjectMarshallingStrategy.Context in project drools by kiegroup.

the class PersisterHelper method writeStrategiesIndex.

private static void writeStrategiesIndex(MarshallerWriteContext context, ProtobufMessages.Header.Builder _header) throws IOException {
    for (Entry<ObjectMarshallingStrategy, Integer> entry : context.usedStrategies.entrySet()) {
        Builder _strat = ProtobufMessages.Header.StrategyIndex.newBuilder().setId(entry.getValue().intValue()).setName(entry.getKey().getName());
        Context ctx = context.strategyContext.get(entry.getKey());
        if (ctx != null) {
            Output os = ByteString.newOutput();
            ctx.write(new DroolsObjectOutputStream(os));
            _strat.setData(os.toByteString());
            os.close();
        }
        _header.addStrategy(_strat.build());
    }
}
Also used : Context(org.kie.api.marshalling.ObjectMarshallingStrategy.Context) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) Builder(org.drools.core.marshalling.impl.ProtobufMessages.Header.StrategyIndex.Builder) Output(com.google.protobuf.ByteString.Output) DroolsObjectOutputStream(org.drools.core.common.DroolsObjectOutputStream)

Example 4 with Context

use of org.kie.api.marshalling.ObjectMarshallingStrategy.Context in project drools by kiegroup.

the class PersisterHelper method writeStrategiesIndex.

private static void writeStrategiesIndex(MarshallerWriteContext context, ProtobufMessages.Header.Builder _header) throws IOException {
    for (Entry<ObjectMarshallingStrategy, Integer> entry : context.getUsedStrategies().entrySet()) {
        Builder _strat = ProtobufMessages.Header.StrategyIndex.newBuilder().setId(entry.getValue().intValue()).setName(entry.getKey().getName());
        Context ctx = context.getStrategyContext().get(entry.getKey());
        if (ctx != null) {
            Output os = ByteString.newOutput();
            ctx.write(new DroolsObjectOutputStream(os));
            _strat.setData(os.toByteString());
            os.close();
        }
        _header.addStrategy(_strat.build());
    }
}
Also used : Context(org.kie.api.marshalling.ObjectMarshallingStrategy.Context) MarshallerReaderContext(org.drools.core.marshalling.MarshallerReaderContext) MarshallerWriteContext(org.drools.core.marshalling.MarshallerWriteContext) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) Builder(org.drools.serialization.protobuf.ProtobufMessages.Header.StrategyIndex.Builder) Output(com.google.protobuf.ByteString.Output) DroolsObjectOutputStream(org.drools.core.common.DroolsObjectOutputStream)

Aggregations

ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)4 Context (org.kie.api.marshalling.ObjectMarshallingStrategy.Context)4 Output (com.google.protobuf.ByteString.Output)2 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)2 DroolsObjectOutputStream (org.drools.core.common.DroolsObjectOutputStream)2 MarshallerReaderContext (org.drools.core.marshalling.MarshallerReaderContext)2 MarshallerWriteContext (org.drools.core.marshalling.MarshallerWriteContext)2 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 Header (org.drools.core.marshalling.impl.ProtobufMessages.Header)1 Builder (org.drools.core.marshalling.impl.ProtobufMessages.Header.StrategyIndex.Builder)1 Header (org.drools.serialization.protobuf.ProtobufMessages.Header)1 Builder (org.drools.serialization.protobuf.ProtobufMessages.Header.StrategyIndex.Builder)1 ProjectClassLoader (org.drools.wiring.api.classloader.ProjectClassLoader)1