org.drools
Interface KnowledgeBase

All Superinterfaces:
KnowledgeBaseEventManager
All Known Implementing Classes:
ProcessBaseImpl

public interface KnowledgeBase
extends KnowledgeBaseEventManager

The KnowledgeBase is a repository of all the application's knowledge definitions. It will contain rules, processes, functions, type models. The KnowledgeBase itself does not contain runtime data, instead sessions are created from the KnowledgeBase in which data can be inserted and process instances started. Creating the KnowledgeBase can be heavy, where as session creation is very light, so it is recommended that KnowledgeBases be cached where possible to allow for repeated session creation. The KnowledgeAgent can be used for this purpose. The KnowledgeBase is created from the KnowledgeBaseFactory, and a KnowledgeBaseConfiguration can be used.

 KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
 

Create sequential KnowledgeBase using the given ClassLoader.

 Properties properties = new Properties();
 properties.setProperty( "org.drools.sequential", "true");
 KnowledgeBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(properties, myClassLoader);
 KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
 

See Also:
KnowledgeBaseFactory

Method Summary
 void addKnowledgePackages(Collection<KnowledgePackage> kpackages)
          Add the collection of KnowledgePackages to the KnowledgeBase.
 Set<String> getEntryPointIds()
          Returns the set of the entry points declared and/or used in this knowledge base
 FactType getFactType(String packageName, String typeName)
          Returns the FactType identified by the given package and type names.
 KnowledgePackage getKnowledgePackage(String packageName)
          Returns a reference to the KnowledgePackage identified by the given name.
 Collection<KnowledgePackage> getKnowledgePackages()
          Return an immutable collection of the packages that exist in this KnowledgeBase.
 Process getProcess(String processId)
          Returns a referent to the Process identified by the given processId
 Collection<Process> getProcesses()
           
 Query getQuery(String packageName, String queryName)
          Returns a reference to the Rule identified by the given package and rule names.
 Rule getRule(String packageName, String ruleName)
          Returns a reference to the Rule identified by the given package and rule names.
 Collection<StatefulKnowledgeSession> getStatefulKnowledgeSessions()
          Return a collection of the StatefulKnowledgeSessions that exist in this KnowledgeBase.
 StatefulKnowledgeSession newStatefulKnowledgeSession()
          Create a new StatefulKnowledgeSession using the default session configuration.
 StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf, Environment environment)
          Create a new StatefulKnowledgeSession using the given session configuration and/or environment.
 StatelessKnowledgeSession newStatelessKnowledgeSession()
          Create a new StatelessKnowledgeSession using the default session configuration.
 StatelessKnowledgeSession newStatelessKnowledgeSession(KnowledgeSessionConfiguration conf)
          Create a new StatelessKnowledgeSession using the given session configuration.
 void removeFunction(String packageName, String ruleName)
          Remove a function from the specified package.
 void removeKnowledgePackage(String packageName)
          Remove a KnowledgePackage and all the definitions it contains from the KnowledgeBase.
 void removeProcess(String processId)
          Remove a process from the specified package.
 void removeQuery(String packageName, String queryName)
          Remove a rule from the specified package.
 void removeRule(String packageName, String ruleName)
          Remove a rule from the specified package.
 
Methods inherited from interface org.drools.event.knowledgebase.KnowledgeBaseEventManager
addEventListener, getKnowledgeBaseEventListeners, removeEventListener
 

Method Detail

addKnowledgePackages

void addKnowledgePackages(Collection<KnowledgePackage> kpackages)
Add the collection of KnowledgePackages to the KnowledgeBase. It is recommended that you ALWAYS check KnowledgeBuilder.hasErrors() first before doing this.

Parameters:
knowledgePackage -

getKnowledgePackages

Collection<KnowledgePackage> getKnowledgePackages()
Return an immutable collection of the packages that exist in this KnowledgeBase.

Returns:

getKnowledgePackage

KnowledgePackage getKnowledgePackage(String packageName)
Returns a reference to the KnowledgePackage identified by the given name.

Parameters:
packageName - the name of the KnowledgePackage to return
Returns:
the KnowledgePackage identified by the the given name or null if package not found.

removeKnowledgePackage

void removeKnowledgePackage(String packageName)
Remove a KnowledgePackage and all the definitions it contains from the KnowledgeBase.

Parameters:
packageName -

getRule

Rule getRule(String packageName,
             String ruleName)
Returns a reference to the Rule identified by the given package and rule names.

Parameters:
packageName - the package name to which the rule belongs to.
ruleName - the name of the rule.
Returns:
the Rule object or null if not found.

removeRule

void removeRule(String packageName,
                String ruleName)
Remove a rule from the specified package.

Parameters:
packageName -
ruleName -

getQuery

Query getQuery(String packageName,
               String queryName)
Returns a reference to the Rule identified by the given package and rule names.

Parameters:
packageName - the package name to which the rule belongs to.
ruleName - the name of the rule.
Returns:
the Rule object or null if not found.

removeQuery

void removeQuery(String packageName,
                 String queryName)
Remove a rule from the specified package.

Parameters:
packageName -
ruleName -

removeFunction

void removeFunction(String packageName,
                    String ruleName)
Remove a function from the specified package.

Parameters:
packageName -
ruleName -

getFactType

FactType getFactType(String packageName,
                     String typeName)
Returns the FactType identified by the given package and type names.

Parameters:
packageName - the name of the package the fact belongs to.
typeName - the name of the type.
Returns:
the FactType identified by the parameters or null if FactType not found.

getProcess

Process getProcess(String processId)
Returns a referent to the Process identified by the given processId

Parameters:
processId - the id of the process
Returns:
the Process identified by the given processId or null if process not found.

removeProcess

void removeProcess(String processId)
Remove a process from the specified package.

Parameters:
processId -

getProcesses

Collection<Process> getProcesses()

newStatefulKnowledgeSession

StatefulKnowledgeSession newStatefulKnowledgeSession(KnowledgeSessionConfiguration conf,
                                                     Environment environment)
Create a new StatefulKnowledgeSession using the given session configuration and/or environment. Either one can be null and it will use a default. Don't forget to dispose() session when you are done.

Parameters:
conf -
environment -
Returns:
The StatefulKnowledgeSession.

newStatefulKnowledgeSession

StatefulKnowledgeSession newStatefulKnowledgeSession()
Create a new StatefulKnowledgeSession using the default session configuration. Don't forget to dispose() session when you are done.

Returns:
The StatefulKnowledgeSession.

getStatefulKnowledgeSessions

Collection<StatefulKnowledgeSession> getStatefulKnowledgeSessions()
Return a collection of the StatefulKnowledgeSessions that exist in this KnowledgeBase. Be careful as sessions are not thread-safe and could be in use elsewhere.

Returns:
a Collection of StatefulKnowledgeSessions

newStatelessKnowledgeSession

StatelessKnowledgeSession newStatelessKnowledgeSession(KnowledgeSessionConfiguration conf)
Create a new StatelessKnowledgeSession using the given session configuration. You do not need to call dispose() on this.

Parameters:
conf -
Returns:
The StatelessKnowledgeSession.

newStatelessKnowledgeSession

StatelessKnowledgeSession newStatelessKnowledgeSession()
Create a new StatelessKnowledgeSession using the default session configuration. You do not need to call dispose() on this.

Returns:
The StatelessKnowledgeSession.

getEntryPointIds

Set<String> getEntryPointIds()
Returns the set of the entry points declared and/or used in this knowledge base

Returns:


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