ScalaScriptEngine 1.2.0 with java sandbox

116 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Kostas kougios

ungelesen,
16.10.2012, 18:28:1416.10.12
an scala...@googlegroups.com
This is now live now with support for java sandbox and extra limitations on classes that scripts can access. Also it is available for scala 2.9.2 and 2.10.0-M7.

ScalaScriptEngine is a scala library that allows scala source files to be compiled and loaded (and reloaded if changed) on the fly. It supports various loading methods (i.e. compiling a script on the background while using a previous version of the same script and then using the compiled script when compilation is done) and has eval() capability.

http://code.google.com/p/scalascriptengine/

Usage

This is not the most efficient usage of the library, but is the one with the most expected behavior:

// sourceDir is the folder with the scala source files
val sse
= ScalaScriptEngine.onChangeRefresh(sourceDir)
// get the class which should extend statically
// compiled trait ClzTrait
val clzTraitClass
=sse.get[ClzTrait]("my.dynamic.Clz")
// or get a new instance
val clzTrait
=sse.newInstance[ClzTrait]("my.dynamic.Clz")


How does it work

The ScalaScriptEngine class works by keeping versions of compiled source directories. Version 1 can be loaded during initialization of the engine or during the request for the first script. After that, there are different policies to refresh the changed source files:

  • manual : the client of the engine manually calls ScalaScriptEngine.refresh to check for code changes in the source directories.
  • on-change-refresh : as soon as the src file for a requested class changes, the source dirs are recompiled (only changed files). The code requesting for the changed class blocks till compilation completes
  • on-change-refresh-async: as soon as the src file for a requested class changes, the source dirs are recompiled (only changed files). The code requesting for the changed class resumes execution but uses an old version of the class till compilation completes. This method scales up better for i.e. servers that need to process hundreds of requests per second and blocking till compilation completes is not an option.
  • timed refresh: a background thread periodically scans the source folders for changes and recompiles them. During recompilation, old version classes are returned by the engine but as soon as compilation completes the new version classes are used.

In case of compilation errors, the previous version remains in use.




Eric Kolotyluk

ungelesen,
17.10.2012, 10:12:3217.10.12
an scala...@googlegroups.com
Holy cow - this is so cool!

I built something like this a year ago to support some utilities for a project I was working on. Scala is really a wonderful scripting language, but the default behavior of the Scala interpreter and friends leaves a lot to be desired. I so glad other people are finding ways to improve it.

Cheers, Eric

Razvan Cojocaru

ungelesen,
18.10.2012, 10:00:2018.10.12
an Eric Kolotyluk, scala...@googlegroups.com

Hey – does it work from sbt? i.e. inside a play app?

Konstantinos Kougios

ungelesen,
18.10.2012, 10:07:5418.10.12
an scala...@googlegroups.com
it does, please have a look at sbt section on the home page, http://code.google.com/p/scalascriptengine/

Razvan Cojocaru

ungelesen,
18.10.2012, 10:22:0018.10.12
an Konstantinos Kougios, scala...@googlegroups.com

Sorry – I know how to embed it in an sbt project file.

 

The question was if it does work if my project is ran with SBT – there’s a hole can of worms hiding there, that’s why the question…

Razvan Cojocaru

ungelesen,
18.10.2012, 10:23:3518.10.12
an Konstantinos Kougios, scala...@googlegroups.com

https://gist.github.com/404272

 

I was doing this again yesterday and forgot how to generate the app.class.path file, I though you may have done it recently.

 

From: Razvan Cojocaru [mailto:p...@razie.com]
Sent: October-18-12 10:22 AM
To: 'Konstantinos Kougios'; 'scala...@googlegroups.com'
Subject: RE: [scala-user] ScalaScriptEngine 1.2.0 with java sandbox

 

Sorry – I know how to embed it in an sbt project file.

 

The question was if it does work if my project is ran with SBT – there’s a hole can of worms hiding there, that’s why the question…

 

Konstantinos Kougios

ungelesen,
18.10.2012, 10:43:0218.10.12
an Razvan Cojocaru, scala...@googlegroups.com
I haven't tried in a play project. ScalaScriptEngine uses it's own classloader (with the current classloader set as parent of the scripts classloader). It should work except if play is doing something very weird. Now sandbox again should work.

I am using ScalaScriptEngine myself on a big project (tomcat, J2EE web app) and works fine.
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten