<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Erlang-style Supervisor Module for Scala Actors</title>
	<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/</link>
	<description>Down To The Bone</description>
	<pubDate>Sat, 22 Nov 2008 04:26:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38862</link>
		<pubDate>Sat, 21 Jun 2008 19:34:34 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38862</guid>
					<description>&lt;p&gt;Thanks Rafael.&lt;/p&gt;

&lt;p&gt;To answer your question, no reason at all, it should probably be a symbol, will change that.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks Rafael.</p>

<p>To answer your question, no reason at all, it should probably be a symbol, will change that.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Rafael de F. Ferreira</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38845</link>
		<pubDate>Sat, 21 Jun 2008 18:04:06 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38845</guid>
					<description>&lt;p&gt;Very cool work. I have just one, admittedly silly question, why is the name of the actor passed as a String rather than a Symbol?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very cool work. I have just one, admittedly silly question, why is the name of the actor passed as a String rather than a Symbol?</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38141</link>
		<pubDate>Wed, 18 Jun 2008 06:07:49 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38141</guid>
					<description>&lt;p&gt;Hi Jon.&lt;/p&gt;

&lt;p&gt;The server code that calls 'body' is similar to this (see my comment above for the exact definition): &lt;/p&gt;

&lt;pre&gt;
def act = loop { react { body } }
&lt;/pre&gt;

&lt;p&gt;The 'loop' method is looping and the act method never returns normally, e.g. constantly recurring. &lt;/p&gt;

&lt;p&gt;There are two ways of modeling stateful actors: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Keep regular state in the actor (using 'var' or 'val') and make sure that you never publish a reference to it somehow, e.g. it should only be mutated from the actor main loop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create your own 'loop' and pass the state on recursively. E.g. something like this: &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;
def act = {
  loop(new State)
}

def loop(state: State) {
  react {
    case Bla =&amp;#62;
      ... // use and / or update state
      loop(state)
  }
}
&lt;/pre&gt;

&lt;p&gt;Makes sense?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Jon.</p>

<p>The server code that calls &#8216;body&#8217; is similar to this (see my comment above for the exact definition): </p>

<pre>
def act = loop { react { body } }
</pre>

<p>The &#8216;loop&#8217; method is looping and the act method never returns normally, e.g. constantly recurring. </p>

<p>There are two ways of modeling stateful actors: </p>

<ol>
<li><p>Keep regular state in the actor (using &#8216;var&#8217; or &#8216;val&#8217;) and make sure that you never publish a reference to it somehow, e.g. it should only be mutated from the actor main loop.</p></li>
<li><p>Create your own &#8216;loop&#8217; and pass the state on recursively. E.g. something like this: </p></li>
</ol>

<pre>
def act = {
  loop(new State)
}

def loop(state: State) {
  react {
    case Bla =&gt;
      ... // use and / or update state
      loop(state)
  }
}
</pre>

<p>Makes sense?</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jon Tirse</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38139</link>
		<pubDate>Wed, 18 Jun 2008 05:57:14 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-38139</guid>
					<description>&lt;p&gt;I might be misreading things but it looks like the &quot;body&quot; of your GenericServer only uses threaded &quot;receive&quot; style actors rather than the more scalable &quot;react&quot; style. Or is &quot;body&quot; called from &quot;react&quot; and just calls &quot;body&quot; again directly afterwards? The problem with that approach would be that it's hard (impossible?) to model stateful actor protocols.&lt;/p&gt;

&lt;p&gt;I'm not ruling out I've completely misunderstood though, this all is still a bit new for me... :-)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I might be misreading things but it looks like the &#8220;body&#8221; of your GenericServer only uses threaded &#8220;receive&#8221; style actors rather than the more scalable &#8220;react&#8221; style. Or is &#8220;body&#8221; called from &#8220;react&#8221; and just calls &#8220;body&#8221; again directly afterwards? The problem with that approach would be that it&#8217;s hard (impossible?) to model stateful actor protocols.</p>

<p>I&#8217;m not ruling out I&#8217;ve completely misunderstood though, this all is still a bit new for me&#8230; <img src='http://jonasboner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37835</link>
		<pubDate>Mon, 16 Jun 2008 20:36:59 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37835</guid>
					<description>&lt;p&gt;Thanks for your comment Patrick. &lt;/p&gt;

&lt;p&gt;I agree that a library similar OTP is needed for Scala actors in order to write real-world actor-based server applications. Therefore this initial attempt :-)&lt;/p&gt;

&lt;p&gt;Scala actors have remote capabilities, however I not used it much myself. You are right that much of the power of Erlang comes with the location transparency, the ability to not only scale out on multi-core but also on multiple nodes. My next step will be to make sure that this works as expected.&lt;/p&gt;

&lt;p&gt;...and yes, it only runs on the JVM. Scala has a port to .NET but this lib (and Scala actors package itself) is making use of some Java specific libraries such as java.util.concurrent.  &lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for your comment Patrick. </p>

<p>I agree that a library similar OTP is needed for Scala actors in order to write real-world actor-based server applications. Therefore this initial attempt <img src='http://jonasboner.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Scala actors have remote capabilities, however I not used it much myself. You are right that much of the power of Erlang comes with the location transparency, the ability to not only scale out on multi-core but also on multiple nodes. My next step will be to make sure that this works as expected.</p>

<p>&#8230;and yes, it only runs on the JVM. Scala has a port to .NET but this lib (and Scala actors package itself) is making use of some Java specific libraries such as java.util.concurrent.  </p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Patrick Logan</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37810</link>
		<pubDate>Mon, 16 Jun 2008 19:05:45 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37810</guid>
					<description>&lt;p&gt;Nice. Supervisors and the OTP framework for servers, etc. is something overlooked often by initial attempts to duplicate Erlang features in some other language. Does this currently only run in one JVM? Do Scala actors have the ability out of the box now to send messages, etc. across JVMs? The real power of Erlang's supervisor hierarchy is to run them on multiple machines. Easy distribution is the really huge feature of Erlang overlooked often by initial attempts to duplicate it in other languages.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Nice. Supervisors and the OTP framework for servers, etc. is something overlooked often by initial attempts to duplicate Erlang features in some other language. Does this currently only run in one JVM? Do Scala actors have the ability out of the box now to send messages, etc. across JVMs? The real power of Erlang&#8217;s supervisor hierarchy is to run them on multiple machines. Easy distribution is the really huge feature of Erlang overlooked often by initial attempts to duplicate it in other languages.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37777</link>
		<pubDate>Mon, 16 Jun 2008 15:31:33 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37777</guid>
					<description>&lt;p&gt;Hi Stephan.&lt;/p&gt;

&lt;p&gt;You are right.&lt;/p&gt;

&lt;p&gt;Conceptually, and from a user's perspective, it is swapping the implementation of a method. But if you look at the implementation it is using a method on Scala's &lt;code&gt;PartialFunction &lt;/code&gt;(&lt;code&gt;orElse&lt;/code&gt;) to chain pattern matching code. Such as: &lt;/p&gt;

&lt;pre&gt;
  // the actor's main loop
  def act = loop { react { genericBase orElse actorBase } }

  // should we go with the hotswapped impl or the regular server impl (body)
  private def actorBase: PartialFunction[Any, Unit] = hotswap getOrElse body

  // the hotswapped impl
  private var hotswap: Option[PartialFunction[Any, Unit]] = None

  // generic functionality
  private val genericBase: PartialFunction[Any, Unit] = {
    case Init(config) =&gt; init(config)
    case HotSwap(code) =&gt; hotswap = code
    case Shutdown(reason) =&gt; shutdown(reason); reply('success)
    case Terminate(reason) =&gt; exit(reason)
  }
&lt;/pre&gt;

&lt;p&gt;&lt;p&gt;Scala, while being statically typed, has a feel of being dynamic and has such powerful constructs that you won't actually miss &quot;real&quot; bytecode hotswapping. At least IMO.&lt;/p&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Stephan.</p>

<p>You are right.</p>

<p>Conceptually, and from a user&#8217;s perspective, it is swapping the implementation of a method. But if you look at the implementation it is using a method on Scala&#8217;s <code>PartialFunction </code>(<code>orElse</code>) to chain pattern matching code. Such as: </p>

<pre>
  // the actor's main loop
  def act = loop { react { genericBase orElse actorBase } }

  // should we go with the hotswapped impl or the regular server impl (body)
  private def actorBase: PartialFunction[Any, Unit] = hotswap getOrElse body

  // the hotswapped impl
  private var hotswap: Option[PartialFunction[Any, Unit]] = None

  // generic functionality
  private val genericBase: PartialFunction[Any, Unit] = {
    case Init(config) => init(config)
    case HotSwap(code) => hotswap = code
    case Shutdown(reason) => shutdown(reason); reply('success)
    case Terminate(reason) => exit(reason)
  }
</pre>

<p><p>Scala, while being statically typed, has a feel of being dynamic and has such powerful constructs that you won&#8217;t actually miss &#8220;real&#8221; bytecode hotswapping. At least IMO.</p></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Stephan Schmidt</title>
		<link>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37772</link>
		<pubDate>Mon, 16 Jun 2008 14:57:34 +0000</pubDate>
		<guid>http://jonasboner.com/2008/06/16/erlang-style-supervisor-module-for-scala-actors/#comment-37772</guid>
					<description>&lt;p&gt;For my understanding: Your hotswap code is swapping objects (not classes for example)&lt;/p&gt;

&lt;p&gt;Peace
-stephan&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>For my understanding: Your hotswap code is swapping objects (not classes for example)</p>

<p>Peace
-stephan</p>
]]></content:encoded>
				</item>
</channel>
</rss>
