use of org.kie.api.marshalling.ObjectMarshallingStrategy in project drools by kiegroup.
the class InputMarshaller method readWorkItem.
public static WorkItem readWorkItem(MarshallerReaderContext context) throws IOException {
ObjectInputStream stream = context.stream;
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(stream.readLong());
workItem.setProcessInstanceId(stream.readLong());
workItem.setName(stream.readUTF());
workItem.setState(stream.readInt());
// WorkItem Paramaters
int nbVariables = stream.readInt();
if (nbVariables > 0) {
for (int i = 0; i < nbVariables; i++) {
String name = stream.readUTF();
try {
int index = stream.readInt();
ObjectMarshallingStrategy strategy = null;
// Old way of retrieving strategy objects
if (index >= 0) {
strategy = context.resolverStrategyFactory.getStrategy(index);
if (strategy == null) {
throw new IllegalStateException("No strategy of with index " + index + " available.");
}
} else // New way
if (index == -2) {
String strategyClassName = stream.readUTF();
// fix for backwards compatibility (5.x -> 6.x)
if ("org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy".equals(strategyClassName)) {
strategyClassName = "org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy";
}
strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
Object value = strategy.read(stream);
workItem.setParameter(name, value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + name);
}
}
}
return workItem;
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project drools by kiegroup.
the class ProtobufInputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(MarshallerReaderContext context, EntryPoint entryPoint, FactHandle _handle) throws IOException, ClassNotFoundException {
Object object = null;
ObjectMarshallingStrategy strategy = null;
if (_handle.hasStrategyIndex()) {
strategy = context.usedStrategies.get(_handle.getStrategyIndex());
object = strategy.unmarshal(context.strategyContexts.get(strategy), context, _handle.getObject().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
EntryPointId confEP;
if (entryPoint != null) {
confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
} else {
confEP = context.wm.getEntryPoint();
}
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
InternalFactHandle handle = null;
switch(_handle.getType()) {
case FACT:
{
handle = new DefaultFactHandle(_handle.getId(), object, _handle.getRecency(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
break;
}
case QUERY:
{
handle = new QueryElementFactHandle(object, _handle.getId(), _handle.getRecency());
break;
}
case EVENT:
{
handle = new EventFactHandle(_handle.getId(), object, _handle.getRecency(), _handle.getTimestamp(), _handle.getDuration(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
((EventFactHandle) handle).setExpired(_handle.getIsExpired());
((EventFactHandle) handle).setOtnCount(_handle.getOtnCount());
// ((EventFactHandle) handle).setActivationsCount( _handle.getActivationsCount() );
break;
}
default:
{
throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + _handle.getType());
}
}
return handle;
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project drools by kiegroup.
the class ProtobufInputMarshaller method readBeliefSet.
private static void readBeliefSet(MarshallerReaderContext context, TruthMaintenanceSystem tms, EqualityKey key, ProtobufMessages.EqualityKey _key) throws IOException, ClassNotFoundException {
if (_key.hasBeliefSet()) {
ProtobufMessages.BeliefSet _beliefSet = _key.getBeliefSet();
InternalFactHandle handle = (InternalFactHandle) context.handles.get(_key.getHandleId());
// phreak might serialize empty belief sets, so he have to handle it during deserialization
if (_beliefSet.getLogicalDependencyCount() > 0) {
for (ProtobufMessages.LogicalDependency _logicalDependency : _beliefSet.getLogicalDependencyList()) {
ProtobufMessages.Activation _activation = _logicalDependency.getActivation();
Activation activation = (Activation) context.filter.getTuplesCache().get(PersisterHelper.createActivationKey(_activation.getPackageName(), _activation.getRuleName(), _activation.getTuple())).getContextObject();
Object object = null;
ObjectMarshallingStrategy strategy = null;
if (_logicalDependency.hasObjectStrategyIndex()) {
strategy = context.usedStrategies.get(_logicalDependency.getObjectStrategyIndex());
object = strategy.unmarshal(context.strategyContexts.get(strategy), context, _logicalDependency.getObject().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
Object value = null;
if (_logicalDependency.hasValueStrategyIndex()) {
strategy = context.usedStrategies.get(_logicalDependency.getValueStrategyIndex());
value = strategy.unmarshal(context.strategyContexts.get(strategy), context, _logicalDependency.getValue().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
}
ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(((NamedEntryPoint) handle.getEntryPoint()).getEntryPoint(), handle.getObject());
tms.readLogicalDependency(handle, object, value, activation, activation.getPropagationContext(), activation.getRule(), typeConf);
}
} else {
handle.getEqualityKey().setBeliefSet(tms.getBeliefSystem().newBeliefSet(handle));
}
}
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project drools by kiegroup.
the class OldOutputMarshallerMethods method writeWorkItem_v1.
// Changed with JBRULES-3257
public static void writeWorkItem_v1(MarshallerWriteContext context, WorkItem workItem) throws IOException {
ObjectOutputStream stream = context.stream;
stream.writeLong(workItem.getId());
stream.writeLong(workItem.getProcessInstanceId());
stream.writeUTF(workItem.getName());
stream.writeInt(workItem.getState());
// Work Item Parameters
Map<String, Object> parameters = workItem.getParameters();
Collection<Object> notNullValues = new ArrayList<Object>();
for (Object value : parameters.values()) {
if (value != null) {
notNullValues.add(value);
}
}
stream.writeInt(notNullValues.size());
for (String key : parameters.keySet()) {
Object object = parameters.get(key);
if (object != null) {
stream.writeUTF(key);
int index = context.objectMarshallingStrategyStore.getStrategy(object);
stream.writeInt(index);
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategy(index);
if (strategy.accept(object)) {
strategy.write(stream, object);
}
}
}
}
use of org.kie.api.marshalling.ObjectMarshallingStrategy in project drools by kiegroup.
the class EventAccessorRestoreTest method createMarshaller.
private Marshaller createMarshaller(KieBase kbase) {
ObjectMarshallingStrategyAcceptor acceptor = MarshallerFactory.newClassFilterAcceptor(new String[] { "*.*" });
ObjectMarshallingStrategy strategy = MarshallerFactory.newSerializeMarshallingStrategy(acceptor);
return MarshallerFactory.newMarshaller(kbase, new ObjectMarshallingStrategy[] { strategy });
}
Aggregations