public void Run() { try { var activeClients = _store.GetActiveClientSubscriptions(TimeSpan.FromMilliseconds(_interval)); if (activeClients != null) { OperationContext context = OperationContext.CreateWith(OperationContextFieldName.InternalOperation, true); foreach (KeyValuePair <string, IList <string> > pair in activeClients) { foreach (string client in pair.Value) { if (_context.NCacheLog.IsInfoEnabled) { _context.NCacheLog.Info("SubscriptionRefresher", client + " being refreshed for topic " + pair.Key); } _store.TopicOperation(new SubscriptionOperation(pair.Key, Common.Enum.TopicOperationType.RefreshSubscription, new SubscriptionInfo() { ClientId = client }), context); } } } } catch (Exception e) { _context.NCacheLog.Error("SubscriptionReresherTask", e.ToString()); } }
private void RemoveInactiveClients() { var inactiveClients = _store.GetInActiveClientSubscriptions(TimeSpan.FromMinutes(10)); int runCount = 0; if (inactiveClients != null) { OperationContext context = OperationContext.CreateWith(OperationContextFieldName.InternalOperation, true); foreach (KeyValuePair <string, IList <string> > pair in inactiveClients) { foreach (string inactiveClient in pair.Value) { if (runCount++ > 200) { _hadPendingWork = true; break; //to prevent starvation and let other operations happen } try { if (_context.NCacheLog.IsInfoEnabled) { _context.NCacheLog.Info("MessageProcessor.RemoveInactiveClients", inactiveClient + " subscription removed due to inactivity against topic " + pair.Key); } _store.TopicOperation(new SubscriptionOperation(pair.Key, TopicOperationType.UnSubscribe, new SubscriptionInfo() { ClientId = inactiveClient }), context); } catch (Exception e) { _context.NCacheLog.Error("MessageProcessor.RemoveInactiveClients", e.ToString()); } } } } }