- Blog Xebia France - -
Roman Posted By Screw One on Monday, November 23rd, 2009 15:38 In Java No Comments

The language La Scala was very represented this year in Devoxx with a session on , other one on or else that on the framework web . This last unfortunately did not hold all his promises: the half of presentation was focused on the specificity of language and another part on already seen application by David Pollack without real explanation of code, leaving as well as very few place for Topspin it even.
We will dedicate therefore a return to La Scala in two parts: the first one on the actors (present ticket) and the second on ScalaTest.
Presentation starts drum beating with a diagramme on total The evil of state and, in the case of the distribution of variables between several threads, the inevitable:
All threads can achieve this variable, it is therefore necessary to synchronise it.
The passage of messages is right away introduced with the same example: a speed and 2 threads / actors who want to achieve this variable. But this time, no synchronised variable but an actor SpeedSensor who carries value, an actor CruiseControl who recovers the message and carries adequate actions out, in this case to call another actor who will make an adjustment of the speed. They are with an example where all threads shares the same currentSpeed data but thanks to programming by message, he needs no more synchronise this variable there.
Ideas transported by the actors can then come down by:
All these listed points make us fast tilt in the head and they think of course of language of La Scala which carries these stocks completely. For recall, La Scala is a language which:
You should not forget that besides the actors are not included into language La Scala, it is only one IPA - INTERNATIONAL PHONETIC ALPHABET who is given with La Scala. The writing of calls makes believe in the syntax peculiar to language but it is only DSL who invokes simple methods. ScalaTest will show you (before some days) the power of this DSLS and of what it is possible to make with. Besides, if the realisation of the actors does not please you, you can completely do again them in your own way (and at your own risk)
The statement of an actor in La Scala is made by spreading feature Actor and by redefining method def act() . The definition of messages can be made by case class what allows to see fast all types of available messages for our actors and so to perform a legible pattern matching:
The dispatch of message is made of different ways:
chatRoom ! Subscribe(User("Foo")), not blocking, immediate return.var result = chatRoom !? Subscribe(User("Bar")), blocking, in waiting of the return of method.var future = chatRoom !! Subscribe(User("Baz")), not blocking, in waiting of the return of method.The part high performance of the actors comes then. Franck introduces us so Remote actors or distributed actors. These actors have feature to have talks between them even if they are on different physical machines. The creation of an actor Remote is made thanks to call in alive (who creates a socket and a bind on the definite harbour) and in register :
The dispatch of message is made by recovering a proxy on common knot, call in select will allow to recover the actor whose alias was recorded by register (see above). The actor Remote will have good reference at the level of the sender (reference to the one who sent the message):
The part scalabilit approaches with big step and the presenter recalls currently both ways to start our actors:
You will find an example of actors In action given by the presenter in this url as well as a very good article on .
Article printed from Blog Xebia France:
url to article: / 2009 / 11 / 23 / devoxx-jour-2-scala-actors /
Click here to print.