Re: New RelayResponder in AS 2.0 Components

Sebastien Blanc <[email protected]>
Newsgroups gmane.comp.java.openamf.user
Organization ALCATEL USA
Message-ID <[email protected]>
Hi,
the following is how I use it today on client side. I don't do anything
specific on my app srv side.
hope this'll help,
seb.

* CreateNeClip.as

  m_controller.createNe(neId, type, release, userLabel, acd, tlocation,
  userName, password, hostname, port,
  pa, sa, this);
 }

* TopoController.as

 public function createNe(neId:Number, type:String, release:String,
userLabel:String, acd:String, tlocation:String,
   userName:String, password:String, hostname:String, port:Number,
  pa:String, sa:String, clientContext:Object):Void
 {
  Util.debug("TopoController::createNe with userLabel " + userLabel + "
---");
  // NOTE: WE SHOULD CHECK THE STATE OF THE OBJECT HERE FIRST
  m_delegate.createNE(new
TopoRemotingContext(this,"createNe",arguments,"createNeCbk","errorCbk",clientContext),

       Number(neId), type, release, userLabel, acd, tlocation, userName,
password, hostname, port, pa, sa);
 }

 public function createNeCbk(res:RecordSet, context:Object):Void
 {
  if ((context != null) && (context != undefined))
  {
   var ctx:TopoRemotingContext = TopoRemotingContext(context);
   var msg:String = "TopoController::" + ctx.callingFunc + " SUCCESS for
";
   msg += arg2string(ctx.callingArgs);
   Util.debug(msg);
  }

  for (var i = 0; i < res.length; i++)
  {
   var row:Object = res.getItemAt (i);
   m_nesModel.addItem(row);
  }
  // note that reacting on events would be more generic, but event does
not contain all dbValue info for now (only neId)
  /*
  var it:Iterator = res.getIterator();
  while (it.hasNext())
  {
   m_nesModel.addItem(it.next());
  }
  */
 }

* TopoDelegate

 public function createNE (tRspd:TopoRemotingContext, neId:Number,
type:String, release:String, userLabel:String, acd:String,
tlocation:String, userName:String, password:String, hostname:String,
port:Number,
 pa:String, sa:String):Void
 {
  s_log.logDebug ("TopoDelegate::createNE " + neId);
  Object.registerClass ("com.alcatel.gem.ems.ne.interfaces.NEDBValue",
NEDBValue);
  Object.registerClass ("com.alcatel.gem.ems.tl1.types.TelnetNEAddress",
TelnetNEAddress);
  Object.registerClass ("com.alcatel.gem.ems.tl1.types.NEAddress",
NEAddress);
  var o:Object = new NEDBValue ();
  o.setNeId (Number (neId));
  // problem here ? o.type is gonna be used per OpenAMF
  //o.type = "com.alcatel.gem.ems.ne.interfaces.NEDBValue";
  o.setType (type);
  o.setRelease (release);
                o.setLocation (tlocation);
  o.setUserLabel (userLabel);
  o.setAccessControlDomain (acd);
  var ta:TelnetNEAddress = new TelnetNEAddress ();
  ta.setPort (3082);
  o.setPrimaryAddress (null);
  o.setSecondaryAddress (null);
  var pc:PendingCall = m_service.createNEs ([o]);
  pc.responder = tRspd;
 }


* TopoRemotingContext.as

import mx.remoting.RecordSet;
import mx.rpc.Responder;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
import mx.rpc.Fault;
import com.alcatel.gem.web.topo.TopoControllerIF;

/**
 This is a responder object that relays result and fault calls to a
corresponding
 function on the specified object.

 @tiptext Dispatches results from a method invocation to user defined
methods
*/
class com.alcatel.gem.web.topo.TopoRemotingContext extends Object
implements Responder
{
 private var m_controller:TopoControllerIF;
 private var m_callingFunc:String;
 private var m_callingArgs:Array;
 private var m_onFault:String;
 private var m_onResult:String;
 private var m_clientContext:Object;

 // Members to force the complete loading of RecordSet before invoking the
callback if needed
 private var m_partialRecordSet:RecordSet = null;
 private var m_waitingPartialRecordSetHack:Number = -1;

 /**
     Constructs an instance of the relay that will call the specified
methods
     for result or fault on a given object.

     @param resp Object Object that will handle the fault or result calls
     @param resultFunc String String containing the name of the function
to call, when result is recieved.
     @param faultFunc String containing the name of the function to call,
when a fault is recieved.
     @tiptext Creates a new TopoResponser
     @helpid 4492
 */
 function TopoRemotingContext (resp:TopoControllerIF, callingFunc:String,
callingArgs:Array, resultFunc:String, faultFunc:String,
clientContext:Object)
 {
  super ();
  m_controller = resp;
  m_callingFunc = callingFunc;
  m_callingArgs = callingArgs
  m_onFault = faultFunc;
  m_onResult = resultFunc;
  m_clientContext = clientContext;
 }

 /**
  * return the name of the calling method
  */
 function get callingFunc():String
 {
  return m_callingFunc;
 }

 /**
  * return the argument of the calling method
  */
 function get callingArgs():Array
 {
  return m_callingArgs;
 }

 /**
  * return the client data
  */
 function get clientContext():Object
 {
  return m_clientContext;
 }

 /*
   When a fault in recieved, Fault Handler is called. onFault dispatches
the fault message.
   @param fault Object  contains information of the fault recieved. This
includes specified code, message, and details
 */
 function onFault (oopsEvent:mx.rpc.FaultEvent):Void
 {
  // m_controller[m_onFault].apply(m_controller,
Fault(oopsEvent.fault).faultcode, this);
  m_controller[m_onFault](Fault(oopsEvent.fault).faultcode, this);
 }

 /*
     Result Handler is called when a result is recieved. onResult
dispatches the result message
  @param result reference to the result after successfult method
invocation
 */
 function onResult (resEvent:mx.rpc.ResultEvent):Void
 {
  if (resEvent.result instanceof RecordSet)
  {
   var waited:RecordSet = RecordSet(resEvent.result);
   if (waited.isFullyPopulated())
   {
    m_controller[m_onResult](waited, this );
   }
   else
   {
    m_partialRecordSet = waited;
    waited.setDeliveryMode("fetchAll", 50);
    m_waitingPartialRecordSetHack =
setInterval(checkPartialRecordSetState, 500, this);
   }
  }
  else
  {
   m_controller[m_onResult](resEvent.result, this );
  }
 }

 function checkPartialRecordSetState(remotingContext:TopoRemotingContext)
 {
  var waited:RecordSet = remotingContext.m_partialRecordSet;
  if (waited.isFullyPopulated())
  {
   clearInterval(remotingContext.m_waitingPartialRecordSetHack);
   remotingContext.m_controller[remotingContext.m_onResult](waited,
remotingContext );
   remotingContext.m_partialRecordSet = null;
  }
 }
}

Leif Wells wrote:

> All,
>
> I am preparing a presentation for the Atlanta Macromedia User Group
> that reviews the new AS 2.0 Remoting Components. There are a lot of
> really cool features here to cover.
>
> I was wondering if anyone has gotten the new code to work with
> OpenAMF, specifically if people are using the RelayResponder Class?
>
> Also, what needs to happen on the Java side for the RelayResponder
> Class to actually make Flash throw an error? Perhaps I am not
> understanding *exactly* how the RelayResponder actually works. Since I
> am not a Java programmer, I don't exactly understand how to tell a
> programmer how to utilize it.
>
> My fruitful efforts will result in a new OpenAMF demo file that uses
> AS 2.0 code which I will share with everyone after my presentation.
>
> Leif
> Manager, Atlanta Macromedia User Group
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> Openamf-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openamf-user
Sebastien.Blanc.vcf (text/x-vcard, 713 B)
begin:vcard 
n:BLANC;SEBASTIEN
tel;fax:972 519 3781
tel;work:972 519 4880
x-mozilla-html:FALSE
org:Alcatel USA
adr:;;;;;;
version:2.1
email;internet:[email protected]
note;quoted-printable:THIS TRANSFER OF COMMODITIES, TECHNOLOGY OR SOFTWARE IF FROM THE UNITED=0D=0ASTATES IS AN EXPORT IN ACCORDANCE WITH THE U.S. EXPORT ADMINISTRATION=0D=0AREGULATIONS. DIVERSION CONTRARY TO U.S. LAW PROHIBITED. THE EXPORT OR=0D=0ARE-EXPORT (FURTHER TRANSFER) OF SUCH COMMODITIES, TECHNOLOGY, SOFTWARE=0D=0AOR PRODUCTS MADE FROM SUCH TECHNOLOGY, IS PROHIBITED WITHOUT PROPER=0D=0AAUTHORIZATION(S) FROM THE U.S. DEPARTMENT OF COMMERCE OR OTHER =0D=0AAPPROPRIATE U.S. GOVERNMENT AGENCY(S). 
fn:SEBASTIEN BLANC
end:vcard
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.