In What JVM-based scripting language support @WebService to create services at runtime? I was suggested to use Groovy to provide web services configured in a script read in at runtime.
To make this work with our existing infrastructure I need essentially to be able to add new entries to a List<Callable<String>>
which I then can ask an executor to invokeAny upon.
The basic structure will be something like:
- Groovy is embedded using
GroovyScriptEngine
- Initial list passed in from Java as "l" in the Binding passed in.
- Groovy script defines and instantiates N objects, all implementing
Callable<String>
and add them to the list. - Back in Java the list is then further processed and then passed to the executor.
My initial feeble steps show that I will most likely need to use def c = { ... } as Callable<String>
but then I get a ClassCastException. Reading up I see that it appears that this is a bit hard and involves closures.
What is the correct way to define and instantiate an object in Groovy which implements Callable<String>
?