public void Cleanup() { if (Size < 0 && Timeout < 0) { return; //no nead for cleanup } while (Size >= 0 && Buffer.Count > Size) { if (Buffer.Remove(Buffer.Keys.First())) { _TickerCleanup.SetNow(); } } var keys = Keys; if (keys.IsNullOrEmpty()) { return; } foreach (var v in keys) { if (v.Timeout(Timeout, TimeoutUnit)) { if (Buffer.Remove(v)) { _TickerCleanup.SetNow(); } } } }
/// <summary> /// Removes tasks, that are done and not marked for rerun (Oneitis) /// </summary> public void Cleanup() { var keys = Data.KeysArray; if (keys.IsNullOrEmpty()) { return; } foreach (string key in keys) { lock (locker) { var task = Data.TryGetValue(key, null); if (task == null || (!task.Oneitis && !task.IsRunning)) { Data.Remove(key); } } } }
public void Cleanup() { var keys = Buffer.KeysArray; if (keys.IsNullOrEmpty()) { return; } foreach (var v in keys) { if (v.Timeout(Timeout, TimeoutUnit)) { Buffer.Remove(v); } } _TickerCleanup.SetNow(); }
private void PruneMap(ThreadedDictionary<ulong, List<PostUID>> map) { if (map.SafeCount < PruneSize) return; List<ulong> removeIDs = new List<ulong>(); map.LockWriting(delegate() { while (map.Count > 0 && map.Count > PruneSize) { ulong furthest = Core.UserID; // get furthest id foreach (ulong id in map.Keys) if ((id ^ Core.UserID) > (furthest ^ Core.UserID)) furthest = id; // remove one map.Remove(furthest); } }); }
void Core_SecondTimer() { OpCore global = Core.Context.Lookup; // global publish - so others can find entry to the op if (Core.User.Settings.OpAccess != AccessType.Secret && global != null && global.Network.Responsive && (global.Firewall == FirewallType.Open || Network.UseLookupProxies) && Core.TimeNow > NextGlobalPublish) { PublishGlobal(); } if (!Network.Established) { return; } // run code below every quarter second if (Core.TimeNow.Second % 15 != 0) { return; } // keep local client from being pinged, or removed LocalClient.LastSeen = Core.TimeNow.AddMinutes(1); LocalClient.NextPing = Core.TimeNow.AddMinutes(1); // remove expired clients - either from not notifying us, or we've lost interest and stopped pinging Clients.LockWriting(delegate() { foreach (ClientInfo client in Clients.Values.Where(c => Core.TimeNow > c.Timeout).ToArray()) { Clients.Remove(client.RoutingID); SignalUpdate(client, false); } }); // get form services users that we should keep tabs on LocalPings.Clear(); KnowOnline.Invoke(LocalPings); // ping clients that we are locally caching, or we have interest in Clients.LockReading(delegate() { foreach (ClientInfo client in (from c in Clients.Values where Core.TimeNow > c.NextPing && (Network.Routing.InCacheArea(c.UserID) || LocalPings.Contains(c.UserID)) select c).ToArray()) { Send_Ping(client); } }); // remove users no longer interested in our upates foreach (DhtClient expired in (from id in NotifyUsers.Keys where Core.TimeNow > NotifyUsers[id] select id).ToArray()) { NotifyUsers.Remove(expired); if (PendingNotifications.Contains(expired)) { PendingNotifications.Remove(expired); } } // send 2 per second, if new update, start over again foreach (DhtClient client in PendingNotifications.Take(2).ToArray()) { LocationNotify notify = new LocationNotify(); notify.Timeout = CurrentTimeout; notify.SignedLocation = LocalClient.SignedData; Network.LightComm.SendReliable(client, ServiceID, 0, notify); PendingNotifications.Remove(client); } }