Building Concurrent Applications with WebObjects and Scala

Version 122.1 by Ravi Mendis on 2010/03/04 18:11

Given that todays processors ship with dual or quad cores and server processors ship with between 8 to 32 cores, languages like Java, Ruby, Groovy and Python are struggling to keep up. Scala, as its name suggests is built from the ground-up for concurrent programming - a methodology that can take advantage of these modern multi-core processors.

If you use Scala for a concurrent programming application, the chances are that you're using Scala Actors to do that.

Information
Scala Actors

Concurrent programming in Scala is based on *Actors* (with an inbox) - a common metaphor that is alternatively known as *Message Queues*.

Using Scala Actors with EOF

EOF being notoriously single-threaded, is incredibly unsuitable for use by Scala Actors.
Instead you may still use EOF but only to execute SQL directly.

Using EOAccess to execute SQL

Use Wonder API: ERXEOAccessUtilities.evaluateSQLWithEntityNamed()

Caveats

If you're updating the state of EOs directly in the database using SQL from Scala Actors, you will subsequently need to refresh/refetch these EOs for the WebObjects application to see those changes.

EOF Alternatives

You may also manipulate the database from outside the EOF stack.

Squeryl

Squeryl is a Scala internal Domain-specific language for database access (via SQL).
You may update the database from Scala Actors using Squeryl instead of using EOF. The advantage here is that you may access the database concurrently avoiding the single-threaded EOF bottleneck in your concurrent application.

However the same caveat applies - you will need to refresh EOs in the EOF stack for the WebObjects application to reflect the changes made by Squeryl.