Inheritance: SimpleSource, IDataHandler
Ejemplo n.º 1
0
    //Methods:

    protected PathELManager(EdgeListener el, bool thread) {
      _el = el;
      _sync = new object();
      _edges = new List<Edge>();
      _unannounced = new Dictionary<Edge, PathEdge>();
      _pel_map = new Dictionary<string, PathEdgeListener>();
      //Use the reqrep protocol with a special prefix:
      _rrm = new ReqrepManager("PathELManager:" + el.ToString(), PType.Protocol.Pathing);
      _rrm.Subscribe(this, null);
      Rpc = new RpcManager(_rrm);
      Rpc.AddHandler("sys:pathing", this);
      _el.EdgeEvent += HandleEdge;
      _running = true;

      if(thread) {
        _timer_thread = new Thread(
          delegate() {
            int counter = 0;
            int max_counter = EDGE_PERIOD / 1000;
            while(_running) {
              Thread.Sleep(1000);
              ReqrepTimeoutChecker();
              if(++counter == max_counter) {
                counter = 0;
                EdgeTimeoutChecker();
              }
            }
          }
        );

        _timer_thread.IsBackground = true;
        _timer_thread.Start();
      }
    }
Ejemplo n.º 2
0
 public BrunetRpc() {
   _rrm = new ReqrepManager("BrunetRpc");
   _rrm.Subscribe(this, null);
   Rpc = new RpcManager(_rrm);
   IPHandler = new IPHandler();
   IPHandler.Subscribe(this, null);
   _running = 1;
   _timer = new Thread(TimerThread);
   _timer.IsBackground = true;
   _timer.Start();
 }
Ejemplo n.º 3
0
 public SymphonySecurityOverlord(Node node, RSACryptoServiceProvider rsa,
     CertificateHandler ch, ReqrepManager rrman) :
   base(rsa, ch, rrman)
 {
   _ch.AddCertificateVerification(new SymphonyVerification(node.ConnectionTable));
   _node = node;
   _address_to_sa = new Dictionary<Address, SecurityAssociation>();
   _sa_to_address = new Dictionary<SecurityAssociation, Address>();
   lock(_sync) {
     _node.Rpc.AddHandler("Security", this);
   }
 }
Ejemplo n.º 4
0
 public ProtocolSecurityOverlord(Node node,
     RSACryptoServiceProvider rsa,
     ReqrepManager rrman,
     CertificateHandler ch) :
     base(rsa, rrman, ch)
 {
   _node = node;
   _address_to_sa = new Dictionary<Address, SecurityAssociation>();
   _sa_to_address = new Dictionary<SecurityAssociation, Address>();
   lock(_sync) {
     _node.Rpc.AddHandler("Security", this);
   }
 }
Ejemplo n.º 5
0
 public void HandleError(ReqrepManager man, int message_number,
                ReqrepManager.ReqrepError err, ISender ret_path, object state) {
   _rrman.StopRequest(message_number, this);
   RpcManager my_rpc = System.Threading.Interlocked.Exchange(ref _rpc, null);
   if( my_rpc != null ) {
     //We have not sent any reply yet:
     my_rpc.SendResult( _req_state,
                 new Exception(String.Format("Error: {0} from: {1}", err, ret_path)));
   }
 }
Ejemplo n.º 6
0
 public bool HandleReply(ReqrepManager man, ReqrepManager.ReqrepType rt,
                int mid,
                PType prot,
                MemBlock payload, ISender returnpath,
                ReqrepManager.Statistics statistics,
                object state) {
   DateTime reply_time = DateTime.UtcNow;
   
   ListDictionary res_dict = new ListDictionary();
   AHSender ah_rp = returnpath as AHSender;
   if( ah_rp != null ) {
     res_dict["target"] = ah_rp.Destination.ToString();
   }
   //Here are the number of microseconds
   res_dict["musec"] = (int)( 1000.0 * ((reply_time - _start_time).TotalMilliseconds) );
   //Send the RPC result now;
   RpcManager my_rpc = System.Threading.Interlocked.Exchange(ref _rpc, null);
   if( my_rpc != null ) {
     //We have not sent any reply yet:
     my_rpc.SendResult(_req_state, res_dict);
   }
   return false;
 }
Ejemplo n.º 7
0
 public EchoSendHandler(Node n, ISender dest, object req_state) {
   _rrman = n.Rrm;
   _rpc = n.Rpc;
   _req_state = req_state;
   _dest = dest;
 }
Ejemplo n.º 8
0
 /** 
  * Static method to create ReqrepManager objects
  * @param context the object that this manager works for
  */
 public static ReqrepManager GetInstance(string context) {
   lock(_inst_tab_sync) {
     var inst = _instance_table.GetValue(context);
     if(null == inst) {
       //This puts the item into _instance_table:
       inst = new ReqrepManager(context);
     }
     return inst;
   }
 }
Ejemplo n.º 9
0
 public RpcResult(ISender ret_path, object res, ReqrepManager.Statistics stats) {
   _ret_path = ret_path;
   _result = res;
   _statistics = stats;
 }
Ejemplo n.º 10
0
 /**
  * When an error comes in, this handles it
  */
 public void HandleError(ReqrepManager man, int message_number,
                  ReqrepManager.ReqrepError err, ISender ret_path, object state)
 {
   Exception x = null;
   RpcRequestState rs = (RpcRequestState) state;
   Channel bq = rs.Results;
   switch(err) {
       case ReqrepManager.ReqrepError.NoHandler:
         x = new AdrException(-32601, "No RPC Handler on remote host");
         break;
       case ReqrepManager.ReqrepError.HandlerFailure:
         x = new AdrException(-32603, "The remote RPC System had a problem");
         break;
       case ReqrepManager.ReqrepError.Timeout:
         //In this case we close the Channel:
         if( bq != null ) { bq.Close(); }
         break;
       case ReqrepManager.ReqrepError.Send:
         if( rs.RpcTarget is Edge ) { 
           Edge e = (Edge)rs.RpcTarget;
           //This definitely won't get any more responses:
           if( e.IsClosed && bq != null ) { bq.Close(); } 
         }
         //We had some problem sending, but ignore it for now
         break;
   }
   if( x != null && (bq != null) ) {
     RpcResult res = new RpcResult(ret_path, x);
     bq.Enqueue(res);
   }
 }
Ejemplo n.º 11
0
  /**
   * Implements the IReplyHandler (also provides some light-weight statistics)
   */
  public bool HandleReply(ReqrepManager man, ReqrepManager.ReqrepType rt,
			  int mid, PType prot, MemBlock payload, ISender ret_path,
			  ReqrepManager.Statistics statistics, object state)
  {
    RpcRequestState rs = (RpcRequestState) state;
    //ISender target = rs.RpcTarget;
    Channel bq = rs.Results;
    if( bq != null ) {
      object data = AdrConverter.Deserialize(payload);
      RpcResult res = new RpcResult(ret_path, data, statistics);
      //handle possible exception:
      try {
        bq.Enqueue(res);
        //Keep listening unless the queue is closed
        return (!bq.Closed);
      }
      catch(System.InvalidOperationException) {
        //The queue is closed, stop listening for more results:
        return false;
      }
    }
    else {
      //If they didn't even pass us a queue, I guess they didn't want to
      //listen too long
      return false;
    }
  }
Ejemplo n.º 12
0
 public RpcManager(ReqrepManager rrm) {
   _sync = new Object();
   _rrman = rrm;
   _method_cache = new Cache(CACHE_SIZE);
   _method_handlers = new Hashtable();
 }
Ejemplo n.º 13
0
 /** 
  * Static method to create ReqrepManager objects
  * @param context the object that this manager works for
  */
 public static ReqrepManager GetInstance(object context) {
   lock(_inst_tab_sync) {
     ReqrepManager inst;
     if( !_instance_table.TryGetValue(context, out inst)) {
       //This puts the item into _instance_table:
       inst = new ReqrepManager(context);
     }
     return inst;
   }
 }
Ejemplo n.º 14
0
 protected MockRpcManager(ReqrepManager rrm) : base(rrm) { }
Ejemplo n.º 15
0
  public RpcManager(ReqrepManager rrm) {
    _sync = new Object();
    _rrman = rrm;
    _method_cache = new Cache(CACHE_SIZE);
    _method_handlers = new Hashtable();

#if DAVID_ASYNC_INVOKE
    _rpc_command = new BlockingQueue();
    _rpc_thread = new Thread(RpcCommandRun);
    _rpc_thread.IsBackground = true;
    _rpc_thread.Start();
#endif
  }