Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }