Archive for June, 2008

Jun 27 2008

Functionality and Features v/s Performance and Cost

Published by under General

This is a major issue in developing applications, what functionality and features do we require and they come at what expense. I usually like to things simple for the user and that generally means better performance and less cost. Ofcourse there are certain features those need to be implemented irrespective of the cost, performance has to be optimized for them. 

 

Here is an example of when i personally think that a feature is irrelevant, I had to implement a shopping cart in Flex and as soon as a product is added to the shopping cart its saved on the server as well. The idea behind this is that if the user doesn’t buy the product and returns to the site again he still has the product saved in the cart.

It just doesn’t make sense to me, making a server call every time product is added will increase the load tremendously, yes we need to make a server call when the product is removed as well. If the client logs in after a week or so and the product is no longer available, we need to handle it differently, is it worth the effort????? i would say NO. The end user i think doesn’t care if their cart information is saved, if i add something to cart then i will buy it right away. 

It might seem just a server call but on the server there is a call to the database, insertion, deletion etc, all those operations take up precious server time and resources. It doesn’t matter if its a call to webservice or a remote method the basic idea is the same. If the number of users increases then the load on the server will increase like crazy, every tiny bit of operation has to be optimized.

 

I would use a shared object to store the cart information as a compromise but then I am just getting paid to write the code, its not my problem to maintain the servers etc. I have presented my case to them and its their choice. 

 

Another scenario was when we wanted to save users favorites data on the server and were faced with the same problem. It just wouldn’t make sense to update that information every time user will add an item or delete something from favorites, it would literally kill the server. So we decided to store that information in memory on the client side and then send it out every 2 minutes, a reasonable compromise i would say.

 

So next time if you decide to add a feature it would be wise to consider the server performance, most of the times people can get away with it because the number of users are not that much and the server is heavy duty server with lots of RAM and CPU power. Only when the number of users increase exponentially and then people start to realize the importance of taking all these points into consideration. 

One response so far

Jun 22 2008

Cairngorm and Web Services

Published by under Flex

I had to use Cairngorm where the data was coming from web services and i had little trouble initially setting up services in my command class. But after a few tries and misses i was able to get web services to work. This is how i have implemented it.

Service class just defines a webservice as follows,

 

Pretty straightforward and the services are global so any changes in the server can be easily changed. Now the execute method of the command class which calls this service looks like this.

 

public function execute(event:CairngormEvent):void {
    var service:WebService;
    var operation:Operation;
    var token:AsyncToken;
    var requestObj:Object;
    var email:String = event.data.email;
    var password:String = event.data.password;

    service = ServiceLocator.getInstance().getWebService("signUpService");
//load the wsdl file
    service.loadWSDL();

//we assign the operation to the function that needs to be called inside the wsdl
    operation = service.getOperation("GetItemsFromStore") as Operation;
//the result format we need is e4x
    operation.resultFormat = "e4x";
//this object will pass all the required parameters for this function
    requestObj = new Object();
    requestObj.email = email;
    requestObj.password = password;
    operation.request = requestObj;
    token = operation.send() as AsyncToken;
//this is the line where the responder object is passed to the Asynctoken
    token.addResponder(event.data.responderObj);

}

Disclaimer: The above code is a copy paste and then modified so please forgive the coding style.

Now the fault or the result method of our responderObj will be called accordingly.

One response so far

Jun 20 2008

Connecting Cairngorm View with the Command Class.

Published by under AS 3.0,Flex

I have been playing with Cairngorm quite a bit and usually when i dispatch cairngorm event, i rely on flex data binding with the model class to manage the view. This is applicable in most of the cases but then sometimes its not required to bind some data in your view with the model. 

I came up with this solution to convert my view to a responder and then once data is fetched, I can update my view as required. Its really an easy solution, your view container has to implement mx.rpc.IResponder Interface and then in the cairngorm event you just pass its reference. It looks as follows,

<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”343” height=”389” show=”initModule()” implements=”mx.rpc.IResponder>

there are only two methods in this interface, result and fault, this is how my script block looks inside this Canvas.

import com.adobe.cairngorm.control.CairngormEventDispatcher;
import com.sampleapp.events.GetStoreItemsEvent;
import com.sampleapp.model.SampleAppModel;
import mx.controls.Alert;

private var model:SampleAppModel;

public function fault(data:Object):void{
}

private function initModule():void{
    if (!SampleAppModel.getInstance().albumDataList){
        model = SampleAppModel.getInstance();
        var event:GetStoreItemsEvent = new GetStoreItemsEvent(GetStoreItemsEvent.GET_STOREITEM);
        event.data = new Object();
        event.data.responderObj = this;
        CairngormEventDispatcher.getInstance().dispatchEvent(event);
    }

}

public function result(data:Object):void{
    var resultXML:XMLList = data.result[0].children().children();
    var finalXML:XML = new XML(resultXML[0].toString());
    model.albumDataList = finalXML.children();
}

and this is how the execute block inside my command class looks like,

public function execute(event:CairngormEvent):void {
    var service:WebService;
    var operation:Operation;
    var token:AsyncToken;
    var requestObj:Object;
    itemType = event.data.itemType;

    service = ServiceLocator.getInstance().getWebService("storeService");

    service.loadWSDL();

    operation = service.getOperation("GetItemsFromStore") as Operation;
    operation.resultFormat = "e4x";
    requestObj = new Object();
    requestObj.itemType = itemType;
    operation.request = requestObj;
    token = operation.send() as AsyncToken;
    //this is the line where the responder object is passed to the Asynctoken
    token.addResponder(event.data.responderObj);

}

so using the above method, We make sure that the result function inside the canvas will be called when the data is received. Now you can do whatever you need to inside this function.

Questions, Comments, Suggestions always welcome.

One response so far

Jun 17 2008

Hike to Mt Islip

Published by under Hiking

I decided to join Travis and James for a hike to Mt Islip and it was a very pleasant hike, here is my trip report.

Woke up at about 4.30 am, it didn’t bother me that previous night i had went to bed at like 2 am. Got ready, had breakfast and then headed out to Travis’s place. On my way i had to get some trail mix and was there at about 5.50. We immediately headed out in James’s car and reached the trailhead at about 6.50 am. It was an ideal time to start the hike.

We started at about 7 and i really found going tough. My legs weren’t ready at all after not hiking for about 6 months or so but i managed to hang in there and we walked at a steady pace with Travis leading the pack. He was way ahead of myself and James.

We took a short break near Little Jimmy campground at about 8.15 or so and then continued our hike to the summit. The day was clear and we had good views of the area. As the hike went on, I was starting to feel lot better and going on at a decent pace. We reached the summit at about 8.45 am and it was beautiful day. The sky was clear and the views were excellent.

Travis decided to make tea on summit and since we had plenty of time we really took it easy. He really enjoyed chivda, James liked it too. So after chilling on the summit for almost an hour we started heading out. We reached the trailhead in an hour or so and were back at Travis’s place at noon. It was a pleasant hike and we were all glad that we finished it before the heat kicked in.

Below are some of the pictures from the hike, coming soon……

No responses yet

Jun 16 2008

Flex/Flash Fullscreen problems

Published by under AS 3.0,Flash,Flex

I have been playing with Fullscreen mode of Flash in Flex and had this annoying problem.

My listener is setup,

Application.application.stage.addEventListener(Event.RESIZE,stageResized);

private function stageResized(event:Event):void{
    mx.controls.Alert.show(Application.application.stage.displayState);
}

and then I call the function which looks as follows,

private function fullScreenFunction(rect:Rectangle):void{

    if (Application.application.stage.displayState != StageDisplayState.FULL_SCREEN){

        Application.application.stage.fullScreenSourceRect = rect;
        Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
    }
}

Nothing wrong so far, the reason i am doing it this way is because i need to make different sections of Application full screen.

This is the function call i make, my application is 1024×768,

1
fullScreenFunction(new Rectangle(1,1,1022,766));

Above function call triggers the stageResized properly but,

1
fullScreenFunction(new Rectangle(0,0,1024,768));

doesn’t trigger the listener.

I have no clue why it does that and also i haven’t bothered to find out because that one pixel isn’t that important to me.

No responses yet

Jun 10 2008

Flex Videodisplay Component Problems

Published by under AS 3.0,Flex


These are the problems i faced in Flex 3.0 inbuilt videodisplay component. I had tried using it but gave up on it a couple months ago this post is written. I created my own videodisplay component for our application.

  • There is no video smoothing option, Very very weird since that was introduced in Flash player version 6.
  • You cannot get the netStream.bufferLength property, there is no getter for it. So you cannot display the buffer status. 
  • If you are encoding flv files which broadcast onLastSecond near the end, it will throw an error. 
  • Also there was a state problem, the player would go into unresponsive state while seeking or something like that which was completely messing up the video.

There was some else major as well but i can’t remember right now, i think it was the way videos were playing. Anyway i am happy with my custom component, which works perfect for our application.

 

I have seen that this post is the most popular among the very few posts i have, so if you need any help writing your own video display component i will be more than happy to share my knowledge. Sorry i can’t share the code for the component i have created.

 

edit: July 20th 08. 

 

Flex component might also give you problems while seeking the video to the end, specially if your buffer is long. lets say if you have a buffer of 20 seconds and someone seeks to the last 18th second then the status will be buffering and since the buffer would never get full. The status of the video will be buffering always and the video won’t play. 

 

In my custom component i had to add a condition to see the seek time and buffer length etc and then accordingly change the status of the video.

 

96 responses so far