public static void readRightTuple(MarshallerReaderContext context, InternalFactHandle factHandle)
      throws IOException {
    ObjectInputStream stream = context.stream;

    int sinkId = stream.readInt();
    RightTupleSink sink = (sinkId >= 0) ? (RightTupleSink) context.sinks.get(sinkId) : null;

    RightTuple rightTuple = new RightTuple(factHandle, sink);
    context.rightTuples.put(new RightTupleKey(factHandle.getId(), sink), rightTuple);

    if (sink != null) {
      BetaMemory memory = null;
      switch (sink.getType()) {
        case NodeTypeEnums.AccumulateNode:
          {
            memory = ((AccumulateMemory) context.wm.getNodeMemory((BetaNode) sink)).betaMemory;
            break;
          }
        default:
          {
            memory = (BetaMemory) context.wm.getNodeMemory((BetaNode) sink);
            break;
          }
      }
      memory.getRightTupleMemory().add(rightTuple);
      memory.linkLeft();
    }
  }
Пример #2
0
  public void setupJoinNode() {
    buildContext = createContext();

    joinNode =
        (JoinNode)
            BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext)
                .setLeftType(A.class)
                .setBinding("object", "$object")
                .setRightType(B.class)
                .setConstraint("object", "!=", "$object")
                .build();

    sinkNode = new JoinNode();
    sinkNode.setId(1);
    sinkNode.setConstraints(new EmptyBetaConstraints());

    joinNode.addTupleSink(sinkNode);

    wm = (InternalWorkingMemory) buildContext.getRuleBase().newStatefulSession(true);

    bm = (BetaMemory) wm.getNodeMemory(joinNode);

    bm0 = (BetaMemory) wm.getNodeMemory(sinkNode);

    smem = new SegmentMemory(joinNode);
    bm.setSegmentMemory(smem);

    smem0 = new SegmentMemory(sinkNode);
    bm0.setSegmentMemory(smem0);
    smem.add(smem0);
  }
Пример #3
0
  @Test
  public void testSubnetworkNoSharing() throws Exception {
    KnowledgeBase kbase = buildKnowledgeBase(" A()  not ( B() and C() ) \n");

    ReteooWorkingMemoryInterface wm =
        ((StatefulKnowledgeSessionImpl) kbase.newStatefulKnowledgeSession()).session;

    ObjectTypeNode aotn = getObjectTypeNode(kbase, A.class);

    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getSinkPropagator().getSinks()[0];

    JoinNode bNode = (JoinNode) liaNode.getSinkPropagator().getSinks()[0];
    JoinNode cNode = (JoinNode) bNode.getSinkPropagator().getSinks()[0];
    RightInputAdapterNode riaNode = (RightInputAdapterNode) cNode.getSinkPropagator().getSinks()[0];

    NotNode notNode = (NotNode) liaNode.getSinkPropagator().getSinks()[1];
    RuleTerminalNode rtn1 = (RuleTerminalNode) notNode.getSinkPropagator().getSinks()[0];

    wm.insert(new A());
    wm.insert(new B());
    wm.insert(new C());

    // LiaNode and Rule are in same segment
    LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
    SegmentMemory smem = liaMem.getSegmentMemory();
    assertEquals(liaNode, smem.getRootNode());
    assertEquals(rtn1, smem.getTipNode());
    assertNull(smem.getNext());
    assertNull(smem.getFirst());

    SegmentMemory bSmem =
        wm.getNodeMemory(bNode).getSegmentMemory(); // it's nested inside of smem, so lookup from wm
    assertEquals(bNode, bSmem.getRootNode());
    assertEquals(riaNode, bSmem.getTipNode());

    BetaMemory bm = (BetaMemory) wm.getNodeMemory(notNode);
    assertEquals(bSmem, bm.getSubnetworkSegmentMemory()); // check subnetwork ref was made
  }
 private static void addToLeftMemory(LeftTuple parentLeftTuple, BetaMemory memory) {
   memory.getLeftTupleMemory().add(parentLeftTuple);
   memory.linkRight();
 }