Esempio 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;
        }
Esempio n. 2
0
        /// <summary>
        /// Remove the objects from the cluster.
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="keys">keys of the entries.</param>
        /// <param name="ir"></param>
        /// <param name="cbEntry"></param>
        /// <param name="notify"></param>
        /// <param name="operationContext"></param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_Remove(Address dest, object[] keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("PartCacheBase.RemoveBlk", "");
            }

            Hashtable removedEntries = new Hashtable();
            ArrayList dests          = new ArrayList();

            dests.Add(dest);
            try
            {
                Function func    = new Function((int)OpCodes.Remove, new object[] { keys, ir, notify, cbEntry, operationContext }, false);
                RspList  results = Cluster.Multicast(dests, func, GetFirstResponse, false);

                if (results == null)
                {
                    return(removedEntries);
                }

                //muds:
                if (results.SuspectedMembers.Count == dests.Count)
                {
                    //All the members of this group has gone down.
                    //we must try this operation on some other group.
                    throw new Runtime.Exceptions.SuspectedException("operation failed because the group member was suspected");
                }

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return(removedEntries);
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp       rsp     = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return(removedEntries);
        }
Esempio n. 3
0
        /// <summary>
        /// This function is called by ItemRemovedCallback
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="reason"></param>
        private void ItemRemoved(object key, object value, ItemRemoveReason reason, BitSet Flag, EventContext eventContext)
        {
            //value which arrives will be null
            value = eventContext.Item.Value;

            if (_client != null)
            {
                //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_EVENT;
                    eventItem.itemRemovedEvent = EventHelper.GetItemRemovedEventResponse(eventContext, (string)key, this.ItemRemovedFilter, Flag, reason, (UserBinaryObject)value);

                    // _client.EnqueueEvent(eventItem);
                    //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 ItemRemovedEvent((string)key, _cacheId, reason, (UserBinaryObject)value, _client.ClientID, Flag, eventContext));
                        Monitor.Pulse(ConnectionManager.CallbackQueue);
                    }
                }
            }
        }
        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
            {
            }
        }
Esempio n. 5
0
        internal static CacheItemRemovedReason ConvertToCIRemoveReason(ItemRemoveReason reason)
        {
            switch (reason)
            {
            case ItemRemoveReason.Expired:
                return(CacheItemRemovedReason.Expired);

                break;

            case ItemRemoveReason.Removed:
                return(CacheItemRemovedReason.Removed);

                break;

            case ItemRemoveReason.Underused:
                return(CacheItemRemovedReason.Underused);

                break;

            default:
                return(CacheItemRemovedReason.Underused);

                break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            CacheEntry e = base.RemoveInternal(key, removalReason, isUserOperation, operationContext);

            if (e != null)
            {
                _grpIndexManager.RemoveFromGroup(key, e.GroupInfo);


                if (_queryIndexManager != null && e.ObjectType != null)
                {
                    _queryIndexManager.RemoveFromIndex(key, e);
                }
            }
            if (_context.PerfStatsColl != null)
            {
                if (_queryIndexManager != null)
                {
                    _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize);
                }

                _context.PerfStatsColl.SetGroupIndexSize(_grpIndexManager.IndexInMemorySize);
            }
            return(e);
        }
 public AsyncLocalNotifyRemoveCallback(ICacheEventsListener listener, object key, object entry, ItemRemoveReason reason)
 {
     _listener = listener;
     _key      = key;
     _entry    = entry;
     _reason   = reason;
 }
Esempio n. 8
0
 /// <summary>
 /// remove item from the primary cache and move items to the secondary cache if items are
 /// being evicted from the primary cache.
 /// </summary>
 /// <param name="keys"></param>
 /// <param name="reason"></param>
 /// <param name="notify"></param>
 /// <returns></returns>
 public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
 {
     if (reason == ItemRemoveReason.Expired)
     {
         return(_context.CacheImpl.RemoveSync(keys, reason, notify, operationContext));
     }
     if (_primary != null)
     {
         for (int i = 0; i < keys.Length; i++)
         {
             CacheEntry entry = _primary.Remove(keys[i], reason, false, null, LockAccessType.IGNORE_LOCK, operationContext);
             if (entry == null)
             {
                 continue;
             }
             if (reason == ItemRemoveReason.Underused && entry != null)
             {
                 _secondary.Add(keys[i], entry, false, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
             }
             else
             {
                 ((IDisposable)entry).Dispose();
             }
         }
     }
     return(null);
 }
Esempio n. 9
0
        /// <summary>
        /// Remove the objects from the cluster. For efficiency multiple objects are sent as one.
        /// </summary>
        /// <param name="keys">list of keys to remove.</param>
        /// <returns>true if succeded, false otherwise.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemoveRange"/> on every server node in the cluster.
        /// </remarks>
        protected bool Clustered_Remove(object[] keys, ItemRemoveReason reason, OperationContext operationContext)
        {
            try
            {
                Function func    = new Function((int)OpCodes.RemoveRange, new object[] { keys, reason, operationContext }, false);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, true);

                if (results != null)
                {
                    for (int i = 0; i < results.size(); i++)
                    {
                        Rsp rsp1 = (Rsp)results.elementAt(i);

                        if (!rsp1.wasReceived())
                        {
                            Context.NCacheLog.Error("ReplicatedBase.Remove[]", "timeout_failure :" + rsp1.Sender + " Keys :" + keys.Length);
                            continue;
                        }
                    }
                }
                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results, Context.NCacheLog);

                return(true);
            }
            catch (Runtime.Exceptions.TimeoutException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Esempio n. 10
0
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            int bucketId = GetBucketId(key as string);

            if (isUserOperation)
            {
                if (IsBucketTransfered(bucketId))
                {
                    throw new StateTransferException("I am no more the owner of this bucket");
                }
            }

            if (_logMgr.IsLoggingEnbaled(bucketId, LogMode.LogBeforeActualOperation) && isUserOperation)
            {
                CacheEntry e = Get(key, operationContext);
                _logMgr.LogOperation(bucketId, key, null, OperationType.Delete);
                return(e);
            }

            CacheEntry entry = base.RemoveInternal(key, removalReason, isUserOperation, operationContext);

            if (entry != null)
            {
                if (isUserOperation)
                {
                    _logMgr.LogOperation(bucketId, key, null, OperationType.Delete);
                }
                DecrementBucketStats(key as string, bucketId, entry.DataSize);
            }
            return(entry);
        }
        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);
        }
Esempio n. 12
0
 public AsyncLocalNotifyRemoval(ICacheEventsListener listener, object key, object value, ItemRemoveReason reason, OperationContext operationContext)
 {
     _listener         = listener;
     _key              = key;
     _value            = value;
     _reason           = reason;
     _operationContext = operationContext;
 }
Esempio n. 13
0
 void ICacheEventsListener.OnItemRemoved(object key, object val, ItemRemoveReason reason, OperationContext operationContext)
 {
     if ((reason == ItemRemoveReason.Underused) && (_parent.Listener != null))
     {
         _parent.Listener.OnItemRemoved(key, val, reason, operationContext);
     }
     ((IDisposable)val).Dispose();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncBroadcastNotifyRemoval(ClusterCacheBase parent, object key, object value, ItemRemoveReason reason, OperationContext operationContext, EventContext[] eventContexts)
 {
     _parent           = parent;
     _key              = key;
     _value            = value;
     _reason           = reason;
     _operationContext = operationContext;
     _eventContexts    = eventContexts;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncBroadcastCustomNotifyRemoval(ClusterCacheBase parent, object key, CacheEntry entry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     _parent           = parent;
     _key              = key;
     _entry            = entry;
     _reason           = reason;
     _operationContext = operationContext;
     _eventContext     = eventContext;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncBroadcastCustomNotifyRemoval(ClusterCacheBase parent, object key, CacheEntry entry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     _parent = parent;
     _key = key;
     _entry = entry;
     _reason = reason;
     _operationContext = operationContext;
     _eventContext = eventContext;
 }
Esempio n. 17
0
 public void Deserialize(Runtime.Serialization.IO.CompactReader reader)
 {
     _cbInfoList = (ArrayList)reader.ReadObject();
     _clientIds  = (List <string>)reader.ReadObject();
     _flag       = (BitSet)reader.ReadObject();
     _key        = (string)reader.ReadObject();
     _reason     = (ItemRemoveReason)reader.ReadObject();
     _value      = (ArrayList)reader.ReadObject();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncLocalNotifyRemoveCallback(ICacheEventsListener listener, object key, object entry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     _listener         = listener;
     _key              = key;
     _entry            = entry;
     _reason           = reason;
     _operationContext = operationContext;
     _eventContext     = eventContext;
 }
Esempio n. 19
0
        /// <summary>
        /// Remove the objects from the cluster.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_Remove(object[] keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext)
        {
            Hashtable removedEntries = new Hashtable();

            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "enter");
                }
                Function func    = new Function((int)OpCodes.Remove, new object[] { keys, ir, notify, cbEntry, operationContext }, false);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL);

                if (results == null)
                {
                    return(removedEntries);
                }

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return(removedEntries);
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp       rsp     = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "exit");
                }
            }
            return(removedEntries);
        }
Esempio n. 20
0
 /// <summary>
 /// Fired when an item is removed from the cache.
 /// </summary>
 void ICacheEventsListener.OnItemRemoved(object key, object val, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     if ((reason == ItemRemoveReason.Underused) && (_parent.Listener != null))
     {
         //if(nTrace.isInfoEnabled) nTrace.info("SecondaryCacheListener.OnItemRemoved()", "discarding from secondary cache : " + key);
         //if (_parent.IsSelfInternal) _parent._context.PerfStatsColl.IncrementEvictPerSecStats();
         _parent.Listener.OnItemRemoved(key, val, reason, operationContext, eventContext);
     }
     ((IDisposable)val).Dispose();
 }
Esempio n. 21
0
 internal ItemRemovedEvent(string key, string cacheId, ItemRemoveReason reason, UserBinaryObject value, string clientId, BitSet Flag, EventContext eventContext)
 {
     _key          = key;
     _cacheId      = cacheId;
     _reason       = reason;
     _value        = value;
     _clientId     = clientId;
     _flag         = Flag;
     _eventContext = eventContext;
 }
Esempio n. 22
0
        /// <summary>
        /// Remove a entrada associada com a chave informada.
        /// </summary>
        /// <param name="key">Chave da entrada que será removida.</param>
        /// <param name="ir"></param>
        /// <param name="notify"></param>
        /// <param name="lockId"></param>
        /// <param name="version"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <returns></returns>
        public override CacheEntry Remove(object key, ItemRemoveReason ir, bool notify, object lockId, ulong version, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry entry = this.Internal.Remove(key, ir, notify, lockId, version, accessType, operationContext);

            if ((entry != null) && (entry.KeysIAmDependingOn != null))
            {
                this.Internal.RemoveDepKeyList(base.GetKeysTable(key, entry.KeysIAmDependingOn), operationContext);
            }
            return(entry);
        }
Esempio n. 23
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;
 }
Esempio n. 24
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;
 }
Esempio n. 25
0
 void ICacheEventsListener.OnItemRemoved(object key, object val, ItemRemoveReason reason, OperationContext operationContext)
 {
     if (reason == ItemRemoveReason.Underused)
     {
         _parent.Secondary.Add(key, (CacheEntry)val, false, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
     }
     else
     {
         ((IDisposable)val).Dispose();
     }
 }
Esempio n. 26
0
 public void OnItemsRemoved(object[] key, object[] val, ItemRemoveReason reason, OperationContext operationContext)
 {
     if ((reason == ItemRemoveReason.Underused) && (_parent.Listener != null))
     {
         for (int i = 0; i < key.Length; i++)
         {
             _parent.Listener.OnItemRemoved(key[i], val[i], reason, operationContext);
             ((IDisposable)val[i]).Dispose();
         }
     }
 }
Esempio n. 27
0
        /// <summary>
        /// Converts between NCache item remove reason and web item remove reason.
        /// </summary>
        /// <param name="reason"></param>
        /// <returns></returns>
        public static CacheItemRemovedReason GetWebItemRemovedReason(ItemRemoveReason reason)
        {
            switch(reason)
            {
                case ItemRemoveReason.Expired:
                    return CacheItemRemovedReason.Expired;

                case ItemRemoveReason.Underused:
                    return CacheItemRemovedReason.Underused;
            }
            return CacheItemRemovedReason.Removed;
        }
Esempio n. 28
0
        internal static CacheItemRemovedReason GetWebItemRemovedReason(ItemRemoveReason reason)
        {
            switch (reason)
            {
            case ItemRemoveReason.Expired:
                return(CacheItemRemovedReason.Expired);

            case ItemRemoveReason.Underused:
                return(CacheItemRemovedReason.Underused);
            }
            return(CacheItemRemovedReason.Removed);
        }
Esempio n. 29
0
 public override Hashtable Remove(object[] keys, ItemRemoveReason ir, bool notify, string taskId, OperationContext operationContext)
 {
     base.Sync.AcquireWriterLock(-1);
     try
     {
         return(this.Internal.Remove(keys, ir, notify, operationContext));
     }
     finally
     {
         base.Sync.ReleaseWriterLock();
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Remove a entrada associada com a chave informada.
 /// </summary>
 /// <param name="key">Chave da entrada que será apagada.</param>
 /// <param name="ir"></param>
 /// <param name="notify"></param>
 /// <param name="taskId"></param>
 /// <param name="lockId"></param>
 /// <param name="version"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns></returns>
 public override CacheEntry Remove(object key, ItemRemoveReason ir, bool notify, string taskId, object lockId, ulong version, LockAccessType accessType, OperationContext operationContext)
 {
     base.Sync.AcquireWriterLock(-1);
     try
     {
         return(this.Internal.Remove(key, ir, notify, lockId, version, accessType, operationContext));
     }
     finally
     {
         base.Sync.ReleaseWriterLock();
     }
 }
Esempio n. 31
0
 /// <summary>
 /// Fired when an item is removed from the cache.
 /// </summary>
 void ICacheEventsListener.OnItemRemoved(object key, object val, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     if (reason == ItemRemoveReason.Underused)
     {
         //if(nnTrace.isInfoEnabled) nTrace.info("PrimaryCacheListener.OnItemRemoved()", "trying to add to secondary cache : " + key);
         _parent.Secondary.Add(key, (CacheEntry)val, false, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
     }
     else
     {
         ((IDisposable)val).Dispose();
     }
 }
Esempio n. 32
0
        /// <summary>
        /// Remove the object from the cluster.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected CacheEntry Clustered_Remove(object key, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry retVal = null;

            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Remove", "enter");
                }
                Function func    = new Function((int)OpCodes.Remove, new object[] { key, ir, notify, cbEntry, lockId, accessType, operationContext }, false, key);
                RspList  results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, _asyncOperation);
                if (results == null)
                {
                    return(retVal);
                }

                ClusterHelper.ValidateResponses(results, typeof(OperationResponse), Name);

                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results);
                if (rsp == null)
                {
                    return(retVal);
                }

                OperationResponse opRes = rsp.Value as OperationResponse;
                if (opRes != null)
                {
                    CacheEntry entry = opRes.SerializablePayload as CacheEntry;
                    if (entry != null)
                    {
                        entry.Value = opRes.UserPayload;
                    }
                    return(entry);
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("RepCacheBase.Remove", "exit");
                }
            }
            return(retVal);
        }
Esempio n. 33
0
            /// <summary>
            /// Fired when multiple items are removed from the cache.
            /// </summary>
            public void OnItemsRemoved(object[] key, object[] val, ItemRemoveReason reason, OperationContext operationContext, EventContext[] eventContext)
            {
                if (reason != ItemRemoveReason.Underused || (_parent.Listener == null))
                {
                    return;
                }

                for (int i = 0; i < key.Length; i++)
                {
                    _parent.Listener.OnItemRemoved(key[i], val[i], reason, operationContext, eventContext[i]);
                    ((IDisposable)val[i]).Dispose();
                }
            }
Esempio n. 34
0
        /// <summary>
        /// Remove a entrada associada com o chave.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="removalReason"></param>
        /// <param name="isUserOperation"></param>
        /// <param name="operationContext"></param>
        /// <returns></returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            CacheEntry entry = base.RemoveInternal(key, removalReason, isUserOperation, operationContext);

            if (entry != null)
            {
                _grpIndexManager.RemoveFromGroup(key, entry.GroupInfo);
                if ((_queryIndexManager != null) && (entry.QueryInfo != null))
                {
                    _queryIndexManager.RemoveFromIndex(key, entry.QueryInfo);
                }
            }
            return(entry);
        }
Esempio n. 35
0
			/// <summary> 
			/// Fired when multiple items are removed from the cache. 
			/// </summary>
            public void OnItemsRemoved(object[] key, object[] val, ItemRemoveReason reason, OperationContext operationContext, EventContext[] eventContext)
			{
                if (reason == ItemRemoveReason.Underused)
                {
                    for (int i = 0; i < key.Length; i++)
                    {
                        _parent.Secondary.Add(key[i], (CacheEntry)val[i], false, operationContext);
                    }
                }
                else 
                {  
                    for (int i = 0; i < key.Length; i++)
                    {
                        ((IDisposable)val[i]).Dispose();
                    }
                }
			}
Esempio n. 36
0
 internal static CacheItemRemovedReason ConvertToCIRemoveReason(ItemRemoveReason reason)
 {
     switch(reason)
     {
         case ItemRemoveReason.Expired:
             return CacheItemRemovedReason.Expired;
             break;
         case ItemRemoveReason.Removed:
             return CacheItemRemovedReason.Removed;
             break;
         case ItemRemoveReason.Underused:
             return CacheItemRemovedReason.Underused;
             break;
         default:
             return CacheItemRemovedReason.Underused;
             break;
     }
 }
Esempio n. 37
0
 /// <summary>
 /// Removes key and value pairs from the cache. The keys are specified as parameter.
 /// Moreover it take a removal reason and a boolean specifying if a notification should
 /// be raised.
 /// </summary>
 /// <param name="keys">keys of the entry.</param>
 /// <param name="removalReason">reason for the removal.</param>
 /// <param name="notify">boolean specifying to raise the event.</param>
 /// <returns>list of removed keys</returns>
 public sealed override Hashtable Remove(object[] keys, ItemRemoveReason removalReason, bool notify, OperationContext operationContext)
 {
     return Remove(keys, removalReason, notify, true, operationContext);
 }
Esempio n. 38
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
        {
            CacheEntry e = base.RemoveInternal(key, removalReason, isUserOperation, operationContext);
            if (e != null)
            {

                //muds:
                if (_queryIndexManager != null && e.ObjectType != null)
                {
                    _queryIndexManager.RemoveFromIndex(key, e.ObjectType);
                }
            }

            if (_context.PerfStatsColl != null && _queryIndexManager != null)
            {
                _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize);
            }

            return e;
        }
Esempio n. 39
0
 public void OnCustomRemoveCallback(object key, object value, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext) { }
Esempio n. 40
0
 /// <summary>
 /// remove item from the primary cache and move items to the secondary cache if items are
 /// being evicted from the primary cache.
 /// </summary>
 /// <param name="keys"></param>
 /// <param name="reason"></param>
 /// <param name="notify"></param>
 /// <returns></returns>
 public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
 {
     if (reason == ItemRemoveReason.Expired)
     {
         return _context.CacheImpl.RemoveSync(keys, reason, notify,operationContext);
     }
     if (_primary != null)
     {
         for (int i = 0; i < keys.Length; i++)
         {
             CacheEntry entry = _primary.Remove(keys[i], reason, false, null, LockAccessType.IGNORE_LOCK,operationContext);
             if (entry == null) continue;
             if (reason == ItemRemoveReason.Underused && entry != null)
             {
                 _secondary.Add(keys[i],entry, false,new OperationContext(OperationContextFieldName.OperationType,OperationContextOperationType.CacheOperation));
             }
             else
             {
                 ((IDisposable)entry).Dispose();
             }
         }
     }
     return null;
 }
Esempio n. 41
0
        /// <summary>
        /// Reaises the custom item remove call baack.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="cbEntry"></param>
        internal void RaiseCustomRemoveCalbackNotifier(object key, CacheEntry cacheEntry, ItemRemoveReason reason, bool async, OperationContext operationContext, EventContext eventContext)
        {
            ArrayList destinations = null;
            ArrayList nodes = null;
            Hashtable intendedNotifiers = new Hashtable();
            CallbackEntry cbEntry = cacheEntry.Value as CallbackEntry;

            if (cbEntry != null && cbEntry.ItemRemoveCallbackListener.Count > 0)
            {
                if (_stats.Nodes != null)
                {
                    nodes = _stats.Nodes.Clone() as ArrayList;

                    destinations = new ArrayList();
                    foreach (CallbackInfo cbInfo in cbEntry.ItemRemoveCallbackListener)
                    {
                        if (reason == ItemRemoveReason.Expired && cbInfo != null && !cbInfo.NotifyOnExpiration)
                            continue;

                        int index = nodes.IndexOf(new NodeInfo(Cluster.LocalAddress));
                        if (index != -1 && ((NodeInfo)nodes[index]).ConnectedClients.Contains(cbInfo.Client))
                        {
                            if (!destinations.Contains(Cluster.LocalAddress))
                            {
                                destinations.Add(Cluster.LocalAddress);
                            }
                            intendedNotifiers[cbInfo] = Cluster.LocalAddress;
                            continue;
                        }
                        else
                        {
                            foreach (NodeInfo nInfo in nodes)
                            {
                                if (nInfo.ConnectedClients != null && nInfo.ConnectedClients.Contains(cbInfo.Client))
                                {
                                    if (!destinations.Contains(nInfo.Address))
                                    {
                                        destinations.Add(nInfo.Address);
                                        intendedNotifiers[cbInfo] = nInfo.Address;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (destinations != null && destinations.Count > 0)
            {
                if (operationContext == null) operationContext = new OperationContext();

                if (eventContext == null || !eventContext.HasEventID(EventContextOperationType.CacheOperation))
                {
                    eventContext = CreateEventContext(operationContext, Persistence.EventType.ITEM_REMOVED_CALLBACK);
                    eventContext.Item = CacheHelper.CreateCacheEventEntry(cbEntry.ItemRemoveCallbackListener, cacheEntry);
                    eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEntry.ItemRemoveCallbackListener.Clone());
                }

                object[] packed = new object[] { key, reason, intendedNotifiers, operationContext, eventContext };
                ///Incase of parition, there can be same clients connected
                ///to multiple server. therefore the destinations list will contain more then 
                ///one servers. so the callback will be sent to the same client through different server
                ///to avoid this, we will check the list for local server. if client is connected with
                ///local node, then there is no need to send callback to all other nodes
                ///if there is no local node, then we select the first node in the list.
                RaiseCustomRemoveCalbackNotifier(destinations, packed, async);
            }

        }
Esempio n. 42
0
 /// <summary>
 /// Removes the object and key pair from the cache. The key is specified as parameter.
 /// Moreover it take a removal reason and a boolean specifying if a notification should
 /// be raised.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="removalReason">reason for the removal.</param>
 /// <param name="notify">boolean specifying to raise the event.</param>
 /// <param name="lockId"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns>item value</returns>
 public sealed override CacheEntry Remove(object key, ItemRemoveReason removalReason, bool notify, object lockId, LockAccessType accessType, OperationContext operationContext)
 {
     return Remove(key, removalReason, notify, true, lockId, accessType, operationContext);
 }
Esempio n. 43
0
 public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
 {
     if (_parentCache != null)
     {
         return _parentCache.RemoveSync(keys, reason, notify, operationContext);
     }
     return null;
 }
Esempio n. 44
0
        /// <summary>
        /// Remove the objects from the cluster. For efficiency multiple objects are sent as one.
        /// </summary>
        /// <param name="keys">list of keys to remove.</param>
        /// <returns>true if succeded, false otherwise.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemoveRange"/> on every server node in the cluster.
        /// </remarks>
        protected bool Clustered_Remove(IList keys, ItemRemoveReason reason, OperationContext operationContext)
        {
            try
            {
                Function func = new Function((int)OpCodes.RemoveRange, new object[] { keys, reason, operationContext }, false);
                RspList results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, true);

                if (results != null)
                {
                    for (int i = 0; i < results.size(); i++)
                    {
                        Rsp rsp1 = (Rsp)results.elementAt(i);
                        
                        if (!rsp1.wasReceived())
                        {
                            Context.NCacheLog.Error("ReplicatedBase.Remove[]", "timeout_failure :" + rsp1.Sender + " Keys :" + keys.Count);
                            continue;
                        }
                    }
                }
                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results, Context.NCacheLog);

                return true;
            }
            catch (Runtime.Exceptions.TimeoutException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
Esempio n. 45
0
 /// <summary>
 /// Remove the objects from the local cache only. 
 /// </summary>
 /// <param name="keys">keys of the entries.</param>
 /// <param name="ir"></param>
 /// <param name="notify"></param>
 /// <returns>keys and values that actualy removed from the cache</returns>
 private Hashtable Local_Remove(object[] keys, ItemRemoveReason ir, Address src, CallbackEntry cbEntry, bool notify, OperationContext operationContext)
 {
     Hashtable retVal = null;
     if (_internalCache != null)
     {
         retVal = _internalCache.Remove(keys, ir, notify, operationContext);
     }
     return retVal;
 }
Esempio n. 46
0
        /// <summary>
        /// Remove the object from the cluster. 
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected CacheEntry Clustered_Remove(object key, ItemRemoveReason ir, CallbackEntry cbEntry,   bool notify, object lockId,  LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry retVal = null;
            try
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.Remove", "enter");
                Function func = new Function((int)OpCodes.Remove, new object[] { key, ir, notify, cbEntry,  lockId, accessType,  operationContext }, false, key);
                RspList results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, _asyncOperation);
                if (results == null)
                {
                    return retVal;
                }

                ClusterHelper.ValidateResponses(results, typeof(OperationResponse), Name);

                Rsp rsp = ClusterHelper.FindAtomicRemoveStatusReplicated(results);
                if (rsp == null)
                {
                    return retVal;
                }

                OperationResponse opRes = rsp.Value as OperationResponse;
                if (opRes != null)
                {
                    CacheEntry entry = opRes.SerializablePayload as CacheEntry;
                    if (entry != null)
                        entry.Value = opRes.UserPayload;
                    return entry;
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.Remove", "exit");
            }
            return retVal;
        }
Esempio n. 47
0
        /// <summary>
        /// Remove the objects from the cluster. 
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>list of failed keys</returns>
        /// <remarks>
        /// This method invokes <see cref="handleRemove"/> on every server node in the cluster.
        /// </remarks>
        protected Hashtable Clustered_Remove(IList keys, ItemRemoveReason ir, CallbackEntry cbEntry,  bool notify, OperationContext operationContext)
        {
            Hashtable removedEntries = new Hashtable();
            try
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "enter");
                Function func = new Function((int)OpCodes.Remove, new object[] { keys, ir, notify, cbEntry, operationContext }, false);
                RspList results = Cluster.BroadcastToServers(func, GroupRequest.GET_ALL);

                if (results == null)
                {
                    return removedEntries;
                }

                ClusterHelper.ValidateResponses(results, typeof(Hashtable), Name);
                ArrayList rspList = ClusterHelper.GetAllNonNullRsp(results, typeof(Hashtable));

                if (rspList.Count <= 0)
                {
                    return removedEntries;
                }

                IEnumerator ia = rspList.GetEnumerator();
                while (ia.MoveNext())
                {
                    Rsp rsp = (Rsp)ia.Current;
                    Hashtable removed = (Hashtable)rsp.Value;

                    IDictionaryEnumerator ide = removed.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        removedEntries.Add(ide.Key, ide.Value);
                    }
                }
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.RemoveBlk", "exit");
            }
            return removedEntries;
        }
Esempio n. 48
0
        /// <summary> 
        /// handler for item remove callback event.
        /// </summary>
        void ICacheEventsListener.OnCustomRemoveCallback(object key, object value, ItemRemoveReason removalReason, OperationContext operationContext, EventContext eventContext)
        {
            try
            {
                // do not notify if explicitly removed by Remove()
                if (Context.NCacheLog.IsInfoEnabled) Context.NCacheLog.Info("Replicated.OnCustomRemoveCallback()", "items evicted/expired, now replicating");

                CacheEntry entry = value as CacheEntry;
                CallbackEntry cbEntry = entry != null ? entry.Value as CallbackEntry : null;
                if (cbEntry != null )
                {


                    if (Cluster.IsCoordinator && _nodesInStateTransfer.Count > 0)
                    {
                        Object data = new object[] { key, removalReason, operationContext, eventContext };
                        RaiseRemoveCallbackNotifier((ArrayList)_nodesInStateTransfer.Clone(), data);
                    }

                    if (_allowEventRaiseLocally)
                    {
                        NotifyCustomRemoveCallback(key, entry, removalReason, true, operationContext, eventContext);
                    }
                }
            }
            catch (Exception e)
            {
                Context.NCacheLog.Warn("Replicated.OnItemsRemoved", "failed: " + e.ToString());
            }
            finally
            {
                UpdateCacheStatistics();
            }
        }
Esempio n. 49
0
 /// <summary>
 /// Reaises the custom item remove call baack.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="cbEntry"></param>
 internal void RaiseCustomRemoveCalbackNotifier(object key, CacheEntry cacheEntry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     RaiseCustomRemoveCalbackNotifier(key, cacheEntry, reason, true, operationContext, eventContext);
 }
Esempio n. 50
0
 /// <summary>
 /// Reaises the custom item remove call baack.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="cbEntry"></param>
 internal void RaiseCustomRemoveCalbackNotifier(object key, CacheEntry cacheEntry, ItemRemoveReason reason)
 {
     RaiseCustomRemoveCalbackNotifier(key, cacheEntry, reason, null,null);
 }
Esempio n. 51
0
        /// <summary>
        /// Removes key and value pairs from the cache. The keys are specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="keys">keys of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>list of removed keys</returns>
        public override Hashtable Remove(object[] keys, ItemRemoveReason removalReason, bool notify, bool isUserOperation, OperationContext operationContext)
        {
            Hashtable table = new Hashtable();
            EventContext eventContext = null;
            EventId eventId = null;
            OperationID opId = operationContext.OperatoinID;
            for (int i = 0; i < keys.Length; i++)
            {
                try
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                    if (notify)
                    {
                        //generate EventId
                        eventId = new EventId();
                        eventId.EventUniqueID = opId.OperationId;
                        eventId.OperationCounter = opId.OpCounter;
                        eventId.EventCounter = i;
                        eventContext = new EventContext();
                        eventContext.Add(EventContextFieldName.EventID, eventId);
                        operationContext.Add(OperationContextFieldName.EventContext, eventContext);
                    }
                    CacheEntry e = Remove(keys[i], removalReason, notify, null, LockAccessType.IGNORE_LOCK, operationContext);
                    if (e != null)
                    {
                        table[keys[i]] = e;
                    }
                }              
                catch (StateTransferException e)
                {
                    table[keys[i]] = e;
                }
                finally
                {
                    operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
                }
            }


            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }

            return table;
        }
Esempio n. 52
0
 /// <summary>
 /// Remove the object from the local cache only. 
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="ir"></param>
 /// <param name="notify"></param>
 /// <returns>cache entry.</returns>
 private CacheEntry Local_Remove(object key, ItemRemoveReason ir, Address src, CallbackEntry cbEntry, bool notify, object lockId,  LockAccessType accessType, OperationContext operationContext)
 {
     CacheEntry retVal = null;
     if (_internalCache != null)
     {
         retVal = _internalCache.Remove(key, ir, notify, lockId,  accessType, operationContext);
     }
     return retVal;
 }
Esempio n. 53
0
 /// <summary>
 /// Removes the object and key pair from the cache. The key is specified as parameter.
 /// Moreover it take a removal reason and a boolean specifying if a notification should
 /// be raised.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="removalReason">reason for the removal.</param>
 /// <param name="notify">boolean specifying to raise the event.</param>
 /// <returns>item value</returns>
 internal virtual CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
 {
     return null;
 }
Esempio n. 54
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// Remove notifications in a repicated cluster are handled differently. If there is an 
        /// explicit request for Remove, the node initiating the request triggers the notifications.
        /// Expirations and Evictions are replicated and again the node initiating the replication
        /// triggers the cluster-wide notification.
        /// </remarks>
        public override CacheEntry Remove(object key, ItemRemoveReason ir, bool notify, object lockId,  LockAccessType accessType, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCache.Remove", "");
            /// Wait until the object enters any running status
            _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();

            object actualKey = key;
            CallbackEntry cbEntry = null;
           
            if (key is object[])
            {
                object[] package = key as object[];
                actualKey = package[0];
                cbEntry = package[2] as CallbackEntry;
            }

            CacheEntry e = null;

            if (accessType != LockAccessType.IGNORE_LOCK)
            {
                //Get internally catters for the state-transfer scenarios.
                e = Get(key, operationContext);
                if (e != null)
                {
                    if (e.IsItemLocked() && !e.CompareLock(lockId))
                    {
                        //this exception directly goes to user. 
                        throw new LockingException("Item is locked.");
                    }
                }
            }       
            try
            {
                if (Cluster.Servers.Count > 1)
                    e = Clustered_Remove(actualKey, ir, cbEntry, false, lockId, accessType, operationContext);
                else
                    e = Local_Remove(actualKey, ir, Cluster.LocalAddress, cbEntry,  true, lockId, accessType, operationContext);
            }
            catch (Runtime.Exceptions.TimeoutException)
            {
                Thread.Sleep(2000);

                if (Cluster.Servers.Count > 1)
                    e = Clustered_Remove(actualKey, ir, cbEntry,  false, lockId,  accessType, operationContext);
                else
                    e = Local_Remove(actualKey, ir, Cluster.LocalAddress, cbEntry,  true, lockId, accessType, operationContext);
            }
          
            if (e != null && notify)
            {
           
                RemoveUpdateIndexOperation(key);
            }

           return e;
        }
Esempio n. 55
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <param name="isUserOperation"></param>
        /// <param name="lockId"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <returns>item value</returns>
        public override CacheEntry Remove(object key, ItemRemoveReason removalReason, bool notify, bool isUserOperation, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry e = null;
            CacheEntry pe = null;
            {
                object actualKey = key;
                if (key is object[])
                {
                    actualKey = ((object[])key)[0];
                }

                if (accessType != LockAccessType.IGNORE_LOCK)
                {
                    pe = GetInternal(actualKey, false, operationContext);
                    if (pe != null)
                    {
                        if (pe.IsItemLocked() && !pe.CompareLock(lockId))
                        {
                            throw new LockingException("Item is locked.");
                        }
                    }
                }



                e = RemoveInternal(actualKey, removalReason, isUserOperation, operationContext);
                EventId eventId = null;
                EventContext eventContext = null;
                OperationID opId = operationContext.OperatoinID;
                if (e != null)
                {
                    if (_stateTransferKeyList != null && _stateTransferKeyList.ContainsKey(key))
                        _stateTransferKeyList.Remove(key);
                    // commented by muds
                    try
                    {
                        if (e.ExpirationHint != null)
                        {
                            _context.ExpiryMgr.RemoveFromIndex(key);
                            ((IDisposable)e.ExpirationHint).Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        NCacheLog.Error("LocalCacheBase.Remove(object, ItemRemovedReason, bool):", ex.ToString());
                    }

                    if (IsSelfInternal)
                    {
                        // Disposed the one and only cache entry.
                        ((IDisposable)e).Dispose();

                        if (removalReason == ItemRemoveReason.Expired)
                        {
                            _context.PerfStatsColl.IncrementExpiryPerSecStats();
                        }
                        else if (!_context.CacheImpl.IsEvictionAllowed && removalReason == ItemRemoveReason.Underused)
                        {
                            _context.PerfStatsColl.IncrementEvictPerSecStats();
                        }
                        _context.PerfStatsColl.IncrementCountStats((long)Count);
                    }
                    if (notify)
                    {
                        CallbackEntry cbEtnry = e.Value as CallbackEntry;// e.DeflattedValue(_context.SerializationContext);
                        
                        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, e);
                            eventContext.Item = eventCacheEntry;
                            eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEtnry.ItemRemoveCallbackListener.Clone());
                            
                            //Will always reaise the whole entry for old clients
                            NotifyCustomRemoveCallback(actualKey, e, removalReason, false, (OperationContext)operationContext.Clone(), eventContext);
                        }
                    }

                   

                }
                else if (_stateTransferKeyList != null && _stateTransferKeyList.ContainsKey(key))
                {
                    _stateTransferKeyList.Remove(key);        
                }

            }
            _stats.UpdateCount(this.Count);

            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }

            return e;
        }
Esempio n. 56
0
 public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify, OperationContext operationContext)
 {
     object result = null;
     try
     {
         if (Cluster.Servers.Count > 1)
             result = Clustered_Remove(keys, reason, operationContext);
         else
             result = handleRemoveRange(new object[] { keys, reason, operationContext });
     }
     catch (Runtime.Exceptions.TimeoutException)
     {
         //we retry the operation.
         Thread.Sleep(2000);
         if (Cluster.Servers.Count > 1)
             result = Clustered_Remove(keys, reason, operationContext);
         else
             result = handleRemoveRange(new object[] { keys, reason, operationContext });
     }
     catch (Exception e)
     {
         Context.NCacheLog.Error("ReplicatedCache.RemoveSync", e.ToString());
         throw;
     }
     return result;
 }
Esempio n. 57
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext)
		{
			if(_primary == null || _secondary == null)
				throw new InvalidOperationException();

			// check the front cache for object
			CacheEntry e = _primary.RemoveInternal(key, ItemRemoveReason.Removed, false,operationContext);
			if(e == null)
			{
				// check the backing cache for object
                e = _secondary.RemoveInternal(key, ItemRemoveReason.Removed, false,operationContext);
			}
			return e;
		}
Esempio n. 58
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);
            }
Esempio n. 59
0
        /// <summary>
        /// Removes the objects and key pairs from the cache. The keys are specified as parameter.
        /// </summary>
        /// <param name="keys">keys of the entries.</param>
        /// <returns>keys that actually removed from the cache</returns>
        /// <remarks>
        /// Remove notifications in a repicated cluster are handled differently. If there is an 
        /// explicit request for Remove, the node initiating the request triggers the notifications.
        /// Expirations and Evictions are replicated and again the node initiating the replication
        /// triggers the cluster-wide notification.
        /// </remarks>
        public override Hashtable Remove(object[] keys, ItemRemoveReason ir, bool notify, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCache.RemoveBlk", "");
            /// Wait until the object enters any running status
            _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();
                      
            CallbackEntry cbEntry = null;
         

            if (keys[0] is object[])
            {
                object[] package = keys[0] as object[];
                keys[0] = package[0];
                
                cbEntry = package[2] as CallbackEntry;
            }     

            Hashtable removed = null;
            if (Cluster.Servers.Count > 1)
                removed = Clustered_Remove(keys, ir, cbEntry,  false, operationContext);
            else
                removed = Local_Remove(keys, ir, Cluster.LocalAddress, cbEntry, true, operationContext);

            if (removed.Count > 0)
            {
                IDictionaryEnumerator ide = removed.GetEnumerator();
                while (ide.MoveNext())
                {
                    object key = ide.Key;
                    CacheEntry e = (CacheEntry)ide.Value;
                    if (e != null)
                    {
                        RemoveUpdateIndexOperation(ide.Key);
                      
                    }
                }
            }

         return removed;
        }
Esempio n. 60
0
        protected void RaiseAsyncCustomRemoveCalbackNotifier(object key, CacheEntry entry, ItemRemoveReason reason, OperationContext opContext, EventContext eventContext)
        {
            try
            {
                bool notify = true;
               
                if (reason == ItemRemoveReason.Expired)
                {
                    int notifyOnExpirationCount = 0;
                    if (entry != null)
                    {
                        CallbackEntry cbEntry = entry.Value as CallbackEntry;

                        if (cbEntry != null && cbEntry.ItemRemoveCallbackListener != null)
                        {
                            for (int i = 0; i < cbEntry.ItemRemoveCallbackListener.Count; i++)
                            {
                                CallbackInfo removeCallbackInfo = (CallbackInfo)cbEntry.ItemRemoveCallbackListener[i];
                                if (removeCallbackInfo != null && removeCallbackInfo.NotifyOnExpiration)
                                    notifyOnExpirationCount++;
                            }
                        }
                    }

                    if (notifyOnExpirationCount <= 0) notify = false;
                }

                if(notify)
                    _context.AsyncProc.Enqueue(new AsyncBroadcastCustomNotifyRemoval(this, key, entry, reason, opContext, eventContext));
            }
            catch (Exception e)
            {

            }
        }