org.drools.agent
Class RuleAgent

java.lang.Object
  extended by org.drools.agent.RuleAgent

public class RuleAgent
extends Object

This manages a single rulebase, based on the properties given. You should only have ONE instance of this agent per rulebase configuration. You can get the rulebase from this agent repeatedly, as needed, or if you keep the rulebase, under most configurations it will be automatically updated. How this behaves depends on the properties that you pass into it (documented below) CONFIG OPTIONS (to be passed in as properties): newInstance: setting this to "true" means that each time the rules are changed a new instance of the rulebase is created (as opposed to updated in place) the default is to update in place. DEFAULT: false. If you set this to true, then you will need to call getRuleBase() each time you want to use it. If it is false, then it means you can keep your reference to the rulebase and it will be updated automatically (as well as any stateful sessions). pollThe number of seconds to poll for changes. Polling happens in a background thread. eg: poll=30 #30 second polling. file: a space seperated listing of files that make up the packages of the rulebase. Each package can only be in one file. You can't have packages spread across files. eg: file=/your/dir/file1.pkg file=/your/dir/file2.pkg If the file has a .pkg extension, then it will be loaded as a binary Package (eg from the BRMS). If its a DRL file (ie a file with a .drl extension with rule source in it), then it will attempt to compile it (of course, you will need the drools-compiler and its dependencies available on your classpath). dir: a single file system directory to monitor for packages. As with files, each package must be in its own file. eg: dir=/your/dir url: A space seperated URL to a binary rulebase in the BRMS. eg: url=http://server/guvnor-webapp/packages/somePakage/VERSION_1 For URL you will also want a local cache directory setup: eg: localCacheDir=/some/dir/that/exists This is needed so that the runtime can startup and load packages even if the BRMS is not available (or the network). name the Name is used in any logging, so each agent can be differentiated (you may have one agent per rulebase that you need in your application). There is also an AgentEventListener interface which you can provide which will call back when lifecycle events happen, or errors/warnings occur. As the updating happens in a background thread, this may be important. The default event listener logs to the System.err output stream.


Field Summary
static String CONFIG_NAME
           
static String DIRECTORY
           
static String ENABLE_BASIC_AUTHENTICATION
           
static String FILES
           
static String LOCAL_URL_CACHE
           
static String NEW_INSTANCE
          Following are property keys to be used in the property config file.
static Map PACKAGE_PROVIDERS
          Here is where we have a map of providers to the key that appears on the configuration.
static String PASSWORD
           
static String POLL_INTERVAL
           
static String URLS
           
static String USER_NAME
           
 
Method Summary
 RuleBase getRuleBase()
          Return a current rulebase.
 boolean isPolling()
           
static RuleAgent newRuleAgent(Properties config)
          Properties configured to load up packages into a rulebase (and monitor them for changes).
static RuleAgent newRuleAgent(Properties config, AgentEventListener listener)
          This allows an optional listener to be passed in.
static RuleAgent newRuleAgent(Properties config, AgentEventListener listener, RuleBaseConfiguration ruleBaseConf)
          This allows an optional listener to be passed in.
static RuleAgent newRuleAgent(Properties config, RuleBaseConfiguration ruleBaseConf)
          Properties configured to load up packages into a rulebase with the provided configuration (and monitor them for changes).
static RuleAgent newRuleAgent(String propsFileName)
          Pass in the name and full path to a config file that is on the classpath.
static RuleAgent newRuleAgent(String propsFileName, AgentEventListener listener)
          This takes in an optional listener.
static RuleAgent newRuleAgent(String propsFileName, AgentEventListener listener, RuleBaseConfiguration ruleBaseConfiguration)
          This takes in an optional listener and RuleBaseConfiguration.
static RuleAgent newRuleAgent(String propsFileName, RuleBaseConfiguration ruleBaseConfiguration)
          Pass in the name and full path to a config file that is on the classpath.
 void refreshRuleBase()
           
 void setName(String name)
           
 void startPolling()
          Will start polling.
 void startPolling(int secondsToRefresh)
          Will start polling.
 void stopPolling()
          Stop the polling (if it is happening)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_INSTANCE

public static final String NEW_INSTANCE
Following are property keys to be used in the property config file.

See Also:
Constant Field Values

FILES

public static final String FILES
See Also:
Constant Field Values

DIRECTORY

public static final String DIRECTORY
See Also:
Constant Field Values

URLS

public static final String URLS
See Also:
Constant Field Values

POLL_INTERVAL

public static final String POLL_INTERVAL
See Also:
Constant Field Values

CONFIG_NAME

public static final String CONFIG_NAME
See Also:
Constant Field Values

USER_NAME

public static final String USER_NAME
See Also:
Constant Field Values

PASSWORD

public static final String PASSWORD
See Also:
Constant Field Values

ENABLE_BASIC_AUTHENTICATION

public static final String ENABLE_BASIC_AUTHENTICATION
See Also:
Constant Field Values

LOCAL_URL_CACHE

public static final String LOCAL_URL_CACHE
See Also:
Constant Field Values

PACKAGE_PROVIDERS

public static Map PACKAGE_PROVIDERS
Here is where we have a map of providers to the key that appears on the configuration.

Method Detail

newRuleAgent

public static RuleAgent newRuleAgent(Properties config)
Properties configured to load up packages into a rulebase (and monitor them for changes).


newRuleAgent

public static RuleAgent newRuleAgent(Properties config,
                                     RuleBaseConfiguration ruleBaseConf)
Properties configured to load up packages into a rulebase with the provided configuration (and monitor them for changes).


newRuleAgent

public static RuleAgent newRuleAgent(Properties config,
                                     AgentEventListener listener)
This allows an optional listener to be passed in. The default one prints some stuff out to System.err only when really needed.


newRuleAgent

public static RuleAgent newRuleAgent(Properties config,
                                     AgentEventListener listener,
                                     RuleBaseConfiguration ruleBaseConf)
This allows an optional listener to be passed in. The default one prints some stuff out to System.err only when really needed.


newRuleAgent

public static RuleAgent newRuleAgent(String propsFileName)
Pass in the name and full path to a config file that is on the classpath.


newRuleAgent

public static RuleAgent newRuleAgent(String propsFileName,
                                     RuleBaseConfiguration ruleBaseConfiguration)
Pass in the name and full path to a config file that is on the classpath.


newRuleAgent

public static RuleAgent newRuleAgent(String propsFileName,
                                     AgentEventListener listener)
This takes in an optional listener. Listener must not be null in this case.


newRuleAgent

public static RuleAgent newRuleAgent(String propsFileName,
                                     AgentEventListener listener,
                                     RuleBaseConfiguration ruleBaseConfiguration)
This takes in an optional listener and RuleBaseConfiguration. Listener must not be null in this case.


setName

public void setName(String name)

refreshRuleBase

public void refreshRuleBase()

getRuleBase

public RuleBase getRuleBase()
Return a current rulebase. Depending on the configuration, this may be a new object each time the rules are updated.


stopPolling

public void stopPolling()
Stop the polling (if it is happening)


startPolling

public void startPolling()
Will start polling. If polling is already running it does nothing.


startPolling

public void startPolling(int secondsToRefresh)
Will start polling. If polling is already happening and of the same interval it will do nothing, if the interval is different it will stop the current Timer and create a new Timer for the new interval.

Parameters:
secondsToRefresh -

isPolling

public boolean isPolling()


Copyright © 2001-2013 JBoss Inc.. All Rights Reserved.