[groovy-user] ResourceConnector vs loading a script file via eval()

31 views
Skip to first unread message

James Thornton

unread,
Jan 23, 2012, 5:56:33 PM1/23/12
to us...@groovy.codehaus.org
What are the differences between loading script files via the GSE
ResourceConnector and loading files using JSR223 eval(java.io.Reader)?

eval(java.io.Reader):
http://docs.oracle.com/javase/6/docs/api/javax/script/ScriptEngine.html#eval(java.io.Reader)

Also, where is documentation explaining the ReosurceConnector? This is
what I've found, but it doesn't go into much detail...

http://groovy.codehaus.org/api/groovy/util/GroovyScriptEngine.html
http://groovy.codehaus.org/api/groovy/util/ResourceConnector.html

Right now we are running the JSR223 script engine in a server and are
looking for ways for clients to be able to upload custom script
libraries via a Web interface and have those classes/functions be
executable via the ScriptEngine.

We are trying to find a more production-quality alternative to loading
script libraries via eval(), and are cool with switching off the
JSR223 script engine and onto the native GroovyScriptEngine.

Is using ResourceConnector the right approach here?

Thanks.

- James

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Guillaume Laforge

unread,
Jan 24, 2012, 3:08:15 PM1/24/12
to us...@groovy.codehaus.org
Hi James,

If you're not tied to JSR-223, it's usually easier to go with Groovy's own integration mechanisms, as they offer more flexibility in general.
That said, even with JSR-223, I think using the implementation directly, you have a means to have access to the underlying GroovyClassLoader on which you can then specify a ResourceLoader (instead of a ResourceConnector like with GroovyScriptEngine).
But you can also use GroovyScriptEngine directly and use ResourceConnector as you've found out.
The choice might depend on your requirements, if JSR-223 is important (if you want to support other languages too), or if you've got some more esoteric needs that would require custom compilation customizers, AST transforms and what not, in which case, going with Groovy's native integration mechanisms are usually the best bet.

Guillaume
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

James Thornton

unread,
Jan 24, 2012, 8:30:21 PM1/24/12
to groov...@googlegroups.com, us...@groovy.codehaus.org
Hi Guillaume -

Thanks for the info. Would you mind explaining the difference between how the ResourceConnector loads files at runtime vs JSR223 eval()?

As I understand it,  eval() builds a class object for each script and stores it in a cache array, which can grow beyond its limits if you feed it a bunch of unique scripts and cause PermGen errors.

How is the ResourceConnector different? -- Is it more akin to compiling the Groovy script into a Java class file and loading it at runtime?

- James
Reply all
Reply to author
Forward
0 new messages