org.jboss.dna.repository.rules
Class RuleService

java.lang.Object
  extended by org.jboss.dna.repository.rules.RuleService
All Implemented Interfaces:
AdministeredService

@ThreadSafe
public class RuleService
extends Object
implements AdministeredService

A rule service that is capable of executing rule sets using one or more JSR-94 rule engines. Sets of rules are added, updated, and removed (usually by some other component), and then these named rule sets can be run with inputs and facts to obtain output.

This service is thread safe. While multiple rule sets can be safely executed at the same time, all executions will be properly synchronized with methods to add, update, and remove rule sets.

Author:
Randall Hauch

Constructor Summary
RuleService()
          Create a new rule service, configured with no rule sets.
 
Method Summary
 boolean addRuleSet(RuleSet ruleSet)
          Add a rule set, or update any existing one that represents the same rule set
 List<?> executeRules(String ruleSetName, Map<String,Object> globals, Object... facts)
          Execute the set of rules defined by the supplied rule set name.
 ServiceAdministrator getAdministrator()
          Return the administrative component for this service.
 ClassLoaderFactory getClassLoaderFactory()
          Get the class loader factory that should be used to load sequencers.
 Logger getLogger()
          Get the logger for this system
 Collection<RuleSet> getRuleSets()
          Obtain the rule sets that are currently available in this service.
 boolean removeRuleSet(String ruleSetName)
          Remove a rule set.
 void setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
          Set the Maven Repository that should be used to load the sequencer classes.
 void setLogger(Logger logger)
          Set the logger for this system.
 boolean updateRuleSet(RuleSet ruleSet)
          Update the configuration for a sequencer, or add it if there is no matching configuration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleService

public RuleService()
Create a new rule service, configured with no rule sets. Upon construction, the system is paused and must be configured and then started .

Method Detail

getAdministrator

public ServiceAdministrator getAdministrator()
Return the administrative component for this service.

Specified by:
getAdministrator in interface AdministeredService
Returns:
the administrative component; never null

getClassLoaderFactory

public ClassLoaderFactory getClassLoaderFactory()
Get the class loader factory that should be used to load sequencers. By default, this service uses a factory that will return either the current thread's context class loader (if not null) or the class loader that loaded this class.

Returns:
the class loader factory; never null
See Also:
setClassLoaderFactory(ClassLoaderFactory)

setClassLoaderFactory

public void setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
Set the Maven Repository that should be used to load the sequencer classes. By default, this service uses a class loader factory that will return either the current thread's context class loader (if not null) or the class loader that loaded this class.

Parameters:
classLoaderFactory - the class loader factory reference, or null if the default class loader factory should be used.
See Also:
getClassLoaderFactory()

getRuleSets

public Collection<RuleSet> getRuleSets()
Obtain the rule sets that are currently available in this service.

Returns:
an unmodifiable copy of the rule sets; never null, but possibly empty ...

addRuleSet

public boolean addRuleSet(RuleSet ruleSet)
Add a rule set, or update any existing one that represents the same rule set

Parameters:
ruleSet - the new rule set
Returns:
true if the rule set was added, or false if the rule set was not added (because it wasn't necessary)
Throws:
IllegalArgumentException - if ruleSet is null
InvalidRuleSetException - if the supplied rule set is invalid, incomplete, incorrectly defined, or uses a JSR-94 service provider that cannot be found
See Also:
updateRuleSet(RuleSet), removeRuleSet(String)

updateRuleSet

public boolean updateRuleSet(RuleSet ruleSet)
Update the configuration for a sequencer, or add it if there is no matching configuration.

Parameters:
ruleSet - the rule set to be updated
Returns:
true if the rule set was updated, or false if the rule set was not updated (because it wasn't necessary)
Throws:
InvalidRuleSetException - if the supplied rule set is invalid, incomplete, incorrectly defined, or uses a JSR-94 service provider that cannot be found
See Also:
addRuleSet(RuleSet), removeRuleSet(String)

removeRuleSet

public boolean removeRuleSet(String ruleSetName)
Remove a rule set.

Parameters:
ruleSetName - the name of the rule set to be removed
Returns:
true if the rule set was removed, or if it was not an existing rule set
Throws:
IllegalArgumentException - if ruleSetName is null or empty
SystemFailureException - if the rule set was found but there was a problem removing it
See Also:
addRuleSet(RuleSet), updateRuleSet(RuleSet)

getLogger

public Logger getLogger()
Get the logger for this system

Returns:
the logger

setLogger

public void setLogger(Logger logger)
Set the logger for this system.

Parameters:
logger - the logger, or null if the standard logging should be used

executeRules

public List<?> executeRules(String ruleSetName,
                            Map<String,Object> globals,
                            Object... facts)
Execute the set of rules defined by the supplied rule set name. This method is safe to be concurrently called by multiple threads, and is properly synchronized with the methods to add, update, and remove rule sets.

Parameters:
ruleSetName - the name of the RuleSet that should be used
globals - the global variables
facts - the facts
Returns:
the results of executing the rule set
Throws:
IllegalArgumentException - if the rule set name is null, empty or blank, or if there is no rule set with the given name
SystemFailureException - if there is no JSR-94 rule service provider with the RuleSet's provider URI.


Copyright © 2008-Present JBoss a division of Red Hat. All Rights Reserved.