Memento Pattern

Posted by admin on April 11th, 2009

Yesterday I tried to implement Undo functionality with Command Patterns. The Memento pattern can also be used to do this. So what is the difference between the two?

Well, with Memento pattern the state of an object (the originator) is being stored by a Caretaker class. So if it’s possible to Undo with returning back to a previous state, use Memento pattern. Sometimes however, the originator is too complex to save each time its state (it could be a composite for instance). In that case the undo facility can use commands. Whenever an action is received a compensating action is set up and stored in the undo facility.

Example in Flex of Memento Pattern. I haven’t added too much comments because the code and example should speak for itself.

thx, Lieven Cardoen

Related: Command Pattern Undo Functionality

<

Rounding up last month – Pex, Mocks, NSK, CHESS, Linq, Silverlight, TechDays

Posted by admin on April 4th, 2009

It has been a while since I wrote anything, but that’s mainly because we have a new family member… Romée, a beautifull daughter, six weeks old!

dsc_0220

Back to the usual stuff. What have I been doing the last month. Well, there were Techdays, on which I wrote a few things but I still need to round that up. I also went looking for best practises to build a .NET layered application. The Northwind Starters Kit was most usefull for this. And there were also the Mocking frameworks, which seemed very complex at first (like everything in it it appears to be very simple afterwards…).

Pex & Chess

Very inspiring talk on Techdays about automated White box Testing and finding and reproducing Heisenbugs in concurrent programs. There was an example of a team that got a report of a bug that had to do with concurrency they just couldn’t reproduce. They let CHESS do its thing and in less than a minute they found the bug. Very impressive.

Mocking frameworks

In my Flex projects I had already used mocks, but they weren’t exactly mocks… Now that I began exploring .NET architecture, I really found out what these mocking frameworks are about. And they impressed me. Certainly the fact that if you want to use mocking frameworks you need good design, is interesting. To me it seems that a mocking framework is very good to test your base design (framework), if it’s done using principles described in books like Patterns of Enterprise Application Architecture or Domain driven Design (or others).

Northwind Starters Kit

This Kit has helped me a lot in having a good example of how you could implement a good .NET layered architecture. I also checked out DinnerNow, but things went wrong when installing (and I just hate that — if you’re limited in time, you don’t want to go looking why this or that doesn’t install properly. If I have to make installers for cd-roms, they need to work…). I’m now implementing a very small part of a product of ours with this NSK example. I will also try to check out a few mocking frameworks and a few IoC frameworks and integrate them in this small part. The best way to check out this NSK is to checkout the svn repo.

SilverLight

A few good presentations on SilverLight at TechDays. I certainly think they got a lot of advantages over Flex, but it will still take a lot of time. What really annoys me a lot is the arrogance by which some presentators present SilverLight. Anyway, their CLR seems a lot more robust that the Flash Player, but so far I haven’t seen business solutions being created with SilverLight. So I’m actually waiting a little bit on such examples. Now it’s always very simple examples or interactive sites that really don’t have to deal with a lot of data. There was a neat example of a Chess Game where they let a Javascript engine play against an .NET engine (SilverLight). SilverLight always won and could precess a lot more paths/second. A colleague of mine ported the engine to Flash, and could then compare Flash against .NET. The original game can be found here. The blog post from my colleague here. After the presentation on this, I asked a Microsoft guy how Flash would compare to this. He told me you couldn’t do this in Flash. Mmmm.

Linq

Very good presentation on Linq! Now I now what Monads are (look them up in Wikipedia). I haven’t used Linq all that much, but loving maths I’m interested in how this is implemented. The presentator quickly went deep into the subject which was fantastic (but also sometimes a labyrinth). Also the possibility to extend Linq to any other sort of data is great.

Oslo

Seemed very interesting, but I’ll have to check more examples to know how this could be used in every day development. The custom parser seemed very powerfull if you would need to convert data to another format.

Cheers, Lieven Cardoen

<

TechDays Day I: Software + Services: The convergence of Saas, SOA and Web 2.0

Posted by admin on March 14th, 2009

Very motivational and interesting presentation, especially because of the different existing examples around on the net.

First of all, everything is about data and how to bring it to clients (whether they are users or other applications) and bringing software above the level of a single device.

An interesting book that was talked about is “Place to Space” by Peter Weill & Michael R. Vitale. “Place to Space” deals with the business models an e-business can adopt. The central idea of the book is that there are 8 atomic business models that exist. It’s a very interesting way to model for example cash flow, product delivery, …

Cool examples:

Eve Online : Very impressive game.
Photosynth I had seen this before and I really will try to make one myself.
British Library Well, this is less fantastic to me in terms of GUI, but it is a enormous access to data.
WorldWide Telescope Very impressive!
Yosemite Extreme Panoramic Imaging Project Also very impressive. Click on result by the way.

The Cloud was off course a topic in this presentation with the .NET Services and SQL Services. Will look into these in the coming weeks.

Lieven Cardoen

<

TechDays Day I: Identity & Cloud Services

Posted by admin on March 14th, 2009

In this presentation I kinda got lost a couple of times. I hoped to see some examples of Azure in practice, but this wasn’t really the case (except one example that I hope to see soon on the blog of Vittorio Bertocci).

My interest was more in Azure for Web Developers. Azure Service Platform is designed to help developers create, deploy, manage and distribute web applications and services. Also, if you have a lot of traffic and load, you’ll pay more, otherwise you’ll pay less. Hosting is provided for you.

I’ll just need to try it out. I know WebORB has managed to run their applications in the Cloud, so it shouldn’t be a problem.

Quote:

Next time you’ll want to build something in house, ask yourself:
Do I really need a generator here, or could I just connect a plug?

Link to Azure Services Platform

thx, Lieven Cardoen

<

TechDays Day I – Architecture: The good, the bad and the ugly

Posted by admin on March 10th, 2009

I was a little bit too late for this session, but I did manage to grab the most important things. The presentation began with a lot of antipatterns and then followed with good patterns. Most of the things were rather obvious. A really funny thing was an example of the MSSQL database behind one of the first versions of SharePoint. There were like hundreds of tables with absolutely no relationships between them. Instead they created some 500 stored procedures that needed to take care of the integrity of the database… Guess there are also ‘disaster developers’ working for Microsoft.

Anti patterns

McKinsey Syndrome

  • We know it all, we don’t nee to listen…
  • They don’t know what they really want…
  • Just a cookie-cutting re-delivery…

Opposite Anti-pattern: Obedient Butler

Napkin Doodle

  • It was so straight-forward requirement…
  • We agreed on all req’s during lunch…
  • Light projects don’t need heavy process…

Opposite Anti-pattern: Documentation Overkill

Measure abuse

  • Each req must have success metrics…
  • If you can’t measure it, it is not there…
  • We need binary criteria of achievement…

Opposite Anti-pattern: Softie-softie

Start small, grow fast

  • Just for couple of users first…
  • Prototype, patch-up, deploy…
  • We’ll add scalability later…

Opposite Anti-pattern: Let’s Go Global NOW!

Best-of-breed

  • All the best tools (best database, best webserver, …) but no communications beween them…

Opposite Anti-pattern: Vendor Lock-in

YAGNI (You Ain’t Gonna Need It)

  • I’m sure nobody needs this requirement…
  • I bet this one is totally irelevant…
  • Too low on priority list…

Opposite Anti-pattern: Analysis Paralysis

Reinventing the wheel

  • We can do it better. Much better…
  • It would be boring to re-use the old stuff!
  • I trust my code and my code only.

Opposite Anti-pattern: Golden Hammer (One thing that solves everything… everything must be a nail…)

Sales-driven Design

  • We sold it, you just implement it…
  • Trust me, I’m technical too…
  • Does it work? Shut-up then…

Opposite Anti-pattern: Technological Purity

YAFL (Yet Another Fine Layer)

  • Architecture is simplicity, not intellectual violence

Good patterns

  • Modularity (degrees of freedom)
  • Open-ended systems (specific vs generic). Move from Application-Specific (solution) to General-Purpose (Infrastructure)
  • Build to grow (Wu Wei)
  • Identifier, Format and Protocol (back to the roots)
  • Middle-out Architecture (Wide range of implementations, Minimal Spec and Wide range of uses)
  • Poor-man Application Model
  • Web-Oriented Architecture
  • Lines matter more than boxes (Protocals are inherently stable, applications are not)
  • Dependency Inversion (Fold knowledge into data so program logic can be stupid and robust, What needs to be easy to understand and change goes into data, What will be stable goes into code). Data should depend on code, Code should not depend on data.
  • New-age development with MetaData and Model-Driven Design
  • Virtual worlds, virtual rules
<

Advanced Design Principles

Posted by admin on January 27th, 2009

The Open/Closed Principle (OCP)

A module should be open for extension but closed for modification.

Liskov’s Substitution Principle (LSP)

Subclasses should be substitutable for their base classes.

The Dependency Inversion Principle (DIP)

High-level modules should not depend upon low-level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.

<

POD component – Dashboard

Posted by admin on January 10th, 2009

Yesterday I was looking for a way to show multiple statistics next to each other. I had a component in mind that could contain Panels. The Panels would have to be divided over the available space. If there was one Panel, it would get all the space, with two Panels the space would be divided in two, … Also you need to maximize, restore and minmize the Panels.

Thx to Tom Van den Eynde from VDE Projects I found a very nice example of such a component.

Here is the link: http://www.adobe.com/devnet/flex/samples/dashboard/dashboard.html. The Panels are also draggable.

I haven’t begun to use it but I’m sure this will be a great example to start from.

Thx, Lieven Cardoen

<

Rounding Up 2008

Posted by admin on December 24th, 2008

I started this year by taking over the lead of a big project for the Belgian government. The project is an e-learning environment created mainly with Flex, WebORB, .NET, MSMQ and MSSQLServer 2005. Daily hundreds of candidates go to Brussels were they are being tested by our software. Typically some 300 candidates start off at the same time to take a test.

So what have I learned this year (some of the things ;-) ):

Database

  1. Indexes are very important because they can speed up things a lot. However they can also be misused!!! So read about them.
  2. Stored Procedures made it easy to quickly write logic (transaction scripts). However it’s hard to maintain these Stored Procedures and Cache dependencies don’t work with complex Stored Procedures.
  3. MetaData was a very usefull mechanism to add new logic in Flex without having to change table designs.
  4. We also used MetaData for tags which wasn’t the best choice.

.NET

  1. I didn’t have a lot of experience in the beginning of this year so things kind of moved in the direction of Transaction Scripts. They aren’t a bad choice but as the project gets complexer, transaction scripts are difficult to maintain.
  2. SubSonic (o/r mapping tool) did it job very good but I’m not very pleased with the lack of documentation, tutorials and clear explanations. I will certainly look into nHibernate and Entity Framework and see how they work with some of the patterns described in ‘Patterns of Enterprise Application Architecture’ by Fowler. In the future the project will certainly need to be scalable so things will have to change.
  3. Visual Studio is a great IDE.

IIS and ASP.NET

  1. By default IIS recycles application pools every 29 hours (will come back to that later because this caused a lot of problems).
  2. HttpHandlers are great.
  3. Cache is a very important feature if you want to speed up your application.

Flex

  1. Very good choice for our client side development. Application development however is far more complex than writing web pages in .NET. If you need your code to be maintainable you need to know about design patterns, frameworks, refactoring, architecture, … Those things are mainly things you learn after having used them a couple of years.
  2. We now work with modules but in the future we will have to check out those shared libraries as well. Our application is now 2mb big so some kind of intelligent caching will be needed.
  3. Prana is great to configure your application externally. Check it out!
  4. The Flexbuilder Eclipse Plugin is a waste of memory and I hope Adobe tries to improve this in the future. Building our project takes far too long.
  5. Resource bundles could be made easier.
  6. Designing a Flex application is a hard thing because you really need a designer who knows some basic things about Flex.
  7. Implementing Pessimistic Concurrency with Messaging was a very hard one this year!
  8. Looking forward to create a desktop application version of our project.

WebORB

  1. Great product. FluorineFX is the open source alternative, but WebORB has a lot more features. Without a support plan however some things are really hard to debug.
  2. Authentication and Authorization is worth to take a look at, but it’s important to fully understand it.
  3. WebORB messaging integration with MSMQ is great to let other applications know what’s happening.

Other tools that have been very usefull are CvsDude, Trac, Mylyn, SubVersion, Charles, SQL Compare, SQL Data Compare, ant, cruisecontrol, Linq, SilverLight (very promising), Spring,…

Ciao!

<

Stress Testing with WebORB

Posted by admin on November 19th, 2008

Yesterday and today I worked on a performance issue where 350 candidates had to wait more than a minute before their data was loaded. The 350 candidates start their exam simultaenously so the server is heavily loaded at that time. I had a couple of ideas in mind like caching certain things but how was I going to test this. I haven't got 350 computers at my desk, I just have one laptop (and a development server).

A first tool I got from an answer on StackOverflow. AB is a tool for benchmarking apache server, but it can be used to benchmark any url(in my case local IIS). To do this I created an aspx page that loaded the same data that was loaded by one candidate. I then used AB to call that page multiple times. With this tool I already got a good idea how good my caching was working but I didn't know if WebORB was also causing performance problems.

Since the last update we put on the development server of the customer, candidates had to wait much longer to get started. My guess was that it had to do with WebORB authentication. I now had to find a way to test my services by using the WebORB gateway. Asynchronous Unit Testing with FlexUnit had to be one of the answers. So I got started and two hours later I had my test. I did however had to try three different things.

In the first try I created a Test and added it a hundred times to the TestSuite. This wasn't so usefull because the next Test starts only if the previous had ended. I needed simulteanously remote calls, parallel, not serial.

In the second try I created a Test that does a remote call a hundred times and is added only once to the TestSuite. This second try looks like this:

Actionscript:
  1. package {
  2.     import flexunit.framework.Assert;
  3.     import flexunit.framework.TestCase;
  4.    
  5.     import mx.rpc.AsyncToken;
  6.     import mx.rpc.Fault;
  7.     import mx.rpc.IResponder;
  8.     import mx.rpc.Responder;
  9.     import mx.rpc.remoting.mxml.RemoteObject;
  10.    
  11.     public class LoadExamSessionTest extends TestCase  {
  12.        
  13.         private var remoteObject:RemoteObject;
  14.        
  15.         override public function setUp():void {
  16.             remoteObject = new RemoteObject("GenericDestination");
  17.             remoteObject.source = "Edu3.ApplicationTestServices.LoadExamSessionBenchMarkTestService";
  18.             remoteObject.endpoint = "http://localhost/edumatic3/local/weborb.aspx";
  19.             // This is needed because the weborb authentication is enabled on the server side.
  20.             remoteObject.setCredentials("credentials", "credentials");
  21.            
  22.         }
  23.        
  24.         public function testLoadExamSessionTest():void {
  25.             for(var i:int ; i <200 ; i++){     
  26.                 loadExamSession();
  27.             }
  28.         }
  29.        
  30.         public function loadExamSession():void{
  31.             var token:AsyncToken = remoteObject.LoadTest();
  32.             var responder:IResponder = new Responder
  33.             (
  34.                 addAsync(onLoadExamSessionResult, 1000000),
  35.                 null
  36.             );
  37.             token.addResponder(responder);
  38.         }
  39.        
  40.         public function onLoadExamSessionResult(data:Object):void {
  41.             assertNotNull(data.result);
  42.         }
  43.     }
  44. }

This worked like a charm, but Authentication on the server side is only done once with the frist call because I'm using the same Remote Object every time. You should also check Charles to see what happens because it's very interesting. Apparently the there are only two calls to weborb.aspx. The first call is the one that will trigger my custom authentication handler, the next call has packages 199 calls to the service... I won't put a screenshot here because testing it is so much cooler. You can actually see in Charles that the server has started 199 threads and you can follow how much of the amf package is downloaded.

But this wasn't what I needed because all 350 candidates are authenticated seperately. To simulate this I just create a new remote object for each call. Class now looks like this:

Actionscript:
  1. package {
  2.     import flexunit.framework.Assert;
  3.     import flexunit.framework.TestCase;
  4.    
  5.     import mx.rpc.AsyncToken;
  6.     import mx.rpc.Fault;
  7.     import mx.rpc.IResponder;
  8.     import mx.rpc.Responder;
  9.     import mx.rpc.remoting.mxml.RemoteObject;
  10.    
  11.     public class LoadExamSessionTest extends TestCase  {
  12.        
  13.         private var remoteObject:RemoteObject;
  14.        
  15.         override public function setUp():void {
  16.         }
  17.        
  18.         public function testLoadExamSessionTest():void {
  19.             for(var i:int ; i <200 ; i++)
  20.             {         
  21.                 loadExamSession();
  22.             }
  23.         }
  24.        
  25.         public function loadExamSession():void{
  26.             remoteObject = new RemoteObject("GenericDestination");
  27.             remoteObject.source = "Edu3.ApplicationTestServices.LoadExamSessionBenchMarkTestService";
  28.             remoteObject.endpoint = "http://localhost/edumatic3/local/weborb.aspx";
  29.             // This is needed because the weborb authentication is still enabled on the server side.
  30.             remoteObject.setCredentials("credentials", "credentials");
  31.            
  32.             var token:AsyncToken = remoteObject.LoadTest();
  33.             var responder:IResponder = new Responder
  34.             (
  35.                 addAsync(onLoadExamSessionResult, 1000000),
  36.                 null
  37.             );
  38.             token.addResponder(responder);
  39.         }
  40.        
  41.         public function onLoadExamSessionResult(data:Object):void {
  42.             assertNotNull(data.result);
  43.         }
  44.     }
  45. }

Now you'll see 200 calls to weborb.aspx in Charles and my custom WebORB authentication handler will be called 200 times. This is somewhat the customers case I wanted to simulate.

What did I find out, well, for 200 remote calls, the third scenario (200 times weborb authentication) takes double as long as the second scenario (once weborb authentication).

The Caching on the server times now speeds up the loading of the data five times!

ps: I do need to dig in a little deeper in the addAsync from FlexUnit because when I add another addAsync for my fault event in the Reponder, things get messy... Will keep you posted on this.

Ciao! Lieven Cardoen aka Johlero

<

IIS Recycling

Posted by admin on November 16th, 2008

Last week I got a call from a big customer saying that the 100 of the 200 candidates had just received an error log window in our Flex Application. I knew that this could happen someday, but what had caused this error log...?

After a lot of searching in the logs of the two servers at the customer, I found out that at a certain time on one of the two servers all sessions and application pool were ended. Why? Well, after again a lot of searching I found out that IIS recycles an application pool every 29 hours... Man, why is this default enabled???

Apparently a lot of these recycle events are nog logged by default. Only the 29 hour recycle event apparently is logged by default. As for now I haven't found this log yet, so I will have to enable all those logs to find the actual reason why the application pool recycled...

That's done by this command on IIS6:

cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs Set w3svc/AppPools/LogEventOnRecycle 255

On IIS7 you can enable them in the Advanced Settings of the application pool.

The problem with our Flex Application was that it uses WebORB Authentication. This authentication is done by the first remote call after which the server side session remembers the credentials. After the recycle the sessions were gone and 100 candidates received a WebORB Security error... We have already solved this problem by re-authenticating when this happens but I'm also really hoping to find out why the application pool recycled in the first place... Any suggestions are welcome... (memory?, too mucht connections?, database problem?, ...).

Ciao, Lieven Cardoen aka Johlero

<

Copyright © 2007 Johlero – Cardoen Lieven. All rights reserved.