public void addEventListener(RuleBaseEventListener listener) { this.ruleBase.addEventListener( listener ); }
public void setRuleBase(InternalRuleBase ruleBase) { this.ruleBase = ruleBase; this.classLoader = this.ruleBase.getRootClassLoader(); }
public void dispose() { this.ruleBase.disposeStatefulSession( this ); super.dispose(); this.executor.shutDown(); }
public StatelessKnowledgeSessionImpl(final InternalRuleBase ruleBase, final KnowledgeAgent kagent, final KnowledgeSessionConfiguration conf) { this.ruleBase = ruleBase; this.kagent = kagent; this.conf = (conf != null) ? conf : SessionConfiguration.getDefaultInstance(); this.environment = EnvironmentFactory.newEnvironment(); if ( this.ruleBase != null ) { // FIXME: this same code exists in ReteooRuleBase#newStatelessSession() this.ruleBase.lock(); try { if ( ruleBase.getConfiguration().isSequential() ) { this.ruleBase.getReteooBuilder().order(); } } finally { this.ruleBase.unlock(); } } }
/** * Creates the actual partition managers and their tasks for multi-thread * processing */ private void initPartitionManagers() { if ( this.ruleBase.getConfiguration().isMultithreadEvaluation() ) { this.partitionManager = new PartitionManager( this ); for ( RuleBasePartitionId partitionId : this.ruleBase.getPartitionIds() ) { this.partitionManager.manage( partitionId ); } } }
public void updateEntryPointsCache() { if (ruleBase.getAddedEntryNodeCache() != null) { for (EntryPointNode addedNode : ruleBase.getAddedEntryNodeCache()) { EntryPoint id = addedNode.getEntryPoint(); if (EntryPoint.DEFAULT.equals(id)) continue; WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(id, addedNode, this); entryPoints.put(id.getEntryPointId(), wmEntryPoint); } } if (ruleBase.getRemovedEntryNodeCache() != null) { for (EntryPointNode removedNode : ruleBase.getRemovedEntryNodeCache()) { entryPoints.remove(removedNode.getEntryPoint().getEntryPointId()); } } }
public Rete(InternalRuleBase ruleBase) { super( 0, RuleBasePartitionId.MAIN_PARTITION, ruleBase != null ? ruleBase.getConfiguration().isMultithreadEvaluation() : false ); this.entryPoints = Collections.synchronizedMap( new HashMap<EntryPoint, EntryPointNode>() ); this.ruleBase = ruleBase; }
public static ObjectTypeNode attachObjectTypeNode(BuildContext context, ObjectType objectType) { final InternalRuleBase ruleBase = context.getRuleBase(); ruleBase.lock(); try { InternalWorkingMemory[] wms = context.getWorkingMemories(); EntryPointNode epn = ruleBase.getRete().getEntryPointNode( context.getCurrentEntryPoint() ); if ( epn == null ) { epn = new EntryPointNode( context.getNextId(), ruleBase.getRete(), context ); epn.attach( context ); ObjectTypeNode otn = context.getRuleBase().getConfiguration().getComponentFactory().getNodeFactoryService().buildObjectTypeNode( context.getNextId(), epn, objectType, ruleBase.unlock();
this.ruleBase = ruleBase; this.entryPoint = entryPoint; this.typeDecl = ruleBase.getTypeDeclaration( clazz ); isEvent = typeDecl != null && typeDecl.getRole() == TypeDeclaration.Role.EVENT; isEvent ) ); this.concreteObjectTypeNode = ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType ); if ( this.concreteObjectTypeNode == null ) { BuildContext context = new BuildContext( ruleBase, ruleBase.getRete().getRuleBase().getReteooBuilder().getIdGenerator() ); context.setCurrentEntryPoint( entryPoint ); if ( DroolsQuery.class == clazz ) { context.setTupleMemoryEnabled( false ); context.setObjectTypeNodeMemoryEnabled( false ); } else if ( context.getRuleBase().getConfiguration().isSequential() ) {
startOperation(); this.lock.lock(); this.ruleBase.readLock(); this.ruleBase.executeQueuedActions(); executeQueuedActions(); BaseNode[] nodes = this.ruleBase.getReteooBuilder().getTerminalNodes( queryObject.getQuery() ); ( queryObject.getQuery() != null ) ? queryObject.getQuery().getParameters() : new Declaration[0] ); } finally { this.ruleBase.readUnlock(); this.lock.unlock(); endOperation();
try { this.lock.lock(); this.ruleBase.readLock(); this.wm.startOperation(); this.ruleBase.executeQueuedActions(); if ( originalObject != object || !AssertBehaviour.IDENTITY.equals( this.ruleBase.getConfiguration().getAssertBehaviour() ) ) { this.objectStore.removeHandle( handle ); this.ruleBase.readUnlock(); this.lock.unlock();
this.ruleBase.readLock(); this.lock.lock(); this.ruleBase.executeQueuedActions(); executeQueuedActions(); } finally { this.lock.unlock(); this.ruleBase.readUnlock(); 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(); } }
private void executeJitting(Object object, InternalWorkingMemory workingMemory, LeftTuple leftTuple) { InternalRuleBase ruleBase = ((InternalRuleBase) workingMemory.getRuleBase()); if ( MemoryUtil.permGenStats.isUsageThresholdExceeded(ruleBase.getConfiguration().getPermGenThreshold()) ) { return; } try { CompositeClassLoader classLoader = ruleBase.getRootClassLoader(); if (analyzedCondition == null) { analyzedCondition = ((MvelConditionEvaluator) conditionEvaluator).getAnalyzedCondition(object, workingMemory, leftTuple); } conditionEvaluator = ASMConditionEvaluatorJitter.jitEvaluator(expression, analyzedCondition, declarations, classLoader, leftTuple); } catch (Throwable t) { if (TEST_JITTING) { if (analyzedCondition == null) { logger.error("Unable to analize condition for expression: " + expression, t); } else { throw new RuntimeException("Exception jitting: " + expression, t); } } else { logger.warn("Exception jitting: " + expression, t.getMessage()); } } }
public void initInitialFact( InternalRuleBase ruleBase, MarshallerReaderContext context ) { ruleBase.lock(); Object initialFact = InitialFactImpl.getInstance(); ObjectTypeConf otc = this.defaultEntryPoint.getObjectTypeConfigurationRegistry() .getObjectTypeConf( this.defaultEntryPoint.entryPoint, initialFact ); this.initialFactHandle = ruleBase.getConfiguration().getComponentFactory().getFactHandleFactoryService().newFactHandle( 0, initialFact, 0, otc, this, this.defaultEntryPoint ); final PropagationContext pctx = new PropagationContextImpl( 0, PropagationContext.ASSERTION, null, null , initialFactHandle, 0, 0, defaultEntryPoint.getEntryPoint(), context ); otc.getConcreteObjectTypeNode().assertObject( this.initialFactHandle, pctx, this ); // ADDED, NOT IN THE ORIGINAL 6.x COMMIT pctx.evaluateActionQueue( this ); ruleBase.unlock(); }
this.ruleBase.readLock(); handle = key.getFactHandle(); if ( AssertBehaviour.IDENTITY.equals( this.ruleBase.getConfiguration().getAssertBehaviour() ) ) { this.ruleBase.readUnlock(); this.lock.unlock();
private static ReteooStatefulSession createAndInitializeSession(MarshallerReaderContext context, int id, ExecutorService executor, Environment environment, SessionConfiguration config, ProtobufMessages.KnowledgeSession _session) throws IOException { FactHandleFactory handleFactory = context.ruleBase.newFactHandleFactory( _session.getRuleData().getLastId(), _session.getRuleData().getLastRecency() ); DefaultAgenda agenda = context.ruleBase.getConfiguration().getComponentFactory().getAgendaFactory().createAgenda( context.ruleBase, false ); readAgenda( context, _session.getRuleData(), agenda ); ReteooStatefulSession session = new ReteooStatefulSession( id, context.ruleBase, executor, handleFactory, false, 1, config, agenda, environment ); new StatefulKnowledgeSessionImpl( session ); return session; }
public void dispose() { if ( this.ruleBase.getConfiguration().isMBeansEnabled() ) { DroolsManagementAgent.getInstance().unregisterKnowledgeSession( this ); } for( WorkingMemoryEntryPoint ep : this.entryPoints.values() ) { ep.dispose(); } this.workingMemoryEventSupport.reset(); this.agendaEventSupport.reset(); for ( Iterator it = this.__ruleBaseEventListeners.iterator(); it.hasNext(); ) { this.ruleBase.removeEventListener( (RuleBaseEventListener) it.next() ); } this.stopPartitionManagers(); if ( processRuntime != null ) { this.processRuntime.dispose(); } if ( timerService != null ) { this.timerService.shutdown(); } }
public FactTemplateTypeConf(final EntryPoint entryPoint, final FactTemplate factTemplate, final InternalRuleBase ruleBase) { this.factTemplate = factTemplate; this.entryPoint = entryPoint; ObjectType objectType = new FactTemplateObjectType( factTemplate ); this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType ); if ( this.concreteObjectTypeNode == null ) { BuildContext context = new BuildContext( ruleBase, ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() ); if ( context.getRuleBase().getConfiguration().isSequential() ) { // We are in sequential mode, so no nodes should have memory context.setTupleMemoryEnabled( false ); context.setObjectTypeNodeMemoryEnabled( false ); } else { context.setTupleMemoryEnabled( true ); context.setObjectTypeNodeMemoryEnabled( true ); } // there must exist an ObjectTypeNode for this concrete class this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context, objectType ); } this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode}; }
if ( candidate instanceof EntryPointNode ) { node = context.getRuleBase().getRete().getEntryPointNode( ((EntryPointNode) candidate).getEntryPoint() ); Map<ObjectType, ObjectTypeNode> map = context.getRuleBase().getRete().getObjectTypeNodes( context.getCurrentEntryPoint() ); if ( map != null ) { ObjectTypeNode otn = map.get( ((ObjectTypeNode) candidate).getObjectType() ); context.setPartitionId( context.getRuleBase().createNewPartitionId() );