Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Remote Objects  (Read 24024 times)
giuly19
Newbie
*
Posts: 7


View Profile Email
« on: January 30, 2009, 05:15:38 »

Is it ok to have all the remote objects declared static in a separate class instead of declaring them into the proxies? I thought of this because I might need at some point to access the same remote object in different proxies. Thanks!
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: January 30, 2009, 06:59:34 »

Sounds like a use case for a delegate class which multiple proxies can utilize. I know there's a few threads around regarding this. Try a search for "delegate".
Logged
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #2 on: February 02, 2009, 04:20:58 »

ok. so I have a delegate class now, in which I've declared all of my remote objects. I register it at startup, and retrieve it in every mediator I need data. Is it ok to do that or do I have to register proxies that will call my Delegate Class. thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: February 02, 2009, 07:04:35 »

You don't want this delegate in your mediators. Instead call them from your proxies and send notifications to the mediators when data is loaded.

-=Cliff>
Logged
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #4 on: February 03, 2009, 06:32:41 »

Ok. The Delegate Class I used is a Proxy.  How do the proxies, that need the data to send it to mediators, know when the data arrives into the Delegate Class from .Net (because they can't listen to Notifications) ?  Using a Command for each proxy results in a big number of commands. Let me know if I should use another approach. Thanks!
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #5 on: February 03, 2009, 10:42:25 »

Ok. The Delegate Class I used is a Proxy.  How do the proxies, that need the data to send it to mediators, know when the data arrives into the Delegate Class from .Net (because they can't listen to Notifications) ?  Using a Command for each proxy results in a big number of commands. Let me know if I should use another approach. Thanks!

I generally make my delegates static classes that are referenced in my interested proxies or run a single command with a switch/case that pushes the data to the appropriate proxies based on the information received.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #6 on: February 04, 2009, 08:26:22 »

Is it ok like this ? :

From view, an event is dispatched to retrieve data, it is caught by a listener defined in mediator, which calls a proxy, which finally will call the Delegate Class in which I have all my remote objects. When data is received from .Net, Delegate Class will send a notification , which is caught by the mediator. Or should I use a Command that, with switch/case depending on the type of the notification, will send a different notification (finally will be caught by a mediator) with the data in body ?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: February 04, 2009, 10:02:51 »

The delegate class should return the data to the proxy, which manages access to that data for the rest of the app. Then the proxy sends a notification that the mediator is interested in. It can send the data along in the body of the note or the mediator can retrieve the proxy and get the data when it receives the note.

-=Cliff>
Logged
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #8 on: February 05, 2009, 01:21:40 »

The delegate class should return the data to the proxy, which manages access to that data for the rest of the app. Then the proxy sends a notification that the mediator is interested in. It can send the data along in the body of the note or the mediator can retrieve the proxy and get the data when it receives the note.

-=Cliff>

This is what I want to ask you. How do I return data from delegate class to proxy (which is a proxy to proxy communication) so that the proxy to know when to send the notification to the mediator ?
« Last Edit: February 05, 2009, 01:24:41 by giuly19 » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: February 05, 2009, 06:27:37 »

Make the proxy implement IResponder and have the Proxy pass itself to the delegate with the call. The delegate should set the Proxy as the responder for the call, not itself. So the response comes directly back to the Proxy not the delegate.

-=Cliff>
Logged
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #10 on: February 05, 2009, 12:40:10 »

Make the proxy implement IResponder and have the Proxy pass itself to the delegate with the call. The delegate should set the Proxy as the responder for the call, not itself. So the response comes directly back to the Proxy not the delegate.

-=Cliff>

public class Delegate{
   
   private var responder:IResponder;
   private ro:RemoteObject;
   
   public function Delegate(responder:IResponder)
   {
      this.responder = responder;
      ro = new RemoteObject("fluorine");
      ro.source = "NameSpace.ClassLibrary";   
   }
   
   public function getData():void
   {
      var token:AsyncToken = ro.DotNetFunction();
      token.addResponder(responder);
   }
}


public class MyProxy extends Proxy implements IProxy,IResponder
{
   ...

   public function callDelegate():void
   {
      var delegate : Delegate =new Delegate( this );
             delegate.getData();
        }
       
        public function result( rpcEvent : Object ) : void
        {
            data = rpcEvent.result;
        }
       
        public function fault( rpcEvent : Object ) : void
        {
            data = new Object();
        }

}


Is it ok like that ? It's similar with CafeTownsend but I am using a remote object with source to .NET to get data, instead of a HttpService from an XML file.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: February 06, 2009, 06:23:51 »

That's it.

-=Cliff>
Logged
newtriks
Courseware Beta
Full Member
***
Posts: 23


 - newtriks
View Profile WWW Email
« Reply #12 on: February 08, 2009, 07:57:00 »

Here is an example of this exact scenario, ensure you check the Manifold as a lot of the queries made are uploaded already there answering your question.

http://trac.puremvc.org/Demo_AS3_Flex_CF_QueryCFC
Logged
giuly19
Newbie
*
Posts: 7


View Profile Email
« Reply #13 on: February 26, 2009, 03:10:36 »

One more question:

Lets say that in MyProxy I have 2 functions that call different methods from Delegate:
 public function callDelegate1():void
   {
      var delegate : Delegate =new Delegate( this );
             delegate.getData1();
        }

 public function callDelegate2():void
   {
      var delegate : Delegate =new Delegate( this );
             delegate.getData2();
        }

  public function result( rpcEvent : Object ) : void
        {
            data = rpcEvent.result;
        }
       
        public function fault( rpcEvent : Object ) : void
        {
            data = new Object();
        }

The Delegate class notifies MyProxy when data is retrieved. The result function is called. If different type of results are expected it's ok, I've resolved that by checking the rpcEvent.result type (one ArrayCollection and the other XML). Now comes the question:
If both functions from delegate class retrieve the same type of data ? How do I handle this ? I thought of something old school like having a property in MyProxy that is set to a specific value when a function is called from Delegate:
private var typeOfResult:String = "";

 public function callDelegate1():void
   {
      var delegate : Delegate =new Delegate( this );
             delegate.getData1();
             typeOfResult = "getData1";
        }

 public function callDelegate2():void
   {
      var delegate : Delegate =new Delegate( this );
             delegate.getData2();
              typeOfResult = "getData2";
        }

  public function result( rpcEvent : Object ) : void
        {
            switch(typeOfResult){
           
            case "getData1": ....
            case "getData2": ....           
}
        }

If there is another approach let me know. thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #14 on: February 26, 2009, 09:19:10 »

Research the use of the AsyncToken returned from service calls in Flex. Have the delegate return the token to the proxy when it makes the call. Have the proxy set dynamic properties on the token that give a clue about the context in which the call was made.

Later, the ResultEvent will have a token property with your values that were set on it so you can figure out what you're supposed to do with the result data.

-=Cliff>
Logged
Pages: [1]
Print