I've put together a simple Struts like action framework by extending the VelocityViewServlet and using the JythonUberspect from here
http://wiki.apache.org/velocity/JythonUberspectBasic idea is on a call to some_page.vm it will first run some_page.py and then pass the request back to some_page.vm, with no configuration. The locals from some_page.py are picked up and automatically made available in the Velocity context.
It all seems to work well, I can easily access the relevant Jython objects on the Velocity pages. However, I had to introduce an interpreter pool, as each request needs to be made in a separate interpreter for things not to clash. Also having to "clean up" the interpreter prior to sending it back to the pool.
I've since come up with another version of this, instead of executing a script each time, this one has all the Actions defined as classes. The definition for these action classes are loaded once, and on each call I get a new instance of the class and run the execute method (just like Struts2). The variables in the class is then made available automatically to the Velocity context. This too seems to work well.
With both ways, I can now do most of the coding using Jython but still have access to all the Java tools. For example, we use Solr a lot and the embedded solr server is started in a Jython module. We have also started up Quartz scheduler and datasources for database the same way. All these services are then easily available to the actions via a simple import statement.
My question is which way to go? I like the first way because the action scripts are very clean, but I'm not sure about keeping a pool of interpreters. I also like the second way because there is only one interpreter and the actions classes are compiled once until they change, but the actions in classes is not as clean as a plain script.
Wonder if anyone can give input about this?
Thanks
Ron
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users