<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Building Blocks &#187; pyAMF</title>
	<atom:link href="http://joelhooks.com/category/pyamf/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelhooks.com</link>
	<description>[without unit tests] you're not refactoring; you're just changing shit. -Hamlet D'Arcy</description>
	<lastBuildDate>Tue, 29 Jun 2010 18:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
		<item>
		<title>Piping the Machine: PureMVC Multicore with Pipes and the Finite State Machine (FSM)</title>
		<link>http://joelhooks.com/2009/05/18/piping-the-machine-puremvc-multicore-with-pipes-and-the-finite-state-machine-fsm/</link>
		<comments>http://joelhooks.com/2009/05/18/piping-the-machine-puremvc-multicore-with-pipes-and-the-finite-state-machine-fsm/#comments</comments>
		<pubDate>Mon, 18 May 2009 20:19:43 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[pyAMF]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software architecture]]></category>

		<guid isPermaLink="false">http://joelhooks.com/?p=177</guid>
		<description><![CDATA[This is going to be a walkthrough of making use of PureMVC Multicore (AS3). To help in building a PureMVC Multicore application, we are going to make use of the StateMachine utility for initial setup and configuration as well as the Pipes utility for communication between cores. Here's the Source. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_PipingTheMachine_88164746"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="/examples/pipemachine/PipingTheMachine.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/examples/pipemachine/PipingTheMachine.swf"
			name="fm_PipingTheMachine_88164746"
			width="400"
			height="300">
	<!--<![endif]-->
		]]></description>
			<content:encoded><![CDATA[<p>This is going to be a walkthrough of making use of PureMVC Multicore (AS3). To help in building a PureMVC Multicore application, we are going to make use of the StateMachine utility for initial setup and configuration as well as the Pipes utility for communication between cores.</p>
<p><a href="http://joelhooks.com/examples/pipemachine/srcview/">Here's the Source.</a></p>
<p style="text-align: center;">[kml_flashembed fversion="9.0.124" movie="/examples/pipemachine/PipingTheMachine.swf" targetclass="flashmovie" useexpressinstall="true" publishmethod="static" width="450" height="500"]<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-177"></span></p>
<h2>Overview</h2>
<p>PureMVC can seem a bit overwhelming at first, but once the core concepts are understood the simplicity of the framework is possibly its biggest strength. Developing multicore applications in PureMVC, that is applications that create multiple instances of the PureMVC core actors (Facade, Model, View, Controller), adds another level of complexity that can be daunting. Luckily, there are utilities to help us out here, and abstract some of the problems with communication between modules loaded into an application.</p>
<p>This tutorial is based on the <a href="http://www.seaofarrows.com" target="_blank">Sea of Arrows player</a> put together by Cliff Hall. My goal was to remove some of the complexity involved with a real application and deconstruct the blocks used to build the player in a form that is easier to digest. It is highly recommended that you check out the player for a further example of this particular application structure.</p>
<p>For the purposes of demonstration this application is kept as simple as possible. For a trivial project, this level of complexity in regards to multiple cores, dynamically loaded modules, a finite state machine, and a plumbed framework for components to communicate is over-engineered (at best). It seems like a lot of work, and it is, but the payoff is when you have a complex project with multiple developers and designers working across many modules. This structure is made to scale, and scale well providing many options for efficient development. It allows for finely grained control of all of the actors in your system.</p>
<h2>The Tools</h2>
<p>Here is a brief overview of the tools we are going to use, and then we will get into some code and look at a simple example of everything put together.</p>
<h3>PureMVC</h3>
<p style="text-align: center;"><img class="aligncenter" src="http://puremvc.org/images/stories/puremvc-icon.jpg" alt="" width="318" height="200" /></p>
<p><em>From the website:</em></p>
<blockquote><p><a href="http://puremvc.org/content/view/67/178/" target="_blank">PureMVC is a lightweight framework</a> for creating applications based upon the classic Model, View and Controller concept.</p>
<p>Based upon proven design patterns, this free, open source framework which was originally implemented in the ActionScript 3 language for use with Adobe Flex, Flash and AIR, is now being ported to all major development platforms.</p></blockquote>
<p>If you want a tutorial for basic PureMVC usage, <a href="http://flash.tutsplus.com/tutorials/workflow/understanding-the-puremvc-open-source-framework/">click here</a>.</p>
<h3>Pipes</h3>
<p><a href="http://trac.puremvc.org/Utility_AS3_MultiCore_Pipes">Pipes</a> is a drop in utility for <a href="http://trac.puremvc.org/PureMVC_AS3_MultiCore">multicore PureMVC</a> applications that utilizes a plumbing metaphor to facilitate communication between cores. If you've ever walked down the PVC aisle of your local mega-hardware store, you are familiar with the objects represented in the utility.</p>
<p style="text-align: center;"><img class="size-full wp-image-187  aligncenter" title="pipes-diagram" src="http://69.164.207.135/wp-content/uploads/2009/05/pipes-diagram.png" alt="pipes-diagram" width="500" height="208" /></p>
<p style="text-align: left;">The above diagram comes from the excellent <a href="http://www.joshuaostrom.com/2008/06/15/understanding-puremvc-pipes/">Pipes overview written by Joshua Ostrom</a>.</p>
<h3>StateMachine</h3>
<p>The <a href="http://trac.puremvc.org/Utility_AS3_StateMachine">StateMachine utility</a> is a <a href="http://en.wikipedia.org/wiki/Finite_state_machine">finite state machine</a> for controlling application state in PureMVC. Configured by XML it seems daunting at first, but is relatively simple with only a handful of classes in the utility to make things happen. It makes for an elegant way to step through logical progressions and control available actions inside your application. This example is utilizing the StateMachine for the initial configuration, but it is possible to create complex workflows with the utility.</p>
<p>Check out the <a href="http://code.google.com/p/puremvc-utilities/">FSMVisualizer</a> for a really cool way to look at the PureMVC StateMachine.</p>
<h2>The Code</h2>
<h3>The Shell</h3>
<p>The shell of the application is the root container that will be in charge of creating instances of the modules and displaying their visual components. In this Flex example of the shell, the main MXML file serves as the viewComponent of the first PureMVC core that will be created.</p>
<p>The application is started like a typical PureMVC application. The difference here is with the naming convention being used. Normally in an application that will make use of a single PureMVC core will will create an ApplicationFacade. In this multicore application we are going to instead name the facade <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/ShellFacade.as.html">ShellFacade</a>.</p>
<p>The <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/ShellFacade.as.html">ShellFacade</a> class contains our notification constants. In this case it also cotains constants related to the StateMachine utility that define the states, their actions, and the notifications associated with those actions.</p>
<p>The StateMachine is initialized in our <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/controller/StartupCommand.as.html">StartupCommand</a>, which is a typical MacroCommand found in most PureMVC applications. The first Command run is the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/controller/state/InjectFSMCommand.as.html">InjectFSMCommand</a> which initializes the StateMachine and provides it with the XML configuration defining the various states. The next Command issued is the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/controller/state/StartShellCommand.as.html">StartShellCommand</a>, which is our initial state as configured by the StateMachine.</p>

<div class="wp_codebox"><table><tr id="p1772"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code" id="p177code2"><pre class="xml" style="font-family:monospace;">var fsm:XML =
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fsm</span> <span style="color: #000066;">initial</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.STARTING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- STARTUP THE SHELL --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;state</span> <span style="color: #000066;">name</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.STARTING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.STARTED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.PLUMBING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.STARTUP_FAILED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.FAILING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- PLUMB THE CORES --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;state</span> <span style="color: #000066;">name</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.PLUMBING<span style="color: #66cc66;">&#125;</span> <span style="color: #000066;">changed</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.PLUMB<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.PLUMBED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.ASSEMBLING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.PLUMB_FAILED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.FAILING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- ASSEMBLE THE VIEW --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;state</span> <span style="color: #000066;">name</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.ASSEMBLING<span style="color: #66cc66;">&#125;</span> <span style="color: #000066;">changed</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.ASSEMBLE<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.ASSEMBLED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.NAVIGATING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">action</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.ASSEMBLY_FAILED<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">       			   <span style="color: #000066;">target</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.FAILING<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- READY TO ACCEPT BROWSER OR USER NAVIGATION --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;state</span> <span style="color: #000066;">name</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.NAVIGATING<span style="color: #66cc66;">&#125;</span> <span style="color: #000066;">changed</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.NAVIGATE<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- REPORT FAILURE FROM ANY STATE --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;state</span> <span style="color: #000066;">name</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.FAILING<span style="color: #66cc66;">&#125;</span> <span style="color: #000066;">changed</span>=<span style="color: #66cc66;">&#123;</span>ShellFacade.FAIL<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fsm<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>;</pre></td></tr></table></div>

<p>StateMachine states are defined by their <strong>name</strong>, a<strong> changed</strong> property, and <strong>transitions</strong>. Transitions define an <strong>action</strong> that triggers the move to a new state, and a <strong>target</strong> which defines the name of the state in which to move when the action notification is received by the StateMachine. The changed property of a state corresponds directly to the Command defined in the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/ShellFacade.as.html">ShellFacade</a>. When the StateMachine receives a notification to move to a new state, the Command defined in the changed property is executed.</p>
<p><img class="aligncenter size-full wp-image-182" title="pipingthemachinestatediagram" src="http://69.164.207.135/wp-content/uploads/2009/05/pipingthemachinestatediagram.png" alt="pipingthemachinestatediagram" width="491" height="131" /></p>
<p>We start off in the <em>Starting</em> state which simply mediates the shell application. From there we move to the <em>Plumbing</em> state which creates some of the initial Pipes, instantiates the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/logger/LoggerModule.as.html">LoggerModule</a> and connects it to the shell. From there we move to the <em>Assembling</em> state which requests a <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/logger/view/components/LoggerWindow.mxml.html">LoggerWindow</a> viewComponent to add to the stage. From here we move to the <em>Navigating</em> state which has no transitions associated with it. It is our final state and means that our application is configured and ready for the user to interact with. There is also a <em>Failing</em> state, which like the <em>Navigating</em> state has no transitions. If some portion of the configuration process were to fail, this state would be called to notify the user that something horrible has happened.</p>
<p>Communications between modules happens in a module's JunctionMediator. This mediator's viewComponent is a Junction. One issue to consider when utilizing dynamic modules is memory management. The connections made between modules with the Pipes utility need to be managed so that when they are disconnect there are no artifacts left to get in the way of Garbage Collection. This application utilizes an extended JunctionMediator defined by the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/view/ManagedJunctionMediator.as.html">ManagedJunctionMediator</a> class which defines a connection pool for the various pipes. When a module is instantiated, the connections are stored in a HashMap. Later, when we want to remove the module, the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/view/ManagedJunctionMediator.as.html">ManagedJunctionMediator</a> references its pool of connections and removes any connections related to that particular module. This is an area that needs more refinement, and while it works well for this demonstration, it could be further abstracted to make a more complete solution for this issue. The <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/view/ShellJunctionMediator.as.html">ShellJunctionMediator</a> is the only class extending <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/view/ManagedJunctionMediator.as.html">ManagedJunctionMediator</a> in this application.</p>
<p>It is important to note that a JunctionMediator's handleNotifications method needs to have the default in the switch set to super.handleNotification( note ). There are standard notifications that a JunctionMediator listens for that need to be handled. In addition, the listNotificationInterests method is handled a bit differently to accommodate this functionality.</p>
<h2>Adding a Doodad</h2>
<p>When you click on the Add Doodad button, the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/controller/AddNewDoodadCommand.as.html">AddNewDoodadCommand</a> is called. This command instantiates a new <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/DoodadModule.as.html">DoodadModule</a> and registers a <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/view/DoodadModuleMediator.as.html">DoodadModuleMediator</a> with the shell's core. The command then connects the module's pipes to the shell's STDIN and STDOUT pipes. After the module is wired to the shell for communication a notification is sent to get the UI associated with the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/DoodadModule.as.html">DoodadModule</a></p>
<p>The <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/DoodadModule.as.html">DoodadModule</a> is not a visual component. It extends <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/view/components/PipeAwareModule.as.html">PipeAwareModule</a>, which is itself an extension of ModuleBase. This is as opposed to Module, which is a visual class, but in this demonstration the visual components are created by the module and then sent to the shell for display. All of the visual components are mediated by their module, but control of their placement rests with the shell.</p>
<p>A <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/view/components/PipeAwareModule.as.html">PipeAwareModule</a> is instantiated with a unique identifier. This provides a way to differentiate it from other instances of the module easily. The <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/DoodadModule.as.html">DoodadModule</a> itself also creates a sequential integer identifier, but this is used here for the purposes of labeling and not marking the module for unique identification.</p>
<p>When the shell asks for a new Doodad, the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/model/message/UIQueryMessage.as.html">UIQueryMessage</a> of type GET is sent from the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/shell/view/ShellJunctionMediator.as.html">ShellJunctionMediator</a> and is received by the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/view/DoodadJunctionMediator.as.html">DoodadJunctionMediator</a>. The <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/DoodadModule.as.html">DoodadModule</a> then creates the visual component in the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/controller/CreateDoodadCommand.as.html">CreateDoodadCommand</a> and sends it back to the shell via a <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/model/message/UIQueryMessage.as.html">UIQueryMessage</a> of type SET. The shell then adds the component to the stage. When the Doodad's 'kill' button is pressed, the <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/modules/doodad/view/DoodadJunctionMediator.as.html">DoodadJunctionMediator</a> is ordered to send out another <a href="http://joelhooks.com/examples/pipemachine/srcview/source/com/joelhooks/pipingthemachine/common/model/message/UIQueryMessage.as.html">UIQueryMessage</a>, this time of type DESTROY which lets the shell know that it needs to unplug the module.</p>
<h2>Conclusion</h2>
<p>There is a lot going on here, and it is complex on many levels. There are huge advantages to engineering a complex application this way. It provides flexibility in terms of development allowing for growth and expansion of the system. This particular example is kept relatively simple, and in a real world application I would strive to make the modules more generic, abstracting out the Doodad-specific bits in the shell so that any module added would share common functionality in terms of memory management and basic mechanisms related to the visual components. Hopefully it provides a helpful overview for people looking to understand multicore applications with PureMVC and make use of some of the handy utilities the community has made available.</p>
<p>Let me know if you have any questions and I will do my best to answer them. If you have anything to add, or find any errors, please don't hesitate to let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2009/05/18/piping-the-machine-puremvc-multicore-with-pipes-and-the-finite-state-machine-fsm/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Installing PyAMF 0.4.0rc1 on Windows XP</title>
		<link>http://joelhooks.com/2008/12/31/installing-pyamf-040rc1-on-windows-xp/</link>
		<comments>http://joelhooks.com/2008/12/31/installing-pyamf-040rc1-on-windows-xp/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 16:32:58 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[pyAMF]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://joelhooks.com/?p=127</guid>
		<description><![CDATA[I wanted to give the latest pyamf a go, but when I used the standard 'setup.py install', the following ominous warning was presented: error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to give the latest pyamf a go, but when I used the standard 'setup.py install', the following ominous warning was presented:</p>
<blockquote><p>error: Python was built with Visual Studio 2003;<br />
extensions must be built with a compiler than can generate compatible binaries.<br />
Visual Studio 2003 was not found on this system. If you have Cygwin installed,<br />
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.</p></blockquote>
<p>Uh oh! I actually <strong>DO</strong> have Cygwin installed, but unfortunately this message is a default and not entirely helpful. It did put me on the right path to actually getting it to go.</p>
<p><a href="http://boodebr.org/main/python/build-windows-extensions">This webpage</a> has a lot of good information on the subject, and it is where I pulled out these steps:</p>
<p>1. Grab the <a href="http://sourceforge.net/project/showfiles.php?group_id=2435&#038;package_id=240780">MingW32 Automated Installer</a> and get it installed. I selected all of the available options as I figured it wouldn't hurt (it didn't)</p>
<p>2. Add the mingw32 binaries to your system path environmental variable (ie <em>c:\mingw32\bin</em>)</p>
<p>3. Tell Python to use mingw32 when it needs to compile a distribution by adding a file called distutils.cfg in this folder: <em>{PYTHON_INSTALL}\lib\distutils\distutils.cfg</em>. The file should contain:</p>
<p><em>[build]<br />
compiler = mingw32</em></p>
<p>4. Version number parsing was throwing errors, so you actually have to edit <em>{PYTHON_INSTALL}\lib\distutils\version.py</em> to get it compiled. At line 100 make the following change:</p>
<p>from:</p>

<div class="wp_codebox"><table><tr id="p1275"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p127code5"><pre class="python" style="font-family:monospace;">    version_re = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^(<span style="color: #000099; font-weight: bold;">\d</span>+) <span style="color: #000099; font-weight: bold;">\.</span> (<span style="color: #000099; font-weight: bold;">\d</span>+) (<span style="color: #000099; font-weight: bold;">\.</span> (<span style="color: #000099; font-weight: bold;">\d</span>+))? ([ab](<span style="color: #000099; font-weight: bold;">\d</span>+))?$'</span>,
                        <span style="color: #dc143c;">re</span>.<span style="color: black;">VERBOSE</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>to:</p>

<div class="wp_codebox"><table><tr id="p1276"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p127code6"><pre class="python" style="font-family:monospace;">    version_re = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^(<span style="color: #000099; font-weight: bold;">\d</span>+) <span style="color: #000099; font-weight: bold;">\.</span> (<span style="color: #000099; font-weight: bold;">\d</span>+) (<span style="color: #000099; font-weight: bold;">\.</span> (<span style="color: #000099; font-weight: bold;">\d</span>+))? (<span style="color: #000099; font-weight: bold;">\.</span> (<span style="color: #000099; font-weight: bold;">\d</span>+))?$'</span>,
                            <span style="color: #dc143c;">re</span>.<span style="color: black;">VERBOSE</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>now with all that done, just run 'setup.py install' and it should compile as expected. Easy as... I dunno, it is actually kind of confusing, but it works and now I can give pyamf a whirl with the c-ext enabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/12/31/installing-pyamf-040rc1-on-windows-xp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Django Authorization from Flex/AIR via PyAMF</title>
		<link>http://joelhooks.com/2008/09/21/django-authorization-from-flex-air-actionscript-via-pyamf/</link>
		<comments>http://joelhooks.com/2008/09/21/django-authorization-from-flex-air-actionscript-via-pyamf/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 01:41:57 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[pyAMF]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://joelhooks.com/?p=88</guid>
		<description><![CDATA[Django views serve nicely as service end-points for Flex applications. Here are some notes on maintaining authenticated sessions between a Flex/Air/Flash application and your Django backend. gateway.py 1 2 3 4 5 6 7 8 from pyamf.remoting.gateway.django import DjangoGateway &#160; import myproject.myapp.views as views &#160; gw = DjangoGateway&#40;&#123; 'login' : views.login_user, 'logout' : views.logout_user, &#125;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://69.164.207.135/wp-content/uploads/2008/09/pyamf-to-django.jpg" alt="" title="pyamf-to-django" width="500" height="121" class="aligncenter size-full wp-image-91" /></p>
<p>Django views serve nicely as service end-points for Flex applications. Here are some notes on maintaining authenticated sessions between a Flex/Air/Flash application and your Django backend.</p>
<p><strong>gateway.py</strong></p>

<div class="wp_codebox"><table><tr id="p8810"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p88code10"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> pyamf.<span style="color: black;">remoting</span>.<span style="color: black;">gateway</span>.<span style="color: black;">django</span> <span style="color: #ff7700;font-weight:bold;">import</span> DjangoGateway
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> myproject.<span style="color: black;">myapp</span>.<span style="color: black;">views</span> <span style="color: #ff7700;font-weight:bold;">as</span> views
&nbsp;
gw = DjangoGateway<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">'login'</span>                       : views.<span style="color: black;">login_user</span>,
    <span style="color: #483d8b;">'logout'</span>                     : views.<span style="color: black;">logout_user</span>,
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>views.py</strong></p>

<div class="wp_codebox"><table><tr id="p8811"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p88code11"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pyamf
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span> <span style="color: #ff7700;font-weight:bold;">import</span> auth
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span> <span style="color: #ff7700;font-weight:bold;">import</span> authenticate, login, logout
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> login_required
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> User
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
    pyamf.<span style="color: black;">register_class</span><span style="color: black;">&#40;</span> User,  <span style="color: #483d8b;">'django.contrib.auth.models.User'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ValueError</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Classes already registered&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> logout_user<span style="color: black;">&#40;</span>http_request<span style="color: black;">&#41;</span>:
    logout<span style="color: black;">&#40;</span>http_request<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> login_user<span style="color: black;">&#40;</span>http_request, username, password<span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">user</span> = authenticate<span style="color: black;">&#40;</span>username=username, password=password<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">user</span> <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
        login<span style="color: black;">&#40;</span>http_request, <span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">user</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
&nbsp;
@login_required
<span style="color: #ff7700;font-weight:bold;">def</span> registered_user_protected_function<span style="color: black;">&#40;</span>http_request<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;You are a registered user.&quot;</span>
&nbsp;
@login_required
<span style="color: #ff7700;font-weight:bold;">def</span> staff_protected_function<span style="color: black;">&#40;</span>http_request<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> http_request.<span style="color: #dc143c;">user</span>.<span style="color: black;">is_staff</span> <span style="color: #66cc66;">!</span>= <span style="color: #008000;">True</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;You are staff.&quot;</span></pre></td></tr></table></div>

<p><strong>from flex</strong></p>

<div class="wp_codebox"><table><tr id="p8812"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p88code12"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">netConnection</span>:<span style="color: #0066CC;">NetConnection</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">netConnection</span>.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://mysite.com/gateway&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> responder:Responder = <span style="color: #000000; font-weight: bold;">new</span> Responder<span style="color: #66cc66;">&#40;</span>loginResult, handleFault<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">netConnection</span>.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;login&quot;</span>, responder, <span style="color: #ff0000;">&quot;username&quot;</span>, <span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>The http_request carries a reference to the currently authenticated user throughout the session. This works for web based Flex application as well as AIR applications on the desktop. Note that I am using a try/except on the pyamf class registration calls. Because this is session based, the classes only need to be registered once. Without the trap, it throws a TypeError letting you know the registration has already taken place.</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/auth/">Django User Authentication Documentation</a><br />
All of the various things you can do with authentication in Django. It is, of course, based mostly on the use of the very nice Django HTML template system. While those bits aren't handy to the likes of us, it is a good read either way.</p>
<p><a href="http://pyamf.org/wiki/ByteArrayExample">pyAMF ByteArray example</a><br />
This example shows the basic structure for setting up Django/Flex communication. It doesn't cover authentication, but covers a good bit of territory with examples in Flash and Flex.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/09/21/django-authorization-from-flex-air-actionscript-via-pyamf/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>VEsession &#8211; Flex photography studio management and client ordering application</title>
		<link>http://joelhooks.com/2008/02/09/vesession-flex-photography-studio-client-ordering-application/</link>
		<comments>http://joelhooks.com/2008/02/09/vesession-flex-photography-studio-client-ordering-application/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 05:42:02 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[VEsession]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[puremvc]]></category>
		<category><![CDATA[pyAMF]]></category>

		<guid isPermaLink="false">http://joelhooks.com/2008/02/09/vesession-flex-photography-studio-client-ordering-application/</guid>
		<description><![CDATA[My wife saw the application that I am working on at work to manage tasks and immediately asked, "Where's mine?" 21st century honey-do list. So far, this is what I have created. PureMVC is the underlying framework. The photos are loaded from SlideShowPro Director XML galleries. Unforutately, the most recent version of SSP-D won't let [...]]]></description>
			<content:encoded><![CDATA[<p>My wife saw the application that I am working on at work to manage tasks and immediately asked, "Where's mine?"</p>
<p>21st century honey-do list.</p>
<p>So far, this is what I have created. <a href="http://www.puremvc.org/">PureMVC is the underlying framework</a>. The photos are loaded from SlideShowPro Director XML galleries. Unforutately, the most recent version of SSP-D won't let you use it as a service in this way. This older version is has all the functionality I need though, so it isn't an issue. Eventually I will implement functionality to eliminate the need for SSP-D with some gallery management. It will be better to keep it all under one roof.</p>
<p>The backend is <a href="http://www.djangoproject.com/">Django</a> using <a href="http://pyamf.org/">pyAMF</a> for communications back and forth.  Django elminates the pain of CRUD operations and provides an excellent admin interface for free.</p>
<p>My goal is to open source the application and provide it as a PureMVC/Django example.</p>
<p><em><font color="#ff0000">UPDATED: This version is a little jacked because I am working on a new version. The demo images are way too big and cause the application to scroll in unsightly ways. The new demo <a href="http://joelhooks.com/session">is located here</a>, and uses the same credentials as below. </font></em></p>
<p>[<a href="http://session.visualempathy.com" target="_blank">Here is the demo</a>]<br />
user: demo_client<br />
pass:demo_client</p>
<p style="text-align: center"><img src="http://69.164.207.135/wp-content/uploads/2008/02/session_sshot.jpg" alt="session_sshot.jpg" /></p>
<p>[<a href="http://code.google.com/p/vesession/">source</a>]</p>
<p><strike>Do to some, uh, laziness on my part, this will only compile with strict mode turned off</strike> The new version does not have this problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://joelhooks.com/2008/02/09/vesession-flex-photography-studio-client-ordering-application/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
	</channel>
</rss>
