Example #1
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item,
                        CacheEventDescriptor discriptor, CacheItemRemovedReason reason)
     : base(cachename, eventType, item)
 {
     _reason     = reason;
     _descriptor = discriptor;
 }
        public void OnCustomUpdateCallback(object key, object value, EventContext eventContext)
        {
            EventCacheItem item    = EventUtil.ConvertToItem(eventContext.Item);
            EventCacheItem oldItem = EventUtil.ConvertToItem(eventContext.OldItem);

            _listener.OnCustomUpdateCallback((string)key, value, true, item, oldItem, null);
        }
        public void OnItemRemoved(object key, object value, ItemRemoveReason reason, BitSet Flag,
                                  EventContext eventContext)
        {
            EventCacheItem item = null;

            try
            {
                BitSet flag = new BitSet(0);

                if (eventContext.Item != null)
                {
                    item = EventUtil.ConvertToItem(eventContext.Item);
                }

                if (_listener != null)
                {
                    _listener.OnItemRemoved((string)key,
                                            value,
                                            reason,
                                            Flag, true, item);
                }
            }
            catch
            {
            }
        }
Example #4
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key, string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem    = null;
            EventCacheItem cloneOldItem = null;

            if (dataFilter != EventDataFilter.None && item != null)
            {
                cloneItem = item.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneItem.Value = null;
                }
            }

            if (dataFilter != EventDataFilter.None && oldItem != null)
            {
                cloneOldItem = oldItem.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneOldItem.Value = null;
                }
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);

            if (eventType == EventType.ItemUpdated)
            {
                eventArg.OldItem = cloneOldItem;
            }

            return(eventArg);
        }
        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
            {
            }
        }
        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 void OnCustomUpdateCallback(short callbackId, string key, bool notifyAsync, EventCacheItem item,
                                           EventCacheItem oldItem, BitSet flag, EventDataFilter dataFilter)
        {
            CallbackInfo cbInfo = new CallbackInfo(null, callbackId, dataFilter);

            _listener.OnCustomUpdateCallback(key, cbInfo, notifyAsync, item, oldItem, flag);
        }
Example #8
0
 internal EventArg(string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem)
 {
     _cacheName = cacheName;
     _eventType = eventType;
     _item = item;
     _oldItem = oldItem;
 }
Example #9
0
 internal EventArg(string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem)
 {
     _cacheName = cacheName;
     _eventType = eventType;
     _item      = item;
     _oldItem   = oldItem;
 }
        public void OnItemUpdated(object key, EventContext eventContext)
        {
            EventCacheItem oldItem = null;
            EventCacheItem item    = null;

            try
            {
                BitSet flag = new BitSet(0);
                if (eventContext != null)
                {
                    if (eventContext.OldItem != null)
                    {
                        oldItem = EventUtil.ConvertToItem(eventContext.OldItem);
                    }
                    if (eventContext.Item != null)
                    {
                        item = EventUtil.ConvertToItem(eventContext.Item);
                    }

                    if (_listener != null)
                    {
                        _listener.OnItemUpdated((string)key, true, item, oldItem, flag);
                    }
                }
            }
            catch
            {
            }
        }
        public void OnCustomRemoveCallback(object key, object value, ItemRemoveReason reason, BitSet Flag,
                                           EventContext eventContext)
        {
            EventCacheItem         item         = EventUtil.ConvertToItem(eventContext.Item);
            CacheItemRemovedReason removeReason = EventUtil.ConvertToCIRemoveReason(reason);

            _listener.OnCustomRemoveCallback((string)key, value, removeReason, Flag, true, item);
        }
Example #12
0
        public object Clone()
        {
            EventCacheItem clone = new EventCacheItem();

            clone._cacheItemPriority = _cacheItemPriority;
            clone._value = _value;

            return clone;
        }
Example #13
0
        public object Clone()
        {
            EventCacheItem clone = new EventCacheItem();

            clone._cacheItemPriority = _cacheItemPriority;
            clone._value             = _value;

            return(clone);
        }
Example #14
0
 internal void OnItemRemoved(string key, bool notifyAsync, EventCacheItem item)
 {
     try
     {
         this.FireCQEvents(key, EventType.ItemRemoved, item, null, notifyAsync, "", null,
                           EventDataFilter.DataWithMetadata); //Supressess all exceptions
     }
     catch (Exception)
     {
     }
 }
 public ItemUpdateCallbackTask(Broker parent, string key, short callBackId, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag,EventDataFilter dataFilter)
 {
     this._parent = parent;
     this._key = key;
     this._callBackId = callBackId;
     this._notifyAsync = notifyAsync;
     this._item = item;
     this._oldItem = oldItem;
     this._flag = flag;
     this._dataFilter = dataFilter;
 }
 public ItemRemoveCallBackTask(Broker parent, string key, short callBackId, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item,EventDataFilter dataFilter)
 {
     this._parent = parent;
     this._key = key;
     this._callBackId = callBackId;
     this._value = value;
     this._reason = reason;
     this._flag = flag;
     this._notifyAsync = notifyAsync;
     this._item = item;
     this._dataFilter = dataFilter;
 }
Example #17
0
 internal void OnItemUpdated(string key, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem)
 {
     try
     {
         this.FireCQEvents(key, EventType.ItemUpdated, item, oldItem, notifyAsync, "", null,
                           EventDataFilter.None); //Supressess all exceptions
     }
     catch (Exception)
     {
         //Logger
     }
 }
Example #18
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>
        internal void RaiseGeneralCacheNotification(string key, EventType eventType, EventCacheItem item,
                                                    EventCacheItem oldItem, CacheItemRemovedReason reason, bool notifyAsync)
        {
            try
            {
                object[] registeredDiscriptors = null;

                ResourcePool eventPool = GetEventPool(eventType);
                if (eventPool != null)
                {
                    registeredDiscriptors = eventPool.GetAllResourceKeys();
                }

                if (registeredDiscriptors != null && registeredDiscriptors.Length > 0)
                {
                    for (int i = 0; i < registeredDiscriptors.Length; i++)
                    {
                        CacheEventDescriptor discriptor = registeredDiscriptors[i] as CacheEventDescriptor;

                        if (discriptor == null)
                        {
                            continue;
                        }

                        var arg = CreateCacheEventArgument(discriptor.DataFilter, key, _cacheName, eventType, item, oldItem,
                                                           reason);
                        arg.Descriptor = discriptor;

                        if (notifyAsync)
                        {
#if !NETCORE
                            discriptor.CacheDataNotificationCallback.BeginInvoke(key, arg, asyn, null);
#elif NETCORE
                            TaskFactory factory = new TaskFactory();
                            Task        task    = factory.StartNew(() => discriptor.CacheDataNotificationCallback(key, arg));
#endif
                        }
                        else
                        {
                            discriptor.CacheDataNotificationCallback.Invoke(key, arg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }
Example #19
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)
                {
                    return;
                }

                if (_notifyAsync)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC,
                                                                  new object[] { callback, key, arg });
                }
                else
                {
                    callback.Invoke(key, arg);
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }
 public void OnItemAdded(string key, bool notifyAsync, EventCacheItem item, BitSet flag)
 {
     try
     {
         if (_listener != null)
         {
             _listener.OnItemAdded(key, notifyAsync, item, flag);
         }
     }
     catch
     {
     }
 }
 public void OnItemRemoved(string key, object value, CacheItemRemovedReason reason, BitSet flag,
                           bool notifyAsync, EventCacheItem item)
 {
     try
     {
         if (_listener != null)
         {
             _listener.OnItemRemoved(key, value, reason, flag, notifyAsync, item);
         }
     }
     catch (Exception e)
     {
     }
 }
Example #22
0
        public object Clone()
        {
            EventCacheItem clone = new EventCacheItem();

            clone._group              = _group;
            clone._subGroup           = _subGroup;
            clone._version            = _version;
            clone._resyncExpiredItems = _resyncExpiredItems;
            clone._resyncProviderName = _resyncProviderName;
            clone._cacheItemPriority  = _cacheItemPriority;
            clone._value              = _value;

            return(clone);
        }
 public void OnActiveQueryChanged(string queryId, QueryChangeType changeType, string key, bool notifyAsync,
                                  EventCacheItem item, EventCacheItem oldItem, BitSet flag, EventDataFilter datafilter)
 {
     try
     {
         if (_listener != null)
         {
             _listener.OnActiveQueryChanged(queryId, changeType, key, notifyAsync, item, oldItem, flag,
                                            datafilter);
         }
     }
     catch
     {
     }
 }
 public virtual void OnItemRemoved(string key, object value, CacheItemRemovedReason reason, BitSet Flag,
                                   bool notifyAsync, EventCacheItem item)
 {
     try
     {
         if (item != null && value != null)
         {
             item.Value = value = GetObject(value, Flag);
         }
         this._eventManager.RaiseGeneralCacheNotification(key, EventType.ItemRemoved, item, null, reason,
                                                          notifyAsync);
     }
     catch
     {
     }
 }
        public void OnItemAdded(object key, EventContext eventContext)
        {
            try
            {
                BitSet         flag = new BitSet(0);
                EventCacheItem item = EventUtil.ConvertToItem(eventContext.Item);

                if (_listener != null)
                {
                    _listener.OnItemAdded((string)key, true, item, flag);
                }
            }
            catch
            {
            }
        }
Example #26
0
        internal static EventCacheItem ConvertToEventEntry(Alachisoft.NCache.Common.Protobuf.EventCacheItem cacheItem)
        {
            Byte[] objectValue = null;

            if (cacheItem == null) return null;

            EventCacheItem item = new EventCacheItem();
            item.CacheItemPriority = (CacheItemPriority)cacheItem.priority;
            if (cacheItem.value != null && cacheItem.value.Count > 0)
            {
                UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(cacheItem.value.ToArray());
                objectValue = ubObject.GetFullObject();
                item.Value = objectValue;
            }

            return item;
        }
 public virtual void OnItemAdded(object key, bool notifyAsync, EventCacheItem item, BitSet flag)
 {
     try
     {
         String keyString = key as string;
         if (key != null)
         {
             if (item != null && item.Value != null)
             {
                 item.Value = GetObject(item.Value, flag);
             }
             _eventManager.RaiseGeneralCacheNotification(keyString, EventType.ItemAdded, item, null,
                                                         CacheItemRemovedReason.Underused, notifyAsync);
         }
     }
     catch
     {
     }
 }
        public virtual void OnActiveQueryChanged(string queryId, QueryChangeType changeType, string key,
                                                 bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag, EventDataFilter datafilter)
        {
            if (item != null && item.Value != null)
            {
                item.Value = GetObject(item.Value, flag);
            }
            if (oldItem != null && oldItem.Value != null)
            {
                oldItem.Value = GetObject(oldItem.Value, flag);
            }

            ContinuousQueryManager.Notify(queryId, changeType, key, notifyAsync, item, oldItem, flag,
                                          this._parent.CacheImpl.Name, datafilter);
            if (_parent._perfStatsCollector != null)
            {
                _parent._perfStatsCollector.IncrementEventsProcessedPerSec();
            }
        }
Example #29
0
        public static void Notify(string queryId, QueryChangeType changeType, string key, bool notifyAsync,
                                  EventCacheItem item, EventCacheItem oldItem, BitSet flag, string cacheName, EventDataFilter datafilter)
        {
            ContinuousQuery[] registeredQueries = null;
            lock (sync)
            {
                if (queries.Count == 0)
                {
                    return;
                }
                registeredQueries = new ContinuousQuery[queries.Count];
                queries.CopyTo(registeredQueries);
            }

            foreach (ContinuousQuery query in registeredQueries)
            {
                try
                {
                    if (query.ServerUniqueID.Equals(queryId))
                    {
                        if (changeType == QueryChangeType.Add)
                        {
                            query.FireCQEvents(key, Runtime.Events.EventType.ItemAdded, item, oldItem, notifyAsync,
                                               cacheName, flag, datafilter);
                        }
                        else if (changeType == QueryChangeType.Remove)
                        {
                            query.FireCQEvents(key, Runtime.Events.EventType.ItemRemoved, item, oldItem, notifyAsync,
                                               cacheName, flag, datafilter);
                        }
                        else
                        {
                            query.FireCQEvents(key, Runtime.Events.EventType.ItemUpdated, item, oldItem, notifyAsync,
                                               cacheName, flag, datafilter);
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
 public virtual void OnItemUpdated(object key, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem,
                                   BitSet flag)
 {
     try
     {
         string ketString = key as string;
         if (ketString != null)
         {
             if (item != null && item.Value != null)
             {
                 item.Value = GetObject(item.Value, flag);
             }
             if (oldItem != null && oldItem.Value != null)
             {
                 oldItem.Value = GetObject(oldItem.Value, flag);
             }
             this._eventManager.RaiseGeneralCacheNotification(ketString, EventType.ItemUpdated, item,
                                                              oldItem, CacheItemRemovedReason.Underused, notifyAsync);
         }
     }
     catch (Exception e)
     {
     }
 }
Example #31
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key,string cacheName,EventType eventType,EventCacheItem item,EventCacheItem oldItem,CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem = null;
            EventCacheItem cloneOldItem = null;

            if (dataFilter != EventDataFilter.None && item != null)
            {
                cloneItem = item.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                    cloneItem.Value = null;
            }

            if (dataFilter != EventDataFilter.None && oldItem != null)
            {
                cloneOldItem = oldItem.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                    cloneOldItem.Value = null;
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);
            if (eventType == EventType.ItemUpdated) eventArg.OldItem = cloneOldItem;

            return eventArg;
        }
Example #32
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());
            }
        }
Example #33
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
                {
                }
            }
Example #34
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 { }
            }
Example #35
0
 internal CQEventArg(string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem)
     : base(cacheName, eventType, item, oldItem)
 {
 }
 public void OnCustomRemoveCallback(short callbackId, string key, object value,
                                    CacheItemRemovedReason reason, BitSet Flag, bool notifyAsync, EventCacheItem item,
                                    EventDataFilter dataFilter)
 {
     object[] val = new object[] { value, new CallbackInfo(null, callbackId, dataFilter) };
     _listener.OnCustomRemoveCallback(key, val, reason, Flag, notifyAsync, item);
 }
Example #37
0
 public void OnCustomUpdateCallback(short callbackId, string key, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag,EventDataFilter dataFilter)
 {
     CallbackInfo cbInfo = new CallbackInfo(null, callbackId,dataFilter);
     _listener.OnCustomUpdateCallback(key, cbInfo, notifyAsync, item, oldItem, flag);
 }
Example #38
0
 public void OnCustomRemoveCallback(short callbackId, string key, object value, CacheItemRemovedReason reason, BitSet Flag, bool notifyAsync, EventCacheItem item,EventDataFilter dataFilter)
 {
     object[] val = new object[] { value, new CallbackInfo(null, callbackId,dataFilter) };
     _listener.OnCustomRemoveCallback(key, val, reason, Flag, notifyAsync, item);
 }
Example #39
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item, CacheEventDescriptor discriptor, EventCacheItem olditem)
     : base(cachename, eventType, item, olditem)
 {
     _descriptor = discriptor;
 }
Example #40
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item, CacheEventDescriptor discriptor, CacheItemRemovedReason reason)
     : base(cachename, eventType, item)
 {
     _reason = reason;
     _descriptor = discriptor;
 }
Example #41
0
        /// <summary>
        /// For Inproc only
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        internal static EventCacheItem ConvertToItem(EventCacheEntry entry)
        {
            Byte[] objectValue = null;
            if (entry != null)
            {
                EventCacheItem item = new EventCacheItem();
                item.CacheItemPriority = (CacheItemPriority)entry.Priority;
                if (entry.Value != null)
                {
                    UserBinaryObject ubObject = entry.Value as UserBinaryObject;
                    if (ubObject != null)
                    {
                        objectValue = ubObject.GetFullObject();
                        item.Value = objectValue;
                    }
                    else
                        item.Value = entry.Value;
                }

                return item;
            }

            return null;
        }
Example #42
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item, CacheEventDescriptor discriptor, EventCacheItem olditem)
     : base(cachename, eventType, item, olditem)
 {
     _descriptor = discriptor;
 }
Example #43
0
        internal void FireCQEvents(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem,
                                   bool notifyAsync, string cacheName, BitSet flag, EventDataFilter datafilter)
        {
            try
            {
                CQEventArg arg = null;

                ICollection  collection = null;
                ResourcePool pool       = null;
                ResourcePool filterPool = null;
                if ((eventType & EventType.ItemAdded) != 0 && _cqAddEventPool != null)
                {
                    pool       = _cqAddEventPool;
                    collection = _cqAddEventPool.Keys;
                    filterPool = _cqAddEventDataFilter;
                }
                else if ((eventType & EventType.ItemUpdated) != 0 && _cqUpdateEventPool != null)
                {
                    pool       = _cqUpdateEventPool;
                    collection = _cqUpdateEventPool.Keys;
                    filterPool = _cqUpdateEventDataFilter;
                }
                else if ((eventType & EventType.ItemRemoved) != 0 && _cqRemoveEventPool != null)
                {
                    pool       = _cqRemoveEventPool;
                    collection = _cqRemoveEventPool.Keys;
                    filterPool = _cqRemoveEventDataFilter;
                }
                else
                {
                    return;
                }


                if (collection != null && collection.Count > 0)
                {
                    QueryDataNotificationCallback[] disc = null;
                    lock (syncLock)
                    {
                        disc = new QueryDataNotificationCallback[collection.Count];
                        collection.CopyTo(disc, 0); //to avoid locking
                    }

                    for (int i = 0; i < disc.Length; i++)
                    {
                        short  index = -1;
                        object obj   = pool.GetResource(disc[i]);
                        index = Convert.ToInt16(obj);

                        if (index > -1)
                        {
                            //Not to fire event if datafilter recieved is less than requried OR noDF present
                            EventDataFilter queryDataFilter = (EventDataFilter)filterPool.GetResource(index);

                            if ((eventType & EventType.ItemAdded) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemAdded, item,
                                                            oldItem);
                            }
                            else if ((eventType & EventType.ItemUpdated) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemUpdated,
                                                            item, oldItem);
                            }
                            else if ((eventType & EventType.ItemRemoved) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemRemoved,
                                                            item, oldItem);
                            }
                            else
                            {
                                return;
                            }

                            arg.ContinuousQuery = this;

                            if (notifyAsync)
                            {
#if !NETCORE
                                disc[i].BeginInvoke(key, arg, asyn, disc[i]);
#elif NETCORE
                                TaskFactory factory = new TaskFactory();
                                int         temp    = i;
                                Task        task    = factory.StartNew(() => disc[temp](key, arg));
#endif
                            }
                            else
                            {
                                disc[i].Invoke(key, arg);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }