public void setKnowledgeRuntime(InternalKnowledgeRuntime kruntime) { this.kruntime = kruntime; this.processRuntime = createProcessRuntime(); }
public void queueWorkingMemoryAction(final WorkingMemoryAction action) { try { startOperation(); getActionQueue().add( action ); this.agenda.notifyHalt(); } finally { endOperation(); } }
public int fireAllRules(final AgendaFilter agendaFilter) throws FactException { return fireAllRules( agendaFilter, -1 ); }
public Entry[] getActivationParameters(long activationId) { Activation[] activations = getAgenda().getActivations(); for ( int i = 0; i < activations.length; i++ ) { if ( activations[i].getActivationNumber() == activationId ) { Map params = getActivationParameters( activations[i] ); return (Entry[]) params.entrySet().toArray( new Entry[params.size()] ); } } return new Entry[0]; }
this.lock.lock(); this.ruleBase.readLock(); this.wm.startOperation(); this.ruleBase.executeQueuedActions(); final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(), PropagationContext.RETRACTION, rule, TruthMaintenanceSystem tms = wm.getTruthMaintenanceSystem(); this.wm.executeQueuedActions(); this.wm.getAgenda().unstageActivations(); this.wm.endOperation(); this.ruleBase.readUnlock(); this.lock.unlock();
if ( this.firing.compareAndSet( false, true ) ) { initInitialFact(); startOperation(); ruleBase.readLock(); if ( liaPropagations != null && isSequential() ) { for ( Iterator it = liaPropagations.iterator(); it.hasNext(); ) { ((LIANodePropagation) it.next()).doPropagation( this ); executeQueuedActions(); } finally { ruleBase.readUnlock(); endOperation(); this.firing.set( false );
this.wm.startOperation(); wm.initInitialFact(); if ( this.wm.isSequential() ) { handle = createHandle( object, typeConf ); TruthMaintenanceSystem tms = wm.getTruthMaintenanceSystem(); if ( handle == null ) { this.wm.endOperation();
/** * Keeps firing activations until a halt is called. If in a given moment, * there is no activation to fire, it will wait for an activation to be * added to an active agenda group or rule flow group. * * @param agendaFilter * filters the activations that may fire * * @throws IllegalStateException * if this method is called when running in sequential mode */ public void fireUntilHalt(final AgendaFilter agendaFilter) { initInitialFact(); if ( isSequential() ) { throw new IllegalStateException( "fireUntilHalt() can not be called in sequential mode." ); } if ( this.firing.compareAndSet( false, true ) ) { try { synchronized ( this ) { executeQueuedActions(); this.agenda.fireUntilHalt( agendaFilter ); } } finally { this.firing.set( false ); } } }
public void executeQueuedActions() { try { startOperation(); if ( evaluatingActionQueue.compareAndSet( false, true ) ) { try { if ( actionQueue!= null && !actionQueue.isEmpty() ) { WorkingMemoryAction action = null; while ( (action = actionQueue.poll()) != null ) { try { action.execute( this ); } catch ( Exception e ) { throw new RuntimeDroolsException( "Unexpected exception executing action " + action.toString(), e ); } } } } finally { evaluatingActionQueue.compareAndSet( true, false ); } } } finally { endOperation(); } }
private void registerSystemListeners(AbstractWorkingMemory wm) { for ( org.drools.event.AgendaEventListener listener : wm.getAgendaEventSupport().getEventListeners()) { this.agendaEventSupport.addEventListener( listener ); } for ( org.drools.event.WorkingMemoryEventListener listener : wm.getWorkingMemoryEventSupport().getEventListeners()) { this.workingMemoryEventSupport.addEventListener( listener ); } InternalProcessRuntime processRuntime = wm.getProcessRuntime(); if ( processRuntime != null ) { for ( ProcessEventListener listener : processRuntime.getProcessEventListeners() ) { this.processEventSupport.addEventListener( listener ); } } }
/** * This method is called to start the multiple partition threads when * running in multi-thread mode */ public void startPartitionManagers() { startOperation(); try { if ( this.ruleBase.getConfiguration().isMultithreadEvaluation() ) { int maxThreads = (this.ruleBase.getConfiguration().getMaxThreads() > 0) ? this.ruleBase.getConfiguration().getMaxThreads() : this.ruleBase.getPartitionIds().size(); if ( this.threadPool.compareAndSet( null, createExecutorService( maxThreads ) ) ) { this.partitionManager.setPool( this.threadPool.get() ); } } } finally { endOperation(); } }
this.ruleBase.executeQueuedActions(); this.wm.executeQueuedActions(); final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(), PropagationContext.ASSERTION, rule, this.wm ); this.wm.executeQueuedActions(); this.wm.getAgenda().unstageActivations();
/** * Keeps firing activations until a halt is called. If in a given moment, * there is no activation to fire, it will wait for an activation to be * added to an active agenda group or rule flow group. * * @throws IllegalStateException * if this method is called when running in sequential mode */ public void fireUntilHalt() { fireUntilHalt( null ); }
public void fireUntilHalt(final AgendaFilter agendaFilter) { unstageActivations(); this.halt.set( false ); while ( continueFiring( -1 ) ) { boolean fired = fireNextItem( agendaFilter ); fired = fired || !((AbstractWorkingMemory) this.workingMemory).getActionQueue().isEmpty(); this.workingMemory.executeQueuedActions(); if ( !fired ) { try { synchronized ( this.halt ) { if( !this.halt.get() ) this.halt.wait(); } } catch ( InterruptedException e ) { this.halt.set( true ); } } else { this.workingMemory.executeQueuedActions(); } } }
this.lock.lock(); this.ruleBase.readLock(); this.wm.startOperation(); this.ruleBase.executeQueuedActions(); key.removeFactHandle( handle ); TruthMaintenanceSystem tms = wm.getTruthMaintenanceSystem(); final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(), PropagationContext.MODIFICATION, rule, this.wm ); this.wm.executeQueuedActions(); this.wm.getAgenda().unstageActivations(); this.wm.endOperation(); this.ruleBase.readUnlock(); this.lock.unlock();
public void stopPartitionManagers() { startOperation(); try { if ( this.ruleBase.getConfiguration().isMultithreadEvaluation() ) { ExternalExecutorService service = this.threadPool.get(); if ( this.threadPool.compareAndSet( service, null ) ) { service.shutdown(); partitionManager.shutdown(); } } } finally { endOperation(); } }
public void setGlobal(final String identifier, final Object value) { // Cannot set null values if ( value == null ) { return; } try { this.ruleBase.readLock(); startOperation(); // Make sure the global has been declared in the RuleBase final Map globalDefintions = this.ruleBase.getGlobals(); final Class type = (Class) globalDefintions.get( identifier ); if ( (type == null) ) { throw new RuntimeException( "Unexpected global [" + identifier + "]" ); } else if ( !type.isInstance( value ) ) { throw new RuntimeException( "Illegal class for global. " + "Expected [" + type.getName() + "], " + "found [" + value.getClass().getName() + "]." ); } else { this.globalResolver.setGlobal( identifier, value ); } } finally { endOperation(); this.ruleBase.readUnlock(); } }
public int fireAllRules() throws FactException { return fireAllRules( null, -1 ); }
public int fireAllRules(int fireLimit) throws FactException { return fireAllRules( null, fireLimit ); }