Drools is an extension on the current Business Layer, not its replacement. It is present in standard package, embedded in FEJ and can be used without some additional components.
FEJ API can be called from Drools rules. External Drools server cannot be used.
2. Drools Engine documentation
The following property is used to configure if Drools Engine is enabled or disabled:
drools.engine.enabled
Possible values: true | false. Default value: false.
This property is specified in fixedge.properties file in FIXEdge Java.
Returns existing stateful session if it exists in sessions cache. Otherwise creates new stateful session, adds it to the sessions cache and returns. SessionName is used to create new session if a session is not found by id.
Please pay attention: When new Drools Config comes from FIXICC H2, the session will be disposed. A user should get session again.
Parameters:
id - the ID of the session in sessions cachet
sessionName - the name of the session
Returns Kie Session from the sessions cache.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used as session id.
Parameters:
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session and fires all matches of the agenda for this session. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session and fires all matches of the agenda for this session. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session and keeps firing Matches until a halt is called for this session. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session, keeps firing Matches until a halt is called for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
values - the facts to be inserted
Returns Kie Session the matches have been fired for.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session and performs consumer operation on the session. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
method - operation performed on the session
values - the facts to be inserted
Returns Kie Session the operation has been performed on.
Throws DroolsException if Drools Engine is not initialized.
Inserts new facts into the stateful session, performs consumer operation on the session and retracts the facts. SessionName is used to create new session if a session is not found by id.
Parameters:
id - the ID of the session in sessions cache
sessionName - the name of the session
method - operation performed on the session
values - the facts to be inserted
Returns Kie Session the operation has been performed on.
Throws DroolsException if Drools Engine is not initialized.
Releases all the current session resources, setting up the session for garbage collection.
Parameters:
id - the ID of the session in sessions cache
Throws DroolsException if Drools Engine is not initialized.
void disposeSessions()
Disposes all Kie stateful sessions.
2.1.3. Other methods
void reset()
Initializes Kie Container and Kie Container Sessions Pool.
void clear()
Disposes Kie Sessions and Kie Container, clear Kie Sessions cache, shutdowns Kie Container Sessions Pool.
org.kie.api.runtime.KieContainer getContatiner()
Returns Kie Container.
3. Drools Config Manager Listener documentation
If you need to create your own listener, you should implement DroolsConfigManagerListener interface and override it's methods. After this, the listener should be registered in fej-routing.xml.
Apply some actions if Drools asset has been deleted.
Parameters:
ruleSetConfig - deleted Drools asset
pathInCache - path where Drools asset is saved in cache
4. Examples
4.1 This example describes how to work with Drools in FEJ with FIXICC-H2
Add the following business rules configuration:
import com.epam.fej.routing.drools.DroolsEngine
import static dsl.CommonRulesDsl.rulesDSL
DroolsEngine dre = drools as DroolsEngine
rulesDSL(routingContext as RoutingContext) {
messageRules {
messageRule("Route FIX message by decision table in kbase1") {
action {
custom {
ctx ->
dre.runStatefulAndClean("ksession1", ctx)
routingContext.getDestinationById(ctx.messageEvent.getHeader("destination")).send(ctx.messageEvent)
}
context exit
}
}
}
}
Then configure Drools. To do it, in FIXICC-H2 select "Edit kmodule.xml" menu item in Server View in Configuration menu and add the following content:
Then add new Drools component. Select "Drools components" menu item in Server View in Configuration menu, click "Add" popup button, choose "Decision table" and upload the following file:
Enter Package value, check Enabled checkbox and click OK button:
Then add FIX sessions. There are 3 acceptor sessions in our example: session1 (target1-sender1), session2 (target2-sender2) and session3 (target3-session3):
After this, connect to these sessions. Create initiator sessions session1 (sender1-target1), session2 (sender2-target2) and session3 (sender3-target3).
To test Drools, send some message to session1. As a result, session3 will receive this message.
4.2 This example describes mixed DSL/Drools calls.
Add the following business rules configuration:
Routing- Other blocks besides messageRules can be called