Steven,
With the help of Macromedia Consulting Group's FAST product, I've almost
completed my implementation. Here is what I have so far...
I created MyServiceLocator which extends ServiceLocator. In
MyServiceLocator, I override getService and inject an invoke method on
the service object like so:
public function getService(serviceId:String):Object
{
var service:Object = super.getService(serviceId);
service.invoke = function(methodName, methodParameters) {
var call = service[methodName].apply(null,
arguments.slice(1));
var callback = function(call) {
call.timedOut = true;
var event = Object();
event.call = call;
event.type = "fault";
event.fault = {faultcode:"Server.TimeOut",
faultstring:"The request timed out."};
call.faultHandler(event);
};
call.timer = setInterval(callback, 5000, call);
return call;
};
return service;
}
Now, in getService's injected invoke method, I create a callback
function which is called when the request times out. In this function, I
set the timedOut property and invoke the call's faultHandler() method
with my Server.TimeOut fault.
I also created a ServiceCommand class that implements the Command and
Responder interfaces. This is needed so I can call clearInterval() on
the timer in execute, onResult and onFault. onResult has some logic
which checks for event.call.timedOut incase a result is returned after a
time out. Now all a command needs to do to repond to a time out is look
for Server.TimeOut in event.fault.faultcode.
With all that said, this implementation forces the developer to change
the way he or she invokes the remote service. Instead of
service.method(arg1[, arg2] ...), they need service.invoke("method",
arg1[, arg2] ...); What do you think about this limitation?
--
Todd Boland
Charged Software
--- In [email protected], "Steven Webster" <[EMAIL PROTECTED]> wrote:
> Hi Todd,
>
> Glad to see you're taking a stab at this; John Bennett of Macromedia
> Consulting implements a neat solution for handling timeouts in the
> Macromedia Consulting framework that was announced recently on
> www.macromedia.com/devnet/flex/
>
> Personally, I think the handling of timeouts/retries etc, would best be
> abstracted in the ServiceLocator; you would define on a service the policy
> for timeout and retry, the business delegate would blindly invoke methods on
> services, and the service locator would handle retries and timeouts on
> behalf of the business delegate. If the service failed catastrophically (ie
> max retries/etc) then a fault could be passed back to the delegate (and the
> commands if needs be).
>
> The reason we didn't implement this ourselves in Cairngorm, was simply to
> keep the framework simple for most people; but if you implement this scheme
> in the ServiceLocator, I'd be keen for you to share your implementation with
> us ?
>
> I'd recommend pushing this functionality down into the ServiceLocator rather
> than up into the Command ... Thoughts ?
>
> Glad to see you thinking on this,
>
> Best,
>
> Steven
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of charged2885
> Sent: 08 June 2005 18:04
> To: [email protected]
> Subject: [flexcoders] Service Call Timeouts in Cairngorm
>
> I'm seeking opinions on implementing service timeouts into a caingorm-based
> application.
> here's what i'm thinking:
>
> I will create a new interface called Timeout which defines a single method:
> onTimeout. The Commands which implement the Responder interface must also
> implement the Timeout interface. When the command is executed, i will set a
> timer (in the execute method) which will be unset once the onResult or
> onFault methods of the responder interface are called. if it is not unset in
> say 5 seconds, an EVENT_TIMEOUT Event will be dispatched with the original
> Event in the Event's data property.
>
> how have others implemented this? if so, how does it compare?
>
> i'm new to flex and actionscript so i'd love to hear some feedback.
>
> todd
>
>
>
>
>
> Yahoo! Groups Links
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/