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());
}
}
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()));
}
}
}
Aggregations