<?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: HotSwap Code using Scala and Actors</title>
	<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/</link>
	<description>Down To The Bone</description>
	<pubDate>Sat, 19 Jul 2008 20:03:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Jason</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16134</link>
		<pubDate>Fri, 21 Dec 2007 06:48:10 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16134</guid>
					<description>&lt;p&gt;for another way to hotswap code you might look at &lt;a href=&quot;http://www.zeroturnaround.com/javarebel/&quot; rel=&quot;nofollow&quot;&gt;javarebel&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>for another way to hotswap code you might look at <a href="http://www.zeroturnaround.com/javarebel/" rel="nofollow">javarebel</a></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16132</link>
		<pubDate>Fri, 21 Dec 2007 05:58:30 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16132</guid>
					<description>&lt;p&gt;Thanks David. I didn't know that. Very cool.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks David. I didn&#8217;t know that. Very cool.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Pollak</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16127</link>
		<pubDate>Fri, 21 Dec 2007 04:25:02 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16127</guid>
					<description>&lt;p&gt;You can achieve even more hot swapping:&lt;/p&gt;

&lt;p&gt;def loop(cmd: PartialFunction[Any, Unit]) {
    react( {
      case HotSwap(newCmd) =&amp;#62;
        println(&quot;hot swapping code...&quot;)
        loop(newCmd)
    } orElse cmd)
  }&lt;/p&gt;

&lt;p&gt;react() takes a PartialFunction as a parameter and does pattern matching against the PartialFunction.  PartialFunctions can be composed with the orElse method.  Thus, you can pass in different cmd's and change what the Actor does.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You can achieve even more hot swapping:</p>

<p>def loop(cmd: PartialFunction[Any, Unit]) {
    react( {
      case HotSwap(newCmd) =&gt;
        println(&#8221;hot swapping code&#8230;&#8221;)
        loop(newCmd)
    } orElse cmd)
  }</p>

<p>react() takes a PartialFunction as a parameter and does pattern matching against the PartialFunction.  PartialFunctions can be composed with the orElse method.  Thus, you can pass in different cmd&#8217;s and change what the Actor does.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16095</link>
		<pubDate>Thu, 20 Dec 2007 14:49:59 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16095</guid>
					<description>&lt;p&gt;Thanks for the correction Rickard. I was fooled by the fact that the enclosing object only has one single val so initialization appeared to be done lazily when first reading the val. Corrected the blog post.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for the correction Rickard. I was fooled by the fact that the enclosing object only has one single val so initialization appeared to be done lazily when first reading the val. Corrected the blog post.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Rickard</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16094</link>
		<pubDate>Thu, 20 Dec 2007 14:41:48 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16094</guid>
					<description>&lt;p&gt;Great article, Jonas! Just wanted to point out that a Scala 'val' is not lazily initialised. All vals are initialised when the class is created (or, for objects, when the object first is used). You can define a 'lazy val', though, for lazy val initialisation.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Great article, Jonas! Just wanted to point out that a Scala &#8216;val&#8217; is not lazily initialised. All vals are initialised when the class is created (or, for objects, when the object first is used). You can define a &#8216;lazy val&#8217;, though, for lazy val initialisation.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16092</link>
		<pubDate>Thu, 20 Dec 2007 13:36:11 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16092</guid>
					<description>&lt;blockquote&gt; 
“avoiding all of the latter one’s problems with deadlocks, live locks, race conditions, thread starvation etc. “

This is just not true. It is very easy to write a race condition with message passing.
&lt;/blockquote&gt; 

&lt;p&gt;Of course. You are right. Sloppy writing. Sorry. Thanks for catching it. Will change the post.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote> 
“avoiding all of the latter one’s problems with deadlocks, live locks, race conditions, thread starvation etc. “

This is just not true. It is very easy to write a race condition with message passing.
</blockquote> 

<p>Of course. You are right. Sloppy writing. Sorry. Thanks for catching it. Will change the post.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16091</link>
		<pubDate>Thu, 20 Dec 2007 13:32:46 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16091</guid>
					<description>&lt;p&gt;the_dormant, thanks for your comments.&lt;/p&gt;

&lt;blockquote&gt;
so far, this solution is not different from:

class Server{
InnerServer inner;
public void setServer(InnerServer inner){ this.inner = inner; }
public String status(){ return inner.status() }
}
you send your bytecode to a class which loads and instanciates your inner class with a different class loader, updates your inner server and voilà. 
&lt;/blockquote&gt;

&lt;p&gt;It is different in that this is an extremely complicated solution compared to the 3 lines of code that I had to add to support this in Scala. Also, using class loader tricks like that could lead to unforeseen problems. Then I think a solution like the aspect hotdeploy/undeploy, based on runtime instrumentation and uninstrumentation, that I implemented in AspectWerkz would be a better solution to this specific problem. However, far from a simple one.  &lt;/p&gt;

&lt;blockquote&gt;
Therefore, I’m not sure that scala Actors solves the main issue of hotswapping, even though it makes it easy to do so.
&lt;/blockquote&gt;

&lt;p&gt;True. But that was not the point for the post. The point was to show an interesting usage of the Scala Actors library and the simplicity and beauty achieved with message-passing and pattern matching.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>the_dormant, thanks for your comments.</p>

<blockquote>
so far, this solution is not different from:

class Server{
InnerServer inner;
public void setServer(InnerServer inner){ this.inner = inner; }
public String status(){ return inner.status() }
}
you send your bytecode to a class which loads and instanciates your inner class with a different class loader, updates your inner server and voilà. 
</blockquote>

<p>It is different in that this is an extremely complicated solution compared to the 3 lines of code that I had to add to support this in Scala. Also, using class loader tricks like that could lead to unforeseen problems. Then I think a solution like the aspect hotdeploy/undeploy, based on runtime instrumentation and uninstrumentation, that I implemented in AspectWerkz would be a better solution to this specific problem. However, far from a simple one.  </p>

<blockquote>
Therefore, I’m not sure that scala Actors solves the main issue of hotswapping, even though it makes it easy to do so.
</blockquote>

<p>True. But that was not the point for the post. The point was to show an interesting usage of the Scala Actors library and the simplicity and beauty achieved with message-passing and pattern matching.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Asd</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16087</link>
		<pubDate>Thu, 20 Dec 2007 11:33:55 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16087</guid>
					<description>&lt;p&gt;&quot;avoiding all of the latter one’s problems with deadlocks, live locks, race conditions, thread starvation etc. &quot;&lt;/p&gt;

&lt;p&gt;This is just not true. It is very easy to write a race condition with message passing.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&#8220;avoiding all of the latter one’s problems with deadlocks, live locks, race conditions, thread starvation etc. &#8220;</p>

<p>This is just not true. It is very easy to write a race condition with message passing.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: the_dormant</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16086</link>
		<pubDate>Thu, 20 Dec 2007 11:32:05 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16086</guid>
					<description>&lt;p&gt;I was given this requirement for HotSwapping the code in a distributed java system, I didn't resist the temptation to show them how it's easily done with Erlang, but I think the 2 main reasons that make this easy in Erlang are :
1) Erlang vm can update the code of a module without raising any issue (JVM can do it too using JDPA but you can't change the structure of your classes- add/remove methods - and you have to enable JDPA even though it seems to not have consequences on the overall performance ), The other way to do it is using a different class loader and throwing it away when done, but you have to be very careful.&lt;br /&gt;
2) Immutability in Erlang makes natural/obligatory the use of tail recursion or looping with your &quot;State of The Wrold&quot; as a parameter  (you always keep a handle on your global state) and this is the Actor Model behavior by definition. 
so far, this solution is not different from:
&lt;code&gt;&lt;/p&gt;

&lt;p&gt;class Server{
  InnerServer inner;
  public void setServer(InnerServer inner){ this.inner = inner; }
  public String status(){ return inner.status() }
} &lt;/p&gt;

&lt;p&gt;&lt;/code&gt;
you send your bytecode to a class which loads and instanciates your inner class with a different class loader, updates your inner server and voilà. Therefore, I'm not sure that scala Actors solves the main issue of hotswapping, even though it makes it easy to do so.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I was given this requirement for HotSwapping the code in a distributed java system, I didn&#8217;t resist the temptation to show them how it&#8217;s easily done with Erlang, but I think the 2 main reasons that make this easy in Erlang are :
1) Erlang vm can update the code of a module without raising any issue (JVM can do it too using JDPA but you can&#8217;t change the structure of your classes- add/remove methods - and you have to enable JDPA even though it seems to not have consequences on the overall performance ), The other way to do it is using a different class loader and throwing it away when done, but you have to be very careful.<br />
2) Immutability in Erlang makes natural/obligatory the use of tail recursion or looping with your &#8220;State of The Wrold&#8221; as a parameter  (you always keep a handle on your global state) and this is the Actor Model behavior by definition. 
so far, this solution is not different from:
<code></p>

<p>class Server{
  InnerServer inner;
  public void setServer(InnerServer inner){ this.inner = inner; }
  public String status(){ return inner.status() }
} </p>

<p></code>
you send your bytecode to a class which loads and instanciates your inner class with a different class loader, updates your inner server and voilà. Therefore, I&#8217;m not sure that scala Actors solves the main issue of hotswapping, even though it makes it easy to do so.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Stephan Schmidt</title>
		<link>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16083</link>
		<pubDate>Thu, 20 Dec 2007 10:50:33 +0000</pubDate>
		<guid>http://jonasboner.com/2007/12/19/hotswap-code-using-scala-and-actors/#comment-16083</guid>
					<description>&lt;p&gt;Very good post, thanks.&lt;/p&gt;

&lt;p&gt;Since reading Erlang books and doing a little Scala development, I wondered if actors are cooperative multitasking versus preemtive multitasking in the thread model? Just wondering.&lt;/p&gt;

&lt;p&gt;Peace
-stephan&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very good post, thanks.</p>

<p>Since reading Erlang books and doing a little Scala development, I wondered if actors are cooperative multitasking versus preemtive multitasking in the thread model? Just wondering.</p>

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