Esempio n. 1
0
        internal EventCacheItem ConvertToEventCacheItem(Common.Protobuf.EventCacheItem entry)
        {
            EventCacheItem cacheItem = new EventCacheItem();

            try
            {
                cacheItem.Group                    = entry.group;
                cacheItem.SubGroup                 = entry.subGroup;
                cacheItem.CacheItemVersion         = new CacheItemVersion();
                cacheItem.CacheItemVersion.Version = entry.itemVersion;
                cacheItem.CacheItemPriority        = (CacheItemPriority)entry.priority;
                //cacheItem.ResyncOptions = new Runtime.Caching.ResyncOptions(false, "");
                cacheItem.Flagmap = new Common.BitSet((byte)entry.flagMap);

                if (entry.value.Count > 0)
                {
                    List <byte[]>    val      = entry.value;
                    UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(entry.value.ToArray());
                    if (ubObject != null)
                    {
                        cacheItem.SetValue(ubObject.GetFullObject());
                    }
                }

                cacheItem.EntryType = Util.MiscUtil.ProtoItemTypeToEntryType(entry.itemType);
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(cacheItem);
        }
Esempio n. 2
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;
            item.CacheItemVersion  = new CacheItemVersion(cacheItem.itemVersion);
            item.Group             = String.IsNullOrEmpty(cacheItem.group) ? null : cacheItem.group;
            item.SubGroup          = String.IsNullOrEmpty(cacheItem.subGroup) ? null : cacheItem.subGroup;
            item.Flagmap           = new Common.BitSet((byte)cacheItem.flagMap);
            if (cacheItem.value != null && cacheItem.value.Count > 0)
            {
                UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(cacheItem.value.ToArray());
                objectValue = ubObject.GetFullObject();
                item.SetValue(objectValue);
            }

            item.EntryType = NCache.Util.MiscUtil.ProtoItemTypeToEntryType(cacheItem.itemType);

            return(item);
        }
Esempio n. 3
0
 internal EventArg(string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem)
 {
     _cacheName = cacheName;
     _eventType = eventType;
     _item      = item;
     _oldItem   = oldItem;
 }
Esempio n. 4
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;
                item.CacheItemVersion  = new CacheItemVersion(entry.Version);
                item.Group             = entry.Group;
                item.SubGroup          = entry.SubGroup;

                if (entry.Value != null)
                {
                    UserBinaryObject ubObject = entry.Value as UserBinaryObject;
                    if (ubObject != null)
                    {
                        objectValue = ubObject.GetFullObject();
                        item.SetValue(objectValue);
                    }
                    else
                    {
                        item.SetValue(entry.Value);
                    }
                }
                item.EntryType = entry.EntryType;

                return(item);
            }

            return(null);
        }
Esempio n. 5
0
 public ItemAddedTask(Broker parent, string key, bool notifyAsync, EventCacheItem item, BitSet flag)
 {
     this._parent      = parent;
     this._key         = key;
     this._notifyAsync = notifyAsync;
     this._item        = item;
     this._flag        = flag;
 }
Esempio n. 6
0
 public ItemRemoveEventTask(Broker parent, string key, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item)
 {
     this._parent      = parent;
     this._key         = key;
     this._value       = value;
     this._reason      = reason;
     this._flag        = flag;
     this._notifyAsync = notifyAsync;
     this._item        = item;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
        /// <summary>
        /// Clones the Event cache item instance.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            EventCacheItem clone = new EventCacheItem();

            clone._group             = _group;
            clone._version           = _version;
            clone._cacheItemPriority = _cacheItemPriority;
            clone._value             = _value;
            clone._entryType         = _entryType;
            clone._subGroup          = _subGroup;
            clone._flagMap           = _flagMap;
            return(clone);
        }
Esempio n. 10
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key, string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem    = null;
            EventCacheItem cloneOldItem = null;

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

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

            return(eventArg);
        }
Esempio n. 11
0
 internal static void UpdateArgItemForRaisedEvent(Cache cache, EventCacheItem eventCacheItem, string itemKey)
 {
 }
Esempio n. 12
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;
                var           bitSet = new BitSet();

                if (_cache.SerializationFormat == Common.Enum.SerializationFormat.Json)
                {
                    bitSet.SetBit(BitSetConstants.JsonData);
                }

                if (item != null)
                {
                    item.SetValue(_cache.SafeDeserialize <object>(item.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                }
                if (oldItem != null)
                {
                    oldItem.SetValue(_cache.SafeDeserialize <object>(oldItem.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                }
                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());
                }
            }
        }
Esempio n. 13
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(EventsUtil.GetEventTypeInternal(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 bitSet = new BitSet();

                        if (_cache.SerializationFormat == Common.Enum.SerializationFormat.Json)
                        {
                            bitSet.SetBit(BitSetConstants.JsonData);
                        }

                        if (item != null)
                        {
                            item.SetValue(_cache.SafeDeserialize <object>(item.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                        }

                        if (oldItem != null)
                        {
                            oldItem.SetValue(_cache.SafeDeserialize <object>(oldItem.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                        }

                        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
                            //TODO: ALACHISOFT (BeginInvoke is not supported in .Net Core thus using TaskFactory)
                            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());
                }
            }
        }
Esempio n. 14
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item, CacheEventDescriptor discriptor, CacheItemRemovedReason reason)
     : base(cachename, eventType, item)
 {
     _reason     = reason;
     _descriptor = discriptor;
 }
Esempio n. 15
0
 internal CacheEventArg(string key, string cachename, EventType eventType, EventCacheItem item, CacheEventDescriptor discriptor, EventCacheItem olditem)
     : base(cachename, eventType, item, olditem)
 {
     _descriptor = discriptor;
 }