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


C# Address.ToMemBlock方法代码示例

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


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

示例1: SimulatorCache

 /// Simulator != thread-safe!
 protected static Address SimulatorCache(Address a) {
   int idx = NumberSerializer.ReadInt(a.ToMemBlock(), 0);
   Address tmp = _cache.GetValue(idx);
   if(a.Equals(tmp)) {
     return tmp;
   }
   _cache.Replace(idx, a);
   return a;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:10,代码来源:AddressParser.cs

示例2: CreateInstance

 /**
  * Factory method to reduce memory allocations by caching
  * commonly used NodeInfo objects
  */
 public static NodeInfo CreateInstance(Address a) {
   //Read some of the least significant bytes out,
   //AHAddress all have last bit 0, so we skip the last byte which
   //will have less entropy
   MemBlock mb = a.ToMemBlock();
   ushort idx = (ushort)NumberSerializer.ReadShort(mb, Address.MemSize - 3);
   NodeInfo ni = _mb_cache[idx];
   if( ni != null ) {
     if (a.Equals(ni._address)) {
       return ni;
     }
   }
   ni = new NodeInfo(a);
   _mb_cache[idx] = ni;
   return ni;
 }
开发者ID:xujyan,项目名称:brunet,代码行数:20,代码来源:NodeInfo.cs

示例3: Node

    /**
     * Create a node with a given local address and
     * a set of Routers.
     * @param addr Address for the local node
     * @param realm the Realm or Namespace this node belongs to
     */

    protected Node(Address addr, string realm)
    {
      //Start with the address hashcode:

      _sync = new Object();
      lock(_sync)
      {
        DemuxHandler = new DemuxHandler();
        /*
         * Make all the hashtables : 
         */
        _local_add = AddressParser.Parse( addr.ToMemBlock() );
        _realm = String.Intern(realm);
        
        /* Set up the heartbeat */
        _heart_period = 500; //500 ms, or 1/2 second.
        _heartbeat_handlers = new Dictionary<EventHandler, Brunet.Util.FuzzyEvent>();

        _task_queue = new NodeTaskQueue(this);
        _packet_queue = new BCon.LFBlockingQueue<IAction>();

        _running = 0;
        _send_pings = 1;
        _LOG = ProtocolLog.Monitor.Enabled;

        _connection_table = new ConnectionTable(new DefaultERPolicy(addr));
        _connection_table.ConnectionEvent += this.ConnectionHandler;
        LockMgr = new ConnectionLockManager(_connection_table);

        //We start off offline.
        _con_state = Node.ConnectionState.Offline;
        
        /* Set up the ReqrepManager as a filter */
        _rrm = new ReqrepManager(this.ToString());
        DemuxHandler.GetTypeSource(PType.Protocol.ReqRep).Subscribe(_rrm, null);
        _rrm.Subscribe(this, null);
        this.HeartBeatEvent += _rrm.TimeoutChecker;
        /* Set up RPC */
        _rpc = new RpcManager(_rrm);
        DemuxHandler.GetTypeSource( PType.Protocol.Rpc ).Subscribe(_rpc, null);
        //Add a map-reduce handlers:
        _mr_handler = new MR.MapReduceHandler(this);
        //Subscribe it with the RPC handler:
        _rpc.AddHandler("mapreduce", _mr_handler);

        /*
         * Where there is a change in the Connections, we might have a state
         * change
         */
        _connection_table.ConnectionEvent += this.CheckForStateChange;
        _connection_table.DisconnectionEvent += this.CheckForStateChange;

#if !BRUNET_SIMULATOR
        _codeinjection = new Brunet.Services.CodeInjection(this);
        _codeinjection.LoadLocalModules();
#endif
        /*
         * We must later make sure the EdgeEvent events from
         * any EdgeListeners are connected to _cph.EdgeHandler
         */
        /**
         * Here are the protocols that every edge must support
         */
        /* Here are the transport addresses */
        _remote_ta = ImmutableList<TransportAddress>.Empty;
        /*@throw ArgumentNullException if the list ( new ArrayList()) is null.
         */
        /* EdgeListener's */
        _edgelistener_list = new ArrayList();
        _co_list = new List<ConnectionOverlord>();
        _edge_factory = new EdgeFactory();
        _ta_discovery = ImmutableList<Discovery>.Empty;
        StateChangeEvent += HandleTADiscoveryState;
        
        /* Initialize this at 15 seconds */
        _connection_timeout = new TimeSpan(0,0,0,0,15000);
        //Check the edges from time to time
        IAction cec_act = new HeartBeatAction(this, this.CheckEdgesCallback);
        _check_edges = Brunet.Util.FuzzyTimer.Instance.DoEvery(delegate(DateTime dt) {
          this.EnqueueAction(cec_act);
        }, 5000, 500);
      }
    }
开发者ID:hseom,项目名称:brunet,代码行数:90,代码来源:Node.cs


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