@SuppressWarnings("unchecked") public RightTuple createRightTuple( final LeftTuple leftTuple, final PropagationContext context, final InternalWorkingMemory workingMemory, final Object object) { InternalFactHandle handle; ProtobufMessages.FactHandle _handle = null; if (objectTypeConf == null) { // use default entry point and object class. Notice that at this point object is assignable to // resultClass objectTypeConf = new ClassObjectTypeConf( workingMemory.getEntryPoint(), resultClass, workingMemory.getKnowledgeBase()); } if (context.getReaderContext() != null) { Map<ProtobufInputMarshaller.TupleKey, List<FactHandle>> map = (Map<ProtobufInputMarshaller.TupleKey, List<ProtobufMessages.FactHandle>>) context.getReaderContext().nodeMemories.get(getId()); if (map != null) { TupleKey key = PersisterHelper.createTupleKey(leftTuple); List<FactHandle> list = map.get(key); if (list != null && !list.isEmpty()) { // it is a linked list, so the operation is fairly efficient _handle = ((java.util.LinkedList<ProtobufMessages.FactHandle>) list).removeFirst(); if (list.isEmpty()) { map.remove(key); } } } } if (_handle != null) { // create a handle with the given id handle = workingMemory .getFactHandleFactory() .newFactHandle( _handle.getId(), object, _handle.getRecency(), objectTypeConf, workingMemory, null); } else { handle = workingMemory .getFactHandleFactory() .newFactHandle(object, objectTypeConf, workingMemory, null); } return newRightTuple(handle, null); }
@SuppressWarnings("unchecked") public InternalFactHandle createFactHandle( final LeftTuple leftTuple, final PropagationContext context, final InternalWorkingMemory workingMemory) { InternalFactHandle handle; 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(), leftTuple, _handle.getRecency(), workingMemory .getObjectTypeConfigurationRegistry() .getObjectTypeConf(context.getEntryPoint(), leftTuple), workingMemory, null); // so far, result is not an event } else { handle = workingMemory .getFactHandleFactory() .newFactHandle( leftTuple, workingMemory .getObjectTypeConfigurationRegistry() .getObjectTypeConf(context.getEntryPoint(), leftTuple), workingMemory, null); // so far, result is not an event } return handle; }