Brunet.Messaging.RpcManager.Invoke C# (CSharp) Метод

Invoke() публичный Метод

public Invoke ( ISender target, Channel q, string method ) : void
target ISender
q Brunet.Concurrent.Channel
method string
Результат void
  virtual public void Invoke(ISender target, Channel q, string method,
                              params object[] args)
  {
    //build state for the RPC call
    RpcRequestState rs = new RpcRequestState();
    rs.Results = q;
    rs.RpcTarget = target;

    object[] rpc_call = new object[2];
    rpc_call[0] = method;
    if( args != null ) {
      rpc_call[1] = args;
    }
    else {
      //There are no args, which we represent as a zero length list
      rpc_call[1] = new object[0];
    }
    
    AdrCopyable req_copy = new AdrCopyable(rpc_call);
#if RPC_DEBUG
    Console.Error.WriteLine("[RpcClient: {0}] Invoking method: {1} on target: {2}",
                     _rrman.Info, method, target);
#endif
    ICopyable rrpayload = new CopyList( PType.Protocol.Rpc, req_copy ); 
    int reqid = _rrman.SendRequest(target, ReqrepManager.ReqrepType.Request,
                                   rrpayload, this, rs);
  
    //Make sure we stop this request when the queue is closed.
    if( q != null ) {
      try {
        q.CloseEvent += delegate(object qu, EventArgs eargs) {
          _rrman.StopRequest(reqid, this);
       };
      }
      catch {
        if(q.Closed) {
          _rrman.StopRequest(reqid, this);
        }
        else {
          throw;
        }
      }
    }
  }

Usage Example

Пример #1
0
 /*** Gracefully close this connection, if it is not already disconnected.
  * Idempotent (calling it twice is the same as once).
  * @return the old state, new state pair.
  */
 public Pair<ConnectionState,ConnectionState> Close(RpcManager rpc, string reason) {
   var old_new = Abort();
   if( old_new.First.Disconnected != true ) {
     //Now try to tell the other node:
     var close_info = new ListDictionary(); 
     if( reason != String.Empty ) {
       close_info["reason"] = reason;
     }
     Edge e = old_new.Second.Edge;
     var results = new Channel(1);
     //Either the RPC call times out, or we get a response.
     results.CloseEvent += delegate(object o, EventArgs args) {
       e.Close();
     };
     try { rpc.Invoke(e, results, "sys:link.Close", close_info); }
     catch { e.Close(); }
   }
   return old_new;
 }