[jboss-jira] [JBoss JIRA] (JBRULES-2700) Allow setting a global variable (for example a service) which can be used by the score rules
Geoffrey De Smet (JIRA)
jira-events at lists.jboss.org
Fri Aug 17 07:04:15 EDT 2012
[ https://issues.jboss.org/browse/JBRULES-2700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12712184#comment-12712184 ]
Geoffrey De Smet commented on JBRULES-2700:
-------------------------------------------
@Henrik That scenario makes sense.
Here's solution proposal A:
DroolsScoreDirectorFactory gets a Map<String, Object> globalVariablesToInjectMap
for every entry in that map, DroolsScoreDirector injects them (key = global variable name, value = instance to inject) when creating a new working memory.
ScoreDirectorFactoryConfig gets a Map<String, Object> droolsGlobalVariablesToInjectMap.
Database connections in XML won't work well (because the connection will never get closed), so the use of droolsGlobalVariablesToInjectMap would call for the use of API configuration (see manual), which is fine.
Chapter-Score_calculation.xml should document how to use it, preferably with a connection based example. It should clearly state that all global variables must be thread-safe.
Open questions: Is the thead-safe requirement doable? In some cases they might need to hack it with ThreadLocals.
Currently this is not a priority for me, but pull requests are welcome :)
> Allow setting a global variable (for example a service) which can be used by the score rules
> --------------------------------------------------------------------------------------------
>
> Key: JBRULES-2700
> URL: https://issues.jboss.org/browse/JBRULES-2700
> Project: Drools
> Issue Type: Feature Request
> Security Level: Public(Everyone can see)
> Components: drools-planner
> Reporter: Wouter Horré
> Assignee: Geoffrey De Smet
>
> Currently, it is not possible to set a global variable in the working memory used by the solver. If a scoring rule needs an external helper for calculating scores (e.g. a dependency injected with OSGi DS), a workaround using a static variable in some class accessible by the scoring rules is needed.
> The easiest implementation is probably a new method in the Solver interface:
> public WorkingMemory getWorkingMemory();
> which provides access to the working memory used by the solver.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list