📄 abstractworkingmemory.java
字号:
}
public abstract void doAssertObject(InternalFactHandle factHandle,
Object object,
PropagationContext propagationContext) throws FactException;
protected void removePropertyChangeListener(final FactHandle handle) throws NoSuchFactObjectException {
Object object = null;
try {
object = getObject( handle );
if(object != null) {
final Method mehod = object.getClass().getMethod( "removePropertyChangeListener",
AbstractWorkingMemory.ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES );
mehod.invoke( object,
this.addRemovePropertyChangeListenerArgs );
}
} catch ( final NoSuchMethodException e ) {
// The removePropertyChangeListener method on the class
// was not found so Drools will be unable to
// stop processing JavaBean PropertyChangeEvents
// on the retracted Object
} catch ( final IllegalArgumentException e ) {
System.err.println( "Warning: The removePropertyChangeListener method" + " on the class " + object.getClass() + " does not take" + " a simple PropertyChangeListener argument" + " so Drools will be unable to stop processing JavaBean"
+ " PropertyChangeEvents on the retracted Object" );
} catch ( final IllegalAccessException e ) {
System.err.println( "Warning: The removePropertyChangeListener method" + " on the class " + object.getClass() + " is not public" + " so Drools will be unable to stop processing JavaBean" + " PropertyChangeEvents on the retracted Object" );
} catch ( final InvocationTargetException e ) {
System.err.println( "Warning: The removePropertyChangeL istener method" + " on the class " + object.getClass() + " threw an InvocationTargetException" + " so Drools will be unable to stop processing JavaBean"
+ " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
} catch ( final SecurityException e ) {
System.err.println( "Warning: The SecurityManager controlling the class " + object.getClass() + " did not allow the lookup of a" + " removePropertyChangeListener method" + " so Drools will be unable to stop processing JavaBean"
+ " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
}
}
// /**
// * Associate an object with its handle.
// *
// * @param handle
// * The handle.
// * @param object
// * The object.
// */
// public void putObject(InternalFactHandle handle,
// Object object) {
// this.assertMap.put( object,
// handle );
//
// handle.setObject( object );
// }
//
// public Object removeObject(InternalFactHandle handle) {
// Object object = handle.getObject();
//
// this.assertMap.remove( object );
//
// return object;
// }
public void retractObject(final FactHandle handle) throws FactException {
retractObject( handle,
true,
true,
null,
null );
}
public abstract void doRetract(InternalFactHandle factHandle,
PropagationContext propagationContext);
/**
* @see WorkingMemory
*/
public void retractObject(final FactHandle factHandle,
final boolean removeLogical,
final boolean updateEqualsMap,
final Rule rule,
final Activation activation) throws FactException {
this.lock.lock();
try {
final InternalFactHandle handle = (InternalFactHandle) factHandle;
if ( handle.getId() == -1 ) {
// can't retract an already retracted handle
return;
}
removePropertyChangeListener( handle );
final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
PropagationContext.RETRACTION,
rule,
activation );
doRetract( handle,
propagationContext );
// Update the equality key, which maintains a list of stated
// FactHandles
final EqualityKey key = handle.getEqualityKey();
// Its justified so attempt to remove any logical dependencies for
// the handle
if ( key.getStatus() == EqualityKey.JUSTIFIED ) {
this.tms.removeLogicalDependencies( handle );
}
key.removeFactHandle( handle );
handle.setEqualityKey( null );
// If the equality key is now empty, then remove it
if ( key.isEmpty() ) {
this.tms.remove( key );
}
final Object object = handle.getObject();
this.workingMemoryEventSupport.fireObjectRetracted( propagationContext,
handle,
object );
this.assertMap.remove( handle );
this.handleFactory.destroyFactHandle( handle );
if ( !this.factQueue.isEmpty() ) {
propagateQueuedActions();
}
} finally {
this.lock.unlock();
}
}
public void modifyObject(final FactHandle handle,
final Object object) throws FactException {
modifyObject( handle,
object,
null,
null );
}
/**
* @see WorkingMemory
*/
public abstract void modifyObject(FactHandle factHandle,
Object object,
Rule rule,
Activation activation) throws FactException;
public void propagateQueuedActions() {
for ( final Iterator it = this.factQueue.iterator(); it.hasNext(); ) {
final WorkingMemoryAction action = (WorkingMemoryAction) it.next();
it.remove();
action.propagate();
}
}
public void queueRetractAction(final InternalFactHandle factHandle,
final boolean removeLogical,
final boolean updateEqualsMap,
final Rule ruleOrigin,
final Activation activationOrigin) {
this.factQueue.add( new WorkingMemoryRetractAction( factHandle,
false,
true,
ruleOrigin,
activationOrigin ) );
}
/**
* Retrieve the <code>JoinMemory</code> for a particular
* <code>JoinNode</code>.
*
* @param node
* The <code>JoinNode</code> key.
*
* @return The node's memory.
*/
public Object getNodeMemory(final NodeMemory node) {
Object memory = this.nodeMemories.get( node.getId() );
if ( memory == null ) {
memory = node.createMemory( this.ruleBase.getConfiguration() );
this.nodeMemories.put( node.getId(),
memory );
}
return memory;
}
public void clearNodeMemory(final NodeMemory node) {
this.nodeMemories.remove( node.getId() );
}
public WorkingMemoryEventSupport getWorkingMemoryEventSupport() {
return this.workingMemoryEventSupport;
}
public AgendaEventSupport getAgendaEventSupport() {
return this.agendaEventSupport;
}
/**
* Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda
* Scheduler used for duration rules.
*
* @param handler
*/
public void setAsyncExceptionHandler(final AsyncExceptionHandler handler) {
// this.agenda.setAsyncExceptionHandler( handler );
}
/*
* public void dumpMemory() { Iterator it = this.joinMemories.keySet(
* ).iterator( ); while ( it.hasNext( ) ) { ((JoinMemory)
* this.joinMemories.get( it.next( ) )).dump( ); } }
*/
public void propertyChange(final PropertyChangeEvent event) {
final Object object = event.getSource();
try {
modifyObject( getFactHandle( object ),
object );
} catch ( final NoSuchFactHandleException e ) {
// Not a fact so unable to process the chnage event
} catch ( final FactException e ) {
throw new RuntimeException( e.getMessage() );
}
}
public long getNextPropagationIdCounter() {
return this.propagationIdCounter++;
}
public void dispose() {
this.ruleBase.disposeWorkingMemory( this );
}
public Lock getLock() {
return this.lock;
}
public interface WorkingMemoryAction {
public void propagate();
}
public class WorkingMemoryRetractAction
implements
WorkingMemoryAction {
private InternalFactHandle factHandle;
private boolean removeLogical;
private boolean updateEqualsMap;
private Rule ruleOrigin;
private Activation activationOrigin;
public WorkingMemoryRetractAction(final InternalFactHandle factHandle,
final boolean removeLogical,
final boolean updateEqualsMap,
final Rule ruleOrigin,
final Activation activationOrigin) {
super();
this.factHandle = factHandle;
this.removeLogical = removeLogical;
this.updateEqualsMap = updateEqualsMap;
this.ruleOrigin = ruleOrigin;
this.activationOrigin = activationOrigin;
}
public void propagate() {
retractObject( this.factHandle,
this.removeLogical,
this.updateEqualsMap,
this.ruleOrigin,
this.activationOrigin );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -