Flex/Parsley - Use AsyncToken to return asynchronous response from Service

In Flex application, we need to manage the asynchronous responses from the service to the commands. The approach to manage this scenario is:

  • Create a AsyncToken in Service method
  • Return it to the command
  • Retain it with service for the time when we shall get the result
  • As we get the result in result handler of service, use AsyncToken to return the result to command.
  • Get the responders form the AsyncToken responders array and hand over the result or fault to these. 
  • The result or fault will be communicated to the Command result or error handler methods.
Here point is that how AsyncToken will get the responder for command. The process under the hood is that as Service return the AsyncToken to Command, and command return the same object further. Parsley framework will capture the return value, create a Responder with Command's result and fault methods and add it to the AsyncToken. So when we are accessing the first responder from AsyncToken, this is the same responder which Parsley has added automatically.

AsyncToken.responders[0].result(resultObject);

Or

AsyncToken.responders[0].fault(faultObject);

Keep in mind, if you are not returning the AsyncToken from the service and hence from the Command, and if the command is dynamic; Parsley will remove the Command reference from the context as soon as control will return from the execute method. Otherwise it will retain it till it gets the result or fault call on AsyncToken>responder.

Another point is that any object in Parsley is not able to capture the event if it has already been removed from the context. So any object should be alive with Parsley context to be a part of framework and to be managed by Parsley, only then it will be eligible for the events and other facilities. 

Dynamic Commands with Parsley

Parsley provides dynamic commands feature where it creates a new instance of command on triggering of a matching event. Dynamic commands means the command instances which will be created dynamically by Parsley at runtime, whenever it finds any event in the system matching with 'selector' attribute of the command.

So instance of the dynamic command is dependent on the system state. If at anytime, the required event has been fired, the parsley will create the instance of corresponding Command and will handover the event to it. 

Dynamic Commands can be singleton or non-singleton. This behavior can be controlled by setting  'singleton' attribute with configuration file while defining the Dynamic Commands. In case of singleton commands, Parsley retain the instance of Dynamic Command once it is generated and always hand over the event to same instance. However for non-singleton command, Parsley creates a new instance of Command every time it gets a matching event. 

One should use 'selector', 'execute', 'error', 'result', and 'singleton' attributes while defining the dynamic commands with configuration file. Alternative approach is to write these tags in code file on the methods. We found that sometime 'error' tag specified with code file is not working properly, hence we followed the configuration file approach. 

Execute function of the command can return 'void', 'AsyncToken' or a 'Task'. We assume that command is interacting with service for some database interaction or for business logic. 
  • void - If service is not returning anything, return type can be void for command execute method. 
  • AsyncToken - If it is returning a asynchronous response, an AsyncToken should be returned. It will invoke the command result and fault handlers whenever it will get the result. 
  • Task - If we want to execute some task on command result, one can return the Task object which can perform the required task. 

MVCS Design implementation in Flex and/or Parsley - II

This is in continuation of the last blog for MVCS implementation using Flex and Parsley.

We have discussed various design for various layers in MVCS. Another approach is:

  • View are having reference of Presentation Model. Better to inject the PM using Parsley DI, however as per requirement, these can be instantiated using constructor also. 
  • Commands are having reference of Service. Services are injected using DI. 
  • Commands are dynamic and non-singleton in nature, and hence every event will result in creation of a new command. Parsley framework will automatically create a new command for every event, and hand over the event to it.
  • View can interact with commands using events, and can pass the PM to commands by putting it in Event. 
  • As commands are non-singleton and existing one per event, so now commands can retain the instance of PM till these get the response back from asynchronous service request in result handler. In result handler, command can use the retained PM and update the state of the PM and hence of the view.
  • Command can interact with view or Model using events. However Model and View need to put the check for the events to filter out the events targeted for other UI of same type.It can be done by putting a check for the PM, as command are having the instance of PM, so same can be passed to view or model with event to filter the required event. 
This design considers all the features given by Parsley and Flex and provide flexibility in terms of interaction among layers.


New version of Expression Engine Released - 2.3

  1. Support for ternary operator
  2. Support for XML expressions, using Xalan XPath
    1. XML Expressions are returning only String type value. 
    2. We can change it to some specific type like Number, String etc in future depending upon data or we should provide some type casting function
  3. Added more test cases 


For Download: http://xpressionengine.blogspot.com/p/downloads.html

New version of Expression Engine Released - 2.2


New version of 'XpressionEngine' has been released at 





Release notes: 
  • Support for more math functions
  • Bitwise operators
  • Change precendence of operators - http://en.wikipedia.org/wiki/Order_of_operations
  • Change '=' operator with '=='
 

MVCS Design implementation in Flex and/or Parsley

Here are varioius approaches to implement MVCS design using Flex and Parsley. MVCS - Model View Controller and Service. MVCS contains one more layer, called as Service. Service is used to contain business logic. It can be on client side or at server side, depending upon the application architecture. (Refer for MVC definition



Here we are defining MVCS from Flex and Parsley perspective.Following MVCS, there can be various kind of layers and interaction.

Layers and Flow of control
  • View
    • MXML and View Logic
    • Interacts with Presentation Model for data
    • May Interact with Commands for action implementation
  • Presentation Model
    • Contains data state for view, may contains data transfer object from Service
    • May interact directly with services for data related operations
    • Or can have interaction channel with Commands to have update for data 
    • Injected in View as stateless object
  • Commands
    • Contains view logic to act upon various user action from UI
    • Helps to break the UI logic in various objects which acts based on the action
    • Interact with Services for data related operations or Business Logic
    • May update the presentation model for data state
    • Can act as singleton stateless objects and linked with event mechanism 
    • Or view can have their reference as per architecture preference
  • Service
    • Contains business logic and data related operations
    • Can be on server side and may be implemented in various language like PHP or Java etc
    • Can be on client side in case of desktop application, can use assql like MySQL connector to interact with database
    • Service Delegates generally injected in Commands or Presentation Model using DI
Now there are many interaction models between these four layers depending upon overall application architecture or architect preference. 



New version of Expression Engine Released

New version of Expression Engine has been released at Google Code. It has the fix for unary operators and now supports expressions like

false || ! false
OR
-3 * -2 / -6
OR
20 - (10/-2 + (-5 * -2)) / (15 * (-5/5) )

Latest release is xpressionengine 2.1.