/**
   * Takes the asserted <code>ReteTuple</code> received from the <code>TupleSource</code> and
   * adapts it into a FactHandleImpl
   *
   * @param tuple
   *            The asserted <code>ReteTuple</code>.
   * @param context
   *             The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.
   * @param workingMemory
   *            the <code>WorkingMemory</code> session.
   */
  public void assertLeftTuple(
      final LeftTuple leftTuple,
      final PropagationContext context,
      final InternalWorkingMemory workingMemory) {
    // creating a dummy fact handle to wrap the tuple
    final InternalFactHandle handle =
        workingMemory
            .getFactHandleFactory()
            .newFactHandle(
                leftTuple,
                workingMemory
                    .getObjectTypeConfigurationRegistry()
                    .getObjectTypeConf(context.getEntryPoint(), leftTuple),
                workingMemory,
                null);
    boolean useLeftMemory = true;
    if (!this.tupleMemoryEnabled) {
      // This is a hack, to not add closed DroolsQuery objects
      Object object = ((InternalFactHandle) leftTuple.get(0)).getObject();
      if (!(object instanceof DroolsQuery) || !((DroolsQuery) object).isOpen()) {
        useLeftMemory = false;
      }
    }

    if (useLeftMemory) {
      final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory(this);
      // add it to a memory mapping
      memory.put(leftTuple, handle);
    }

    // propagate it
    this.sink.propagateAssertObject(handle, context, workingMemory);
  }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 private InternalFactHandle createResultFactHandle(
     final PropagationContext context,
     final InternalWorkingMemory workingMemory,
     final LeftTuple leftTuple,
     final Object result) {
   InternalFactHandle handle = null;
   ProtobufMessages.FactHandle _handle = null;
   if (context.getReaderContext() != null) {
     Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle> map =
         (Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle>)
             context.getReaderContext().nodeMemories.get(getId());
     if (map != null) {
       _handle = map.get(PersisterHelper.createTupleKey(leftTuple));
     }
   }
   if (_handle != null) {
     // create a handle with the given id
     handle =
         workingMemory
             .getFactHandleFactory()
             .newFactHandle(
                 _handle.getId(),
                 result,
                 _handle.getRecency(),
                 workingMemory
                     .getObjectTypeConfigurationRegistry()
                     .getObjectTypeConf(context.getEntryPoint(), result),
                 workingMemory,
                 null); // so far, result is not an event
   } else {
     handle =
         workingMemory
             .getFactHandleFactory()
             .newFactHandle(
                 result,
                 workingMemory
                     .getObjectTypeConfigurationRegistry()
                     .getObjectTypeConf(context.getEntryPoint(), result),
                 workingMemory,
                 null); // so far, result is not an event
   }
   return handle;
 }