Search in sources :

Example 1 with Context

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context in project automatiko-engine by automatiko-io.

the class PersisterHelper method writeStrategiesIndex.

public static void writeStrategiesIndex(MarshallerWriteContext context, AutomatikoMessages.Header.Builder _header) throws IOException {
    for (Entry<ObjectMarshallingStrategy, Integer> entry : context.usedStrategies.entrySet()) {
        Builder _strat = AutomatikoMessages.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 ObjectOutputStream(os));
            _strat.setData(os.toByteString());
            os.close();
        }
        _header.addStrategy(_strat.build());
    }
}
Also used : Context(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) Builder(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header.StrategyIndex.Builder) Output(com.google.protobuf.ByteString.Output) ObjectOutputStream(java.io.ObjectOutputStream)

Example 2 with Context

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context in project automatiko-engine by automatiko-io.

the class PersisterHelper method loadStrategiesIndex.

public static void loadStrategiesIndex(MarshallerReaderContext context, AutomatikoMessages.Header _header) throws IOException, ClassNotFoundException {
    for (AutomatikoMessages.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;
            }
            ctx.read(new ObjectInputStream(_entry.getData().newInput()));
        }
    }
}
Also used : Context(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectMarshallingStrategy (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy)2 Context (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context)2 Output (com.google.protobuf.ByteString.Output)1 Builder (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header.StrategyIndex.Builder)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1