当前位置: 首页>>代码示例>>C#>>正文


C# Channel.Dequeue方法代码示例

本文整理汇总了C#中Channel.Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.Dequeue方法的具体用法?C# Channel.Dequeue怎么用?C# Channel.Dequeue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Channel的用法示例。


在下文中一共展示了Channel.Dequeue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendRpcMessage

    protected void SendRpcMessage(Address addr, string method, 
      string query, bool secure) {

      System.DateTime sent = System.DateTime.Now;

#if !SVPN_NUNIT
      string meth_call = RPCID + "." + method;
      Channel q = new Channel();
      q.CloseAfterEnqueue();
      q.CloseEvent += delegate(object obj, EventArgs eargs) {
        try {
          RpcResult res = (RpcResult) q.Dequeue();
          string result = (string) res.Result;

          if(method == "Ping") {
              System.DateTime recv = System.DateTime.Now;
            _times = _times.InsertIntoNew(result, recv);
            TimeSpan rtt = recv - sent;
            _ssm.UpdateLatency(result, rtt.TotalMilliseconds);
          }

          ProtocolLog.WriteIf(SocialLog.SVPNLog,
            String.Format("RPC {0} {1} {2}", addr.ToString(), method, 
            query));

        } catch(Exception e) {
          ProtocolLog.WriteIf(SocialLog.SVPNLog, e.ToString());
        }
      };

      ISender sender;
      if(!secure) {
        sender = new AHExactSender(_node.Node, addr);
      }
      else {
        sender = _node.Bso.GetSecureSender(addr);
      }
      _rpc.Invoke(sender, q, meth_call, _node.Address, query);
#endif
    }
开发者ID:ikaragkiozoglou,项目名称:brunet,代码行数:40,代码来源:SocialConnectionManager.cs

示例2: EntryCallback

    ///<summary> If half of ttl time passed, this event handler is called. AlarmEventHandler calls
    ///"DhtClient.Put" command to insert the entry to other nodes. It restarts the timer.
    /// If error occurs during ASyncPut, it retries after 30 seconds</summary>
    /// <param name="o">Entry which initiates ttl time expire event</param>
    public void EntryCallback(object o)
    {
      Entry entry = o as Entry;
      Channel returns = new Channel(1);
      returns.CloseEvent += delegate(object obj, EventArgs eargs) {
        bool success = false;
        try {
          object ret = returns.Dequeue();
          if(ret is Exception) {
            throw (ret as Exception);
          }
          success = (bool) ret;
        } catch(Exception e) {
          ProtocolLog.WriteIf(ProtocolLog.Exceptions, "EntryCallback: " + e);
          success = false;
        }

        if(success && !entry.Working) {
          entry.Timer.Stop();
          entry.Working = true;
          int time = entry.Ttl * 1000 / 2;
          entry.Timer = new SimpleTimer(EntryCallback, entry, time, time);
          entry.Timer.Start();
        } else if(!success && entry.Working) {
          entry.Timer.Stop();
          entry.Working = false;
          entry.Timer = new SimpleTimer(EntryCallback, entry, RETRY_TIMEOUT, RETRY_TIMEOUT);
          entry.Timer.Start();
        }
      };

      try {
        _dht.AsyncPut(entry.Key, entry.Value, entry.Ttl, returns);
      } catch(DhtException) {
        returns.Close();
      }
    }
开发者ID:bakriy,项目名称:brunet,代码行数:41,代码来源:RpcDhtProxy.cs

示例3: HandleEC

 public void HandleEC(bool succ, Edge e, Exception x) {
   if( succ ) {
     /*
      * Got the underlying Edge, now do the path protocol
      */ 
     Channel results = new Channel(1);
     results.CloseEvent += delegate(object q, EventArgs args) {
       try {
         RpcResult res = (RpcResult)results.Dequeue();
         object o = res.Result;
         if(o is Exception) {
           Console.WriteLine(o);
           throw (o as Exception);
         }
         //If we get here, everything looks good:
         PathEdge pe = new PathEdge(e, LocalPath, RemotePath);
         //Start sending e's packets into pe
         pe.Subscribe();
         ECB(true, pe, null);
       }
       catch(Exception cx) {
         ECB(false, null, cx);
       }
     };
     //Make sure we hear the packets on this edge:
     e.Subscribe(_pel._pem, null);
     //Now make the rpc call:
     _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath ); 
   }
   else {
     ECB(false, null, x);
   }
 }
开发者ID:johnynek,项目名称:brunet,代码行数:33,代码来源:PathEdgeListener.cs

示例4: Put

    /**
    <summary>Called by a Dht client to store data here, this supports both Puts
    and Creates by using the unique parameter.</summary>
    <remarks>Puts will store the value no matter what, Creates will only store
    the value if they are the first ones to store data on that key.  This is
    the first part of a Put operation.  This calls PutHandler on itself and
    the neighbor nearest to the key, which actually places the data into the
    store.  The result is returned to the client upon completion of the call
    to the neighbor, if that fails the data is removed locally and an exception
    is sent to the client indicating failure.</remarks>
    <param name="key">The index to store the data at.</param>
    <param name="value">Data to store at the key.</param>
    <param name="ttl">Dht lease time in seconds</param>
    <param name="unique">True if this should perform a create, false otherwise.
    </param>
    <param name="rs">The return state sent back to the RpcManager so that it
    knows who to return the result to.</param>
    <returns>True on success, thrown exception on failure</returns>
    <exception cref="Exception">Data is too large, unresolved remote issues,
    or the create is no successful</exception>
    */

    public bool Put(MemBlock key, MemBlock value, int ttl, bool unique, object rs) {
      if(value.Length > MAX_BYTES) {
        throw new Exception(String.Format(
          "Dht only supports storing data smaller than {0} bytes.", MAX_BYTES));
      }
      PutHandler(key, value, ttl, unique);
      Channel remote_put = new Channel();
      remote_put.CloseAfterEnqueue();
      remote_put.CloseEvent += delegate(Object o, EventArgs eargs) {
        object result = false;
        try {
          result = remote_put.Dequeue();
          RpcResult rpcResult = (RpcResult) result;
          result = rpcResult.Result;
          if(result.GetType() != typeof(bool)) {
            throw new Exception("Incompatible return value.");
          }
          else if(!(bool) result) {
            throw new Exception("Unknown error!");
          }
        }
        catch (Exception e) {
          lock(_sync) {
            _data.RemoveEntry(key, value);
          }
          result = new AdrException(-32602, e);
        }
        _rpc.SendResult(rs, result);
      };

      try {
        Address key_address = new AHAddress(key);
        ISender s = null;
        var structs =
        _node.ConnectionTable.GetConnections(ConnectionType.Structured);
        // We need to forward this to the appropriate node!
        if(((AHAddress)_node.Address).IsLeftOf((AHAddress) key_address)) {
          var con = structs.GetRightNeighborOf(_node.Address);
          s = con.Edge;
        }
        else {
          var con = structs.GetLeftNeighborOf(_node.Address);
          s = con.Edge;
        }
        _rpc.Invoke(s, remote_put, "dht.PutHandler", key, value, ttl, unique);
      }
      catch (Exception) {
        lock(_sync) {
          _data.RemoveEntry(key, value);
        }
        throw;
      }
      return true;
    }
开发者ID:johnynek,项目名称:brunet,代码行数:76,代码来源:TableServer.cs

示例5: AttemptToCreateOverlap

    /// <summary>First we try to find a third party we can connect with for
    /// overlap, if that is successful, we attempt to connect to him, if that
    /// is successful, we create a new tunnel edge.</summary>
    protected void AttemptToCreateOverlap(TunnelEdgeCallbackAction teca)
    {
      WaitCallback create_connection = delegate(object o) {
        Address target = o as Address;
        if(o == null) {
          FailedEdgeCreate(teca);
          return;
        }

        ConnectionList cons = _connections;
        int index = cons.IndexOf(target);
        if(index < 0) {
          FailedEdgeCreate(teca);
          return;
        }

        List<Connection> overlap = new List<Connection>(1);
        overlap.Add(cons[index]);
        CreateEdge(teca, overlap);
      };

      Channel chan = new Channel(1);
      chan.CloseEvent += delegate(object o, EventArgs ea) {
        Address target = null;
        try {
          IDictionary msg = (chan.Dequeue() as RpcResult).Result as IDictionary;
          target = _ito.EvaluatePotentialOverlap(msg);
        } catch {
        }

        if(target == null) {
          FailedEdgeCreate(teca);
        } else {
          _oco.ConnectTo(target, create_connection);
        }
      };

      ISender s = new AHExactSender(_node, teca.TunnelTA.Target);
      _node.Rpc.Invoke(s, chan, "tunnel.RequestSync");
    }
开发者ID:johnynek,项目名称:brunet,代码行数:43,代码来源:TunnelEdgeListener.cs

示例6: TraceRoute

    static void TraceRoute(IList nodes) {
      Random my_r = new Random();
      int idx0 = my_r.Next(0, nodes.Count);
      int idx1 = my_r.Next(0, nodes.Count);
      Node n0 = (Node)nodes[idx0];
      Node n1 = (Node)nodes[idx1];
      RpcManager pinger = n0.Rpc;
      Channel results = new Channel();
      Console.WriteLine("Traceroute: {0} -> {1}", n0.Address, n1.Address);
      results.EnqueueEvent += delegate(object q, EventArgs a) {
        object result = results.Dequeue();
	RpcResult r = (RpcResult)result;
	IList data = (IList)r.Result;
	int hop = 0;
	foreach(IDictionary d in data) {
          Console.WriteLine("Hop: {0} :: {1}\n  :: {2}", hop, d["node"], d["next_con"]);
	  hop++;
	}
      };
      try {
        pinger.Invoke(n0, results, "trace.GetRouteTo", n1.Address.ToString());
      }
      catch(Exception x) {
        Console.WriteLine("Exception: {0}", x);
      }
    }
开发者ID:johnynek,项目名称:brunet,代码行数:26,代码来源:BootStrapTester.cs

示例7: BenchmarkHops

    public void BenchmarkHops(int reps) {
      List<int> hops = new List<int>();
      Random my_r = new Random();
      ArrayList nodes = null;
      lock(_sync) {
        //Make a copy
        nodes = new ArrayList(_node_list);
      }
      Stack<Action> pings = new Stack<Action>();
      for(int i = 0; i < reps; i++) {
        int idx0 = my_r.Next(0, nodes.Count);
        int idx1 = my_r.Next(0, nodes.Count);
        Node n0 = (Node)nodes[idx0];
        Node n1 = (Node)nodes[idx1];
        Action ping = delegate() {
          RpcManager pinger = n0.Rpc;
          Channel results = new Channel(1);
          results.CloseEvent += delegate(object q, EventArgs a) {
            try {
              object result = results.Dequeue();
	      RpcResult r = (RpcResult)result;
	      IList data = (IList)r.Result;
              hops.Add(data.Count - 1);
            }
            catch(Exception x) {
              Console.WriteLine("target: {0}, Exception: {1}", n1.Address, x);
            }
            if( pings.Count > 0 ) {
              var next = pings.Pop();
              next();
            }
            else {
              double ave_rtt = 0;
              foreach(int s in hops) {
                ave_rtt += (double)s;     
              }
              ave_rtt /= hops.Count;
              double var = 0;
              foreach(int s in hops) {
                var += (ave_rtt - (double)s) * (ave_rtt - (double)s);
              }
              var /= hops.Count;
              var stdev = Math.Sqrt(var);
              Console.WriteLine("Average: {0} Stdev: {1} Samples: {2} Reps: {3}", ave_rtt, stdev, hops.Count, reps); 
            }
          };
          try {
            pinger.Invoke(n0, results, "trace.GetRouteTo", n1.Address.ToString());
          }
          catch(Exception x) {
            Console.WriteLine("Exception: {0}", x);
            if( pings.Count > 0 ) {
              var next = pings.Pop();
              next();
            }
            else {
              double ave_rtt = 0;
              foreach(int s in hops) {
                ave_rtt += (double)s;     
              }
              ave_rtt /= hops.Count;
              double var = 0;
              foreach(int s in hops) {
                var += (ave_rtt - (double)s) * (ave_rtt - (double)s);
              }
              var /= hops.Count;
              var stdev = Math.Sqrt(var);
              Console.WriteLine("Average: {0} Stdev: {1} Samples: {2} Reps: {3}", ave_rtt, stdev, hops.Count, reps); 
            }
          }
        };
        pings.Push(ping);
      }
      //Now pop off the first one and go:
      var first = pings.Pop();
      first();
    }
开发者ID:johnynek,项目名称:brunet,代码行数:77,代码来源:BootStrapTester.cs

示例8: GetMedianEstimation

    //protected void EstimateNetworkMean(object req_state) {
    protected void GetMedianEstimation(object obj, EventArgs eargs) {
      _median_network_size = _local_network_size;
      ConnectionTable tab = _node.ConnectionTable;
      IEnumerable structs = tab.GetConnections("structured.shortcut");
      List<Connection> cons = new List<Connection>();
      foreach (Connection c in structs) {
        cons.Add(c);
      }
      int q_size = cons.Count;
      if (q_size > 0) {
        Channel queue = new Channel(q_size);
        foreach(Connection c in structs) {
          _rpc.Invoke(c.Edge, queue, "Deetoo.getestimatedsize",0);
        }
        queue.CloseEvent += delegate(object o, EventArgs args) {
          Channel q = (Channel)o;
	  List<int> size_list = new List<int>();
	  size_list.Add(_local_network_size);
	  //int sum = _network_size1;
	  int q_cnt = q.Count;
	  for(int i = 0; i < q_cnt; i++) {
	    RpcResult rres = (RpcResult)queue.Dequeue();
	    try {
              int res = (int)rres.Result;
	      //sum += res;
	      size_list.Add(res);
	    }
	    catch (Exception e) {
              Console.WriteLine("{0} Exception caught. couldn't retrieve neighbor's estimation.",e);
	    }
	  }
	  int median_size = GetMedian(size_list);
	  //int mean_size = sum / (q_cnt);
	  //_network_size1 = mean_size;
	  _median_network_size = median_size;
	  //_rpc.SendResult(req_state,mean_size);
        };
      }
    }
开发者ID:kyungyonglee,项目名称:brunet-deetoo,代码行数:40,代码来源:DeetooHandler.cs

示例9: Ping

    static void Ping(IList nodes) {
      Random my_r = new Random();
      int idx0 = my_r.Next(0, nodes.Count);
      int idx1 = my_r.Next(0, nodes.Count);
      Node n0 = (Node)nodes[idx0];
      Node n1 = (Node)nodes[idx1];
      RpcManager pinger = n0.Rpc;
      Channel results = new Channel();
      results.EnqueueEvent += delegate(object q, EventArgs a) {
        object result = results.Dequeue();
	RpcResult r = (RpcResult)result;
        try {
	  IDictionary data = (IDictionary)r.Result;
	  Console.WriteLine("target: {0}, rtt: {1}", data["target"], data["musec"]);
        }
        catch(Exception x) {
          Console.WriteLine("target: {0}, Exception: {1}", n1.Address, x);
        }
      };
      Console.WriteLine("Pinging: {0} -> {1}", n0.Address, n1.Address);
      try {
        pinger.Invoke(n0, results, "trace.GetRttTo", n1.Address.ToString());
      }
      catch(Exception x) {
        Console.WriteLine("Exception: {0}", x);
      }
    }
开发者ID:johnynek,项目名称:brunet,代码行数:27,代码来源:BootStrapTester.cs

示例10: HandleRpc

    public void HandleRpc(ISender caller, string method, IList args, object rs) {
      if(LocalUseOnly) {
        try {
          ReqrepManager.ReplyState _rs = (ReqrepManager.ReplyState) caller;
          Node node = (Node) _rs.ReturnPath;
          if(node != _node) {
            throw new Exception();
          }
        } catch {
          AdrException e = new AdrException(-32602, new Exception("Must send from local node!"));
          _node.Rpc.SendResult(rs, e);
          return;
        }
      }

      object result = null;
      try {
        switch(method) {
          case "Create":
          {
            // Needs to be Async so we don't deadlock!
            MemBlock key = MemBlock.Reference((byte[]) args[0]);
            MemBlock value = MemBlock.Reference((byte[]) args[1]);
            int ttl = (int) args[2];
            Channel returns = new Channel(1);
            returns.CloseEvent += delegate(object o, EventArgs eargs) {
              _node.Rpc.SendResult(rs, returns.Dequeue());
            };
            _dht.AsyncCreate(key, value, ttl, returns);
            return;
          }
          case "Put":
          {
            // Needs to be Async so we don't deadlock!
            MemBlock key = MemBlock.Reference((byte[]) args[0]);
            MemBlock value = MemBlock.Reference((byte[]) args[1]);
            int ttl = (int) args[2];
            Channel returns = new Channel(1);
            returns.CloseEvent += delegate(object o, EventArgs eargs) {
              _node.Rpc.SendResult(rs, returns.Dequeue());
            };
            _dht.AsyncPut(key, value, ttl, returns);
            return;
          }
          case "Get":
          {
            // Needs to be Async so we don't deadlock!
            MemBlock key = MemBlock.Reference((byte[]) args[0]);
            Channel returns = new Channel();
            returns.CloseEvent += delegate(object o, EventArgs eargs) {
              Hashtable []results = new Hashtable[returns.Count];
              int pos = 0;
              while(returns.Count > 0) {
                results[pos++] = (Hashtable) returns.Dequeue();
              }
              _node.Rpc.SendResult(rs, results);
            };
            _dht.AsyncGet(key, returns);
            return;
          }
          case "BeginGet":
          {
            MemBlock key = MemBlock.Reference((byte[]) args[0]);
            result = BeginGet(key);
            break;
          }
          case "ContinueGet":
          {
            MemBlock token = MemBlock.Reference((byte[]) args[0]);
            ContinueGet(token, rs);
            return;
          }
          case "EndGet":
          {
            MemBlock token = MemBlock.Reference((byte[]) args[0]);
            EndGet(token);
            result = true;
            break;
          }
        }
      } catch (Exception e) {
        result = new AdrException(-32602, e);
      }
      _node.Rpc.SendResult(rs, result);
    }
开发者ID:johnynek,项目名称:brunet,代码行数:85,代码来源:RpcDht.cs

示例11: HandleRpc

        /**
          * <summary>This is the only method declared by IRpcHandler.  All xml rpc calls
          * which start with ("HwRpc.") will arrive here. HandleRpc creates a channel to send
          * result to the client. If Close event occurs at the channel, it calls RpcManager.SendResult
          * It also forwards Rpc call to other end points, which the user registered manually.
          * Rpc call inside the brunet node has prefix "HW."
          * "HW" handler is defined in HelloWorldDataHandler class</summary>
          * @param caller the ISender that sends to the Node that made the RPC call
          * @param method the part after the first "." in the method call
          * @param arguments a list of arguments passed
          * @param request_state used to send the response via RpcManager.SendResult
          */
        public void HandleRpc(ISender caller, string method, IList arguments, object request_state)
        {
            Console.WriteLine("inside handle RPC caller = " + caller + "\t" + "method = " + method);

              Channel returns = new Channel(1);
              returns.CloseEvent += delegate(object o, EventArgs eargs) {
            RpcResult result;
            result = (RpcResult)returns.Dequeue();
            _app_node.Node.Rpc.SendResult(request_state, result.Result);
              };

              foreach(Address a in _addr){
            AHSender sender = new AHSender(_app_node.Node, a, 3);
            MemBlock key = MemBlock.Reference((byte[]) arguments[0]);
            _app_node.Node.Rpc.Invoke(sender, returns, "HW.Test", key);
              }
        }
开发者ID:kyungyonglee,项目名称:BootstrapApp,代码行数:29,代码来源:HelloWorldRpcSCHandler.cs

示例12: Test

 public void Test() {
   Channel q = new Channel(1);
   rpc.Invoke(null, q, "test.test");
   RpcResult res = (RpcResult) q.Dequeue();
   bool val = (bool) res.Result;
   Assert.IsTrue(val, "Reflection Test");
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:7,代码来源:MockRpcManager.cs

示例13: Start

      public void Start()
      {
        Channel returns = new Channel();
        returns.EnqueueEvent += delegate(object o, EventArgs ea) {
          while(returns.Count > 0) {
            Hashtable result = null;
            try {
              result = returns.Dequeue() as Hashtable;
            } catch {
              continue;
            }

            byte[] res = result["value"] as byte[];
            if(res != null) {
              Results.Enqueue(MemBlock.Reference(res));
            }
          }
          if(_enqueue != null) {
            _enqueue(this, EventArgs.Empty);
          }
        };

        returns.CloseEvent += delegate(object o, EventArgs ea) {
          if(_close != null) {
            _close(this, EventArgs.Empty);
          }
          _done = true;
        };

        Dht dht = new Dht(Node, 3, 20);
        dht.AsyncGet(_key, returns);
      }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:32,代码来源:Simulator.cs


注:本文中的Channel.Dequeue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。