Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        public CompactCacheEntry(object key, object value, ExpirationHint dependency,
                                 Alachisoft.NCache.Caching.CacheSynchronization.CacheSyncDependency syncDependency, long expiration,
                                 byte options, object itemRemovedCallback, string group, string subgroup, Hashtable queryInfo, BitSet Flag, object lockId, ulong version, LockAccessType accessType, string providername, string resyncProviderName)
        {
            _key   = key;
            _flag  = Flag;
            _value = value;

            _dependency          = dependency;
            _syncDependency      = syncDependency;
            _expiration          = expiration;
            _options             = options;
            _itemRemovedCallback = itemRemovedCallback;
            if (group != null)
            {
                _group = group;
                if (subgroup != null)
                {
                    _subgroup = subgroup;
                }
            }
            _queryInfo = queryInfo;

            _lockId             = lockId;
            _accessType         = accessType;
            _version            = version;
            _providerName       = providername;
            _resyncProviderName = resyncProviderName;
        }
Exemplo n.º 3
0
        private bool RemoveCacheSyncDependencyInternal(string key, CacheSyncDependency dependency)
        {
            SyncItem item = new SyncItem(key, dependency.Key, dependency.CacheId);

            lock (_dependenciesStatus.SyncRoot)
            {
                if (_dependenciesKeyMap.Contains(item))
                {
                    ClusteredArrayList dependentKeys = _dependenciesKeyMap[item] as ClusteredArrayList;
                    if (dependentKeys != null)
                    {
                        dependentKeys.Remove(key);
                        if (dependentKeys.Count > 0)
                        {
                            return(false);
                        }
                    }
                    _dependenciesKeyMap.Remove(item);
                }

                if (_dependenciesStatus.Contains(item))
                {
                    _dependenciesStatus.Remove(item);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
 internal ISyncCache GetSyncCacheInstance(CacheSyncDependency dependency)
 {
     if (_synCaches.Contains(dependency.CacheId))
     {
         return(_synCaches[dependency.CacheId] as ISyncCache);
     }
     return(dependency.SyncCache);
 }
Exemplo n.º 5
0
        public void RemoveDependency(object key, CacheSyncDependency dependency)
        {
            if (_context.IsDbSyncCoordinator)
            {
                if (dependency == null)
                {
                    return;
                }
                try
                {
                    SyncItem item = new SyncItem(key, dependency.Key, dependency.CacheId);

                    lock (_dependenciesStatus.SyncRoot)
                    {
                        if (_dependenciesKeyMap.Contains(item))
                        {
                            ClusteredArrayList dependentKeys = _dependenciesKeyMap[item] as ClusteredArrayList;
                            if (dependentKeys != null)
                            {
                                dependentKeys.Remove(key);
                                if (dependentKeys.Count > 0)
                                {
                                    return;
                                }
                            }
                            _dependenciesKeyMap.Remove(item);
                        }

                        if (_dependenciesStatus.Contains(item))
                        {
                            _dependenciesStatus.Remove(item);
                        }
                        else
                        {
                            return;
                        }
                    }
                    ISyncCache syncCache = _synCaches[item.CacheId] as ISyncCache;
                    ISyncCacheEventsListener listener = _listeners[item.CacheId] as ISyncCacheEventsListener;
                    if (syncCache != null && listener != null)
                    {
                        syncCache.UnRegisterSyncKeyNotifications((string)item.Key, listener);
                    }
                }
                catch (Exception e)
                {
                    NCacheLog.Error("CacheSyncManager:", e.ToString());
                }
            }
            else
            {
                lock (_inactiveDependencies.SyncRoot)
                {
                    _inactiveDependencies.Remove(key);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes all the inactive dependencies.
        /// </summary>
        public void ActivateDependencies()
        {
            try
            {
                IDictionaryEnumerator iDic = _inactiveDependencies.GetEnumerator();
                while (iDic.MoveNext())
                {
                    SyncItem            item       = (SyncItem)iDic.Key;
                    CacheSyncDependency dependency = (CacheSyncDependency)iDic.Value;

                    AddDependency(item.ThisKey, dependency);
                }
                lock (_inactiveDependencies.SyncRoot)
                {
                    _inactiveDependencies.Clear();
                }
            }
            catch (Exception e)
            {
                NCacheLog.Error("CacheSyncManager.ActivateDependencies()", e.ToString());
            }
        }
Exemplo n.º 7
0
        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());
                    }
                }
            }
        }
Exemplo n.º 8
0
        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);
                    }
                }
            }
        }
Exemplo n.º 9
0
        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);
        }