public void AddBulkDependencies(ArrayList keys, IList <CacheSyncDependency> dependencies) { Hashtable dependencyList = new Hashtable(); ISyncCache syncCache = null; SyncEventListener listener = null; for (int i = 0; i < keys.Count; i++) { string key = keys[i] as string; CacheSyncDependency dependency = dependencies[i]; if (_context.IsDbSyncCoordinator) { syncCache = dependency.SyncCache; listener = null; if (dependency != null && dependency.CacheId != null) { lock (_dependenciesStatus.SyncRoot) { if (AddDependencyInternal(key, dependency)) { List <string> dependencyKeyList = dependencyList[dependency.CacheId] as List <string>; if (dependencyKeyList == null) { dependencyKeyList = new List <string>(keys.Count); dependencyList.Add(dependency.CacheId, dependencyKeyList); } dependencyKeyList.Add(dependency.Key); } } } } else { SyncItem syncItem = new SyncItem(key, dependency.Key, dependency.CacheId); lock (_inactiveDependencies.SyncRoot) { if (!_inactiveDependencies.Contains(syncItem)) { _inactiveDependencies.Add(syncItem, dependency); } } } } IDictionaryEnumerator ide = dependencyList.GetEnumerator(); while (ide.MoveNext()) { listener = _listeners[ide.Key] as SyncEventListener; syncCache = _synCaches[ide.Key] as ISyncCache; List <string> depdencyKeyList = ide.Value as List <string>; if (syncCache != null && listener != null) { syncCache.RegisterBulkSyncKeyNotifications(depdencyKeyList.ToArray(), listener, CallbackType.PushBasedNotification); } } }
private void UpdateSyncData(string cacheId, PollingResult result) { SyncEventListener listener = _listeners[cacheId] as SyncEventListener; if (listener != null) { foreach (string key in result.UpdatedKeys) { if (key.Equals("$$$CacheClear$$C")) { listener.CacheCleared(); } listener.SyncItemUpdated(key); } foreach (string key in result.RemovedKeys) { listener.SyncItemRemoved(key); } } }
/// <summary> /// Adiciona uma dependencia para o gerenciador. /// </summary> /// <param name="key">Chave da entrada.</param> /// <param name="dependency">Instancia da dependencia.</param> public void AddDependency(object key, CacheSyncDependency dependency) { if (_context.IsDbSyncCoordinator) { ISyncCache syncCache = dependency.SyncCache; SyncEventListener listener = null; if ((dependency == null) || (dependency.CacheId == null)) { return; } lock (_dependenciesStatus.SyncRoot) { SyncItem item = new SyncItem(key, dependency.Key, dependency.CacheId); ArrayList list = null; if (!_dependenciesKeyMap.Contains(item)) { list = new ArrayList(); list.Add(item.ThisKey); _dependenciesKeyMap.Add(item, list); } else { list = _dependenciesKeyMap[item] as ArrayList; if (!list.Contains(item.ThisKey)) { list.Add(item.ThisKey); } } if (!_dependenciesStatus.Contains(item)) { _dependenciesStatus.Add(item, DependencyStatus.Unchanged); } if (_synCaches.Contains(dependency.CacheId)) { listener = _listeners[dependency.CacheId] as SyncEventListener; syncCache = _synCaches[dependency.CacheId] as ISyncCache; } else { syncCache.Initialize(); _synCaches.Add(dependency.CacheId, syncCache); if (_listeners.Contains(dependency.CacheId)) { listener = _listeners[dependency.CacheId] as SyncEventListener; } else { listener = new SyncEventListener(dependency.CacheId, this); _listeners.Add(dependency.CacheId, listener); } } if ((list != null) && (list.Count < 2)) { syncCache.RegisterSyncKeyNotifications((string)item.Key, listener); } return; } } SyncItem item2 = new SyncItem(key, dependency.Key, dependency.CacheId); if (!_inactiveDependencies.Contains(item2)) { _inactiveDependencies.Add(item2, dependency); } }
public void RemoveBulkDependencies(ArrayList keys, IList <CacheSyncDependency> dependencies) { string key = null; CacheSyncDependency dependency = null; Hashtable dependencyList = new Hashtable(); ISyncCache syncCache = null; for (int i = 0; i < keys.Count; i++) { key = keys[i] as string; dependency = dependencies[i]; if (_context.IsDbSyncCoordinator) { if (dependency == null) { return; } try { if (RemoveCacheSyncDependencyInternal(key, dependency)) { List <string> dependencyKeyList = dependencyList[dependency.CacheId] as List <string>; syncCache = _synCaches[dependency.CacheId] as ISyncCache; if (dependencyKeyList == null) { dependencyKeyList = new List <string>(keys.Count); dependencyList.Add(dependency.CacheId, dependencyKeyList); } dependencyKeyList.Add(dependency.Key); } } catch (Exception e) { NCacheLog.Error("CacheSyncManager.RemoveBulkDependencies", e.ToString()); } } else { lock (_inactiveDependencies.SyncRoot) { _inactiveDependencies.Remove(key); } } } if (dependencyList.Count > 0) { IDictionaryEnumerator ide = dependencyList.GetEnumerator(); while (ide.MoveNext()) { try { SyncEventListener listener = _listeners[ide.Key] as SyncEventListener; syncCache = _synCaches[ide.Key] as ISyncCache; List <string> depdencyKeyList = ide.Value as List <string>; if (syncCache != null && listener != null) { syncCache.UnRegisterBulkSyncKeyNotifications(depdencyKeyList.ToArray(), listener); } } catch (Exception e) { NCacheLog.Error("CacheSyncManager.RemoveBulkDependencies", e.ToString()); } } } }
public void AddDependency(object key, CacheSyncDependency dependency) { if (_context.IsDbSyncCoordinator) { ISyncCache syncCache = dependency.SyncCache; SyncEventListener listener = null; if (dependency != null && dependency.CacheId != null) { lock (_dependenciesStatus.SyncRoot) { SyncItem syncItem = new SyncItem(key, dependency.Key, dependency.CacheId); ClusteredArrayList dependentKeys = null; if (!_dependenciesKeyMap.Contains(syncItem)) { dependentKeys = new ClusteredArrayList(); dependentKeys.Add(syncItem.ThisKey); _dependenciesKeyMap.Add(syncItem, dependentKeys); } else { dependentKeys = _dependenciesKeyMap[syncItem] as ClusteredArrayList; if (!dependentKeys.Contains(syncItem.ThisKey)) { dependentKeys.Add(syncItem.ThisKey); } } if (!_dependenciesStatus.Contains(syncItem)) { _dependenciesStatus.Add(syncItem, DependencyStatus.Unchanged); } if (_synCaches.Contains(dependency.CacheId)) { syncCache = _synCaches[dependency.CacheId] as ISyncCache; listener = _listeners[dependency.CacheId] as SyncEventListener; } else { //// Only the coordinator or sub-coordinator(inacse of POR) can initialize //// SyncCache. syncCache.Initialize(); _synCaches.Add(dependency.CacheId, syncCache); if (_listeners.Contains(dependency.CacheId)) { listener = _listeners[dependency.CacheId] as SyncEventListener; } else { listener = new SyncEventListener(dependency.CacheId, this); _listeners.Add(dependency.CacheId, listener); } } if (dependentKeys != null && dependentKeys.Count < 2) { syncCache.RegisterSyncKeyNotifications((string)syncItem.Key, listener, CallbackType.PushBasedNotification); } } } } else { SyncItem syncItem = new SyncItem(key, dependency.Key, dependency.CacheId); lock (_inactiveDependencies.SyncRoot) { if (!_inactiveDependencies.Contains(syncItem)) { _inactiveDependencies.Add(syncItem, dependency); } } } }
private bool AddDependencyInternal(string key, CacheSyncDependency dependency) { SyncEventListener listener = null; ISyncCache syncCache = dependency.SyncCache; if (dependency != null && dependency.CacheId != null) { lock (_dependenciesStatus.SyncRoot) { SyncItem syncItem = new SyncItem(key, dependency.Key, dependency.CacheId); ClusteredArrayList dependentKeys = null; if (!_dependenciesKeyMap.Contains(syncItem)) { dependentKeys = new ClusteredArrayList(); dependentKeys.Add(syncItem.ThisKey); _dependenciesKeyMap.Add(syncItem, dependentKeys); } else { dependentKeys = _dependenciesKeyMap[syncItem] as ClusteredArrayList; if (!dependentKeys.Contains(syncItem.ThisKey)) { dependentKeys.Add(syncItem.ThisKey); } } if (!_dependenciesStatus.Contains(syncItem)) { _dependenciesStatus.Add(syncItem, DependencyStatus.Unchanged); } if (_synCaches.Contains(dependency.CacheId)) { syncCache = _synCaches[dependency.CacheId] as ISyncCache; listener = _listeners[dependency.CacheId] as SyncEventListener; } else { _synCaches.Add(dependency.CacheId, syncCache); if (_listeners.Contains(dependency.CacheId)) { listener = _listeners[dependency.CacheId] as SyncEventListener; } else { listener = new SyncEventListener(dependency.CacheId, this); _listeners.Add(dependency.CacheId, listener); } } ///This registering for every key needs reviewing if (dependentKeys != null && dependentKeys.Count < 2) { return(true); } } } return(false); }