<?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:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>AaronHardy.com &#187; macro</title>
	<atom:link href="http://aaronhardy.com/tag/macro/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaronhardy.com</link>
	<description>For all your Aaron Hardy needs.</description>
	<lastBuildDate>Fri, 20 Apr 2012 14:53:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Macrobot: Macro Commands For Robotlegs</title>
		<link>http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/</link>
		<comments>http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 03:27:05 +0000</pubDate>
		<dc:creator>Aaron Hardy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[RobotLegs]]></category>
		<category><![CDATA[sequence]]></category>

		<guid isPermaLink="false">http://aaronhardy.com/?p=990</guid>
		<description><![CDATA[Robotlegs is a fantastic micro-architecture for ActionScript. One pattern used with Robotlegs is the command pattern. Commands are generally short-lived objects that execute a segment of code in response to an event. By encapsulating code in a command, you can maintain low coupling in your app (the view and the command don&#8217;t need to be [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://robotlegs.org" target="_blank">Robotlegs</a> is a fantastic micro-architecture for <a href="http://en.wikipedia.org/wiki/ActionScript" target="_blank">ActionScript</a>.  One pattern used with Robotlegs is the command pattern. Commands are generally short-lived objects that execute a segment of code in response to an event.  By encapsulating code in a command, you can maintain low coupling in your app (the view and the command don&#8217;t need to be aware of each other) and reduce duplicate code. See the <a href="https://github.com/robotlegs/robotlegs-framework/wiki/Best-Practices" target="_blank">Robotlegs Best Practices</a> page for more info regarding commands.</p>
<p>You may run into situations where you wish to batch commands.  Macrobot simplifies this process and provides two ways to batch commands:</p>
<p><b>Sequence:</b> The batch of commands will be executed in order.  The second command will not be executed until the first is complete, the third command will not be executed until the second is complete, and so on.  The batch will not be complete until all its commands are complete.</p>
<p><b>Parallel:</b> The batch of commands will be executed as quickly as possible without respect to completion of any of the other commands.  The commands may complete out-of-order.  The batch as a whole will not be complete until all its commands are complete.<span id="more-990"></span></p>
<p>To create a macro command, extend one of the two macro command classes Macrobot provides: <i>SequenceCommand</i> or <i>ParallelCommand</i>.  Add subcommands by calling either <i>addCommand()</i> or <i>addCommandInstance()</i>.  <i>addCommand()</i> lets you specify a command class and a payload (such as an event).  At the appropriate time, the command instance will be created, the payload injected, and the command executed.  This automated process of instantiation, injection, and execution is very similar to how commands are normally prepared and executed in Robotlegs.  <i>addCommandInstance()</i>, on the other hand, allows you to add a command you have already instantiated and prepared yourself.</p>
<p>Here&#8217;s an example of how a macro command might look (in this case, sequential):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyMacroCommand <span style="color: #0066CC;">extends</span> SequenceCommand
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyMacroCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// Commands for Macrobot to prepare before execution.</span>
		addCommand<span style="color: #66cc66;">&#40;</span>CommandA, <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		addCommand<span style="color: #66cc66;">&#40;</span>CommandB, <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		addCommand<span style="color: #66cc66;">&#40;</span>CommandC, <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// Custom-prepared commands.</span>
		<span style="color: #000000; font-weight: bold;">var</span> command:Command = <span style="color: #000000; font-weight: bold;">new</span> CommandD<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		command.<span style="color: #006600;">event</span> = <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		addCommandInstance<span style="color: #66cc66;">&#40;</span>command<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		command = <span style="color: #000000; font-weight: bold;">new</span> CommandE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		command.<span style="color: #006600;">event</span> = <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		addCommandInstance<span style="color: #66cc66;">&#40;</span>command<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		command = <span style="color: #000000; font-weight: bold;">new</span> CommandF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		command.<span style="color: #006600;">event</span> = <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		addCommandInstance<span style="color: #66cc66;">&#40;</span>command<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h2>Asynchronous Commands</h2>
<p>While Macrobot can be used to execute solely synchronous commands, it may come in handy to execute commands that are asynchronous, that is, the command is not deemed complete until a later time.  The command may need to wait for a response from the server or for user interaction before being marked complete.  In this case, your subcommands can extend from Macrobot&#8217;s <i>AsyncCommand</i> and call <i>dispatchComplete()</i> once the subcommand should be deemed complete. <i>dispatchComplete()</i> receives a single parameter which reports whether the subcommand completed successfully.  The importance of this distinction will become clearer when we discuss atomic execution below. Here&#8217;s an example of a simulated asynchronous subcommand:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyCommandWhichHappensToBeASubcommand <span style="color: #0066CC;">extends</span> AsyncCommand
<span style="color: #66cc66;">&#123;</span>
	protected <span style="color: #000000; font-weight: bold;">var</span> timer:Timer;
&nbsp;
	override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
		timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER_COMPLETE</span>, timerCompleteHandler<span style="color: #66cc66;">&#41;</span>;
		timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	protected <span style="color: #000000; font-weight: bold;">function</span> timerCompleteHandler<span style="color: #66cc66;">&#40;</span>event:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		timer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER_COMPLETE</span>, timerCompleteHandler<span style="color: #66cc66;">&#41;</span>;
		timer = <span style="color: #000000; font-weight: bold;">null</span>;
		dispatchComplete<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h2>Atomic Execution</h2>
<p>In our first example, subcommands A-F would all be executed by default.  However, the <i>atomic</i> property can be set to false (it&#8217;s true by default) to modify this behavior.  If atomic is set to false and at least one of the subcommands dispatches a failure (using <i>dispatchComplete(false)</i>), subsequent subcommands will not be executed and the macro command itself will dispatch failure.  The concept of atomic execution does not apply to parallel commands.</p>
<h2>Command Nesting</h2>
<p>If you want, you can get crazy and nest your macro commands.  Take this as an example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyMacroCommand <span style="color: #0066CC;">extends</span> SequenceCommand
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyMacroCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
			addCommand<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandA<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> parallel1:ParallelCommand = <span style="color: #000000; font-weight: bold;">new</span> ParallelCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			parallel1.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			parallel1.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandC<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			addCommandInstance<span style="color: #66cc66;">&#40;</span>parallel1<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			addCommandInstance<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandD<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> parallel2:ParallelCommand = <span style="color: #000000; font-weight: bold;">new</span> ParallelCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			parallel2.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> sequence:SequenceCommand = <span style="color: #000000; font-weight: bold;">new</span> SequenceCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			sequence.<span style="color: #006600;">atomic</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			sequence.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			sequence.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			parallel2.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span>sequence<span style="color: #66cc66;">&#41;</span>;
			parallel2.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandH<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			parallel2.<span style="color: #006600;">addCommandInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandI<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			addCommandInstance<span style="color: #66cc66;">&#40;</span>parallel2<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			addCommandInstance<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommandJ<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The overall execution structure of this example looks like this:</p>
<ul>
<li>sequence</li>
<ul>
<li>command A</li>
<li>parallel</li>
<ul>
<li>command B</li>
<li>command C</li>
</ul>
<li>command D</li>
<li>parallel</li>
<ul>
<li>command E</li>
<li>sequence</li>
<ul>
<li>command F</li>
<li>command G</li>
</ul>
<li>command H</li>
<li>command I</li>
</ul>
<li>command J</li>
</ul>
</ul>
<p>Sequential, parallel, and atomic rules apply as you would expect.</p>
<h2>Tests</h2>
<p>Macrobot comes with a full suite of tests to make sure everything is squeaky clean.</p>
<h2>Feedback</h2>
<p>If you have any questions or comments regarding Macrobot, please post a comment below!</p>
<div class="goodies"><a href="https://github.com/Aaronius/robotlegs-utilities-Macrobot/zipball/master" target="_blank">Download Source (zip)</a><a href="https://github.com/Aaronius/robotlegs-utilities-Macrobot" target="_blank">Fork Project</a><br class="break"></div>
]]></content:encoded>
			<wfw:commentRss>http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Nimbus &#8211; MVC Framework Intro</title>
		<link>http://aaronhardy.com/flex/nimbus-mvc-framework-intro/</link>
		<comments>http://aaronhardy.com/flex/nimbus-mvc-framework-intro/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 22:51:45 +0000</pubDate>
		<dc:creator>Aaron Hardy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[model view controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[nimbus]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[redo]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[undo]]></category>

		<guid isPermaLink="false">http://aaronhardy.com/?p=221</guid>
		<description><![CDATA[UPDATE: Since the writing of this post, I&#8217;ve converted to and fully endorse Robotlegs as my MVC framework of choice. I invite you to check it out. For those who don&#8217;t know, Nimbus is a Flex MVC framework (or micro-architecture for the technically-inclined). Sponsored by Rain, we develop it primarily for use on our applications [...]]]></description>
			<content:encoded><![CDATA[<hr/>
<b>UPDATE: Since the writing of this post, I&#8217;ve converted to and fully endorse Robotlegs as my MVC framework of choice. I invite you to <a href="http://www.robotlegs.org" target="_blank">check it out</a>.</b></p>
<hr/>
<p>For those who don&#8217;t know, <a href="http://code.google.com/p/nimbus-as3" target="_blank">Nimbus</a> is a Flex MVC framework (or micro-architecture for the technically-inclined).  Sponsored by <a href="http://mediarain.com" target="_blank">Rain</a>, we develop it primarily for use on our applications but make it available for public use and encourage the community to <a href="http://code.google.com/p/nimbus-as3" target="_blank">contribute</a>.</p>
<p>Nimbus pulls core concepts from <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm" target="_blank">Cairngorm</a> but is meant to cut out a lot of the plumbing developers groan about when they hear &#8220;Cairngorm.&#8221;  It&#8217;s light, but it&#8217;s not <a href="http://i260.photobucket.com/albums/ii22/shastymax/fluffy.jpg" target="_blank">fluffy</a>.  Baked in are those rare and tasty flavor morsels you thought only existed in those <a href="http://laparisiennecentre.com/blog/nfblog/wp-content/uploads/2007/07/confetticupcakes.JPG" target="_blank">Funfetti cupcakes</a> <a href="http://www.chaos.gwdg.de/~sinan/resimler/GRANDMA_KISS.GIF" target="_blank">your grandmother</a> bakes with love on your birthday.<span id="more-221"></span></p>
<p>Until the end of 2008, Nimbus had been shaped, re-shaped, patched, and plugged.  A complete re-write was merited so that&#8217;s what we did.  And really, what makes for a better Christmas than sitting down with your stocking stuffed with jelly beans and re-writing an MVC framework.  A few months later, the code is settling down along with the sugar and we&#8217;re ready for action.</p>
<p>Here are some features of Nimbus:</p>
<ul>
<li>Notification system of command completion so portions of the application can know when a command has finished executing.</li>
<li>Nestable &#8220;macro&#8221; commands.  Think &#8220;I want commands A and B to run in parallel, then C, then D and E in parallel, but inside D I want F and G to run sequentially&#8230;&#8221;</li>
<li>Undo/Redo functionality.</li>
<li>Progress feedback system.  You as a developer can associate a processing message with each command or macro command to provide feedback to users.</li>
<li>Interaction blocking system.  While commands are executing, easily disable user interaction to protect your service calls.</li>
<li>Combinable commands.  Ensure that similar command instances can be grouped appropriately in the undo/redo history.</li>
</ul>
<p><em><a href="/flex/the-best-flex-mvc-framework/">Nimbus may not be right for everyone</a>.  Call your system administrator if your scalability problem worsens or is not better within 7 to 10 days.  This may mean that there is another condition causing your RTE problems.  Do not take Nimbus with alcohol.  Call your system administrator right away if after taking Nimbus you are unable to walk, drive, eat, or engage in other activities.  In rare cases, severe allergic reactions can occur.  Most MVC frameworks carry some risk of dependency.  Do not use MVC frameworks for extended periods without first talking to your system administrator.  You are encouraged to report negative side effects of Nimbus.  Visit <a href="http://code.google.com/p/nimbus-as3" target="_blank">http://code.google.com/p/nimbus-as3</a> for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronhardy.com/flex/nimbus-mvc-framework-intro/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

