Пример #1
0
  public static ObjectTypeNode attachObjectTypeNode(BuildContext context, ObjectType objectType) {
    final InternalRuleBase ruleBase = context.getRuleBase();
    ruleBase.readLock();
    try {
      InternalWorkingMemory[] wms = context.getWorkingMemories();

      EntryPointNode epn = ruleBase.getRete().getEntryPointNode(context.getCurrentEntryPoint());
      if (epn == null) {
        epn = new EntryPointNode(context.getNextId(), ruleBase.getRete(), context);
        if (wms.length > 0) {
          epn.attach(wms);
        } else {
          epn.attach();
        }
      }

      ObjectTypeNode otn = new ObjectTypeNode(context.getNextId(), epn, objectType, context);

      long expirationOffset = getExpiratioOffsetForType(context, objectType);
      otn.setExpirationOffset(expirationOffset);

      if (wms.length > 0) {
        otn.attach(wms);
      } else {
        otn.attach();
      }

      return otn;
    } finally {
      ruleBase.readUnlock();
    }
  }
Пример #2
0
  public static void writeInitialFactHandleRightTuples(MarshallerWriteContext context)
      throws IOException {
    ObjectOutputStream stream = context.stream;
    InternalRuleBase ruleBase = context.ruleBase;

    ObjectTypeNode initialFactNode =
        ruleBase
            .getRete()
            .getEntryPointNode(EntryPoint.DEFAULT)
            .getObjectTypeNodes()
            .get(ClassObjectType.InitialFact_ObjectType);

    // do we write the fact to the objecttypenode memory
    if (initialFactNode != null) {
      ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory(initialFactNode);
      if (initialFactMemory != null && !initialFactMemory.isEmpty()) {
        // context.out.println( "InitialFactMemory true int:" + initialFactNode.getId() );
        stream.writeBoolean(true);
        stream.writeInt(initialFactNode.getId());

        // context.out.println( "InitialFact RightTuples" );
        writeRightTuples(context.wm.getInitialFactHandle(), context);
      } else {
        // context.out.println( "InitialFactMemory false " );
        stream.writeBoolean(false);
      }
    } else {
      // context.out.println( "InitialFactMemory false " );
      stream.writeBoolean(false);
    }
  }