public static CompressedValueEntry CreateCompressedCacheEntry(PoolManager poolmanger, CacheEntry entry) { CompressedValueEntry compressedEntry = CreateCompressedCacheEntry(poolmanger, entry.Value, entry.Flag, entry.Type); compressedEntry.Entry = entry; return(compressedEntry); }
public static CompressedValueEntry CreateCompressedCacheEntry(PoolManager poolmanger, object value, BitSet flag, EntryType entryType) { CompressedValueEntry entry = CreateCompressedCacheEntry(poolmanger); entry.Value = value; entry.Flag = flag; entry.Type = entryType; return(entry); }
private void RaiseBulkEvent(object arg) { try { Alachisoft.NCache.Caching.EventId eventId; Address remoteServerAddress = null; if (arg == null || ((object[]) arg).Length != 2) return; remoteServerAddress = ((object[]) arg)[0] as Address; List<Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse> bulkEvents = ((object[]) arg)[1] as List<Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse>; if (bulkEvents == null) return; foreach (Alachisoft.NCache.Common.Protobuf.BulkEventItemResponse eventItem in bulkEvents) { try { if (_perfStatsColl2 != null) { _perfStatsColl2.IncrementEventsTriggeredPerSeconds(); } eventId = new Alachisoft.NCache.Caching.EventId(); switch (eventItem.eventType) { case Common.Protobuf.BulkEventItemResponse.EventType.ITEM_UPDATED_CALLBACK: { eventId.EventUniqueID = eventItem.ItemUpdatedCallback.eventId.eventUniqueId; eventId.EventCounter = eventItem.ItemUpdatedCallback.eventId.eventCounter; eventId.OperationCounter = eventItem.ItemUpdatedCallback.eventId.operationCounter; eventId.EventType = NCache.Persistence.EventType.ITEM_UPDATED_CALLBACK; BitSet flag = new BitSet((byte) eventItem.ItemUpdatedCallback.flag); EventCacheItem item = EventUtil.ConvertToEventEntry(eventItem.ItemUpdatedCallback.eventId.item); EventCacheItem oldItem = EventUtil.ConvertToEventEntry(eventItem.ItemUpdatedCallback.eventId.oldItem); if (_notifyAsync) { if (_cache != null && _cache.AsyncEventHandler != null) { _cache.EventListener.OnCustomUpdateCallback( (Int16) eventItem.ItemUpdatedCallback.callbackId, eventItem.ItemUpdatedCallback.key, _notifyAsync, item, oldItem, flag, (EventDataFilter) eventItem.ItemUpdatedCallback.dataFilter); } } else _eventProcessor.Enqueue(new ItemUpdateCallbackTask(this, eventItem.ItemUpdatedCallback.key, (Int16) eventItem.ItemUpdatedCallback.callbackId, _notifyAsync, item, oldItem, flag, (EventDataFilter) eventItem.ItemUpdatedCallback.dataFilter)); } break; case Common.Protobuf.BulkEventItemResponse.EventType.ITEM_REMOVED_CALLBACK: { CompressedValueEntry flagValueEntry = new CompressedValueEntry(); flagValueEntry.Flag = new BitSet((byte) eventItem.itemRemoveCallback.flag); EventCacheItem item = EventUtil.ConvertToEventEntry(eventItem.itemRemoveCallback.eventId.item); byte[] value = null; if (item != null && eventItem.itemRemoveCallback.value != null && eventItem.itemRemoveCallback.value.Count > 0) { UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject( eventItem.itemRemoveCallback.value.ToArray()); value = ubObject.GetFullObject(); if (item != null) { item.Value = value; } } eventId.EventUniqueID = eventItem.itemRemoveCallback.eventId.eventUniqueId; eventId.EventCounter = eventItem.itemRemoveCallback.eventId.eventCounter; eventId.OperationCounter = eventItem.itemRemoveCallback.eventId.operationCounter; eventId.EventType = NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK; if (_notifyAsync) { if (_cache != null && _cache.AsyncEventHandler != null) _cache.EventListener.OnCustomRemoveCallback( (Int16) eventItem.itemRemoveCallback.callbackId, eventItem.itemRemoveCallback.key, value, (CacheItemRemovedReason) eventItem.itemRemoveCallback.itemRemoveReason, flagValueEntry.Flag, _notifyAsync, item, (EventDataFilter) eventItem.itemRemoveCallback.dataFilter); } else _eventProcessor.Enqueue(new ItemRemoveCallBackTask(this, eventItem.itemRemoveCallback.key, (Int16) eventItem.itemRemoveCallback.callbackId, value, (CacheItemRemovedReason) eventItem.itemRemoveCallback.itemRemoveReason, flagValueEntry.Flag, _notifyAsync, item, (EventDataFilter) eventItem.itemRemoveCallback.dataFilter)); } break; } } catch (Exception ex) { if (_logger.IsErrorLogsEnabled) _logger.NCacheLog.Error("Broker.RaiseBulkEvent", "An error occurred while raising bulk event of type : " + eventItem.eventType + ". Error :" + ex.ToString()); } } } catch (Exception ex) { } }
/// <summary> /// Removes the objects for the given keys from the cache. /// The keys are specified as parameter. /// </summary> /// <param name="keys">array of keys to be removed</param> /// <param name="flagMap"></param> /// <param name="cbEntry"></param> /// <param name="operationContext"></param> /// <returns>keys that failed to be removed</returns> public IDictionary Remove(object[] keys, BitSet flagMap, CallbackEntry cbEntry, OperationContext operationContext) { if (keys == null) throw new ArgumentNullException("keys"); // Cache has possibly expired so do default. if (!IsRunning) return null; try { HPTimeStats removeTime = new HPTimeStats(); removeTime.BeginSample(); IDictionary removed = CascadedRemove(keys, ItemRemoveReason.Removed, true, operationContext); removeTime.EndSample(); CompressedValueEntry val = null; if (removed != null) { object[] keysCollection = new object[removed.Count]; removed.Keys.CopyTo(keysCollection, 0); IEnumerator ie = keysCollection.GetEnumerator(); while (ie.MoveNext()) { CacheEntry entry = removed[ie.Current] as CacheEntry; if (entry != null) { val = new CompressedValueEntry(); val.Value = entry.Value; if (val.Value is CallbackEntry) val.Value = ((CallbackEntry)val.Value).Value; val.Flag = entry.Flag; removed[ie.Current] = val; } } } return removed; } catch (Exception inner) { _context.NCacheLog.Error("Cache.Remove()", inner.ToString()); throw new OperationFailedException("Remove operation failed. Error : " + inner.Message, inner); } return null; }
public CompressedValueEntry Remove(string key, BitSet flag, CallbackEntry cbEntry, object lockId, LockAccessType accessType, OperationContext operationContext) { if (key == null) throw new ArgumentNullException("key"); if (!key.GetType().IsSerializable) throw new ArgumentException("key is not serializable"); // Cache has possibly expired so do default. if (!IsRunning) return null; try { HPTimeStats removeTime = new HPTimeStats(); removeTime.BeginSample(); _context.PerfStatsColl.MsecPerDelBeginSample(); object packedKey = key; CacheEntry e = CascadedRemove(key, packedKey, ItemRemoveReason.Removed, true, lockId,accessType, operationContext); _context.PerfStatsColl.MsecPerDelEndSample(); _context.PerfStatsColl.IncrementDelPerSecStats(); removeTime.EndSample(); if (e != null) { CompressedValueEntry obj = new CompressedValueEntry(); obj.Value = e.Value; obj.Flag = e.Flag; if (obj.Value is CallbackEntry) obj.Value = ((CallbackEntry)obj.Value).Value; return obj; } } catch (OperationFailedException ex) { if (ex.IsTracable) _context.NCacheLog.Error("Cache.Remove()", ex.ToString()); throw ex; } catch (Exception inner) { _context.NCacheLog.Error("Cache.Remove()", inner.ToString()); throw new OperationFailedException("Remove operation failed. Error : " + inner.Message, inner); } return null; }
/// <summary> /// Retrieve the array of objects from the cache. /// An array of keys is passed as parameter. /// </summary> public IDictionary GetBulk(object[] keys, BitSet flagMap, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Cache.GetBlk", ""); if (keys == null) throw new ArgumentNullException("keys"); // Cache has possibly expired so do default. if (!IsRunning) return null; Hashtable table = null; try { HPTimeStats getTime = new HPTimeStats(); getTime.BeginSample(); table = _context.CacheImpl.Get(keys, operationContext); if (table != null) { for (int i = 0; i < keys.Length; i++) { if (table.ContainsKey(keys[i])) { if (table[keys[i]] != null) { CacheEntry entry = table[keys[i]] as CacheEntry; CompressedValueEntry val = new CompressedValueEntry(); val.Value = entry.Value is CallbackEntry ? ((CallbackEntry)entry.Value).Value : entry.Value; val.Flag = entry.Flag; table[keys[i]] = val; } } } } } catch (OperationFailedException inner) { if (inner.IsTracable) _context.NCacheLog.Error("Cache.Get()", inner.ToString()); throw; } catch (Exception inner) { _context.NCacheLog.Error("Cache.Get()", inner.ToString()); throw new OperationFailedException("Get operation failed. Error : " + inner.Message, inner); } return table; }
public CompressedValueEntry Get(object key, BitSet flagMap,ref object lockId, ref DateTime lockDate, TimeSpan lockTimeout, LockAccessType accessType, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Cache.GetGrp", ""); // Cache has possibly expired so do default. if (!IsRunning) return null; CompressedValueEntry result = new CompressedValueEntry(); CacheEntry e = null; try { _context.PerfStatsColl.MsecPerGetBeginSample(); _context.PerfStatsColl.IncrementGetPerSecStats(); _context.PerfStatsColl.IncrementHitsRatioPerSecBaseStats(); HPTimeStats getTime = new HPTimeStats(); getTime.BeginSample(); LockExpiration lockExpiration = null; if (accessType == LockAccessType.ACQUIRE) { lockId = GetLockId(key); lockDate = DateTime.UtcNow; if (!TimeSpan.Equals(lockTimeout, TimeSpan.Zero)) { lockExpiration = new LockExpiration(lockTimeout); } } object generatedLockId = lockId; e = _context.CacheImpl.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext); if (e == null && accessType == LockAccessType.ACQUIRE) { if (lockId == null || generatedLockId.Equals(lockId)) { lockId = null; lockDate = new DateTime(); } } if (flagMap != null) { if (e != null) { /// increment the counter for hits/sec _context.PerfStatsColl.MsecPerGetEndSample(); result.Value = e.Value; result.Flag = e.Flag; } } _context.PerfStatsColl.MsecPerGetEndSample(); getTime.EndSample(); /// update the counter for hits/sec or misses/sec if (result.Value != null) { _context.PerfStatsColl.IncrementHitsRatioPerSecStats(); _context.PerfStatsColl.IncrementHitsPerSecStats(); } else { _context.PerfStatsColl.IncrementMissPerSecStats(); } if (result.Value is CallbackEntry) result.Value = ((CallbackEntry)result.Value).Value; } catch (OperationFailedException inner) { if (inner.IsTracable) _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString()); throw; } catch (Exception inner) { _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString()); throw new OperationFailedException("Get operation failed. Error :" + inner.Message, inner); } return result; }