Ignore:
Timestamp:
Feb 28, 2010, 5:08:01 PM (12 years ago)
Author:
arnold
Message:

SubscriberManagement: Added a try/catch to a critical region
P2PPub/Mngr: Make Manager-Exchange possible. A new incoming Manager waits as long as the "old" Manager is waiting for the last job result. After that the "old" Manager removes its ID from the DHT and the new Manager can assume the old Managers functionality

Location:
trunk/CrypPlugins/PeerToPeerPublisher
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisherBase.cs

    r1166 r1220  
    88using System.Timers;
    99using System.IO;
     10using System.Threading;
    1011
    1112/*
     
    2627        protected SubscriberManagement peerManagement;
    2728        private string topic = String.Empty;
    28         private Timer timerWaitingForAliveMsg;
     29        private System.Timers.Timer timerWaitingForAliveMsg;
    2930       
    3031        private PeerId ownPeerId;
     
    4950        /// </summary>
    5051        private const long INTERVAL_WAITING_FOR_OTHER_PUBS_PONG = 10000;
    51         private Timer waitingForOtherPublishersPong;
     52        private System.Timers.Timer waitingForOtherPublishersPong;
    5253        /// <summary>
    5354        /// if this value is set, you are between the TimeSpan of checking liveness of the other peer.
     
    5758        private bool otherPublisherHadResponded = false;
    5859
     60        /// <summary>
     61        /// counter, which counts the trials to assume publishers/managers functionality
     62        /// </summary>
     63        int cycleCheckCount = 0;
     64
    5965        #endregion
    6066
     
    6369            this.p2pControl = p2pControl;
    6470
    65             this.timerWaitingForAliveMsg = new Timer();
     71            this.timerWaitingForAliveMsg = new System.Timers.Timer();
    6672            this.timerWaitingForAliveMsg.AutoReset = true;
    6773            this.timerWaitingForAliveMsg.Elapsed += new ElapsedEventHandler(OnWaitingForAliveMsg);
    6874
    69             this.waitingForOtherPublishersPong = new Timer();
     75            this.waitingForOtherPublishersPong = new System.Timers.Timer();
    7076            this.waitingForOtherPublishersPong.AutoReset = false;
    7177            this.waitingForOtherPublishersPong.Interval = INTERVAL_WAITING_FOR_OTHER_PUBS_PONG;
     
    7379        }
    7480
    75         // Publisher-exchange extension - Arnie 2010.02.02
     81        // Publisher-exchange extension - Arnie 2010.02.02       
    7682        /// <summary>
    7783        /// Callback function for waitingForOtherPublishersPong-object. Will be only executed, when a
    7884        /// different Publisher-ID was found in the DHT, to check if the "old" Publisher is still
    79         /// alive!
     85        /// alive! When "old" Publisher is still alive, try as long as it leaves the network!
    8086        /// </summary>
    8187        /// <param name="sender"></param>
     
    8591            if (this.otherPublisherHadResponded)
    8692            {
    87                 GuiLogging("Can't assume functionality of an alive Publishers. So starting this workspace isn't possible!", NotificationLevel.Error);
    88                 Stop(PubSubMessageType.PublisherRivalryProblem);
     93                //GuiLogging("Can't assume functionality of an alive Publishers. So starting this workspace isn't possible!", NotificationLevel.Error);
     94                //Stop(PubSubMessageType.PublisherRivalryProblem);
     95                cycleCheckCount++;
     96                GuiLogging("Can't assume functionality of an alive Publishers. So waiting till the other Manager leaves the network! Cycle: " + cycleCheckCount, NotificationLevel.Warning);
     97                // wait one second longer with every trial
     98                Thread.Sleep(cycleCheckCount * 1000);
     99                Start(this.topic, this.aliveMessageInterval);
    89100            }
    90101            else
     
    218229        public virtual void Stop(PubSubMessageType msgType)
    219230        {
     231            GuiLogging("Stopping all timers.", NotificationLevel.Debug);
     232
     233            this.timerWaitingForAliveMsg.Stop();
     234            this.waitingForOtherPublishersPong.Stop();
     235
     236            GuiLogging("Deregister message-received-events", NotificationLevel.Debug);
     237            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
     238            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
     239
    220240            // don't remove informations, when it occurs a rivalry problem between two
    221241            // Publishers, because otherwise this will kill the whole topic-solution-network.
     
    233253                // send unregister message to all subscribers
    234254                int i = SendInternalMsg(msgType);
    235                 GuiLogging("Unregister messages were sent to " + i.ToString() + " subscribers!", NotificationLevel.Info);
    236             }
    237 
    238             GuiLogging("Stopping all timers.", NotificationLevel.Debug);
    239 
    240             this.timerWaitingForAliveMsg.Stop();
    241             this.waitingForOtherPublishersPong.Stop();
    242 
    243             GuiLogging("Deregister message-received-events", NotificationLevel.Debug);
    244             this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
    245             this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
     255                GuiLogging("Unregister messages were sent to " + i.ToString() + " subscribers/workers!", NotificationLevel.Info);
     256            }
    246257
    247258            GuiLogging("Publisher completely stopped!", NotificationLevel.Info);
    248259
    249260            this.Started = false;
     261            cycleCheckCount = 0;
    250262        }
    251263
  • trunk/CrypPlugins/PeerToPeerPublisher/SubscribersManagement.cs

    r1199 r1220  
    5959            bool retValue = false;
    6060
     61            // locking checkList instead of activeSubsList, because all other functions work on checkList, not on activeSubsList
    6162            lock (this.checkList)
    6263            {
     
    6465                {
    6566                    this.dateTimeNow = DateTime.Now;
    66                     // locking checkList instead of activeSubsList, because all other functions work on checkList, not on activeSubsList
    67                     lock (this.checkList)
    68                     {
    69                         this.checkList.Add(subscriberId, this.dateTimeNow);
    70                         retValue = true;
    71                     }
     67                    this.checkList.Add(subscriberId, this.dateTimeNow);
     68                    retValue = true;
    7269                }
    7370            } // end lock
     
    132129            lock (this.checkList)
    133130            {
    134                 foreach (KeyValuePair<PeerId, DateTime> entry in this.checkList)
    135                 {
    136                     DateTime valueWithExpirationTime = entry.Value.AddMilliseconds(ExpirationTime);
    137 
    138                     // if time is expired AND the ID is already in the secondChanceList --> Add to remove list
    139                     if (this.dateTimeNow > valueWithExpirationTime && secondChanceList.Contains(entry.Key))
     131                // added try/catch because checkList could be changed while iterating on it = boom!
     132                try
     133                {
     134                    foreach (KeyValuePair<PeerId, DateTime> entry in this.checkList)
    140135                    {
    141                         removeSubscribersFromDict.Add(entry.Key);
     136                        DateTime valueWithExpirationTime = entry.Value.AddMilliseconds(ExpirationTime);
     137
     138                        // if time is expired AND the ID is already in the secondChanceList --> Add to remove list
     139                        if (this.dateTimeNow > valueWithExpirationTime && secondChanceList.Contains(entry.Key))
     140                        {
     141                            removeSubscribersFromDict.Add(entry.Key);
     142                        }
     143                        else if (this.dateTimeNow > valueWithExpirationTime) //otherwise give a second chance
     144                        {
     145                            this.secondChanceList.Add(entry.Key);
     146                        }
    142147                    }
    143                     else if (this.dateTimeNow > valueWithExpirationTime) //otherwise give a second chance
    144                     {
    145                         this.secondChanceList.Add(entry.Key);
    146                     }
     148                }
     149                catch (Exception ex)
     150                {
     151                    // don't handle this case, because outdated Peers will be added to the 2ndChanceList
     152                    // or will be removed the next time
    147153                }
    148154            } //end lock(this.checkList)
Note: See TracChangeset for help on using the changeset viewer.