コード例 #1
0
ファイル: MaintenanceTask.cs プロジェクト: lanicon/TomP2P.NET
        private void Run(object state)
        {
            //Console.WriteLine("Maintenance Thread {0}: Maintenance triggered on peer {1}.", Thread.CurrentThread.ManagedThreadId, _peer.PeerId);
            lock (_lock)
            {
                // make sure we only have 5 pings in parallel
                if (_shutdown || Counter.Get() > MaxPing)
                {
                    return;
                }
                foreach (var maintainable in _maintainables)
                {
                    var peerStatistic = maintainable.NextForMaintenance(_runningTasks.Values);
                    if (peerStatistic == null)
                    {
                        return;
                    }
                    var task = _peer.Ping().SetPeerAddress(peerStatistic.PeerAddress).Start();
                    Logger.Debug("Maintenance ping from {0} to {1}.", _peer.PeerAddress, peerStatistic.PeerAddress);

                    _peer.NotifyAutomaticFutures(task);
                    _runningTasks.Add(task, peerStatistic.PeerAddress);
                    Counter.IncrementAndGet();
                    task.ContinueWith(t =>
                    {
                        lock (_lock)
                        {
                            _runningTasks.Remove(task);
                            Counter.Decrement();
                        }
                    });
                }
            }
        }
コード例 #2
0
ファイル: PeerBuilder.cs プロジェクト: lanicon/TomP2P.NET
 public PingBuilder Create()
 {
     return(_peer.Ping());
 }