📄 defaultagenda.java
字号:
*/
public AgendaGroup getAgendaGroup(final String name) {
return (AgendaGroup) this.agendaGroups.get( name );
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#getAgendaGroups()
*/
public AgendaGroup[] getAgendaGroups() {
return (AgendaGroup[]) this.agendaGroups.values().toArray( new AgendaGroup[this.agendaGroups.size()] );
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#getStack()
*/
public AgendaGroup[] getStack() {
return (AgendaGroup[]) this.focusStack.toArray( new AgendaGroup[this.focusStack.size()] );
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#getActivationGroup(java.lang.String)
*/
public ActivationGroup getActivationGroup(final String name) {
ActivationGroupImpl activationGroup = (ActivationGroupImpl) this.activationGroups.get( name );
if ( activationGroup == null ) {
activationGroup = new ActivationGroupImpl( name );
this.activationGroups.put( name,
activationGroup );
}
return activationGroup;
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#focusStackSize()
*/
public int focusStackSize() {
int size = 0;
for ( final Iterator iterator = this.focusStack.iterator(); iterator.hasNext(); ) {
final AgendaGroup group = (AgendaGroupImpl) iterator.next();
size += group.size();
}
return size;
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#agendaSize()
*/
public int agendaSize() {
int size = 0;
for ( final Iterator iterator = this.agendaGroups.values().iterator(); iterator.hasNext(); ) {
final AgendaGroup group = (AgendaGroupImpl) iterator.next();
size += group.size();
}
return size;
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#getActivations()
*/
public Activation[] getActivations() {
final List list = new ArrayList();
for ( final Iterator it = this.agendaGroups.values().iterator(); it.hasNext(); ) {
final AgendaGroup group = (AgendaGroup) it.next();
list.addAll( Arrays.asList( group.getActivations() ) );
}
return (Activation[]) list.toArray( new Activation[list.size()] );
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#getScheduledActivations()
*/
public Activation[] getScheduledActivations() {
final List list = new ArrayList( this.scheduledActivations.size() );
for ( LinkedListNode node = this.scheduledActivations.getFirst(); node != null; node = node.getNext() ) {
list.add( node );
}
return (Activation[]) list.toArray( new Activation[list.size()] );
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#clearAgenda()
*/
public void clearAgenda() {
// Cancel all items and fire a Cancelled event for each Activation
for ( final Iterator agendaGroupIterator = this.agendaGroups.values().iterator(); agendaGroupIterator.hasNext(); ) {
final AgendaGroupImpl group = (AgendaGroupImpl) agendaGroupIterator.next();
clearAgendaGroup( group );
}
final EventSupport eventsupport = (EventSupport) this.workingMemory;
if ( this.scheduledActivations != null && !this.scheduledActivations.isEmpty() ) {
for ( ScheduledAgendaItem item = (ScheduledAgendaItem) this.scheduledActivations.removeFirst(); item != null; item = (ScheduledAgendaItem) this.scheduledActivations.removeFirst() ) {
item.remove();
eventsupport.getAgendaEventSupport().fireActivationCancelled( item );
}
}
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#clearAgendaGroup(java.lang.String)
*/
public void clearAgendaGroup(final String name) {
final AgendaGroupImpl agendaGroup = (AgendaGroupImpl) this.agendaGroups.get( name );
if ( agendaGroup != null ) {
clearAgendaGroup( agendaGroup );
}
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#clearAgendaGroup(org.drools.common.AgendaGroupImpl)
*/
public void clearAgendaGroup(final AgendaGroup agendaGroup) {
final EventSupport eventsupport = (EventSupport) this.workingMemory;
final Queueable[] queueable = ( ( AgendaGroupImpl) agendaGroup ).getQueueable();
for ( int i = 0, length = queueable.length; i < length; i++ ) {
final AgendaItem item = (AgendaItem) queueable[i];
if ( item == null ) {
continue;
}
// this must be set false before removal from the XorGroup. Otherwise the XorGroup will also try to cancel the Actvation
item.setActivated( false );
if ( item.getActivationGroupNode() != null ) {
item.getActivationGroupNode().getActivationGroup().removeActivation( item );
}
eventsupport.getAgendaEventSupport().fireActivationCancelled( item );
}
( ( AgendaGroupImpl )agendaGroup ).clear();
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#clearActivationGroup(java.lang.String)
*/
public void clearActivationGroup(final String name) {
final ActivationGroup activationGroup = (ActivationGroup) this.activationGroups.get( name );
if ( activationGroup != null ) {
clearActivationGroup( activationGroup );
}
}
/* (non-Javadoc)
* @see org.drools.common.AgendaI#clearActivationGroup(org.drools.spi.ActivationGroup)
*/
public void clearActivationGroup(final ActivationGroup activationGroup) {
final EventSupport eventsupport = (EventSupport) this.workingMemory;
for ( final Iterator it = activationGroup.iterator(); it.hasNext(); ) {
final Activation activation = ((ActivationGroupNode) it.next()).getActivation();
activation.setActivationGroupNode( null );
if ( activation.isActivated() ) {
activation.setActivated( false );
activation.remove();
eventsupport.getAgendaEventSupport().fireActivationCancelled( activation );
}
}
activationGroup.clear();
}
/**
* Fire the next scheduled <code>Agenda</code> item.
*
* @throws ConsequenceException
* If an error occurs while firing an agenda item.
*/
public boolean fireNextItem(final AgendaFilter filter) throws ConsequenceException {
final AgendaGroupImpl group = (AgendaGroupImpl) getNextFocus();
// return if there are no Activations to fire
if ( group == null ) {
return false;
}
final AgendaItem item = (AgendaItem) group.getNext();
if ( item == null ) {
return false;
}
if ( filter == null || filter.accept( item ) ) {
fireActivation( item );
}
return true;
}
/**
* Fire this item.
*
* @param workingMemory
* The working memory context.
*
* @throws ConsequenceException
* If an error occurs while attempting to fire the consequence.
*/
public synchronized void fireActivation(final Activation activation) throws ConsequenceException {
final EventSupport eventsupport = (EventSupport) this.workingMemory;
eventsupport.getAgendaEventSupport().fireBeforeActivationFired( activation );
if ( activation.getActivationGroupNode() != null ) {
final ActivationGroup activationGroup = activation.getActivationGroupNode().getActivationGroup();
activationGroup.removeActivation( activation );
clearActivationGroup( activationGroup );
}
activation.setActivated( false );
try {
final KnowledgeHelper knowledgeHelper = new org.drools.base.DefaultKnowledgeHelper( activation,
this.workingMemory );
activation.getRule().getConsequence().evaluate( knowledgeHelper,
this.workingMemory );
} catch ( final Exception e ) {
e.printStackTrace();
throw new ConsequenceException( e,
activation.getRule() );
}
eventsupport.getAgendaEventSupport().fireAfterActivationFired( activation );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -