Re: Scalatra praise (and thoughts)

87 views
Skip to first unread message

Ivan Porto Carerro

unread,
Oct 25, 2010, 5:57:23 AM10/25/10
to Wille Faler, scalat...@googlegroups.com
Hi

Thanks for the praise. We are in fact discussing adding an extra layer of abstraction over the servlet API to bring it more inline with Rack (ruby), Ring (clojure), WSGI (python) and JSGI (server side javascript). I think this should address most of the issues you mention.

Somewhere under the covers there will still be a servlet of some sort so that you can still integrate with existing 3rd party components or existing applications that use the raw servlet api.
We're now working our way to a scalatra 2.0 release with the first RC imminent.

Another thing that will be in version 3.0 will be a good integration for comet support, most likely through the atmosphere runtime, and perhaps a good integration with Akka although that part may get a home in the akka-contrib repository.

I hope this is the reply you were expecting.

On Mon, Oct 25, 2010 at 10:32 AM, Wille Faler <wille...@gmail.com> wrote:
Hi,
Just started looking at Scalatra this weekend, and it's just what I've been looking for. Traditionally I've been an Apache Wicket user, which is a great framework for stateful webapps, however I was looking for something more RESTful to enable me to do a more RIA type app with UI logic in the browser calling JSON backend services (via Scalatra).

One thought/gotcha I ran into though:
As I am effectively extending a ScalatraServlet, it made me slightly vary of what is thread safe and what is not of the available variables when I define routes (instance variables/values in Servlets are not thread-safe).

Maybe this will become clearer/more encapsulated in future releases as you separate the DSL from the servlet and filter as you explained in an InfoQ interview?
At the moment, it is one of those things I worry will come and bite me due to the straight Servlet extension.

Anyway, just thought I'd mention this, while at the same time sending some praise your way, it really looks promising!

Regards
Wille



--

Met vriendelijke groeten - Best regards - Salutations

Ivan Porto Carrero
Co-founder & Developer at Mojolly
Mojolly

Ross A. Baker

unread,
Oct 25, 2010, 11:24:38 AM10/25/10
to scalat...@googlegroups.com, Wille Faler
> On Mon, Oct 25, 2010 at 10:32 AM, Wille Faler <wille...@gmail.com> wrote:
>> One thought/gotcha I ran into though:
>> As I am effectively extending a ScalatraServlet, it made me slightly vary
>> of what is thread safe and what is not of the available variables when I
>> define routes (instance variables/values in Servlets are not thread-safe).

This is a good point. Scalatra handles this by storing the request
and response, among other things, inside of a DynamicVariable.
DynamicVariable is built on Java's ThreadLocal, so each thread gets
its own bindings. Application developers still need to be careful
when creating their own instance variables in a servlet or filter.
For these, you may wish to consider a DynamicVariable or a def that
gets/sets to a request attribute.

--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA

Ross A. Baker

unread,
Oct 25, 2010, 1:03:04 PM10/25/10
to Wille Faler, scalat...@googlegroups.com
On Mon, Oct 25, 2010 at 11:34 AM, Wille Faler <wille...@gmail.com> wrote:
> Don't have my IDE available to me right now, but are these values available
> in an accessible DynamicVariable with a specific name in the
> ScalatraServlet?
> Gives a little bit more confidence if you access them through a val/var you
> know is Thread safe. :)
> If it is not available, one way of giving a little more confidence would
> possibly be to expose this and recommend accessing thread-specific instance
> variables through this (strongly typed for the default ones, maybe a Map of
> some sort for user-defined).
> Just an idea off the top of my head, not sure it's the best or cleanest way.

You already have request-scoped and session-scoped maps via request
attributes. If either of these scopes is appropriate for your needs,
then you can define "variables" as this (disclaimer: untested, no
compiler handy):

def foo: Foo = request.getAttribute("foo").asInstanceOf[Foo]
def foo_=(foo: Foo) { request.setAttribute("foo", foo) }

In the latest snapshot, request and session implicitly implement
scala.collection.mutable.Map, further simplifying things:

def foo: Foo = request("foo")
def foo_=(foo: Foo) { request("foo") = foo }

Ravi Mendis

unread,
Oct 25, 2010, 8:09:26 PM10/25/10
to scalatra-user
I have a question (which might help with defining an API that
abstracts Servlets):

How difficult would it be to write Netty as a mover for Scalatra
instead of Servlets?
http://www.jboss.org/netty

FYI: I recently ran apachebench on several Scala web servers
including:
1. WebObjects (with a Netty adaptor),
2. Play (with its Netty module)
3. Lift
4. Scalatra
5. Netty + Scala xml

The fastest was the latter. But Scalatra came a very close second.
I was very impressed!
> *Met vriendelijke groeten - Best regards - Salutations*
>
> *Ivan Porto Carrero*
> Co-founder & Developer at Mojolly
> Mojolly
> Visit us at *www.mojolly.com, flanders.co.nz*
> We tweet at @mojolly <http://twitter.com/mojolly>,
> @casualjim<http://twitter.com/casualjim>
>
> Phone: +44.7513.233.465

Ross A. Baker

unread,
Oct 25, 2010, 9:26:24 PM10/25/10
to scalat...@googlegroups.com
On Mon, Oct 25, 2010 at 8:09 PM, Ravi Mendis <mendis...@gmail.com> wrote:
> I have a question (which might help with defining an API that
> abstracts Servlets):
>
> How difficult would it be to write Netty as a mover for Scalatra
> instead of Servlets?
> http://www.jboss.org/netty

The layer that Ivan mentions below is called SSGI, which you can
follow at http://github.com/scalatra/ssgi. It would provide the
necessary abstraction to support a Netty backend in Scalatra. It's a
thought experiment into what a statically-typed Rack/*SGI would look
like, with the hope that Scalatra can be retrofitted to this interface
with minimal breaking changes. It's still very experimental, and we
welcome all comments.

> FYI: I recently ran apachebench on several Scala web servers
> including:
> 1. WebObjects (with a Netty adaptor),
> 2. Play (with its Netty module)
> 3. Lift
> 4. Scalatra
> 5. Netty + Scala xml
>
> The fastest was the latter. But Scalatra came a very close second.
> I was very impressed!

Excellent. We've heard good things about the performance from others as well.

--

Reply all
Reply to author
Forward
0 new messages