Exemple #1
0
        /// <summary>
        /// Initializes the SyncCache.
        /// </summary>
        public void Initialize()
        {
            try
            {
                CacheInitParams initParams = new CacheInitParams();
                initParams.Server      = _server;
                initParams.Port        = _port;
                initParams.LoadBalance = true;
                _syncCache             = Caching.NCache.InitializeCache(_cacheId, initParams, false);
                _updateCallback        = new CacheDataNotificationCallback(OnItemChangedCallback);
                _removedCallback       = new CacheDataNotificationCallback(OnItemRemovedCallback);
                _cacheClearCallback    = new CacheClearedCallback(OnCacheClear);
                _cacheStoppedCallback  = new CacheStoppedCallback(OnCacheStopped);
                _synEventListeners     = new ArrayList();

                if (_syncCache != null)
                {
                    _syncCache.ExceptionsEnabled = true;
                    _syncCache.CacheCleared     += _cacheClearCallback;
                    _syncCache.CacheStopped     += _cacheStoppedCallback;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to initialize " + _cacheId + " while creating CacheSyncDependency", ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Unregister the callbacks registered with cache
        /// </summary>
        private void UnRegisterNotifications()
        {
            if (_onItemUpdatedCallback != null)
            {
                _cache.CustomUpdateCallbackNotif -= _onItemUpdatedCallback;
                _onItemUpdatedCallback            = null;
            }
            if (_onItemRemoveCallback != null)
            {
                _cache.CustomRemoveCallbackNotif -= _onItemRemoveCallback;
                _onItemRemoveCallback             = null;
            }

            if (_cacheStopped != null)
            {
                _cache.CacheStopped -= _cacheStopped;
                _cacheStopped        = null;
            }
            if (this._hashmapChanged != null)
            {
                this._cache.HashmapChanged -= this._hashmapChanged;
                _hashmapChanged             = null;
            }
            if (_nodeJoined != null)
            {
                _cache.MemberJoined -= _nodeJoined;
                _nodeJoined          = null;
            }
            if (_nodeLeft != null)
            {
                _cache.MemberLeft -= _nodeLeft;
                _nodeLeft          = null;
            }
        }
Exemple #3
0
        /// <summary>
        /// Initialize the cache instance.
        /// </summary>
        internal NCache(string cacheId, bool isDotNetClient, ClientManager client, string licenceInfo)
        {
            this._cacheId        = cacheId;
            this._isDotNetClient = isDotNetClient;
            this._client         = client;
            this._licenceCode    = licenceInfo;


            try
            {
                _cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cacheId);
            }
            catch (Exception) { throw; }

            if (_cache == null)
            {
                throw new Exception("Cache is not registered");
            }
            if (!_cache.IsRunning)
            {
                throw new Exception("Cache is not running");
            }


            _onItemUpdatedCallback            = new CustomUpdateCallback(CustomUpdate);
            _cache.CustomUpdateCallbackNotif += _onItemUpdatedCallback;

            _onItemRemoveCallback             = new CustomRemoveCallback(CustomRemove);
            _cache.CustomRemoveCallbackNotif += _onItemRemoveCallback;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Registering cache stopped event for " + _client.ClientID);
            }

            _cacheStopped        = new CacheStoppedCallback(OnCacheStopped);
            _cache.CacheStopped += _cacheStopped;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Cache stopped event registered for " + _client.ClientID);
            }
            _cache.ClientsInvalidated += new ClientsInvalidatedCallback(OnClientsInvalidated);

            _cache.OnClientConnected(client.ClientID, cacheId);
        }
Exemple #4
0
        /// <summary>
        /// Initialize the cache instance.
        /// </summary>
        internal NCache(string cacheId, ClientManager client)
        {
            this._cacheId = cacheId;
            this._client = client;

            try
            {
              _cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cacheId);
            }
            catch (Exception) { throw; }

            if (_cache == null) throw new Exception("Cache is not registered");
            if (!_cache.IsRunning) throw new Exception("Cache is not running");

            _onItemUpdatedCallback = new CustomUpdateCallback(CustomUpdate);
            _cache.CustomUpdateCallbackNotif += _onItemUpdatedCallback;

            _onItemRemoveCallback = new CustomRemoveCallback(CustomRemove);
            _cache.CustomRemoveCallbackNotif += _onItemRemoveCallback;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver+".ctor", "Registering cache stopped event for " + _client.ClientID);
            }

            _cacheStopped = new CacheStoppedCallback(OnCacheStopped);
            _cache.CacheStopped += _cacheStopped;

            if (SocketServer.Logger.IsErrorLogsEnabled) SocketServer.Logger.NCacheLog.Error(_cacheserver+".ctor", "Cache stopped event registered for " + _client.ClientID);
            _cache.ClientsInvalidated += new ClientsInvalidatedCallback(OnClientsInvalidated);

            _cache.OnClientConnected(client.ClientID, cacheId);
        }
Exemple #5
0
        /// <summary>
        /// Unregister the callbacks registered with cache
        /// </summary>
        private void UnRegisterNotifications()
        {
            if (_onItemUpdatedCallback != null)
            {
                _cache.CustomUpdateCallbackNotif -= _onItemUpdatedCallback;
                _onItemUpdatedCallback = null;
            }
            if (_onItemRemoveCallback != null)
            {
                _cache.CustomRemoveCallbackNotif -= _onItemRemoveCallback;
                _onItemRemoveCallback = null;
            }

            if (_cacheStopped != null)
            {
                _cache.CacheStopped -= _cacheStopped;
                _cacheStopped = null;
            }
            if (this._hashmapChanged != null)
            {
                this._cache.HashmapChanged -= this._hashmapChanged;
                _hashmapChanged = null;
            }
            if (_nodeJoined != null)
            {
                _cache.MemberJoined -= _nodeJoined;
                _nodeJoined = null;
            }
            if (_nodeLeft != null)
            {
                _cache.MemberLeft -= _nodeLeft;
                _nodeLeft = null;
            }
        }
Exemple #6
0
        /// <summary>
        /// Unregister the callbacks registered with cache
        /// </summary>

        private void UnRegisterNotifications()
        {
            if (_onItemUpdatedCallback != null)
            {
                _cache.CustomUpdateCallbackNotif -= _onItemUpdatedCallback;
                _onItemUpdatedCallback            = null;
            }
            if (_onItemRemoveCallback != null)
            {
                _cache.CustomRemoveCallbackNotif -= _onItemRemoveCallback;
                _onItemRemoveCallback             = null;
            }
            if (_pollRequestCallback != null)
            {
                _cache.PollRequestCallbackNotif -= _pollRequestCallback;
                _pollRequestCallback             = null;
            }

            if (_cacheCleared != null)
            {
                _cache.CacheCleared -= _cacheCleared;
                _cacheCleared        = null;
            }
            if (_cacheStopped != null)
            {
                _cache.CacheStopped -= _cacheStopped;
                _cacheStopped        = null;
            }
            if (_onCompactTypeModifiedCallback != null)
            {
                _cache.CompactTypeModified    -= _onCompactTypeModifiedCallback;
                _onCompactTypeModifiedCallback = null;
            }

            if (_asyncOperationCallback != null)
            {
                _cache.AsyncOperationCompleted -= _asyncOperationCallback;
                _asyncOperationCallback         = null;
            }
            if (_dsUpdatedCallback != null)
            {
                _cache.DataSourceUpdated -= _dsUpdatedCallback;
                _dsUpdatedCallback        = null;
            }

            if (_itemAdded != null)
            {
                _cache.ItemAdded -= _itemAdded;
                _itemAdded        = null;
                lock (sync_lock_AddDataFilter)
                {
                    ItemAddedFilter = EventDataFilter.None;
                    _addSeq         = -1;
                }
            }
            if (_itemUpdated != null)
            {
                _cache.ItemUpdated -= _itemUpdated;
                _itemUpdated        = null;
                lock (sync_lock_UpdateDataFilter)
                {
                    ItemUpdatedFilter = EventDataFilter.None;
                    _updateSeq        = -1;
                }
            }
            if (_itemRemoved != null)
            {
                _cache.ItemRemoved -= _itemRemoved;
                _itemRemoved        = null;
                lock (sync_lock_RemoveDataFilter)
                {
                    ItemRemovedFilter = EventDataFilter.None;
                    _removeSeq        = -1;
                }
            }

            if (_customNotif != null)
            {
                _cache.CustomNotif -= _customNotif;
                _customNotif        = null;
            }

            if (_nodeJoined != null)
            {
                _cache.MemberJoined -= _nodeJoined;
                _nodeJoined          = null;
            }
            if (_nodeLeft != null)
            {
                _cache.MemberLeft -= _nodeLeft;
                _nodeLeft          = null;
            }
            if (_cacheBecomeActive != null)
            {
                _cache.CacheBecomeActive -= _cacheBecomeActive;
                _cacheBecomeActive        = null;
            }
            if (_configModified != null)
            {
                _cache.ConfigurationModified -= _configModified;
                _configModified = null;
            }

#if !DEVELOPMENT
            if (this._hashmapChanged != null)
            {
                this._cache.HashmapChanged -= this._hashmapChanged;
                _hashmapChanged             = null;
            }
#endif

            if (_operationModeChanged != null)
            {
                _cache.OperationModeChanged -= _operationModeChanged;
                _operationModeChanged        = null;
            }
            if (this._blockClientActivity != null)
            {
                this._cache.BlockActivity -= this._blockClientActivity;
                _blockClientActivity       = null;
            }

            if (this._unblockClientActivity != null)
            {
                this._cache.UnBlockActivity -= this._unblockClientActivity;
                _unblockClientActivity       = null;
            }
        }
Exemple #7
0
        internal NCache(string cacheId, bool isDotNetClient, ClientManager client, string licenceInfo, string userId, string password, byte[] userIdBinary, byte[] paswordBinary, Runtime.Caching.ClientInfo clientInfo)
        {
            this._cacheId        = cacheId;
            this._isDotNetClient = isDotNetClient;
            this._client         = client;
            this._licenceCode    = licenceInfo;


            _cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cacheId);

            if (_cache == null)
            {
                throw new Exception("Cache is not registered");
            }

            if (!_cache.IsRunning)
            {
                throw new Exception("Cache is not running");
            }

            EventHelper.EventDataFormat = _cache.SocketServerDataService;
#if !CLIENT
            if (_cache.CacheType.Equals("mirror-server") && !_cache.IsCoordinator)
            {
                throw new OperationNotSupportedException("Cannot connect to Passive Node in Mirror Cluster.");
            }
#endif

            _onItemUpdatedCallback            = new CustomUpdateCallback(CustomUpdate);
            _cache.CustomUpdateCallbackNotif += _onItemUpdatedCallback;

            _onItemRemoveCallback             = new CustomRemoveCallback(CustomRemove);
            _cache.CustomRemoveCallbackNotif += _onItemRemoveCallback;

            _pollRequestCallback             = new Caching.PollRequestCallback(PollRequest);
            _cache.PollRequestCallbackNotif += _pollRequestCallback;


            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Registering cache stopped event for " + _client.ClientID);
            }

            _cacheStopped        = new CacheStoppedCallback(OnCacheStopped);
            _cache.CacheStopped += _cacheStopped;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Cache stopped event registered for " + _client.ClientID);
            }



            _asyncOperationCallback         = new AsyncOperationCompletedCallback(AsyncOperationCompleted);
            _cache.AsyncOperationCompleted += _asyncOperationCallback;


            _cacheBecomeActive        = new CacheBecomeActiveCallback(OnCacheBecomeActive);
            _cache.CacheBecomeActive += _cacheBecomeActive;

            _configModified = new ConfigurationModified(OnConfigModified);
            _cache.ConfigurationModified += _configModified;

            _onCompactTypeModifiedCallback = new CompactTypeModifiedCallback(CompactTypesModified);
            _cache.CompactTypeModified    += _onCompactTypeModifiedCallback;

            _blockClientActivity  = new BlockClientActivity(BlockClientActivity);
            _cache.BlockActivity += this._blockClientActivity;

            _unblockClientActivity  = new UnBlockClientActivity(UnBlockClientActivity);
            _cache.UnBlockActivity += this._unblockClientActivity;

            _operationModeChanged       += new OperationModeChangedCallback(OperationModeChanged);
            _cache.OperationModeChanged += _operationModeChanged;
        }
Exemple #8
0
        /// <summary>
        /// Register callbacks with cache.
        /// </summary>
        /// <param name="type"></param>
        public void RegisterNotification(NotificationsType type)
        {
            switch (type)
            {
            case NotificationsType.RegAddNotif:
                if (_itemAdded == null)
                {
                    _itemAdded        = new ItemAddedCallback(ItemAdded);
                    _cache.ItemAdded += _itemAdded;
                }
                break;

            case NotificationsType.RegUpdateNotif:
                if (_itemUpdated == null)
                {
                    _itemUpdated        = new ItemUpdatedCallback(ItemUpdated);
                    _cache.ItemUpdated += _itemUpdated;
                }
                break;

            case NotificationsType.RegRemoveNotif:
                if (_itemRemoved == null)
                {
                    _itemRemoved        = new ItemRemovedCallback(ItemRemoved);
                    _cache.ItemRemoved += _itemRemoved;
                }
                break;

            case NotificationsType.RegClearNotif:
                if (_cacheCleared == null)
                {
                    _cacheCleared        = new CacheClearedCallback(CacheCleared);
                    _cache.CacheCleared += _cacheCleared;
                }
                break;

            case NotificationsType.RegCustomNotif:
                if (_customNotif == null)
                {
                    _customNotif        = new CustomNotificationCallback(CustomNotification);
                    _cache.CustomNotif += _customNotif;
                }
                break;

            case NotificationsType.RegNodeJoinedNotif:
                if (_nodeJoined == null)
                {
                    _nodeJoined          = new NodeJoinedCallback(NodeJoined);
                    _cache.MemberJoined += _nodeJoined;
                }
                break;

            case NotificationsType.RegNodeLeftNotif:
                if (_nodeLeft == null)
                {
                    _nodeLeft          = new NodeLeftCallback(NodeLeft);
                    _cache.MemberLeft += _nodeLeft;
                }
                break;

            case NotificationsType.RegCacheStoppedNotif:

                _cacheStopped        = new CacheStoppedCallback(OnCacheStopped);
                _cache.CacheStopped += _cacheStopped;
                this._cacheStoppedEventRegistered = true;
                break;



#if !DEVELOPMENT
            case NotificationsType.RegHashmapChangedNotif:
                if (this._hashmapChanged == null)
                {
                    this._hashmapChanged        = new HashmapChangedCallback(HashmapChanged);
                    this._cache.HashmapChanged += this._hashmapChanged;
                }
                break;
#endif
            case NotificationsType.UnregAddNotif:
                if (_itemAdded != null)
                {
                    _cache.ItemAdded -= _itemAdded;
                    _itemAdded        = null;
                    lock (sync_lock_AddDataFilter)
                    {
                        ItemAddedFilter = EventDataFilter.None;
                        _addSeq         = -1;
                    }
                }
                break;

            case NotificationsType.UnregUpdateNotif:
                if (_itemUpdated != null)
                {
                    _cache.ItemUpdated -= _itemUpdated;
                    _itemUpdated        = null;
                    lock (sync_lock_UpdateDataFilter = -1)
                    {
                        ItemUpdatedFilter = EventDataFilter.None;
                        _updateSeq        = -1;
                    }
                }
                break;

            case NotificationsType.UnregRemoveNotif:
                if (_itemRemoved != null)
                {
                    _cache.ItemRemoved -= _itemRemoved;
                    _itemRemoved        = null;
                    lock (sync_lock_RemoveDataFilter)
                    {
                        ItemRemovedFilter = EventDataFilter.None;
                        _removeSeq        = -1;
                    }
                }
                break;

            case NotificationsType.UnregClearNotif:
                if (_cacheCleared != null)
                {
                    _cache.CacheCleared -= _cacheCleared;
                    _cacheCleared        = null;
                }
                break;

            case NotificationsType.UnregCustomNotif:
                if (_customNotif != null)
                {
                    _cache.CustomNotif -= _customNotif;
                    _customNotif        = null;
                }
                break;

            case NotificationsType.UnregNodeJoinedNotif:
                if (_nodeJoined != null)
                {
                    _cache.MemberJoined -= _nodeJoined;
                    _nodeJoined          = null;
                }
                break;



            case NotificationsType.UnregNodeLeftNotif:
                if (_nodeLeft != null)
                {
                    _cache.MemberLeft -= _nodeLeft;
                    _nodeLeft          = null;
                }
                break;

            case NotificationsType.UnregCacheStoppedNotif:
                this._cacheStoppedEventRegistered = false;
                break;


#if !DEVELOPMENT
            case NotificationsType.UnregHashmapChangedNotif:
                if (this._hashmapChanged != null)
                {
                    this._cache.HashmapChanged -= this._hashmapChanged;
                    this._hashmapChanged        = null;
                }
                break;
#endif
            }
        }