Class cache on GroovyShell

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Class cache on GroovyShell

Rapheal Kaplan
  Groovy-folk,

  I am using Groovy as the default embedded scripting engine for my
application, and so far, it's pretty groovy, so to speak.  The main part
that I use groovy for is scripting columns for user interface tables.  
The application allows the user to work on multiple datasets where each
dataset will have a slightly different fields associated with each of
its entities, hence each dataset has scripts that describe their user
interface.

  The problem is that when switching datasets, it can take quite a
while, especially on older machines, which we are required to support.  
Most of this seems to be taken up by the Groovy compilation process,
naturally.

  I would like to implement a simple dynamic cache which will store
compiled class objects in a user directory and only recompile them when
the sources have been updated.  I would prefer to stick with using the
GroovyShell class because of its simplicity and integration with my
BSF-like scripting engine.

  Does anyone know how best to do this?

  Thanks.

  - Rapheal Kaplan
    Human Rights Data Analysis Group
    Benetech Inc

Reply | Threaded
Open this post in threaded view
|

Re: Class cache on GroovyShell

Guillaume Laforge
Administrator
Hello Rapheal,

You might have a look at the GroovyScriptEngine, as shown on our page
about embedding Groovy, which does some caching and reloading:

http://groovy.codehaus.org/Embedding+Groovy



On 13/12/05, Rapheal Kaplan <[hidden email]> wrote:

>   Groovy-folk,
>
>   I am using Groovy as the default embedded scripting engine for my
> application, and so far, it's pretty groovy, so to speak.  The main part
> that I use groovy for is scripting columns for user interface tables.
> The application allows the user to work on multiple datasets where each
> dataset will have a slightly different fields associated with each of
> its entities, hence each dataset has scripts that describe their user
> interface.
>
>   The problem is that when switching datasets, it can take quite a
> while, especially on older machines, which we are required to support.
> Most of this seems to be taken up by the Groovy compilation process,
> naturally.
>
>   I would like to implement a simple dynamic cache which will store
> compiled class objects in a user directory and only recompile them when
> the sources have been updated.  I would prefer to stick with using the
> GroovyShell class because of its simplicity and integration with my
> BSF-like scripting engine.
>
>   Does anyone know how best to do this?
>
>   Thanks.
>
>   - Rapheal Kaplan
>     Human Rights Data Analysis Group
>     Benetech Inc
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: Class cache on GroovyShell

Rapheal Kaplan
  Thank you for your response.  I have looked at that class before, and
it is quite nice, but I think I am looking for something a little
different.  I sort of need the whole range of functionality provided by
the GroovyShell class as I will often need to run little script
fragements or scripts that do not come from URLs.  For example, one tool
I have is a groovy console where the user can type in a script fragement
and execute it.

  Also, most of the time, I will be executing scripts from class
resources.  This means I will have a URL independent of any pre-set root
set.

  The main thing I need this for is to cache those resource based
scripts.  When the groovy implementation of my scripting framework
receives a URL, it transforms it in to a class name and evaluates or
executes the stream.  The first step to implementing a cache to do what
I would like is to have an intermediate class loader that keeps track of
all the URL generated classes in a cache directory and loads those
classes when they are up to date.  It would fail to load when they are
out of date, but I am not sure how to use groovy to generate a class
file to the right place.  I suspect the Compiler classes in the codehaus
packages is where to look, but I am nervous about using those packages
in the same way I am nervous about using sun.* packages.

  Do I sound delusional and is this in fact really the only way to go?  
Is there still a way I could use the GroovyScriptEngine for what I need?

>Hello Rapheal,
>
>You might have a look at the GroovyScriptEngine, as shown on our page
>about embedding Groovy, which does some caching and reloading:
>
>http://groovy.codehaus.org/Embedding+Groovy
>
>
>
>On 13/12/05, Rapheal Kaplan <[hidden email]> wrote:
>  
>
>>  Groovy-folk,
>>
>>  I am using Groovy as the default embedded scripting engine for my
>>application, and so far, it's pretty groovy, so to speak.  The main part
>>that I use groovy for is scripting columns for user interface tables.
>>The application allows the user to work on multiple datasets where each
>>dataset will have a slightly different fields associated with each of
>>its entities, hence each dataset has scripts that describe their user
>>interface.
>>
>>  The problem is that when switching datasets, it can take quite a
>>while, especially on older machines, which we are required to support.
>>Most of this seems to be taken up by the Groovy compilation process,
>>naturally.
>>
>>  I would like to implement a simple dynamic cache which will store
>>compiled class objects in a user directory and only recompile them when
>>the sources have been updated.  I would prefer to stick with using the
>>GroovyShell class because of its simplicity and integration with my
>>BSF-like scripting engine.
>>
>>  Does anyone know how best to do this?
>>
>>  Thanks.
>>
>>  - Rapheal Kaplan
>>    Human Rights Data Analysis Group
>>    Benetech Inc
>>
>>
>>    
>>
>
>
>--
>Guillaume Laforge
>Groovy Project Manager
>http://glaforge.free.fr/blog/groovy
>  
>