Fusioncube

The online journey of a technophile, by Steve Brownlee

Archive for March, 2009

I Was A 1D-10t Classification

  • Filed under: errata
Tuesday
Mar 31,2009

Yesterday I had a rare 1D-10t user moment. Having worked with technology all these long years (ever since I got my first TRS-80 at the age of 11), I rarely have found myself needing to call Tier 1 support to solve a simple problem with hardware or software.

Well, the other day we had our first tornado warning in our area… lots of hail, lightning, wind, etc…

After the show was over, my wife discovered that she couldn’t turn her computer on. I wander over and try a few simple thing like unplugging it from the wall and back in, removing the battery and back in, and pressing the power button a few times (kind of like how we all press the elevator button to make it “hurry up”).

Nada, and I’m pissed.

The brand new (well, brand new for us, it’s a refurb) laptop I bought my wife is now a $500 brick, because I assume that an electric surge took out the motherboard and I was stupid enough to not put a surge protector on the outlet in the kitchen that she uses.

Last night I call up the vendor to see what the 90-day limited warranty covers and if I can get a replacement (obviously excluding the electrical storm, sans protection, bit) and the support starts going through his usual spiel.

“Hold down the power for 10 seconds”

“Hold down the power for 30 seconds”

“Remove the battery, and plug the AC adapter in, and power up”

Now I’m sitting there as patiently as possible because I know they have to do all this with the schmucks who call in who don’t know that the power cord has to be plugged in for an electrical appliance to work. When we got to this step though, the unit powered on.

Weird.

I powered down real quick, placed the battery back in it’s slot and move the laptop a little. I try to power up but then it doesn’t work again!! WTF???

Ok, plug the AC adapter back in and now it powers up. A little light goes off in my head, and after the OS boots, I unplug the power cord and am immediately presented with a low battery alert. Turns out that the AC adapter connection was a little finicky and so the laptop was running on battery power and had eventually run out of juice.

All I needed to do was jiggle the little thingy on the back of the gizmo and it would have worked and not provided yet another 1D-10t story to the Tier 1 support tech I talked to last night.

Cairngorm Patterns: Batch Commands

Tuesday
Mar 31,2009

Related Posts

Abstract Commands

Basic Cairngorm Commands

In the base implementation of the Cairngorm micro-architecture, events and commands are mapped on a 1-1 basis. For every invoker (event) you have to specify one command in your controller.

public function Controller()
{
   super();
   addCommand(TeammateEvent.LOAD_TEAMMATES, LoadTeammatesCommand);
   addCommand(EffortEvent.LOAD_TYPES, LoadEffortTypesCommand);
   addCommand(ProjectEvent.LOAD_PROJECTS, LoadProjectsCommand);
   addCommand(TeammateEvent.LOAD_TEAMMATE_ROLES, LoadTeammateRolesCommand);
   ...
}

For most cases, this is perfectly fine, but in a data-heavy model, such as the one being built for my current application, I need to initialize the application and fire off many individual events in order to load my model with base data.

// Load all teammates in the database for display in the reports tab
new TeammateEvent(TeammateEvent.LOAD_TEAMMATES).dispatch();

// Load all effort types
new EffortEvent(EffortEvent.LOAD_TYPES).dispatch();

// Load all projects
new ProjectEvent(ProjectEvent.LOAD_PROJECTS).dispatch();

// Load all roles
new TeammateEvent(TeammateEvent.LOAD_TEAMMATE_ROLES).dispatch();

...

Batch Commands

In order to avoid having to dispatch n events for n commands to be executed, I would rather map 1 event to n commands and have them fired off in sequence. Then, if I need a batch of commands to fire, I only need to dispatch one event, instead of the 4 I used in the example above.

new ApplicationEvent(ApplicationEvent.LOAD_MODEL).dispatch();

Unfortunately, Cairngorm does not allow this, so I had to extend the basic architecture. I created a addCommands() function that maps a single event to multiple commands as an array.

public class Controller extends ExtendedFrontController
{
   public function Controller()
   {
      addCommands(ApplicationEvent.LOAD_MODEL, [LoadTeammatesCommand,
                                LoadEffortTypesCommand,
                                LoadProjectsCommand,
                                LoadTeammateRolesCommand,
                                ...]);
   }
}

Extended Controller Class

Here’s the code that I’ve come up with so far. This is working fine, but there still some things I plan on implementing in the future.

ExtendedFrontController.as

public class ExtendedFrontController extends FrontController
{
   public function ExtendedFrontController()
   {
      super();
   }

   public function addCommands(commandName:String, commandRefs:Array, useWeakReference:Boolean = true):void
   {
      if(commands[ commandName ] != null)
      {
         throw new CairngormError( CairngormMessageCodes.COMMAND_ALREADY_REGISTERED, commandName );
      }

      if (commandRefs == null)
      {
         throw new Error("The commandRefs argument to addCommands() is null");
      }

      commands[commandName] = commandRefs;

      for (var priority:uint = 0; priority < commandRefs.length; priority++)
      {
         CairngormEventDispatcher.getInstance().addEventListener(commandName, executeCommands, false, priority, useWeakReference);
      }
   }

   protected function executeCommands(event:AbstractEvent):void
   {
      var commandsToInitialise:Array = getCommands(event.type);
      var commandRef:Class;

      for (var i:uint = 0; i < commandsToInitialise.length; i++)
      {
         commandRef = commandsToInitialise[i];
         var commandToExecute:ICustomCommand = new commandRef();
         commandToExecute.execute(event);
      }
   }

   protected function getCommands(commandName:String):Array
   {
      var commands:Array = commands[commandName];

      if ( commands == null )
         throw new CairngormError( CairngormMessageCodes.COMMAND_NOT_FOUND, commandName );

      return commands;
   }
}

My Girls

  • Filed under: errata
Tuesday
Mar 24,2009

Tessa

I call her Mini-Michelle because she looks so much more like my wife than me, but she did get my red hair and blue eyes. Lately she’s been standing up with no help other than an occasional need for some parental arms for balance. I’m convinced she’s going to skip crawling and go straight to walking. She’s got some powerful legs on her. I think she’ll grow up to be the introspective observer (like her mother) who doesn’t like to be in the spotlight. We’ll see how her personality develops over the next couple of years.
Tessa

Sabrina

This little one is going to grow up to be that person who lights up a room when she walks in. Her personality and sense of humor brings a smile to my face no matter how tired I am, or how much of a crappy day I’ve had. I just know that I’m going to have to buy a shotgun when she’s in her teens and place it by the front door, so that it’s the last thing the boys see when they come to pick her up for a date.
Sabrina

The Three I’s of Software Development

Tuesday
Mar 24,2009

There are three types of software developer…

I’ve held this belief for quite some time because of my natural, human tendency to group my fellow humans into categories that I can easily understand. Of the hundreds of people I’ve met over the years who share my passion for software, the passion falls into three distinct areas.

Innovator

I liken software innovators to theoretical physicists, though it’s not a strong comparison. These folks are the ones who identify common patterns, and develop common toolkits. Good examples would be the creators of HTML and DHTML, Java, AOP, and Groovy… the foundations of software authoring and architecture. The innovator looks at core problems, or gaps, in their particular industry of field of interest and can develop a solution to fill it in an powerful, yet elegant way.

Implementer

The implementer would, then, be akin to an applied physicist. They take the “ideas” of the theoretical physicist and apply them to create something that is usable by engineers. A good example of an implementer would be the authors of jQuery. They took the basic tool of Javascript provided by the innovator, and created a fantastic implementation that makes it more powerful, easy to use, and wrapped up in a nice package so that an integrator (see below) can use it without having to know what goes on behind the scenes.

Integrator

The integrator is at the end of the software ladder, and is usually the one who sits at that fine line between the technical and non-technical worlds. They are experienced at using many of the tools that the Implementers have created and can think at the level of an architect. They see how all the pieces fit together to produce a quality, polished end product in which the non-technical world sees value.

Like I said at the beginning, these categories are simply a reference guide and I’m sure that there are many exceptions – people who can be an innovator one day but also think like an integrator – but in general I’ve seen that people have a passion for only one of these schools of thought.

A Better, Stronger Flex Architecture

Monday
Mar 23,2009

Cairngorm++

Call me a junkie, that’s fine, but this stuff works. I’ve said many times in the past that the whole purpose of using design patterns, code frameworks, and application architectures should be to reduce the code I write (as time progresses), make an application easier to extend, and reduce the cost of turnover.

After quickly learning what the Cairngorm architecture had to offer, I noticed several gaps that needed to be filled. One of which was the inordinate amount of files that are created using the base patterns (which I alleviated with my abstract classes for Event, Command, and Delegate). Another gap is that it doesn’t have a view mediator. That’s the one feature from the PureMVC framework that I actually was a huge fan of.

Mediators

You see, PureMVC uses a Mediator pattern in order to provide a mechanism by which views could interact with the business logic, as well as with each other, while remaining ignorant of the man behind the curtain. Keeping the views decoupled from the model is good – especially with my apps – because subtle changes to the data model happen often, and while a good part of that is handled in the business logic, it often bubbles up to the UI model as well.

I am a Command, I am an Island

Another value feature that other frameworks have is that ability for a View – via a Mediator – to actually know if a Command was successful or not. Gasp! With the base Cairngorm implementation, the only way to perform an action on success of a Command was in the Command itself. Very bad, otherwise you end up with situations that call for SaveProjectAndReloadModelCommand in which you do one action and then immediately call another Command, and SaveProjectWithNoModelReloadCommand for when you don’t need to do the second Command.

A Command should be as insular as possible. It should never directly call another Command.

Responseful Commands

My way around this was to implement a function callback feature in the Event and Command abstract classes.

abstract

When an Event is dispatched from a View, the name of a local function is passed as an argument. The Command consumes this function reference and then runs it if the execution was successful.

Tested in the Field

Sure, theory is fine, but how does all this work when actually writing a Flex app? Well, I put that to the test just the other day. An app I’m working needed a significant enhancement and change. After changing the database model, I was able to crank out the business logic, and three views in Flex in which users could create new items, deactivate/activate them, and a few other doo-dads in just under 40 minutes.

Conclusion

Don’t be afraid to enhance a framework or code architecture with your own ideas. Trust yourself and your ideas because you’re smart, too.

Latest Tweets

  • Watch video on this page to see a quick shot my family's biz and a heapin' helpin' of Pittsburghese - http://bit.ly/aMxuLN
  • Ever wonder how insignifcant the Earth is on a cosmic scale? http://bit.ly/PV4o
  • How did I miss this highlight??? Hasek takes out Gaborik http://su.pr/1KZtN2
  • Rooted & upgraded my HTC Hero w/#Froyo. Holy shit is it faster and have improved features. Painless, too. http://bit.ly/cBjvuH #fusprint
  • @Antipimp You will do what Father Jobs tell you to do, peon.