Monday, April 30, 2007

Communication over HTTP in FLEX 2.

So, it seems that things are not that easy with FLEX2.0 after all.
We need to write a piece of code that sends some ( XML ?) message through an HTTP request to some servlet, get the HTTP response and extract the reply XML message from the response.

First, create an instance of the URLLoader class, The URLLoader class downloads data from a URL as text (default), binary data, or URL-encoded variables.
var requestSender:URLLoader = new URLLoader();

Second, add event handler for the complete event of the loader class:
requestSender.addEventListener(Event.COMPLETE, completeHandler);

We then have to create a URLRequest instance, taking the URL of the servlet. The URLRequest class captures all of the information in a single HTTP request.

var urlRequest :URLRequest = new URLRequest("serverUrl");

Next, we create the message to be sent and put it in the "data" property of the URLRequest instance created above, set the value of the URLRequest.method property to URLRequestMethod.POST.

var msg:String = “valid XML msg” ; = msg;

After that, the request object is then passed to URLLoader.load(), which does the HTTP request and posts the message:

When the URLLoader has finished loading the text file the Event.COMPLETE event fires, triggering the completeHandler() method.
function completeHandler(event:Event)
var response:URLLoader = URLLoader(;
String responseData =;

Note that the reply XML message is obtained from the property on the instance obtained from the
We now have that working piece of code:

var requestSender:URLLoader = new URLLoader();
var urlRequest :URLRequest = new URLRequest("serverUrl");
var msg:String = “valid XML msg” ;

requestSender.addEventListener(Event.COMPLETE, completeHandler); = msg;

function completeHandler(event:Event)
var response:URLLoader = URLLoader(;
String responseData =;

As you might already have guessed, the responseData can be then used to construct an XMLDocument instance, where you can perform different XML parsing operations.

Communication Barriers

I think that we are the most skillful people to achieve a team work. I thought that the majority of us have been working in teams since their first academic year, and for me, this was good reason to justify my theory.
Ironically, I am totally convinced with my theory, while all other careers look to developers as freaks. Well, I show up hands to agree with this. My theory isn't precise...I should add "teams of developers". At least the freaks can understand each other :)

Team chit chat
It should be curious that our teams may still have problems in communication. I got some remarks from my partners, through the projects, concerning my communication success with them.
The big majority confirmed that:
  1. I have a problem in transferring my knowledge to them.
  2. I am "expression-less", so that someone asked me to put a sign indicating my mood whether "I am sad" or "I am happy".
The 2nd point is little bit tough. The 1st point can be analyzed and managed.
It was normal that I spend time thinking about how much people think that I have deficiencies in transferring my knowledge and my talk skills. At the beginning I was trying to evaluate myself and think how can I overcome my problems.
hence, whenever someone asks me about anything, I make a flash back to the days when I was still learning that thing, memorize all the questions I got at that time, and then start my brief session.
I worked on this thinking that I am overcoming my problems with partners. But I was totally wrong.
one day, I was making a brief introduction to my partner, he shouted "Fizo, I really don't get you, your explanation is really vague....Why don't you make a flash back to the days when you started to learn this thing and explain to me based on the question you got in your head?"
"huh...?" That what I am doing all the time.

Again, there should be something wrong...This time I thought about it in more abstract way.

Evaluation Barrier
My partner's comment made me notice a small problem...
It's the "Tendency to Evaluate", this is a human nature, the first reaction of a statement is to evaluate it from "your" point of view. It's a tendency to judge, approve/disapprove person's statement. What was really happening is that my explanation was evaluated by my partner more than listening with understanding.

Listening with Understanding
You should achieve real communication by avoiding evaluative tendency. This means seeing the attitude from the other person's point of view, touch his/her frame of reference about the subject.
I see that I should answer question, in the contest I can do it. Some efforts should be done by the questioner to get and understand the whole picture. In practical life we are not open books, my head is not indexed like the book, I have no appendices pointing to keywords which the questioner look for.
What will happen when you listen to my answer and analyze it to get your satisfactory answer? Does this sound absurdly simple??
Actually "listening" is not widely used. There are a lot of reasons in my opinion to avoid the "listening" thing.
  1. Most of us have a defensive attitude when it comes to opinions' discussions. We are afraid to get affected and changed by what we hear. Weird, isn't it?
  2. Emotions, in some discussions emotions become strongest, so they forbid us from achieving the frame of reference of the others. (let's not focus on this right now, as we are more involved with technical discussions)
I don't think I am saying something new. What the entry includes is very obvious for all of us, "the importance of listening"...But the fact, is, the problem has endured because it is a basic truth about human interaction.

XML changes in FLEX 2.0

I was debugging in an ActionScript 2.0 code using Flex 2.0 SDK before the code was ported to use ActionScript 3.0 (FLEX 2.0). The code uses the wonderful combination of the sendAndLoad method and the onLoad property of the AS2.0 XML class to do communication with an HTTP servlet via XML messages which are sent and received in the HTML body of the requests and responses.
This has been very straight forward:

var login_str:String = "valid xml that contains user info";
var my_xml:XML = new XML(login_str);
var myLoginReply_xml:XML = new XML();
myLoginReply_xml.onLoad = myOnLoad;
my_xml.sendAndLoad("servletURL", myLoginReply_xml);
function myOnLoad(success:Boolean) {
//extract reply message from myLoginReply_xml object
if (success)


The code has been working under FLEX (AS2.0) SDK. However, when running it under FLEX2.0 SDK, I was shocked with the following exception ! : “onLoad property does not exist for object ..” After looking at the FLEX2.0 changes here , it turned out that the XML class has been renamed to XMLDocument and moved under another package (flash.xml) to avoid conflict with the new top-level XML class that implements ECMAScript for XML (E4X).
Not only the class has been moved and renamed, but also it was dramatically changed. For example the sendAndLoad method now does not exist!, and of course the onLoad property that used to set the event handler for the "load" event has been removed (since the new event model of FLEX2.0 now took place, and events could be only set via the addEventListener method).
Now for me to retain the functionality of the above few lines of code, i have to use a combination of 3 classes: URLLoader, URLRequest and of course the new XMLDocument class (The details will be posted in a later post).

The funny thing is that Adobe claims they made the XMLDocument class for backward compatibility with AS2.0 code, horray!

Sunday, April 1, 2007

Me, Myself and MySQL Falcon

I have been getting more and more into MySQL for the last couple of months, and to tell you the truth i was really impressed, i can't say i am a database guru, but i had my experience with database engines before, and for my surprise.. MySQL does match up with the big players in this sector.

I can still remember MySQL from the old days when it was used to be thought of as a light, fast database storage engine, that can only use with personal websites, but now MySQL has everything an enterprise DB engine would need.... and more.

What got me really dazzled in this engine, is its layered architecture and pluggable storage engine architecture, this DB engine was designed in a way to separate the storage engine from the other system, so you can plug in any engine from a vast list, or even do your own !!

One of the new players in MySQL's storage is FALCON , this one is to be said the Oracle innodb killer, or isn't it?

Falcon (code name) is a transactional storage engine, based on Netfrastructure database engine, extended and integrated into MySQL.

The main goals of Falcon are to exploit large memory for more than just a bigger cache, to use threads and processors for data migration. Falcon has a larger row cache with age group scavenging. Falcon is multi-version in memory and single version on disk, True Multi Version Concurrency Control (MVCC) enables records and tables to be updated without the overhead associated with row-level locking mechanisms. The MVCC implementation virtually eliminates the need to lock tables or rows during the update process, also data and index caching provides quick access to data without the requirement to load index data from disk.

So it seems that it has everything to be the ace of all storages, no? think again, a benchmark was made to compare the performance of this new engine with old MyISAM and InnoDB here, but regretfully benchmarks are not in the favor of Falcon.. InnoDB and MyISAM scored over Falcon in different queries.

From what I read I can say that Multi version Concurrent Control system implemented in the new engine, made a draw back in some cases rather than boosting the performance, having multiple snapshots for every session, so achieving better locking, but at the same time the need to access the data beside the key is needed, and as we know keys are used a lot for optimizing, this is beside the overhead coming from such mechanism.

We can see also that it has a bug with queries that have LIMIT in it, the performance drops drastically when used.

The question here lies, will Jim Starkey bring his house into order and make Falcon the number one storage engine as promised? In all ways we are the winners, as we have other alternatives , and as they say.. competition is the consumer's number one friend. Revisited

We finally made it!

I'm pleased to announce that eSpace's new web site is online. We are on the test stage and your suggestions are welcome.

Please give it a try and I'm waiting for your feedback.