public virtual void OnCustomUpdateCallback(string key, object value, bool notifyAsync, EventCacheItem item,
                                                   EventCacheItem oldItem, BitSet flag)
        {
            try
            {
                CallbackInfo cbInfo = value as CallbackInfo;
                if (cbInfo != null)
                {
                    if (item != null)
                    {
                        item.Value = GetObject(item.Value, flag);
                    }
                    if (oldItem != null)
                    {
                        oldItem.Value = GetObject(oldItem.Value, flag);
                    }

                    if (_parent._perfStatsCollector != null)
                    {
                        _parent._perfStatsCollector.IncrementEventsProcessedPerSec();
                    }

                    EventHandle handle = new EventHandle((short)cbInfo.Callback);
                    this._eventManager.RaiseSelectiveCacheNotification(key, EventType.ItemUpdated, item, oldItem,
                                                                       CacheItemRemovedReason.Underused, notifyAsync, handle, cbInfo.DataFilter);
                }
            }
            catch
            {
            }
        }
        public virtual void OnCustomRemoveCallback(string key, object value, CacheItemRemovedReason reason,
                                                   BitSet flag, bool notifyAsync, EventCacheItem item)
        {
            try
            {
                object[] args = value as object[];
                if (args != null)
                {
                    object val = args[0];


                    CallbackInfo cbInfo = args[1] as CallbackInfo;
                    if (cbInfo != null)
                    {
                        if (_parent._perfStatsCollector != null)
                        {
                            _parent._perfStatsCollector.IncrementEventsProcessedPerSec();
                        }

                        if (item != null)
                        {
                            item.Value = GetObject(item.Value, flag);
                        }
                        EventHandle handle = new EventHandle((short)cbInfo.Callback);
                        _parent.EventManager.RaiseSelectiveCacheNotification(key, EventType.ItemRemoved, item, null,
                                                                             reason, notifyAsync, handle, cbInfo.DataFilter);
                    }
                }
            }
            catch
            {
            }
        }
示例#3
0
        /// <summary>
        /// TheadSafe and no locks internally
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eventType">Should contain one type i.e. should not be used as a flag.
        /// Every EventType should be executed from another thread</param>
        /// <param name="item"></param>
        /// <param name="oldItem"></param>
        /// <param name="reason"></param>
        /// <param name="_notifyAsync"></param>
        /// <param name="eventhandle"></param>
        internal void RaiseSelectiveCacheNotification(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason reason, bool _notifyAsync, EventHandle eventhandle,EventDataFilter dataFilter)
        {
            try
            {
                ResourcePool poolID = null;

                CacheEventArg arg = null;

                if ((eventType & EventType.ItemUpdated) != 0)
                {
                    poolID = _selectiveUpdateEventIDPool;
                }
                else if ((eventType & EventType.ItemRemoved) != 0)
                {
                    poolID = _selectiveRemoveEventIDPool;
                }

                arg = CreateCacheEventArgument(dataFilter, key, _cacheName, eventType, item, oldItem, reason);

                if (poolID == null)
                    return;

                CacheDataNotificationCallback callback = poolID.GetResource((short)eventhandle.Handle) as CacheDataNotificationCallback;

                if (callback == null) //Can occur if Unregistered concurrently
                    return;

                if (_notifyAsync)
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC, new object[] { callback, key, arg}); //Faster and better
                else
                    callback.Invoke(key, arg);
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled) _logger.CriticalInfo(ex.ToString());
            }
        }
示例#4
0
            public virtual void OnCustomUpdateCallback(string key, object value, bool notifyAsync, EventCacheItem item,
                EventCacheItem oldItem, BitSet flag)
            {
                try
                {

                    CallbackInfo cbInfo = value as CallbackInfo;
                    if (cbInfo != null)
                    {
                        if (item != null) item.Value = GetObject(item.Value, flag);
                        if (oldItem != null) oldItem.Value = GetObject(oldItem.Value, flag);

                        if (_parent._perfStatsCollector != null)
                            _parent._perfStatsCollector.IncrementEventsProcessedPerSec();

                        EventHandle handle = new EventHandle((short) cbInfo.Callback);
                        this._eventManager.RaiseSelectiveCacheNotification(key, EventType.ItemUpdated, item, oldItem,
                            CacheItemRemovedReason.Underused, notifyAsync, handle, cbInfo.DataFilter);
                    }
                }
                catch
                {
                }
            }
示例#5
0
            public virtual void OnCustomRemoveCallback(string key, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item)
            {
                try
                {
                    object[] args = value as object[];
                    if (args != null)
                    {
                        object val = args[0];
                        CallbackInfo cbInfo = args[1] as CallbackInfo;
                        if (cbInfo != null)
                        {
                            if (_parent._perfStatsCollector != null)
                                _parent._perfStatsCollector.IncrementEventsProcessedPerSec();

                            if (item != null) item.Value = GetObject(item.Value, flag);
                            EventHandle handle = new EventHandle((short)cbInfo.Callback);
                            _parent.EventManager.RaiseSelectiveCacheNotification(key, EventType.ItemRemoved, item, null, reason, notifyAsync, handle, cbInfo.DataFilter);
                        }
                    }
                }
                catch { }
            }
示例#6
0
        /// <summary>
        /// TheadSafe and no locks internally
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eventType">Should contain one type i.e. should not be used as a flag.
        /// Every EventType should be executed from another thread</param>
        /// <param name="item"></param>
        /// <param name="oldItem"></param>
        /// <param name="reason"></param>
        /// <param name="_notifyAsync"></param>
        /// <param name="eventhandle"></param>
        internal void RaiseSelectiveCacheNotification(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason reason, bool _notifyAsync, EventHandle eventhandle, EventDataFilter dataFilter)
        {
            try
            {
                ResourcePool poolID = null;

                CacheEventArg arg = null;

                if ((eventType & EventType.ItemUpdated) != 0)
                {
                    poolID = _selectiveUpdateEventIDPool;
                }
                else if ((eventType & EventType.ItemRemoved) != 0)
                {
                    poolID = _selectiveRemoveEventIDPool;
                }

                arg = CreateCacheEventArgument(dataFilter, key, _cacheName, eventType, item, oldItem, reason);

                if (poolID == null)
                {
                    return;
                }

                CacheDataNotificationCallback callback = poolID.GetResource((short)eventhandle.Handle) as CacheDataNotificationCallback;

                if (callback == null) //Can occur if Unregistered concurrently
                {
                    return;
                }

                if (_notifyAsync)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC, new object[] { callback, key, arg }); //Faster and better
                }
                else
                {
                    callback.Invoke(key, arg);
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }
示例#7
0
        private bool RegisterGeneralDiscriptor(CacheEventDescriptor discriptor, EventType eventType)
        {
            if (discriptor == null)
            {
                return(false); //FAIL CONDITION
            }
            EventHandle handle = null;

            foreach (EventType type in Enum.GetValues(typeof(EventType)))
            {
                ResourcePool pool = null;
                bool         registrationUpdated = false;

                #region Pool selection

                if ((type & eventType) != 0)
                {
                    pool = GetEventPool(type);
                }

                if (pool == null)
                {
                    continue;
                }

                #endregion

                short registrationSequenceId = -1;

                lock (SyncLockGeneral)
                {
                    pool.AddResource(discriptor, 1); // Everytime a new Discriptor is forcefully created

                    //Keeps a sequence number

                    switch (type)
                    {
                    case EventType.ItemAdded:
                        if (discriptor.DataFilter > _generalAddDataFilter ||
                            _addEventRegistrationSequence == REFSTART)
                        {
                            registrationUpdated    = true;
                            registrationSequenceId = ++_addEventRegistrationSequence;
                            _generalAddDataFilter  = discriptor.DataFilter;
                        }
                        else
                        {
                            registrationSequenceId = _addEventRegistrationSequence;
                        }

                        break;

                    case EventType.ItemRemoved:
                        if (discriptor.DataFilter > _generalRemoveDataFilter ||
                            _removeEventRegistrationSequenceId == REFSTART)
                        {
                            registrationUpdated      = true;
                            registrationSequenceId   = ++_removeEventRegistrationSequenceId;
                            _generalRemoveDataFilter = discriptor.DataFilter;
                        }
                        else
                        {
                            registrationSequenceId = _removeEventRegistrationSequenceId;
                        }

                        break;

                    case EventType.ItemUpdated:
                        if (discriptor.DataFilter > _generalUpdateDataFilter ||
                            _updateEventRegisrationSequenceId == REFSTART)
                        {
                            registrationUpdated      = true;
                            registrationSequenceId   = ++_updateEventRegisrationSequenceId;
                            _generalUpdateDataFilter = discriptor.DataFilter;
                        }
                        else
                        {
                            registrationSequenceId = _updateEventRegisrationSequenceId;
                        }

                        break;
                    }

                    //Although the handle doesnt matter in general events
                    if (handle == null)
                    {
                        handle = new EventHandle(registrationSequenceId);
                    }
                }

                if (_cache != null && registrationSequenceId != -1)
                {
                    _cache.RegisterCacheNotificationDataFilter(type, discriptor.DataFilter, registrationSequenceId);
                }
            }

            discriptor.IsRegistered = true;
            discriptor.Handle       = handle;
            return(true);
        }