| Allows any BSF script to be used as a con:cern condition. Two environment
variables must be set in order for this to concern: language and script.
"language" should contain the BSF name for the scripting language of the
script, and "script" should contain the script itself. As a convenience,
you may set the "default-script-language" environment variable at the
process level if you plan on using the same scripting language throughout
your process.
This implementation assumes that you have already configured BSFManager
with any additional languages you need. This implementation will declare
the following additional beans before executing the script:
- subject = the subject instance, as passed into the condition
- condition = the condition instance
- environment = the java.util.Map representing the environment for
this condition.
- controller = the controller instance
For most scripting languages, these beans will be made available for
direct use. For example (in groovy):
subject.approval == subject.ACCEPTED
Note: for those using the Groovy scripting language, testing has shown
that Groovy's current implementation of the BSF scripting engine
(org.codehaus.groovy.bsf.GroovyEngine) is extremely slow,
probably because it is parsing the script for every invocation (by slow,
we mean that we have observed 500-1100 ms execution time per
invocation of a condition). We've found that a good workaround is to
use Groovy's caching BSF scripting engine
(org.codehaus.groovy.bsf.CachingGroovyEngine). Obviously, since
this engine caches based on the script String, it will consume more
memory. However, Con:cern processes tend to use a fairly static set of
small script Strings, which fits well with the caching strategy, bringing
memory consumption in line with typical expectations. Here is an example
configuration:
BSFManager.registerScriptingEngine("groovy",
"org.codehaus.groovy.bsf.CachingGroovyEngine",
new String[] { "groovy", "gy" });
author: Andy DePue |