Rule provider is implemented as BTT services, which provides
the common interfaces to visit rule engines, including ILog and Java
Code rule engine.
Rule provider services must implement the
IBTTRuleProvider interface,
and extend BTT Service class.
checkRule method
in
IBTTRuleProvider connects to the rule engine,
and check the policy.
ILogRuleProviderService and
JavaCodeRuleProviderService are
both extended from
IBTTRuleProvider.
ILogRuleProviderService
provides a default implementation to access local ILog Rule Engine.
To access remote ILog or Java local rule engine, you need to extend
JavaCodeRuleProviderService yourself
The following codes give an example to use these services:
IBTTRuleProvider ruleService= (IBTTRuleProvider) Service.readObject("testIlogJ2SEService");
Loan loan = new miniloan.Loan(50000000, 240, 0.05);
Borrower borrower =new miniloan.Borrower("Joe", 600, 80000);
Map<String, Object> inputParameters=new HashMap<String, Object>();
inputParameters.put("loan", loan);
inputParameters.put("borrower", borrower);
Map result =ruleService.checkRule(inputParameters);
To
use the Rule Provider Service, you need to:
Configure the service
If you want to use a
Rule Provider Service, you need to configure the service firstly.
- ILog Rule Provider Service definition:
Use ILog Rule Provider
Service, you can access the ILog rule engine in local and remote.
The following are format to define local and remote ILog Rule Provider
Service.
Local ILog Rule Provider Service definition:
< ILogRuleProviderService id=“ILogConnectService" ruleID=“/miniloanruleapp/1.0/miniloanrules/1.0” mode=“j2ee” />
- ILogLocalRuleProviderService: Define in file btt.xml,
and point to the implementation class of the service. ILogLocalRuleProviderService is
the implementation class provided by BTT, and you can point to your
implementation also;
- id: the ID of the service
- ruleID: rule ID in ILog project
- mode:
- j2ee: default value, and application connects
to ILog rule engine in same JVM in j2ee mode by ILog connector service;
- j2se: application connects to ILog rule engine
in same JVM in J2SE mode by ILog connector service;
Remote ILog Rule Provider Service definition:
<ILogRemoteRuleProviderService id=“TransferRuleService"/>
- ILogRemoteRuleProviderService: Define in file btt.xml,
and point to the implementation class of the service. The class should
extend the abstract class: JavaCodeRuleProviderService.
Take calling ILog by Web Service as example, ILog provides a tool
to generate the client stub, and you can call the stub in checkRule() method
to access ILog engine.
- id: the ID of the service
- Java Local Rule Provider Service definition:
<JavaLocalRuleProviderService id=“TransferRuleService" ruleID=“checkLimit” />
- JavaLocalRuleProviderService: Define in file btt.xml,
and point to the implementation class of the service. The class should
extend the abstract class: JavaCodeRuleProviderService;
- id: the ID of the service
- ruleID: rule ID in the specified rule service
Prepare the parameter
Rule Provider service
accepts Map<String>as input, you need to prepare the parameters
as key-value pair. The input should follow the definition of ILog
or Java Code Rule Engine. Rule Provider service accepts Map<String>
as output also.
Extending the Java code rule provider service
BTT
provides an abstract service class---
JavaCodeRuleProviderService,
and you can extend it for Remote ILog Service and Java Local Rule
Service.
For Java Local Rule Service, you just need implement the
abstract method
checkRule() to do the rule judgment.
public class UserTransferRuleProviderExample extends JavaCodeRuleProviderService {
public Map<String, Object> checkRule(Map<String, Object> params) {
System.out.println("#######UserTransferRuleProviderExample checkRule for ruleID="+this.getRuleID());
if(getRuleID().equalsIgnoreCase("checkLimit")){
Double amount = (Double) params.get("amount");
Double limit = (Double) params.get("limit");
if(amount<=limit)
params.put("approve", new Boolean(true));
}
return null;
}
}
For Remote ILog Service, you need to implement the
invoker process to the remote ILog server in
checkRule() method.
Note: When
you connect to ILog server in J2EE module, you need to configure a resource-ref
in Web project as following: