DelegateInvoker for the Mate Flex Framework

| No Comments | No TrackBacks

I've been using the Mate Flex Framework a lot in recent history.   I think it's a solid framework that does a lot of things right and it's very lightweight and easy to use.  If you haven't used it yet, it's at least worth looking into.

That said, I was recently confronted with a situation in which the current service invokers were insufficient.  By service invokers, I mean specifically the RemoteObjectInvoker, HTTPServiceInvoker, and WebServiceInvoker classes.  Let me explain.

When you use the Web Service code generation tools from FlexBuilder Gumbo MAX Preview, you end up with a service class that wraps a web service and provides a well defined public interface.  Each method in the class returns an AsyncToken that allows you to add a responder to be notified of success/failure when the remote method call comes back.  The generated code looks something like this:

public class MyService extends WebServiceWrapper
{
    public function myRemoteMethod(param1:String, param2:int) : AsyncToken
    {
        loadWSDLIfNecessary();
        var operation:AbstractOperation = _serviceControl.getOperation("myRemoteMethod");
        var token:AsyncToken = operation.send(param1, param2);
        return token;
    }
}

If you've used Cairngorm before, this code should look very familiar.  It's the same type of code that you would normally see in the Delegate layer.

How do we use this type of delegate class in Mate?  My first approach was to try and use a WebServiceInvoker, but the delegate class is not a WebService.  My second approach was to try and leverage AsyncMethodInvoker, but that had a few other problems.  The biggest was that the success/failure listeners respond to the class itself and not the token returned by the method.  Additionally, the AsyncMethodInvoker doesn't integrate with the UnhandledFaultEvent approach to application-wide service fault handling.

So, I decided the best approach was to create a new kind of invoker, DelegateInvoker, specifically to handle calling these types of delegate classes. Usage is essentially the same as the other Mate service invokers:

<DelegateInvoker instance="{ services.myService }" method="myRemoteMethod"
	arguments="{ [ 'param1', 12 ] }"
	showBusyCursor="true">
			
	<resultHandlers>
		...
	</resultHandlers>
			
	<faultHandlers>
		...
	</faultHandlers>
</DelegateInvoker>

If no faultHandlers are defined, then an UnhandledFaultEvent is generated. This allows the DelegateInvoker to integrate with the application-wide service fault handler.

The DelegateInvoker can be used with any method that returns an AsyncToken. Behind the scenes, the DelegateInvoker attaches a responder to the AsyncToken returned by the method. The responder listens for success/failure and triggers the inner handlers when the method call returns. If the method does not return an AsyncToken to attach a responder to a runtime error is logged.

I've spoken with Nahuel about getting this new DelegateInvoker class incorporated into the Mate core. He will be adding it into the Mate in_development branch. It should be available for download in the next day or so, and I'll update this entry when the class is posted.

The DelegateInvoker class is available as of revision 93 in Mate's SVN. It's currently in the in_development branch, but will eventually be moved to the trunk in a future release.

No TrackBacks

TrackBack URL: http://www.darronschall.com/mt/mt-tb.cgi/164

Leave a comment



About this Entry

This page contains a single entry by darron published on February 2, 2009 11:15 AM.

Flex 2.0.1 SDK is dying was the previous entry in this blog.

Flash Camp Atlanta 2009 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02