/** * Create a pattern matcher instance for a given state. */ public IPatternMatcherState createMatcherState(IOAVState state, AbstractAgenda agenda) { return new RetePatternMatcherState(node, state, new ReteMemory(state), agenda); }
/** * Get the memory for this node. * @return The memory. */ public Collection getNodeMemory(ReteMemory mem) { return mem.hasNodeMemory(this) ? (Collection)mem.getNodeMemory(this) : null; }
/** * Get the string representation. * @return The string representation. */ public String toString() { //return Srules.getInnerClassName(this.getClass())+"(values="+memory+")"; StringBuffer ret = new StringBuffer(SReflect.getInnerClassName(this.getClass())); ret.append(", size="+getTotalMemorySize()); ret.append(" : \n"); for(Iterator it=memory.keySet().iterator(); it.hasNext(); ) { Object node = it.next(); ret.append(node).append(" : "); ret.append(memory.get(node)).append("\n"); } return ret.toString(); } }
/** * Check if a match is contained. */ protected boolean isMatchContained(IOAVState state, Tuple left, Object right, ReteMemory mem) { return mem.hasNodeMemory(this) && ((BetaMemory)mem.getNodeMemory(this)).getResultMemory() .contains(mem.getTuple(state, left, right)); }
/** * Add a match to the node memory and propagate if necessary. */ protected void addMatch(Tuple left, Object right, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { Tuple result = mem.getTuple(state, left, right); BetaMemory bmem = (BetaMemory)mem.getNodeMemory(this); if(bmem.addResultTuple(result)) { ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].addTuple(result, state, mem, agenda); } }
((Collection)mem.getNodeMemory(this)).remove(object); propagateRemovalToObjectConsumers(object, state, mem, agenda); ((Collection)mem.getNodeMemory(this)).add(object); propagateAdditionToObjectConsumers(object, state, mem, agenda);
/** * Propagate a change of a tuple in the result memory. */ protected void propagateModification(Tuple left, Object right, int tupleindex, OAVAttributeType type, Object oldvalue, Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { Tuple tuple = mem.getTuple(state, left, right); ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].modifyTuple(tuple, tupleindex, type, oldvalue, newvalue, state, mem, agenda); }
/** * Check if a match is contained. */ protected boolean isMatchContained(IOAVState state, Tuple left, Object right, ReteMemory mem) { return mem.hasNodeMemory(this) && ((BetaMemory)mem.getNodeMemory(this)).getResultMemory() .contains(mem.getTuple(state, left, right)); }
((Collection)mem.getNodeMemory(this)).remove(object); propagateRemovalToObjectConsumers(object, state, mem, agenda); ((Collection)mem.getNodeMemory(this)).add(object); propagateAdditionToObjectConsumers(object, state, mem, agenda);
/** * Add a match to the node memory and propagate if necessary. */ protected void addMatch(Tuple left, Object right, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { Tuple result = mem.getTuple(state, left, right); BetaMemory bmem = (BetaMemory)mem.getNodeMemory(this); if(bmem.addResultTuple(result)) { ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].addTuple(result, state, mem, agenda); } }
/** * Propagate a change of a tuple in the result memory. */ protected void propagateModification(Tuple left, Object right, int tupleindex, OAVAttributeType type, Object oldvalue, Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { Tuple tuple = mem.getTuple(state, left, right); ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].modifyTuple(tuple, tupleindex, type, oldvalue, newvalue, state, mem, agenda); }
/** * Get the memory for this node. * @return The memory. */ public Collection getNodeMemory(ReteMemory mem) { return mem.hasNodeMemory(this) ? (Collection)mem.getNodeMemory(this) : null; }
/** * Remove a match from the node memory and propagate if necessary. */ protected void removeMatch(Tuple left, Object right, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { if(mem.hasNodeMemory(this)) { Tuple result = mem.getTuple(state, left, right); if(((BetaMemory)mem.getNodeMemory(this)).removeResultTuple(result)) { // if(getNodeId()==3713) // System.out.println("remmi: "+result); ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].removeTuple(result, state, mem, agenda); } } }
/** * Add a match to the node memory and propagate if necessary. */ protected void addMatch(Tuple left, Object right, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { // if(getNodeId()==1137) // System.out.println(this+".addMatch: "+left+", "+right); NotMemory nomem = (NotMemory)mem.getNodeMemory(this); nomem.addMapping(state, left, right); if(!nomem.isDelay() && nomem.removeResultTuple(left)) { ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].removeTuple(left, state, mem, agenda); } }
/** * Send an object to this node. * @param object The object. */ public void addObject(Object object, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { //System.out.println("Add object called: "+this+" "+object); state.getProfiler().start(IProfiler.TYPE_NODE, this); state.getProfiler().start(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); Collection amem = (Collection)mem.getNodeMemory(this); Tuple tuple = mem.getTuple(state, null, object); amem.add(tuple); ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].addTuple(tuple, state, mem, agenda); state.getProfiler().stop(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); state.getProfiler().stop(IProfiler.TYPE_NODE, this); }
/** * Create an index tuple from a tuple. * The index tuple excludes the index position at * which the compression happens (and all elements * thereafter -> why, could be the last node?). * @param tuple The tuple. * @return The index tuple. */ protected Tuple createIndexTuple(IOAVState state, Tuple tuple, ReteMemory mem) { List obs = tuple.getObjects(); Tuple t = null; for(int i=0; i<obs.size(); i++) { if(i<tupleindex) t = mem.getTuple(state, t, obs.get(i)); // Create tuple from tuples } return t; }
/** * Create a pattern matcher instance for a given state. */ public IPatternMatcherState createMatcherState(IOAVState state, AbstractAgenda agenda) { return new RetePatternMatcherState(node, state, new ReteMemory(state), agenda); }
/** * Get the string representation. * @return The string representation. */ public String toString() { //return Srules.getInnerClassName(this.getClass())+"(values="+memory+")"; StringBuffer ret = new StringBuffer(SReflect.getInnerClassName(this.getClass())); ret.append(", size="+getTotalMemorySize()); ret.append(" : \n"); for(Iterator it=memory.keySet().iterator(); it.hasNext(); ) { Object node = it.next(); ret.append(node).append(" : "); ret.append(memory.get(node)).append("\n"); } return ret.toString(); } }
/** * Get the memory for this node. * @return The memory. */ public Collection getNodeMemory(ReteMemory mem) { return mem.hasNodeMemory(this) ? (Collection)mem.getNodeMemory(this) : null; }
/** * Remove a match from the node memory and propagate if necessary. */ protected void removeMatch(Tuple left, Object right, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { if(mem.hasNodeMemory(this)) { Tuple result = mem.getTuple(state, left, right); if(((BetaMemory)mem.getNodeMemory(this)).removeResultTuple(result)) { // if(getNodeId()==3713) // System.out.println("remmi: "+result); ITupleConsumerNode[] tcs = tconsumers; for(int j=0; tcs!=null && j<tcs.length; j++) tcs[j].removeTuple(result, state, mem, agenda); } } }