Exemplo n.º 1
0
        internal static ItemRemoveCallbackResponse GetItemRemovedCallbackResponse(EventContext eventContext, short id, string key, UserBinaryObject value, BitSet flag, ItemRemoveReason reason,EventDataFilter dataFilter)
        {
            Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse itemRemovedCallback = new Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse();

            itemRemovedCallback.key = key;
            itemRemovedCallback.callbackId = id;
            itemRemovedCallback.itemRemoveReason = (int)reason;
            itemRemovedCallback.flag = flag != null? (int)flag.Data : 0;
            itemRemovedCallback.dataFilter = (short)dataFilter;
            itemRemovedCallback.eventId = new Common.Protobuf.EventId();
            UserBinaryObject binaryObject = eventContext.Item != null ?(UserBinaryObject) eventContext.Item.Value : null;
            if(binaryObject != null) itemRemovedCallback.value.AddRange(binaryObject.DataList);

            if (eventContext != null)
            {
                itemRemovedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID;
                itemRemovedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter;
                itemRemovedCallback.eventId.eventCounter = eventContext.EventID.EventCounter;
                if (eventContext.Item != null)
                    itemRemovedCallback.flag = eventContext.Item.Flags.Data;
                itemRemovedCallback.eventId.item = ConvertToEventItem(eventContext.Item, null);
                if (itemRemovedCallback.eventId.item != null && itemRemovedCallback.eventId.item.value != null)
                {
                    itemRemovedCallback.eventId.item.value.Clear();//data will be travalling in old fashion due to old callbacks
                }
            }

            return itemRemovedCallback;
        }
Exemplo n.º 2
0
 internal ItemUpdateCallback(short id, string key, string clientId, EventContext eventContext, EventDataFilter dataFilter)
 {
     _id = id;
     _key = key;
     _clientID = clientId;
     _eventContext = eventContext;
     _dataFilter = dataFilter;
 }
Exemplo n.º 3
0
 internal ItemRemoveCallback(short id, string key, object value, ItemRemoveReason reason, string clientId, BitSet Flag, EventContext eventContext,EventDataFilter dataFilter)
 {
     _id = id;
     _key = key;
     _value = value as UserBinaryObject;
     _flag = Flag;
     _reason = reason;
     _clientID = clientId;
     _eventContext = eventContext;
     _dataFilter = dataFilter;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
            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);
            }
Exemplo n.º 6
0
        internal static ItemUpdatedCallbackResponse GetItemUpdatedCallbackResponse(EventContext eventContext, string key, short callbackid, EventDataFilter dataFilter)
        {
            Alachisoft.NCache.Common.Protobuf.ItemUpdatedCallbackResponse itemUpdatedCallback = new Alachisoft.NCache.Common.Protobuf.ItemUpdatedCallbackResponse();

            itemUpdatedCallback.key = key;
            itemUpdatedCallback.callbackId = callbackid;
            itemUpdatedCallback.dataFilter = (short)dataFilter;
            itemUpdatedCallback.eventId = new Common.Protobuf.EventId();
            if (eventContext != null)
            {
                itemUpdatedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID;
                itemUpdatedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter;
                itemUpdatedCallback.eventId.eventCounter = eventContext.EventID.EventCounter;

                itemUpdatedCallback.eventId.item = ConvertToEventItem(eventContext.Item, dataFilter);
                itemUpdatedCallback.eventId.oldItem = ConvertToEventItem(eventContext.OldItem, dataFilter);
            }

            return itemUpdatedCallback;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deep clone.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            EventContext oc = new EventContext();
            lock (this)
            {
                if (oc._fieldValueTable == null) oc._fieldValueTable = new Hashtable();
                else oc._fieldValueTable.Clear();

                if (_fieldValueTable != null)
                {
                    IDictionaryEnumerator ide = _fieldValueTable.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        Object clone = ide.Value is ICloneable ? ((ICloneable)ide.Value).Clone() : ide.Value;

                        oc._fieldValueTable.Add(ide.Key, clone);
                    }
                }
            }
            return oc;
        }
Exemplo n.º 8
0
 /// <summary>
 /// This function is called by NodeLeftCallback
 /// </summary>
 /// <param name="notifId"></param>
 /// <param name="value"></param>
 private void NodeLeft(object clusterAddress, object serverAddress, EventContext eventContext)
 {
     lock (ConnectionManager.CallbackQueue)
     {
         if (_client == null) return;
         ConnectionManager.CallbackQueue.Enqueue(new NodeLeftEvent(_cacheId, clusterAddress as Alachisoft.NCache.Common.Net.Address, serverAddress as Alachisoft.NCache.Common.Net.Address, _client.ClientID));
         Monitor.Pulse(ConnectionManager.CallbackQueue);
     }
 }
Exemplo n.º 9
0
 private void HashmapChanged(NewHashmap newmap, EventContext eventContext)
 {
     lock (ConnectionManager.CallbackQueue)
     {
         if (_client != null)
         {
             ConnectionManager.CallbackQueue.Enqueue(new HashmapChangedEvent(_cacheId, _client.ClientID, newmap));
             Monitor.Pulse(ConnectionManager.CallbackQueue);
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Called when item is updated
        /// </summary>
        /// <param name="key">key of the item being updated</param>
        /// <param name="callbackEntry">callback entry that contains the updated value</param>
        private void CustomUpdate(object key, object callbackInfo, EventContext eventContext)
        {
            if (_client != null)
            {
                CallbackInfo cbInfo = callbackInfo as CallbackInfo;
                if (cbInfo != null && cbInfo.Client == _client.ClientID)
                {
                    //client older then 4.1 sp2 private patch 4 does not support bulk Events
                    if (_client.ClientVersion > 4124)
                    {
                        Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventitem = new Common.Protobuf.BulkEventItemResponse();
                        eventitem.eventType = Common.Protobuf.BulkEventItemResponse.EventType.ITEM_UPDATED_CALLBACK;
                        eventitem.ItemUpdatedCallback = EventHelper.GetItemUpdatedCallbackResponse(eventContext, (string)key, (short)cbInfo.Callback, cbInfo.DataFilter);

                        //To avoid NullReference problem if both evnt and NCache.Dispose are called simultaenously
                        ClientManager client = _client;
                        if (client != null) client.ConnectionManager.EnqueueEvent(eventitem, _client.SlaveId);
                    }
                    else
                    {
                        lock (ConnectionManager.CallbackQueue)
                        {
                            ConnectionManager.CallbackQueue.Enqueue(new ItemUpdateCallback((short)cbInfo.Callback, (string)key, cbInfo.Client, eventContext, cbInfo.DataFilter));
                            Monitor.Pulse(ConnectionManager.CallbackQueue);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="callbackEntry"></param>
        /// <param name="reason"></param>
        private void CustomRemove(object key, object value, ItemRemoveReason reason, BitSet Flag, EventContext eventContext)
        {
            if (_client != null)
            {
                object[] args = value as object[];
                if (args != null)
                {
                    object val = args[0];
                    CallbackInfo cbInfo = args[1] as CallbackInfo;
                    if (cbInfo != null && cbInfo.Client == _client.ClientID)
                    {
                        //client older then 4.1 sp2 private patch 4 does not support bulk Events
                        if (_client.ClientVersion > 4124)
                        {
                            Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventItem = new Common.Protobuf.BulkEventItemResponse();
                            eventItem.eventType = Common.Protobuf.BulkEventItemResponse.EventType.ITEM_REMOVED_CALLBACK;
                            eventItem.itemRemoveCallback = EventHelper.GetItemRemovedCallbackResponse(eventContext, (short)cbInfo.Callback, (string)key, (UserBinaryObject)val, Flag, reason,cbInfo.DataFilter);

                            //To avoid NullReference problem if both evnt and NCache.Dispose are called simultaenously
                            ClientManager client = _client;
                            if (client != null) client.ConnectionManager.EnqueueEvent(eventItem, _client.SlaveId);
                        }
                        else
                        {
                            lock (ConnectionManager.CallbackQueue)
                            {
                                ConnectionManager.CallbackQueue.Enqueue(new ItemRemoveCallback((short)cbInfo.Callback, (string)key, val, reason, _client.ClientID, Flag, eventContext,cbInfo.DataFilter));
                                Monitor.Pulse(ConnectionManager.CallbackQueue);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// This function is called by CacheStoppedCallback
 /// </summary>
 public void OnCacheStopped(string cacheId, EventContext eventContext)
 {
     //break the connection of the socket server with the client.
     if (_client != null) _client.OnCacheStopped(cacheId);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Fired when an item is updated and it has CacheItemUpdate callback attached with it.
        /// </summary>
        /// <param name="key">key of the cache item</param>
        /// <param name="value">CallbackEntry containing the callback and actual item</param>
        void ICacheEventsListener.OnCustomUpdateCallback(object key, object value, OperationContext operationContext, EventContext eventContext)
        {
            ArrayList updateListeners = value as ArrayList;

            if (updateListeners != null && updateListeners.Count > 0)
            {
                updateListeners = updateListeners.Clone() as ArrayList;
                foreach (CallbackInfo cbInfo in updateListeners)
                {
                    if (_connectedClients != null && _connectedClients.Contains(cbInfo.Client))
                    {
                        if (_customUpdateNotif != null)
                        {
                            Delegate[] dltList = _customUpdateNotif.GetInvocationList();
                            for (int i = dltList.Length - 1; i >= 0; i--)
                            {
                                CustomUpdateCallback subscriber = (CustomUpdateCallback)dltList[i];
                                try
                                {
                                    subscriber.BeginInvoke(key, cbInfo, eventContext, new System.AsyncCallback(CustomUpdateAsyncCallbackHandler), subscriber);
                                }
                                catch (System.Net.Sockets.SocketException e)
                                {
                                    _context.NCacheLog.Error("Cache.OnCustomUpdateCallback()", e.ToString());
                                    _customUpdateNotif -= subscriber;
                                }
                                catch (Exception e)
                                {
                                    _context.NCacheLog.Error("Cache.OnCustomUpdateCallback", e.ToString());
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Fired when an item is removed from the cache having CacheItemRemoveCallback.
        /// </summary>
        /// <param name="key">key of the cache item</param>
        /// <param name="value">CallbackEntry containing the callback and actual item</param>
        /// <param name="reason">reason the item was removed</param>
        void ICacheEventsListener.OnCustomRemoveCallback(object key, object value, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
        {
            CallbackEntry cbEntry = value as CallbackEntry;

            ArrayList removeCallbacklist = eventContext.GetValueByField(EventContextFieldName.ItemRemoveCallbackList) as ArrayList;


            if (removeCallbacklist != null && removeCallbacklist.Count > 0)
            {
                foreach (CallbackInfo cbInfo in removeCallbacklist)
                {

                    if (reason == ItemRemoveReason.Expired && cbInfo != null && !cbInfo.NotifyOnExpiration)
                        continue;

                    if (_connectedClients != null && _connectedClients.Contains(cbInfo.Client))
                    {
                        if (_customRemoveNotif != null)
                        {
                            Delegate[] dltList = _customRemoveNotif.GetInvocationList();
                            for (int i = dltList.Length - 1; i >= 0; i--)
                            {
                                CustomRemoveCallback subscriber = (CustomRemoveCallback)dltList[i];
                                try
                                {
                                    subscriber.BeginInvoke(key, new object[] { null, cbInfo }, reason, null, eventContext, new System.AsyncCallback(CustomRemoveAsyncCallbackHandler), subscriber);
                                }
                                catch (System.Net.Sockets.SocketException e)
                                {
                                    _context.NCacheLog.Error("Cache.OnCustomRemoveCallback()", e.ToString());
                                    _customRemoveNotif -= subscriber;
                                }
                                catch (Exception e)
                                {
                                    _context.NCacheLog.Error("Cache.OnCustomRemoveCallback", e.ToString());
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
 void ICacheEventsListener.OnCustomRemoveCallback(object key, object value, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 16
0
        public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
        {
            ArrayList depenedentItemList = new ArrayList();
            try
            {

                Hashtable totalRemovedItems = new Hashtable();

                CacheEntry entry = null;
                IDictionaryEnumerator ide = null;


                for (int i = 0; i < keys.Length; i++)
                {
                    try
                    {
                        if (keys[i] != null)
                            entry = Internal.Remove(keys[i], reason, false, null, LockAccessType.IGNORE_LOCK, operationContext);


                        if (entry != null)
                        {
                            totalRemovedItems.Add(keys[i], entry);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                ide = totalRemovedItems.GetEnumerator();
                while (ide.MoveNext())
                {
                    try
                    {
                        entry = ide.Value as CacheEntry;
                        if (entry != null)
                        {
                            if (entry.Value is CallbackEntry)
                            {
                                EventId eventId = null;
                                OperationID opId = operationContext.OperatoinID;
                                CallbackEntry cbEtnry = (CallbackEntry)entry.Value;
                                EventContext eventContext = null;

                                if (cbEtnry != null && cbEtnry.ItemRemoveCallbackListener != null && cbEtnry.ItemRemoveCallbackListener.Count > 0)
                                {
                                    //generate event id
                                    if (!operationContext.Contains(OperationContextFieldName.EventContext)) //for atomic operations
                                    {
                                        eventId = EventId.CreateEventId(opId);
                                    }
                                    else //for bulk
                                    {
                                        eventId = ((EventContext)operationContext.GetValueByField(OperationContextFieldName.EventContext)).EventID;
                                    }

                                    eventId.EventType = EventType.ITEM_REMOVED_CALLBACK;
                                    eventContext = new EventContext();
                                    eventContext.Add(EventContextFieldName.EventID, eventId);
                                    EventCacheEntry eventCacheEntry = CacheHelper.CreateCacheEventEntry(cbEtnry.ItemRemoveCallbackListener, entry);
                                    eventContext.Item = eventCacheEntry;
                                    eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEtnry.ItemRemoveCallbackListener.Clone());

                                    //Will always reaise the whole entry for old clients
                                    NotifyCustomRemoveCallback(ide.Key, entry, reason, true, operationContext, eventContext);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }


            }
            catch (Exception)
            {
                throw;
            }

            return depenedentItemList;
        }