Anstis, Michael (M.) wrote:
Wouldn't the best approach be to get the FactHandles iterator and retact
them from working memory rather than removing them through the iterator?
Iterator itr = wm.iterateFactHandles();
While(itr.next()) {
FactHandle h = itr.next();
wm.retract(h);
}
This would ensure truth maintenance is preserved.
Actually I'm not sure that would be safe.... the objects and the handles are in the same hashtable. Those internal data structures where built for performance and lightweightness, not thread safeness and mutability. If you actually look we have an internal, fast, iterator which we simple adapt to a slower
java.util.Iterator. At the moment none of our iterators are thread safe, but I do see a valid use case here, we will have to think on it for the next major release - cleam implementation patch welcome with unit tests :) I'm less concerned about the iterator adapter performance, but I cannot compromise on the performance of our internal iterators.
public static class HashTableIterator
implements
Iterator {
private static final long serialVersionUID = 400L;
private AbstractHashTable hashTable;
private Entry[] table;
private int row;
private int length;
private Entry entry;
public HashTableIterator(final AbstractHashTable hashTable) {
this.hashTable = hashTable;
}
/* (non-Javadoc)
* @see org.drools.util.Iterator#next()
*/
public Object next() {
if ( this.entry == null ) {
// keep skipping rows until we come to the end, or find one that is populated
while ( this.entry == null ) {
this.row++;
if ( this.row == this.length ) {
return null;
}
this.entry = this.table[this.row];
}
} else {
this.entry = this.entry.getNext();
if ( this.entry == null ) {
this.entry = (Entry) next();
}
}
return this.entry;
}
/* (non-Javadoc)
* @see org.drools.util.Iterator#reset()
*/
public void reset() {
this.table = this.hashTable.getTable();
this.length = this.table.length;
this.row = -1;
this.entry = null;
}
}
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users