Search in sources :

Example 1 with MarshallerWriteContext

use of org.drools.core.marshalling.MarshallerWriteContext in project drools by kiegroup.

the class WorkItemInfo method transform.

// @PreUpdate
@Override
public void transform() {
    this.state = workItem.getState();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        MarshallerWriteContext context = new ProtobufMarshallerWriteContext(baos, null, null, null, null, this.env);
        ProtobufOutputMarshaller.writeWorkItem(context, workItem);
        context.close();
        this.workItemByteArray = baos.toByteArray();
    } catch (IOException e) {
        throw new IllegalArgumentException("IOException while storing workItem " + workItem.getId() + ": " + e.getMessage());
    }
}
Also used : ProtobufMarshallerWriteContext(org.drools.serialization.protobuf.ProtobufMarshallerWriteContext) ProtobufMarshallerWriteContext(org.drools.serialization.protobuf.ProtobufMarshallerWriteContext) MarshallerWriteContext(org.drools.core.marshalling.MarshallerWriteContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with MarshallerWriteContext

use of org.drools.core.marshalling.MarshallerWriteContext 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

MarshallerWriteContext (org.drools.core.marshalling.MarshallerWriteContext)2 Output (com.google.protobuf.ByteString.Output)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 DroolsObjectOutputStream (org.drools.core.common.DroolsObjectOutputStream)1 MarshallerReaderContext (org.drools.core.marshalling.MarshallerReaderContext)1 ProtobufMarshallerWriteContext (org.drools.serialization.protobuf.ProtobufMarshallerWriteContext)1 Builder (org.drools.serialization.protobuf.ProtobufMessages.Header.StrategyIndex.Builder)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 Context (org.kie.api.marshalling.ObjectMarshallingStrategy.Context)1