<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>dantwining.co.uk</title>
	<atom:link href="http://dantwining.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://dantwining.co.uk</link>
	<description>every day is a school day</description>
	<lastBuildDate>Wed, 15 Feb 2012 20:41:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dantwining.co.uk' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>dantwining.co.uk</title>
		<link>http://dantwining.co.uk</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dantwining.co.uk/osd.xml" title="dantwining.co.uk" />
	<atom:link rel='hub' href='http://dantwining.co.uk/?pushpress=hub'/>
		<item>
		<title>So long .com, hello .co.uk!</title>
		<link>http://dantwining.co.uk/2011/11/10/so-long-com-hello-co-uk/</link>
		<comments>http://dantwining.co.uk/2011/11/10/so-long-com-hello-co-uk/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 21:18:35 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dantwining.co.uk/?p=964</guid>
		<description><![CDATA[I&#8217;m sure that my many and varied fans, especially those plumbed in through Google Reader, will be very interested to hear that, from the middle of this month, dantwining.com will be switched off and only dantwining.co.uk will point to this blog. It&#8217;s time to update those bookmarks!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=964&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure that my many and varied fans, especially those plumbed in through Google Reader, will be very interested to hear that, from the middle of this month, dantwining.com will be switched off and only dantwining.co.uk will point to this blog. It&#8217;s time to update those bookmarks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/964/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/964/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/964/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=964&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2011/11/10/so-long-com-hello-co-uk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>How to shrink a dynamically-expanding guest virtualbox image</title>
		<link>http://dantwining.co.uk/2011/07/18/how-to-shrink-a-dynamically-expanding-guest-virtualbox-image/</link>
		<comments>http://dantwining.co.uk/2011/07/18/how-to-shrink-a-dynamically-expanding-guest-virtualbox-image/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 20:51:14 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>

		<guid isPermaLink="false">http://dantwining.co.uk/?p=951</guid>
		<description><![CDATA[Sometimes bigger isn&#8217;t always better. If your dynamically-expanding virtual machine images are growing out of control, then here&#8217;s how to trim them back&#8230; Background I’m a big fan of VirtualBox, and use separate virtual machines (VMs) for the various separate bits and pieces I’ve got on the go (as I invariably end up messing something [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=951&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p id="internal-source-marker_0.9262335551902652">Sometimes bigger isn&#8217;t always better. If your dynamically-expanding virtual machine images are growing out of control, then here&#8217;s how to trim them back&#8230;</p>
<p><span id="more-951"></span></p>
<h4>Background</h4>
<p>I’m a big fan of VirtualBox, and use separate virtual machines (VMs) for the various separate bits and pieces I’ve got on the go (as I invariably end up messing something up, and can just trash the image and start again, without taking down whatever else it is I’m playing with at the time).</p>
<p>All my VMs use a <a href="http://www.virtualbox.org/manual/ch05.html#vdidetails">dynamically expanding image</a> for their hard drive, where you set the maximum size of the disk, but the system will only grow to fill that space if required. By setting this nice and high, I can be sure that the hard drive space is there if I need it, without taking space away unnecessarily from the rest of the system.</p>
<p>Unfortunately, whilst VirtualBox will dynamically expand the hard drive as it’s required, it won’t dynamically shrink it again if you free up space in the VM. This can be a problem, especially if, like me, the sum total of all those theoretical maximums exceeds the actual maximum capacity of the hard drive hosting all these VMs.</p>
<p>The good news is that you can shrink those images back down again. The bad news is that a lot of the guides on the internet are out-of-date, and woefully misleading. Here’s what I did to get the job done&#8230;</p>
<h4>1. Free up space in the client machine</h4>
<p>It’s a bit of an obvious first step, but you can only shrink down the client VM by the size of the available free space therein, so delete the files and uninstall the programs that you no longer need but are hogging your resources.</p>
<h4>2. Zero out the free space</h4>
<p>VirtualBox only knows that the space is really free if it’s been set to zero, and standard deletion won’t do this.</p>
<h5>If it’s an Ubuntu VM</h5>
<p>You’ll want to use <a href="http://manpages.ubuntu.com/manpages/natty/man8/zerofree.8.html">zerofree</a>:</p>
<ul>
<li>install with <em>sudo aptitude install zerofree</em></li>
<li>(if you don’t have aptitude, you can either use apt-get to install zerofree  (<em>sudo apt-get install zerofree</em>) or use apt-get to install aptitude (<em>sudo apt-get install aptitude</em>). I’d recommend getting hold of aptitude, as it does a great job of managing packages in Ubuntu)</li>
<li>Reboot the machine (<em>sudo shutdown -r now</em>). During boot, hold down the left shift key. A menu will appear, you need to select “recovery mode”; this should be the second item in the list.</li>
<li>You’ll get another menu, towards the bottom there should be the option to “Drop to root shell prompt”</li>
<li>Run <em>df</em> and look for the mount point that’s that the biggest &#8211; this is where all your files are, and is the one we’ll need to run zerofree against. For the rest of this guide, we’ll assume it’s /dev/sda1</li>
<li>The following three commands (thanks, <a href="http://forum.virtualbox.org/viewtopic.php?f=6&amp;p=148554">VirtualBox forum</a>!) stop background services that we can’t have running:</li>
<ul>
<li><em>service rsyslog stop</em></li>
</ul>
<ul>
<li><em>service network-manager stop</em></li>
<li><em>killall dhclient</em></li>
</ul>
<li>Once they’ve stopped, you can re-mount the partition as readonly (zerofree needs this)</li>
<ul>
<li><em>mount -n -o remount,ro -t ext3 /dev/sda1 /</em></li>
</ul>
<li>You can now run zerofree</li>
<ul>
<li><em>zerofree -v /dev/sda1</em></li>
</ul>
<li>Finally, shut down the VM</li>
<ul>
<li><em>shutdown -h now</em></li>
</ul>
</ul>
<h5>If it’s a Windows VM</h5>
<p>You’ll need to run <em>sdelete</em>; I’ve never done this, but there are instructions on that here:</p>
<ul>
<li><a href="http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06">http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06</a></li>
</ul>
<h4>3. Shrink the VM</h4>
<p>Quite a lot of the online guides say that you’ll have to clone the hard drive image to shrink it, as VirtualBox 2.2 and above dropped support for compacting the image. This isn’t true, certainly not for version 4.0.4, and you can shrink the image in-place with the following command:</p>
<ul>
<li><em>VBoxManage modifyhd my.vdi &#8211;compact</em></li>
</ul>
</div>
<div>where you replace my.vdi with the name of the vdi you’d like to shrink (for more information on this command, see <a href="http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi">the VirtualBox manua</a><a href="http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi">l</a>).</div>
<h4>That&#8217;s it!</h4>
<p>With any luck, you&#8217;ll now have plenty of disk space to fill will equally useless tat&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/951/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=951&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2011/07/18/how-to-shrink-a-dynamically-expanding-guest-virtualbox-image/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>jade-oo: Why I&#8217;m done with done()</title>
		<link>http://dantwining.co.uk/2010/04/27/jade-oo-why-im-done-with-done/</link>
		<comments>http://dantwining.co.uk/2010/04/27/jade-oo-why-im-done-with-done/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 21:47:45 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[jade-oo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=858</guid>
		<description><![CDATA[As I mentioned in my previous article, I&#8217;m not entirely happy with my Block object. For a start, its name is completely wrong; nothing it does ever blocks the thread of execution. Secondly, I&#8217;m not happy that the Block object is responsible for both defining the characteristics of a Block objects, and for constructing their various [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=858&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<div>
<p>As I mentioned in <a href="http://dantwining.com/2010/03/28/jade-oo-exposing-the-hidden-side-effects-of-the-action-method/">my previous article</a>, I&#8217;m not entirely happy with my Block object. For a start, its name is completely wrong; nothing it does ever blocks the thread of execution. Secondly, I&#8217;m not happy that the Block object is responsible for both defining the characteristics of a Block objects, and for constructing their various implementations. Finally, I&#8217;ve realised that having a return type for the <em>action()</em> method makes the <em>done()</em> method entirely redundant.</p>
<p><img title="More..." src="http://dantwining.wordpress.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /><span id="more-858"></span></p>
<p>So, what should the type of the object that&#8217;s returned by <em>action()</em> be called? A well-named type has a name that clearly and succinctly communicates its responsibility. The object returned by <em>action()</em> will represent one of four states:</p>
<ol>
<li>The Behaviour has finished forever; remove it from the pool of active Behaviours.</li>
<li>The Behaviour is still active; keep it in the pool of active behaviours and call its <em>action()</em> method as soon as possible.</li>
<li>The Behaviour is waiting for a message to arrive; only call its <em>action()</em> method again once a message has been received.</li>
<li>The Behaviour is waiting for a message to arrive; only call its <em>action()</em> method again once a message has been received or if a maximum waiting time has elapsed.</li>
</ol>
<p>These are the four states that a Behaviour can be in at the end of its <em>action()</em> method, and so I plan to rename the Block object as BehaviourState. The <em>action()</em> method will then return a BehaviourState object which encapsulates one of those four states:</p>
<ol>
<li>BehaviourStateFactory.FINISHED</li>
<li>BehaviourStateFactory.ACTIVE</li>
<li>BehaviourStateFactory.WAIT_FOR_MESSAGE;</li>
<li>BehaviourStateFactory.WAIT_FOR_MESSAGE.setMaxWaitTime(long)</li>
</ol>
<p>Note that each of those is a BehaviourState, but that they are provided by the BehaviourStateFactory, i.e. a separate object is responsible for BehaviourState construction.</p>
<p>Those four states are equivalent, in standard JADE, to:</p>
<ol>
<li>setting <em>done()</em> to return true.</li>
<li>setting <em>done()</em> to return false.</li>
<li>setting <em>done()</em> to return false, and calling <em>block()</em>.</li>
<li>setting <em>done()</em> to return false, and calling <em>block(long)</em>.</li>
</ol>
<p>This covers all logical combinations of both <em>block()</em> and <em>done()</em>, which means that we can not only replace <em>block()</em>, but also do away with <em>done()</em> altogether.</p>
<h4>Footnotes</h4>
<p>I&#8217;m still not 100% happy. I&#8217;m not sure that WAIT_FOR_MESSAGE should have a <em>setMaxWaitTime(long)</em> method &#8211; I don&#8217;t like the fact that the same mechanism is responsible for waiting for messages *and* setting a timeout. Also, I&#8217;m not sure that I need objects and a factory; part of me feels that an Enum would suffice. Perhaps this is something that will fall out of the implementation.</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/858/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=858&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/04/27/jade-oo-why-im-done-with-done/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>

		<media:content url="http://dantwining.wordpress.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" medium="image">
			<media:title type="html">More...</media:title>
		</media:content>
	</item>
		<item>
		<title>jade-oo: Making Agents testable</title>
		<link>http://dantwining.co.uk/2010/04/01/jade-oo-making-agents-testable/</link>
		<comments>http://dantwining.co.uk/2010/04/01/jade-oo-making-agents-testable/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 14:58:09 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[jade-oo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=832</guid>
		<description><![CDATA[The core of most JADE-based systems are the Behaviours that respond to incoming messages, sent to them by other Agents (and which, in turn, send messages to other Behaviours). Testing these Behaviours is critical, but complicated; instantiating a standard JADE Behaviour in a test involves instantiating much of the JADE architecture that, through inheritance, is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=832&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The core of most JADE-based systems are the Behaviours that respond to incoming messages, sent to them by other Agents (and which, in turn, send messages to other Behaviours). Testing these Behaviours is critical, but complicated; instantiating a standard JADE Behaviour in a test involves instantiating much of the JADE architecture that, through inheritance, is required for the existence of any Behaviour; and that underlying architecture provides mechanisms used by Behaviours that aren&#8217;t accessible to the tests.</p>
<p>jade-oo decouples behavioural logic from the underlying JADE system, allowing isolated testing of these critical components. Here&#8217;s how&#8230;</p>
<p><span id="more-832"></span></p>
<p>The <a href="http://code.google.com/p/jade-oo/source/browse/#svn/trunk/jade-oo-examples/src/com/dantwining/jade/oo%3Fstate%3Dclosed">current jade-oo example</a> consists of two Agents sending messages to each other. One Agent, <a href="http://code.google.com/p/jade-oo/source/browse/trunk/jade-oo-examples/src/com/dantwining/jade/oo/TimeRequestorAgent.java">TimeRequestorAgent</a>, wants to know what the time is, and the other Agent, <a href="http://code.google.com/p/jade-oo/source/browse/trunk/jade-oo-examples/src/com/dantwining/jade/oo/TimeResponderAgent.java">TimeResponderAgent</a>, responds with the current time.</p>
<p>Each Agent has one Behaviour. The TimeRequestorAgent has a jade-oo CyclicBehaviour that, every 12 seconds, sends a message requesting the time. The TimeResponderAgent has one jade-oo MessageReceiver Behaviour, which, every time a message is received, replies with the current time.</p>
<p>We want to test the execution of the business logic contained within the TimeResponderAgent. That logic isn&#8217;t within TimeResponderAgent itself, nor in the MessageReceiver Behaviour; it&#8217;s in the <a href="http://code.google.com/p/jade-oo/source/browse/trunk/jade-oo-examples/src/com/dantwining/jade/oo/TellTheTime.java">TellTheTime</a> POJO that MessageReciver offloads its messages onto. Here&#8217;s the TellTheTime class in full:</p>
<p><pre class="brush: java; gutter: false;">
package com.dantwining.jade.oo;

import jade.core.AID;
import jade.oo.core.behaviours.MessageReceiver;
import jade.oo.core.behaviours.Outbox;

public class TellTheTime implements MessageReceiver {

        private final Outbox outbox;

        public TellTheTime(Outbox outbox) {
                this.outbox = outbox;
        }

        @Override
        public void receive(String message, AID sender) {
                long currentTime = System.currentTimeMillis();
                outbox.send(currentTime, sender);
        }
}

</pre></p>
<p>In the real world, this class (and the classes that it in turn uses) are likely to be much more complicated. These are the classes that you want to test; the classes that add <strong>your</strong> functionality on top of the JADE framework.</p>
<p>Here&#8217;s the test for TellTheTime:</p>
<p><pre class="brush: java; gutter: false;">
package com.dantwining.jade.oo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import jade.core.AID;

import org.junit.Test;

public class TellTheTimeTest {

        @Test
        public void shouldReturnCurrentTimeToRequestingAgent() {
                // Given standard construction...
                FakeOutbox fakeOutbox = new FakeOutbox();
                TellTheTime tellTheTime = new TellTheTime(fakeOutbox);
                AID requester = new AID(&quot;requester&quot;, AID.ISGUID);

                // ...when an incoming message is received...
                long timeBefore = System.currentTimeMillis();
                tellTheTime.receive(null, requester);
                long timeAfter = System.currentTimeMillis();

                // ...a reply should be sent to the requester, with an appropriate time.
                assertEquals(requester, fakeOutbox.getRecipient());

                long reportedTime = (Long) fakeOutbox.getMessage();
                assertTrue(timeBefore &lt;= reportedTime);
                assertTrue(timeAfter &gt;= reportedTime);
        }

}

</pre></p>
<p>Because MessageReceiver guarantees that your receive() method will only be called if a message is available, you don&#8217;t have to test for &#8220;message not present&#8221; behaviour. In fact, I can&#8217;t think of any other tests for this Behaviour, but please post a comment if you can.</p>
<p>Compare our TellTheTime code with a standard JADE Behaviour that performs the same task:</p>
<p><pre class="brush: java; gutter: false;">
package com.dantwining.jade.oo;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;

import java.io.IOException;

public class TimeResponderJadeBehaviour extends CyclicBehaviour {

    @Override
    public void action() {
        ACLMessage message = myAgent.receive();

        if (message == null) {
            block();
            return;
        }

        long currentTime = System.currentTimeMillis();
        ACLMessage reply = message.createReply();
        try {
            reply.setContentObject(currentTime);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        myAgent.send(reply);
    }
}
</pre></p>
<p>How can we test this Behaviour? We&#8217;d probably want tests that:</p>
<ol>
<li>Ensure that no action is taken if no message is received.</li>
<li>Ensure that any reply is addressed to the Agent who asked for the time.</li>
<li>Ensure that the time sent is accurate/appropriate.</li>
</ol>
<p>But how can we&#8230;</p>
<ol>
<li>Control myAgent.receive() so that it does/doesn&#8217;t return a test message?</li>
<li>Capture the argument to myAgent.send() to that we can check its address?</li>
<li>Capture the argument to myAgent.send() to that we can check its contents?</li>
</ol>
<p>In standard JADE, <em>receive()</em>, <em>send()</em> and <em>block()</em> are all <a href="http://dantwining.com/2010/03/28/jade-oo-exposing-the-hidden-side-effects-of-the-action-method/">hidden side-effects</a>. In jade-oo we (a) expose <em>Outbox</em> and <em>Block</em> so that interactions with them are testable, and (b) encapsulate responsibility in the <em>MessageReceiver</em> so that client code is only invoked when a message is available for processing, and doesn&#8217;t know (or care) about any other states.</p>
<hr />Caveat: I have to admit that I&#8217;ve glossed over a few things here. In standard JADE, messaging is more complex than implied here. For example, messages can be filtered by template, conversation and so on. However, it&#8217;s quite straightforward to extend the jade-oo MessageReceiver to include all of these mechanisms. Also, the underlying JADE framework isn&#8217;t (yet) typesafe. The generics used by MessageReceiver imply that the object returned will be strongly typed. It isn&#8217;t; ClassCastExceptions may still occur, but this is the case with both JADE and jade-oo.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/832/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/832/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/832/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=832&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/04/01/jade-oo-making-agents-testable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>jade-oo: Exposing the hidden side-effects of the action() method</title>
		<link>http://dantwining.co.uk/2010/03/28/jade-oo-exposing-the-hidden-side-effects-of-the-action-method/</link>
		<comments>http://dantwining.co.uk/2010/03/28/jade-oo-exposing-the-hidden-side-effects-of-the-action-method/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 21:44:21 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[jade-oo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=819</guid>
		<description><![CDATA[Background In JADE, an Agent has a set of Behaviours, and each Behaviour has an action() method. The Agent calls the action() method of each Behaviour in turn, and so the overall operation of the Agent is performed by each of its individual behaviours. By default, an Agent will continue to call each of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=819&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>In JADE, an Agent has a set of Behaviours, and each Behaviour has an <em>action()</em> method. The Agent calls the <em>action()</em> method of each Behaviour in turn, and so the overall operation of the Agent is performed by each of its individual behaviours.</p>
<p>By default, an Agent will continue to call each of the <em>action()</em> methods of its behaviours, in turn, without pausing. Rather than looping forever at 100% CPU, Behaviours can call one of two <em>block()</em> methods, provided by the Behaviour base class. Calling <em>block()</em> from within the <em>action()</em> method tells the Agent to only call <em>action()</em> again if a message is received; and calling <em>block(long timeout)</em> tells the Agent to only call <em>action()</em> again if a message is received or <em>timeout</em> milliseconds elapses, whichever is sooner.</p>
<h3>The problem</h3>
<p>What happens if, within your <em>action()</em> method, you call <em>block()</em> then <em>block(50)</em>? What happens if you call <em>block()</em> right at the beginning of your <em>action()</em> method? How can you unit test that a certain set of of inputs will prompt a Behaviour to <em>block()</em>?</p>
<p>Hiding calls to <em>block()</em> within the <em>action()</em> method results in hidden side-effects that are difficult to reason about, and difficult to capture and test.<br />
<span id="more-819"></span></p>
<h4>The jade-oo way</h4>
<p>Rather than having a void <em>action()</em> method, jade-oo behaviours have a <em>Block action()</em> method. The behaviour then returns a <em>Block</em> object, which the platform then uses to determine whether to keep the behaviour active, or to leave the behaviour until a new message is received/the timeout has elapsed.</p>
<p>Here&#8217;s <a href="https://code.google.com/p/jade-oo/source/browse/trunk/src/jade/oo/core/behaviours/blocking/Block.java?spec=svn10&amp;r=10">my Block class</a>:</p>
<p><pre class="brush: java; gutter: false;">
package jade.oo.core.behaviours.blocking;

import jade.core.behaviours.Behaviour;

public abstract class Block {
        public static Block NULL = new DontBlock();
        public static Block UNTIL_WOKEN = new BlockUntilWoken();
        public static Block UNTIL_WOKEN_OR_TIMEOUT(long timeout) {
                return new BlockWithTimeout(timeout);
        }
        public void doBlock(Behaviour behaviour) {
        }
}
</pre></p>
<p>Here&#8217;s one of <a href="https://code.google.com/p/jade-oo/source/browse/trunk/src/jade/oo/core/behaviours/blocking?spec=svn10&amp;r=10">the three implementations</a> (note that the behaviour being passed in is the standard JADE Behaviour):</p>
<p><pre class="brush: java; gutter: false;">
package jade.oo.core.behaviours.blocking;

import jade.core.behaviours.Behaviour;

class BlockUntilWoken extends Block {

        @Override
        public void doBlock(Behaviour behaviour) {
                behaviour.block();
        }

}
</pre></p>
<p>Here&#8217;s the modified method in the standard JADE Behaviour class (note that the original is abstract, and so any existing implementations will simply override this and retain their existing behaviour):</p>
<p><pre class="brush: java; gutter: false;">
          /**
         * Runs the behaviour. This abstract method must be implemented by
         * &lt;code&gt;Behaviour&lt;/code&gt;subclasses to perform ordinary behaviour duty. An
         * agent schedules its behaviours calling their &lt;code&gt;action()&lt;/code&gt;
         * method; since all the behaviours belonging to the same agent are
         * scheduled cooperatively, this method &lt;b&gt;must not&lt;/b&gt; enter in an endless
         * loop and should return as soon as possible to preserve agent
         * responsiveness. To split a long and slow task into smaller section,
         * recursive behaviour aggregation may be used.
         *
         * @see jade.core.behaviours.CompositeBehaviour
         */
        public void action() {
                Block blockAction = delegate.action();
                blockAction.doBlock(this);
        }
</pre></p>
<p>And here&#8217;s an example of its use, taken from my new <a href="https://code.google.com/p/jade-oo/source/browse/trunk/src/jade/oo/core/behaviours/TickerBehaviour.java?spec=svn11&amp;r=11">TickerBehaviour</a> (my only changes here are on the two <strong>return</strong> lines at the end):</p>
<p><pre class="brush: java; gutter: false;">
        @Override
        public final Block action() {
                // Someone else may have stopped us in the meanwhile
                if (!finished) {
                        long blockTime = wakeupTime - System.currentTimeMillis();
                        if (blockTime &lt;= 0) {
                                // Timeout is expired --&gt; execute the user defined action and
                                // re-initialize wakeupTime
                                tickCount++;
                                onTick();
                                wakeupTime = System.currentTimeMillis() + period;
                                blockTime = period;
                        }
                        // Maybe this behaviour has been removed within the onTick() method
                        if (!finished) {
                                return Block.UNTIL_WOKEN_OR_TIMEOUT(blockTime);
                        }
                }
                return Block.NULL;
        }
</pre></p>
<h3>Further enhancements</h3>
<ul>
<li>I don&#8217;t like <em>Block</em>; it sounds like the Behaviour is stopping something else from processing, when really it&#8217;s doing the opposite, and freeing up CPU cycles for other behaviours to use.</li>
<li>I&#8217;m not sure about having the static methods within the interface itself. I should probably have a <em>Block</em> interface with a <em>doBlock(Behaviour behaviour)</em> method, and a <em>BlockFactory</em> with the three static methods. Or something else?</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/819/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/819/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=819&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/28/jade-oo-exposing-the-hidden-side-effects-of-the-action-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>jade-oo: Object-Oriented Eye for the Multi-Agent Guy</title>
		<link>http://dantwining.co.uk/2010/03/28/jade-oo-object-oriented-eye-for-the-multi-agent-guy/</link>
		<comments>http://dantwining.co.uk/2010/03/28/jade-oo-object-oriented-eye-for-the-multi-agent-guy/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 20:45:04 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[jade-oo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=815</guid>
		<description><![CDATA[I&#8217;ve spent the last couple of years working on, among other things, a JADE-based multi-agent system. JADE is a stable, mature framework for the development of agent-based systems, but it violates a few of the principles of good object-oriented software. jade-oo is my (outside-of-work) attempt to demonstrate how those issues might be addressed. I hope [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=815&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last couple of years working on, among other things, a <a href="http://jade.tilab.com/">JADE</a>-based multi-agent system. JADE is a stable, mature framework for the development of agent-based  systems, but it violates a few of the principles of good object-oriented  software. <a href="https://code.google.com/p/jade-oo/">jade-oo</a> is my (outside-of-work) attempt to demonstrate how those issues might  be addressed.</p>
<p><span id="more-815"></span>I hope that any improvements I can make will be folded back into the  main JADE code base. ﻿My general plan is to maintain backwards-compatibility though liberal use of deprecation, whilst adding an API that makes better use of OO, with a particular emphasis on unit testing (i.e. software written against my API should be very easy to test).</p>
<p>Well, that&#8217;s the overview; it&#8217;s probably time to write an article or two on what I&#8217;ve actually done so far&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/815/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/815/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=815&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/28/jade-oo-object-oriented-eye-for-the-multi-agent-guy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>The stats never lie</title>
		<link>http://dantwining.co.uk/2010/03/26/the-stats-never-lie/</link>
		<comments>http://dantwining.co.uk/2010/03/26/the-stats-never-lie/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 20:49:55 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=810</guid>
		<description><![CDATA[I&#8217;m not entirely sure what to make of this. It&#8217;s quite amusing though, even if it isn&#8217;t what I&#8217;d intended this blog to be about&#8230;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=810&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not entirely sure what to make of this. It&#8217;s quite amusing though, even if it isn&#8217;t what I&#8217;d intended this blog to be about&#8230;</p>
<p><img class="aligncenter size-full wp-image-809" title="TheSeekers" src="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-25-at-20-43-32.png?w=600" alt=""   /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/810/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/810/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=810&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/26/the-stats-never-lie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>

		<media:content url="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-25-at-20-43-32.png" medium="image">
			<media:title type="html">TheSeekers</media:title>
		</media:content>
	</item>
		<item>
		<title>Beyoncé 1, Orange 0</title>
		<link>http://dantwining.co.uk/2010/03/26/beyonce-1-orange-0/</link>
		<comments>http://dantwining.co.uk/2010/03/26/beyonce-1-orange-0/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 20:30:22 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=805</guid>
		<description><![CDATA[Much in the same way as Microsoft&#8217;s correct use of fewer wasn&#8217;t enough to persuade me to rush out and buy Windows 7, I&#8217;m probably not going to rush out and buy Beyoncé&#8217;s latest album either. Although I guess I am publicly acknowledging the fact that I know the lyrics to at least one of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=805&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-806" title="If_I_were_a_t_rex" src="http://dantwining.files.wordpress.com/2010/03/25-03-10_081647.jpg?w=600&#038;h=450" alt="" width="600" height="450" /></p>
<p>Much in the same way as <a href="http://dantwining.com/2009/12/14/fewer-clicks/">Microsoft&#8217;s correct use of </a><em><a href="http://dantwining.com/2009/12/14/fewer-clicks/">fewer</a></em> wasn&#8217;t enough to persuade me to rush out and buy Windows 7, I&#8217;m probably not going to rush out and buy Beyoncé&#8217;s latest album either. Although I guess I am publicly acknowledging the fact that I know the lyrics to at least <a href="http://en.wikipedia.org/wiki/If_I_Were_a_Boy">one of her songs</a>. Meh.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/805/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/805/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/805/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=805&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/26/beyonce-1-orange-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>

		<media:content url="http://dantwining.files.wordpress.com/2010/03/25-03-10_081647.jpg" medium="image">
			<media:title type="html">If_I_were_a_t_rex</media:title>
		</media:content>
	</item>
		<item>
		<title>All aboard the gwitbus!</title>
		<link>http://dantwining.co.uk/2010/03/19/all-aboard-the-gwitbus/</link>
		<comments>http://dantwining.co.uk/2010/03/19/all-aboard-the-gwitbus/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 22:56:28 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[gwitbus]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=780</guid>
		<description><![CDATA[Like many people, I&#8217;ve been inspired by, and learnt many things from, Ray Ryan&#8217;s talk on GWT Architectural Best Practices from Google I/O 2009. But unlike many people (or, at least, unlike the many people that came up in my Google search) I&#8217;ve not been inspired to put together an entire framework that covers all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=780&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Like many people, I&#8217;ve been inspired by, and learnt many things from, <a href="http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html">Ray Ryan&#8217;s talk on GWT Architectural Best Practices</a> from <a href="http://code.google.com/events/io/2009/sessions.html">Google I/O 2009</a>. But unlike many people (or, at least, unlike the many people that came up in my Google search) I&#8217;ve not been inspired to put together an entire framework that covers all of Ray&#8217;s recommendations. I just want to break out one little piece to use, not just in my GWT projects, but in all my Java GUI projects; and that piece is the Event Bus.</p>
<p><span id="more-780"></span>I&#8217;m fairly sure that I&#8217;m not going to do Ray&#8217;s talk justice here, so if you want to nip off and <a href="http://www.youtube.com/watch?v=PDuhR18-EdM">watch the video</a> or <a href="http://dl.google.com/io/2009/pres/Th_0200_GoogleWebToolkitArchitecture-BestPracticesForArchitectingYourGWTApp.pdf">flick through the slides</a> then please do so. But in a nutshell, two of the things that Ray discusses are; applying the Model-View-Presenter pattern within GWT, and reusing GWT&#8217;s built-in EventManager class to provide an event bus that decouples both the GUI from the back-end, and bits of the GUI from each other.</p>
<h3>Breaking out the gwitbus</h3>
<p>The main reason for pulling the EventManager out of the core GWT library is so that I can use it as the event bus in my non-GWT apps. Because the EventManager and its associated classes are all pure Java, with no dependencies beyond core Java collections, we can just drop them straight into any Java app. Just like I&#8217;ve done in the Swing app that I&#8217;m working on at the moment.</p>
<p>I could just import the core GWT jar, but that&#8217;s over 5MB, which it a bit of an overkill for about seven classes (and I&#8217;m not even sure that four of those are required).</p>
<p>At some point in this post, I need to give credit to <a href="http://www.mattburns.co.uk/blog/">Matt</a>, who pair-programmed with me on our recent GWT-based task, and is now working with me on our new gwitbus-enabled Swing app. It&#8217;ll just get confusing if I try to differentiate between the bits that I&#8217;ve done, the bits that he&#8217;s done, and the bits that we&#8217;ve done together, so I&#8217;ll just stick to the first-person-singular for now; but thanks for your help, and if you wanted to take all the credit, you should&#8217;ve written your own post and checked it into you own Google code project <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h3>How do I use the gwitbus?</h3>
<p>I&#8217;m planning on putting together a really basic Swing app that demonstrates its usage, but to be honest everything you need to know can be divined either from the code, or from Ray&#8217;s slides.</p>
<p>Conceptually, the gwitbus is like any other event bus. It provides an abstract connection between disparate parts of the app; one part can fire events into the gwitbus, and another can listen for those events and react to them. Crucially, the part firing the event has no idea who will be listening, and the part listening has no idea who&#8217;s firing the events.</p>
<h3>If &#8220;the gwitbus is like an other event bus&#8221;, then why should I use it?</h3>
<p>Well, the most important thing is that you don&#8217;t roll your own. <em>Almost everything you can do has already been done better by someone else</em>. If you need an event bus, and your framework comes with an event bus, then feel free to use it. But if you don&#8217;t have one already, then why not use one that sits at the core of a proven, Google-backed technology?</p>
<h3>Where can I get me a gwitbus?</h3>
<p>gwitbus now has its very own project on google code. You can check it out from its subfolder in my subversion repository at <a href="http://gwitbus.googlecode.com/svn/trunk/">http://gwitbus.googlecode.com/svn/trunk/</a>, run the <code>ant jar</code> target, and get yourself a gwitbus.jar.</p>
<p>(If you&#8217;re browsing through the repository, don&#8217;t be fooled by the fact that there doesn&#8217;t appear to be any code in there at all; svn:externals pulls in the latest code straight from GWT)</p>
<p>I&#8217;ve already got a Hudson job building the latest version every time it&#8217;s updated. I hope to have Hudson push the latest release back onto Google Code, but I haven&#8217;t yet worked out how to do so without putting my credentials somewhere where they&#8217;ll be publicly visible. For now, I&#8217;m afraid that you&#8217;ll jut have to build it yourself.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/780/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/780/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=780&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/19/all-aboard-the-gwitbus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>
	</item>
		<item>
		<title>GWT, OpenLayers and Full Screen Maps &#8211; Solved!</title>
		<link>http://dantwining.co.uk/2010/03/01/gwt-openlayers-and-full-screen-maps/</link>
		<comments>http://dantwining.co.uk/2010/03/01/gwt-openlayers-and-full-screen-maps/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:50:24 +0000</pubDate>
		<dc:creator>dantwining</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FullScreenMap]]></category>
		<category><![CDATA[googlecode]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dantwining.com/?p=768</guid>
		<description><![CDATA[I&#8217;m writing a GWT app with an OpenLayers map in it, and no matter how hard I tried, I couldn&#8217;t get the map to open full-screen. The Problem I wanted a full screen map. Like this. But what I got was this. It only happened when the page first opened. If I resized the window, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=768&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing a GWT app with an OpenLayers map in it, and no matter how hard I tried, I couldn&#8217;t get the map to open full-screen.</p>
<p><span id="more-768"></span></p>
<h3>The Problem</h3>
<p>I wanted a full screen map. Like this.</p>
<p><img class="aligncenter size-full wp-image-770" title="FullScreenMap" src="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-01-at-21-36-54.png?w=600&#038;h=347" alt="" width="600" height="347" /></p>
<p>But what I got was this.</p>
<p><img class="aligncenter size-full wp-image-769" title="SmallScreenMap" src="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-01-at-21-36-10.png?w=600&#038;h=347" alt="" width="600" height="347" /></p>
<p>It only happened when the page first opened. If I resized the window, or panned/zoomed the map, then the map redrew to fill the page.</p>
<p>It didn&#8217;t matter if I used GWT-OpenLayers (a Widget that wraps up the OpenLayers library) or just got at the OpenLayers javascript directly. Also, it didn&#8217;t matter which browser I used, they all drew the map in the top left-hand corner.</p>
<h3>The Solution</h3>
<p>The answer is to add a DeferredCommand, which updates the map once GWT has finished doing everything else. Here&#8217;s a cut-down example which uses a GWT-OpenLayers widget, but the fix works perfectly for standard OpenLayers too.</p>
<p><pre class="brush: java;">

public void onModuleLoad() {

   ...

   final MapWidget mapWidget = new MapWidget(&quot;100%&quot;, &quot;100%&quot;, config);

   ...

   mapWidget.getMap().setCenter(new LonLat(lon, lat), zoom);

   DeferredCommand.addCommand(new Command() {

      @Override

      public void execute() {

         mapWidget.getMap().updateSize();

      }

   });

}

</pre></p>
<p>You&#8217;re welcome to <a href="https://code.google.com/p/dantwining/source/browse/trunk/FullScreenMap/src/com/dantwining/webmap/client/FullScreenMap.java#41">check out my <code>onModuleLoad()</code> method in full here</a>.</p>
<p>If you&#8217;re using OpenLayers directly, you need to jump through a little extra hoop (or at least I did, there&#8217;s probably a much better way of doing it) in order to get at the javascript redraw method&#8230;</p>
<p><pre class="brush: plain;">

   DeferredCommand.addCommand(new Command() {

      @Override

      public void execute() {

         updateMapSize();

      }

      private native void updateMapSize() /*-{

         $wnd.map.updateSize();

      }-*/;

   });

}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dantwining.wordpress.com/768/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dantwining.wordpress.com/768/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dantwining.wordpress.com/768/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dantwining.co.uk&amp;blog=10442765&amp;post=768&amp;subd=dantwining&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dantwining.co.uk/2010/03/01/gwt-openlayers-and-full-screen-maps/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">dantwining</media:title>
		</media:content>

		<media:content url="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-01-at-21-36-54.png" medium="image">
			<media:title type="html">FullScreenMap</media:title>
		</media:content>

		<media:content url="http://dantwining.files.wordpress.com/2010/03/screen-shot-2010-03-01-at-21-36-10.png" medium="image">
			<media:title type="html">SmallScreenMap</media:title>
		</media:content>
	</item>
	</channel>
</rss>
