Search in sources :

Example 1 with ActivationKey

use of org.drools.serialization.protobuf.marshalling.ActivationKey in project drools by kiegroup.

the class ProtobufInputMarshaller method readBeliefSet.

private static void readBeliefSet(MarshallerReaderContext context, TruthMaintenanceSystem tms, ProtobufMessages.EqualityKey _key) throws IOException, ClassNotFoundException {
    if (_key.hasBeliefSet()) {
        ProtobufMessages.BeliefSet _beliefSet = _key.getBeliefSet();
        InternalFactHandle handle = (InternalFactHandle) context.getHandles().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();
                ActivationKey activationKey = getActivationKey(context, _activation);
                Activation activation = (Activation) ((PBActivationsFilter) context.getFilter()).getTuplesCache().get(activationKey);
                Object object = null;
                ObjectMarshallingStrategy strategy = null;
                if (_logicalDependency.hasObjectStrategyIndex()) {
                    strategy = context.getUsedStrategies().get(_logicalDependency.getObjectStrategyIndex());
                    object = strategy.unmarshal(context.getStrategyContexts().get(strategy), (ObjectInputStream) context, _logicalDependency.getObject().toByteArray(), (context.getKnowledgeBase() == null) ? null : context.getKnowledgeBase().getRootClassLoader());
                }
                Object value = null;
                if (_logicalDependency.hasValueStrategyIndex()) {
                    strategy = context.getUsedStrategies().get(_logicalDependency.getValueStrategyIndex());
                    value = strategy.unmarshal(context.getStrategyContexts().get(strategy), (ObjectInputStream) context, _logicalDependency.getValue().toByteArray(), (context.getKnowledgeBase() == null) ? null : context.getKnowledgeBase().getRootClassLoader());
                }
                ObjectTypeConf typeConf = context.getWorkingMemory().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject());
                tms.readLogicalDependency(handle, object, value, activation, typeConf);
            }
        } else {
            ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).setBeliefSet(((TruthMaintenanceSystemImpl) tms).getBeliefSystem().newBeliefSet(handle));
        }
    }
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) Activation(org.drools.core.spi.Activation) ActivationKey(org.drools.serialization.protobuf.marshalling.ActivationKey) TruthMaintenanceSystemEqualityKey(org.drools.tms.TruthMaintenanceSystemEqualityKey) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) InternalFactHandle(org.drools.core.common.InternalFactHandle) TruthMaintenanceSystemImpl(org.drools.tms.TruthMaintenanceSystemImpl) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)1 Activation (org.drools.core.spi.Activation)1 ActivationKey (org.drools.serialization.protobuf.marshalling.ActivationKey)1 TruthMaintenanceSystemEqualityKey (org.drools.tms.TruthMaintenanceSystemEqualityKey)1 TruthMaintenanceSystemImpl (org.drools.tms.TruthMaintenanceSystemImpl)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1