Search in sources :

Example 1 with ObjectTypeConfiguration

use of org.drools.serialization.protobuf.ProtobufMessages.ObjectTypeConfiguration in project drools by kiegroup.

the class ProtobufInputMarshaller method readTruthMaintenanceSystem.

public static void readTruthMaintenanceSystem(ProtobufMarshallerReaderContext context, EntryPoint wmep, ProtobufMessages.EntryPoint _ep, List<PropagationContext> pctxs) throws IOException, ClassNotFoundException {
    TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem((NamedEntryPoint) wmep);
    // if 0, then the OTC was not serialized (older versions of drools)
    boolean wasOTCSerialized = _ep.getOtcCount() > 0;
    Set<String> tmsEnabled = new HashSet<String>();
    for (ObjectTypeConfiguration _otc : _ep.getOtcList()) {
        if (_otc.getTmsEnabled()) {
            tmsEnabled.add(_otc.getType());
        }
    }
    ProtobufMessages.TruthMaintenanceSystem _tms = _ep.getTms();
    for (ProtobufMessages.EqualityKey _key : _tms.getKeyList()) {
        InternalFactHandle handle = (InternalFactHandle) context.getHandles().get(_key.getHandleId());
        // ObjectTypeConf state is not marshalled, so it needs to be re-determined
        ObjectTypeConf typeConf = context.getWorkingMemory().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(handle.getEntryPointId(), handle.getObject());
        if (!typeConf.isTMSEnabled() && (!wasOTCSerialized || tmsEnabled.contains(typeConf.getTypeName()))) {
            typeConf.enableTMS();
        }
        EqualityKey key = new TruthMaintenanceSystemEqualityKey(handle, _key.getStatus());
        handle.setEqualityKey(key);
        if (key.getStatus() == EqualityKey.JUSTIFIED) {
            // not yet added to the object stores
            handle.getEntryPoint(((NamedEntryPoint) wmep).getReteEvaluator()).getObjectStore().addHandle(handle, handle.getObject());
            // add handle to object type node
            assertHandleIntoOTN(context, context.getWorkingMemory(), handle, pctxs);
        }
        for (Long factHandleId : _key.getOtherHandleList()) {
            handle = context.getHandles().get(factHandleId);
            key.addFactHandle(handle);
            handle.setEqualityKey(key);
        }
        tms.put(key);
        context.getFilter().fireRNEAs(context.getWorkingMemory());
        readBeliefSet(context, tms, _key);
    }
}
Also used : TruthMaintenanceSystem(org.drools.core.common.TruthMaintenanceSystem) ObjectTypeConfiguration(org.drools.serialization.protobuf.ProtobufMessages.ObjectTypeConfiguration) TruthMaintenanceSystemEqualityKey(org.drools.tms.TruthMaintenanceSystemEqualityKey) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) TruthMaintenanceSystemEqualityKey(org.drools.tms.TruthMaintenanceSystemEqualityKey) EqualityKey(org.drools.core.common.EqualityKey) InternalFactHandle(org.drools.core.common.InternalFactHandle) HashSet(java.util.HashSet)

Example 2 with ObjectTypeConfiguration

use of org.drools.serialization.protobuf.ProtobufMessages.ObjectTypeConfiguration in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeObjectTypeConfiguration.

private static void writeObjectTypeConfiguration(MarshallerWriteContext context, ObjectTypeConfigurationRegistry otcr, ProtobufMessages.EntryPoint.Builder _epb) {
    Collection<ObjectTypeConf> values = otcr.values();
    ObjectTypeConf[] otcs = values.toArray(new ObjectTypeConf[values.size()]);
    Arrays.sort(otcs, new Comparator<ObjectTypeConf>() {

        @Override
        public int compare(ObjectTypeConf o1, ObjectTypeConf o2) {
            return o1.getTypeName().compareTo(o2.getTypeName());
        }
    });
    for (ObjectTypeConf otc : otcs) {
        ObjectTypeNode objectTypeNode = otc.getConcreteObjectTypeNode();
        if (objectTypeNode != null) {
            final ObjectTypeNodeMemory memory = context.getWorkingMemory().getNodeMemory(objectTypeNode);
            if (memory != null) {
                ObjectTypeConfiguration _otc = ObjectTypeConfiguration.newBuilder().setType(otc.getTypeName()).setTmsEnabled(otc.isTMSEnabled()).build();
                _epb.addOtc(_otc);
            }
        }
    }
}
Also used : ObjectTypeConfiguration(org.drools.serialization.protobuf.ProtobufMessages.ObjectTypeConfiguration) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ObjectTypeNodeMemory(org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory)

Aggregations

ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)2 ObjectTypeConfiguration (org.drools.serialization.protobuf.ProtobufMessages.ObjectTypeConfiguration)2 HashSet (java.util.HashSet)1 EqualityKey (org.drools.core.common.EqualityKey)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 TruthMaintenanceSystem (org.drools.core.common.TruthMaintenanceSystem)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 ObjectTypeNodeMemory (org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory)1 TruthMaintenanceSystemEqualityKey (org.drools.tms.TruthMaintenanceSystemEqualityKey)1