org.drools.common
Class AbstractRuleBase

java.lang.Object
  extended by org.drools.common.AbstractRuleBase
All Implemented Interfaces:
Externalizable, Serializable, InternalRuleBase, RuleBase, RuleBaseEventManager
Direct Known Subclasses:
ReteooRuleBase

public abstract class AbstractRuleBase
extends Object
implements InternalRuleBase, Externalizable

Implementation of RuleBase.

Version:
$Id: RuleBaseImpl.java,v 1.5 2005/08/14 22:44:12 mproctor Exp $
See Also:
Serialized Form

Nested Class Summary
static interface AbstractRuleBase.RuleBaseAction
           
 
Field Summary
protected  Map<String,Package> pkgs
           
 
Fields inherited from interface org.drools.RuleBase
RETEOO
 
Constructor Summary
AbstractRuleBase()
          Default constructor - for Externalizable.
AbstractRuleBase(String id, RuleBaseConfiguration config, FactHandleFactory factHandleFactory)
          Construct.
 
Method Summary
protected  void addEntryPoint(Package pkg, String id)
           
protected abstract  void addEntryPoint(String id)
          This method is called with the rulebase lock held.
 void addEventListener(RuleBaseEventListener listener)
          Add an event listener.
 void addPackages(Collection<Package> newPkgs)
          Add a Package to the network.
 void addProcess(org.drools.definition.process.Process process)
           
 void addRule(Package pkg, Rule rule)
           
protected abstract  void addRule(Rule rule)
          This method is called with the rulebase lock held.
 void addStatefulSession(StatefulSession statefulSession)
           
 RuleBasePartitionId createNewPartitionId()
          Creates and allocates a new partition ID for this rulebase
 void disposeStatefulSession(StatefulSession statefulSession)
           
 void executeQueuedActions()
           
 int getAdditionsSinceLock()
          Returns the number of additive operations applied since the last lock() was obtained
 Map getAgendaGroupRuleTotals()
           
 ClassFieldAccessorCache getClassFieldAccessorCache()
           
 RuleBaseConfiguration getConfig()
           
 RuleBaseConfiguration getConfiguration()
           
 Set<String> getEntryPointIds()
           
 FactHandleFactory getFactHandleFactory()
           
 org.drools.definition.type.FactType getFactType(String name)
          Returns a declared FactType.
 Map getGlobals()
           
 String getId()
           
 Package getPackage(String name)
           
 Package[] getPackages()
           
 Map<String,Package> getPackagesMap()
           
 List<RuleBasePartitionId> getPartitionIds()
          Return the list of Partition IDs for this rulebase
 org.drools.definition.process.Process getProcess(String id)
           
 org.drools.definition.process.Process[] getProcesses()
           
 int getRemovalsSinceLock()
          Returns the number of removal operations applied since the last lock() was obtained
 org.drools.util.CompositeClassLoader getRootClassLoader()
           
 List<RuleBaseEventListener> getRuleBaseEventListeners()
          Returns all event listeners.
 StatefulSession[] getStatefulSessions()
          Returns an array of all the referenced StatefulSessions
 TripleStore getTripleStore()
           
 TypeDeclaration getTypeDeclaration(Class<?> clazz)
          Returns the type declaration associated to the given class
 Collection<TypeDeclaration> getTypeDeclarations()
          Returns a collection with all TypeDeclarations in this rulebase
 InternalWorkingMemory[] getWorkingMemories()
           
 int getWorkingMemoryCounter()
           
 boolean isEvent(Class<?> clazz)
          Returns true if clazz represents an Event class.
 void lock()
          This locks the current RuleBase and all there referenced StatefulSessions.
 FactHandleFactory newFactHandleFactory()
           
 FactHandleFactory newFactHandleFactory(int id, long counter)
           
 StatefulSession newStatefulSession()
          Create a new WorkingMemory session for this RuleBase.
 int nextWorkingMemoryCounter()
           
 void readExternal(ObjectInput in)
          Handles the read serialization of the Package.
 void readLock()
          Acquires a read lock on the rulebase
 void readUnlock()
          Releases a read lock on the rulebase
 void removeEventListener(RuleBaseEventListener listener)
          Remove an event listener.
protected  void removeFunction(String functionName)
          Handle function removal.
 void removeFunction(String packageName, String functionName)
          Removes a specific function in a specific package.
 void removePackage(String packageName)
          Remove the package and all it's rules, functions etc
 void removeProcess(String id)
          Removes a process by the process' id
 void removeQuery(String packageName, String ruleName)
          Remove a specific Query in a Package
 void removeRule(Package pkg, Rule rule)
          Notify listeners and sub-classes about imminent removal of a rule from a package.
protected abstract  void removeRule(Rule rule)
          Handle rule removal.
 void removeRule(String packageName, String ruleName)
          Remove a specific Rule in a Package
 void unlock()
          Unlocks the RuleBase and all of the referenced StatefulSessions.
protected abstract  void updateDependentTypes(Package newPkg, TypeDeclaration typeDeclaration)
           
 void writeExternal(ObjectOutput out)
          Handles the write serialization of the Package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.drools.common.InternalRuleBase
assertObject, getAddedEntryNodeCache, getNodeCount, getRemovedEntryNodeCache, getRete, getReteooBuilder, registerAddedEntryNodeCache, registeRremovedEntryNodeCache, retractObject
 
Methods inherited from interface org.drools.RuleBase
addPackage, addPackages, newStatefulSession, newStatefulSession, newStatefulSession, newStatefulSession, newStatefulSession, newStatelessSession
 

Field Detail

pkgs

protected Map<String,Package> pkgs
Constructor Detail

AbstractRuleBase

public AbstractRuleBase()
Default constructor - for Externalizable. This should never be used by a user, as it will result in an invalid state for the instance.


AbstractRuleBase

public AbstractRuleBase(String id,
                        RuleBaseConfiguration config,
                        FactHandleFactory factHandleFactory)
Construct.

Parameters:
id - The rete network.
Method Detail

nextWorkingMemoryCounter

public int nextWorkingMemoryCounter()
Specified by:
nextWorkingMemoryCounter in interface InternalRuleBase

getWorkingMemoryCounter

public int getWorkingMemoryCounter()

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Handles the write serialization of the Package. Patterns in Rules may reference generated data which cannot be serialized by default methods. The Package uses PackageCompilationData to hold a reference to the generated bytecode. The generated bytecode must be restored before any Rules.

Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Handles the read serialization of the Package. Patterns in Rules may reference generated data which cannot be serialized by default methods. The Package uses PackageCompilationData to hold a reference to the generated bytecode; which must be restored before any Rules. A custom ObjectInputStream, able to resolve classes against the bytecode in the PackageCompilationData, is used to restore the Rules.

Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

getId

public String getId()
Specified by:
getId in interface InternalRuleBase
Returns:
the id

getConfig

public RuleBaseConfiguration getConfig()

newStatefulSession

public StatefulSession newStatefulSession()
Description copied from interface: RuleBase
Create a new WorkingMemory session for this RuleBase. By default the RuleBase retains a weak reference to returned WorkingMemory.

The created WorkingMemory uses the default conflict resolution strategy.

Specified by:
newStatefulSession in interface RuleBase
Returns:
A newly initialized WorkingMemory. IMPORTANT: when using the stateful session REMEMBER TO CALL dispose() when you are done with the session.
See Also:
RuleBase

disposeStatefulSession

public void disposeStatefulSession(StatefulSession statefulSession)
Specified by:
disposeStatefulSession in interface InternalRuleBase

getFactHandleFactory

public FactHandleFactory getFactHandleFactory()
See Also:
RuleBase

newFactHandleFactory

public FactHandleFactory newFactHandleFactory()
Specified by:
newFactHandleFactory in interface InternalRuleBase

newFactHandleFactory

public FactHandleFactory newFactHandleFactory(int id,
                                              long counter)
Specified by:
newFactHandleFactory in interface InternalRuleBase

getProcesses

public org.drools.definition.process.Process[] getProcesses()
Specified by:
getProcesses in interface InternalRuleBase

getPackages

public Package[] getPackages()
Specified by:
getPackages in interface RuleBase

getPackagesMap

public Map<String,Package> getPackagesMap()
Specified by:
getPackagesMap in interface InternalRuleBase

getGlobals

public Map getGlobals()
Specified by:
getGlobals in interface InternalRuleBase

getAgendaGroupRuleTotals

public Map getAgendaGroupRuleTotals()
Specified by:
getAgendaGroupRuleTotals in interface InternalRuleBase

getAdditionsSinceLock

public int getAdditionsSinceLock()
Description copied from interface: RuleBase
Returns the number of additive operations applied since the last lock() was obtained

Specified by:
getAdditionsSinceLock in interface RuleBase
Returns:

getRemovalsSinceLock

public int getRemovalsSinceLock()
Description copied from interface: RuleBase
Returns the number of removal operations applied since the last lock() was obtained

Specified by:
getRemovalsSinceLock in interface RuleBase
Returns:

lock

public void lock()
Description copied from interface: RuleBase
This locks the current RuleBase and all there referenced StatefulSessions. This should be used when there is a number of dynamic RuleBase changes you wish to make, but cannot have any normal WorkingMemory operations occuring inbetween.

Specified by:
lock in interface RuleBase

unlock

public void unlock()
Description copied from interface: RuleBase
Unlocks the RuleBase and all of the referenced StatefulSessions.

Specified by:
unlock in interface RuleBase

readLock

public void readLock()
Description copied from interface: InternalRuleBase
Acquires a read lock on the rulebase

Specified by:
readLock in interface InternalRuleBase

readUnlock

public void readUnlock()
Description copied from interface: InternalRuleBase
Releases a read lock on the rulebase

Specified by:
readUnlock in interface InternalRuleBase

addPackages

public void addPackages(Collection<Package> newPkgs)
Add a Package to the network. Iterates through the Package adding Each individual Rule to the network. Before update network each referenced WorkingMemory is locked.

Parameters:
newPkg - The package to add.

updateDependentTypes

protected abstract void updateDependentTypes(Package newPkg,
                                             TypeDeclaration typeDeclaration)

getTypeDeclaration

public TypeDeclaration getTypeDeclaration(Class<?> clazz)
Description copied from interface: InternalRuleBase
Returns the type declaration associated to the given class

Specified by:
getTypeDeclaration in interface InternalRuleBase
Returns:

getTypeDeclarations

public Collection<TypeDeclaration> getTypeDeclarations()
Description copied from interface: InternalRuleBase
Returns a collection with all TypeDeclarations in this rulebase

Specified by:
getTypeDeclarations in interface InternalRuleBase
Returns:

addRule

public void addRule(Package pkg,
                    Rule rule)
             throws InvalidPatternException
Throws:
InvalidPatternException

addEntryPoint

protected void addEntryPoint(Package pkg,
                             String id)
                      throws InvalidPatternException
Throws:
InvalidPatternException

addRule

protected abstract void addRule(Rule rule)
                         throws InvalidPatternException
This method is called with the rulebase lock held.

Parameters:
rule -
Throws:
InvalidPatternException

addEntryPoint

protected abstract void addEntryPoint(String id)
This method is called with the rulebase lock held.

Parameters:
id - the entry point ID
Throws:
InvalidPatternException

removePackage

public void removePackage(String packageName)
Description copied from interface: RuleBase
Remove the package and all it's rules, functions etc

Specified by:
removePackage in interface RuleBase

removeQuery

public void removeQuery(String packageName,
                        String ruleName)
Description copied from interface: RuleBase
Remove a specific Query in a Package

Specified by:
removeQuery in interface RuleBase

removeRule

public void removeRule(String packageName,
                       String ruleName)
Description copied from interface: RuleBase
Remove a specific Rule in a Package

Specified by:
removeRule in interface RuleBase

removeRule

public void removeRule(Package pkg,
                       Rule rule)
Notify listeners and sub-classes about imminent removal of a rule from a package.

Parameters:
pkg -
rule -

removeRule

protected abstract void removeRule(Rule rule)
Handle rule removal. This method is intended for sub-classes, and called after the before-rule-removed event is fired, and before the rule is physically removed from the package. This method is called with the rulebase lock held.

Parameters:
rule -

removeFunction

public void removeFunction(String packageName,
                           String functionName)
Description copied from interface: RuleBase
Removes a specific function in a specific package.

Specified by:
removeFunction in interface RuleBase

removeFunction

protected void removeFunction(String functionName)
Handle function removal. This method is intended for sub-classes, and called after the before-function-removed event is fired, and before the function is physically removed from the package. This method is called with the rulebase lock held.

Parameters:
rule -

addProcess

public void addProcess(org.drools.definition.process.Process process)

removeProcess

public void removeProcess(String id)
Description copied from interface: RuleBase
Removes a process by the process' id

Specified by:
removeProcess in interface RuleBase

getProcess

public org.drools.definition.process.Process getProcess(String id)
Specified by:
getProcess in interface InternalRuleBase

addStatefulSession

public void addStatefulSession(StatefulSession statefulSession)

getPackage

public Package getPackage(String name)
Specified by:
getPackage in interface InternalRuleBase
Specified by:
getPackage in interface RuleBase

getStatefulSessions

public StatefulSession[] getStatefulSessions()
Description copied from interface: RuleBase
Returns an array of all the referenced StatefulSessions

Specified by:
getStatefulSessions in interface RuleBase
Returns:

getWorkingMemories

public InternalWorkingMemory[] getWorkingMemories()
Specified by:
getWorkingMemories in interface InternalRuleBase

getConfiguration

public RuleBaseConfiguration getConfiguration()
Specified by:
getConfiguration in interface InternalRuleBase

getRootClassLoader

public org.drools.util.CompositeClassLoader getRootClassLoader()
Specified by:
getRootClassLoader in interface InternalRuleBase

executeQueuedActions

public void executeQueuedActions()
Specified by:
executeQueuedActions in interface InternalRuleBase

createNewPartitionId

public RuleBasePartitionId createNewPartitionId()
Description copied from interface: InternalRuleBase
Creates and allocates a new partition ID for this rulebase

Specified by:
createNewPartitionId in interface InternalRuleBase
Returns:

getPartitionIds

public List<RuleBasePartitionId> getPartitionIds()
Description copied from interface: InternalRuleBase
Return the list of Partition IDs for this rulebase

Specified by:
getPartitionIds in interface InternalRuleBase
Returns:

addEventListener

public void addEventListener(RuleBaseEventListener listener)
Description copied from interface: RuleBaseEventManager
Add an event listener.

Specified by:
addEventListener in interface RuleBaseEventManager
Parameters:
listener - The listener to add.

removeEventListener

public void removeEventListener(RuleBaseEventListener listener)
Description copied from interface: RuleBaseEventManager
Remove an event listener.

Specified by:
removeEventListener in interface RuleBaseEventManager
Parameters:
listener - The listener to remove.

getRuleBaseEventListeners

public List<RuleBaseEventListener> getRuleBaseEventListeners()
Description copied from interface: RuleBaseEventManager
Returns all event listeners.

Specified by:
getRuleBaseEventListeners in interface RuleBaseEventManager
Returns:
listeners The listeners.

isEvent

public boolean isEvent(Class<?> clazz)
Description copied from interface: InternalRuleBase
Returns true if clazz represents an Event class. False otherwise.

Specified by:
isEvent in interface InternalRuleBase
Returns:

getFactType

public org.drools.definition.type.FactType getFactType(String name)
Description copied from interface: RuleBase
Returns a declared FactType. FactTypes are types that are declared as part of the rules (an alternative to POJOs). From a fact type you can generate instances of facts which you can use to communicate with the engine.

Specified by:
getFactType in interface RuleBase
Parameters:
name - - the name of the declared type (a type defined in the rules). This would typically be packagename + . + type name. Eg, if there is a delcared type of name "Driver", and the package name is "com.company". Then the string you pass in would be "com.company.Driver".

getClassFieldAccessorCache

public ClassFieldAccessorCache getClassFieldAccessorCache()

getEntryPointIds

public Set<String> getEntryPointIds()
Specified by:
getEntryPointIds in interface RuleBase

getTripleStore

public TripleStore getTripleStore()


Copyright © 2001-2012 JBoss by Red Hat. All Rights Reserved.