/// <summary> /// Método de execução da tarefa. /// </summary> void IAsyncTask.Process() { object success = null; try { _cache.Add(_key, _value, _expiryHint, _syncDependency, _evictionHint, _group, _subGroup, _queryInfo, _flag, null, null, _operationContext); success = AsyncOpResult.Success; } catch (Exception exception) { if (this.Logger != null) { this.Logger.Error("AsyncAdd.Process()".GetFormatter(), exception.GetFormatter()); } success = exception; } finally { CallbackEntry entry = _value as CallbackEntry; if ((entry != null) && (entry.AsyncOperationCompleteCallback != null)) { _cache.OnAsyncOperationCompleted(AsyncOpCode.Add, new object[] { _key, entry.AsyncOperationCompleteCallback, success }); } } }
void Update() { if (_callbackEntries != null && (!this.ListenToPause || !PauseController.IsPaused())) { foreach (Object owner in _callbackEntries.Keys) { List <CallbackEntry> entries = _callbackEntries[owner]; for (int i = 0; i < entries.Count;) { CallbackEntry entry = entries[i]; entry.timeRemaining -= Time.deltaTime; if (entry.timeRemaining <= 0.0f) { entries.RemoveAt(i); entry.callback(); } else { ++i; } } } } }
public void OnDSUpdated(object result, CallbackEntry cbEntry, OpCode operationCode) { if (cbEntry != null) { AsyncCallbackInfo info = cbEntry.WriteBehindOperationCompletedCallback as AsyncCallbackInfo; if (info != null && (short)info.Callback != -1) { Hashtable resTbl = result as Hashtable; Hashtable newRes = null; if (resTbl != null) { newRes = new Hashtable(); IDictionaryEnumerator ide = resTbl.GetEnumerator(); while (ide.MoveNext()) { object val = ide.Value; if (val != null && val is string) { newRes[ide.Key] = (DataSourceOpResult)Convert.ToInt32(val); } else { newRes[ide.Key] = ide.Value; } } } _parent.OnDataSourceUpdated((short)info.Callback, newRes as Hashtable, operationCode, true); } } }
public void OnFileChangedCallback(object source, FileSystemEventArgs e) { this.fileSystemWatcher = source as FileSystemWatcher; Mutex mutex = new Mutex(false, "FSW"); mutex.WaitOne(); var entry = new CallbackEntry() { FileWatcher = source as FileSystemWatcher, Name = e.Name, ChangeType = e.ChangeType, Directory = e.FullPath }; if (!this.callbackEntries.Contains(entry)) { this.callbackEntries.Add(entry); } mutex.ReleaseMutex(); this.timer.Change(500, Timeout.Infinite); }
/// <summary> /// Merge the first entry i.e. c1 into c2 /// </summary> /// <param name="c1"></param> /// <param name="c2"></param> /// <returns>returns merged entry c2</returns> public static CacheEntry MergeEntries(CacheEntry c1, CacheEntry c2) { if (c1 != null && c1.Value is CallbackEntry) { CallbackEntry cbEtnry = null; cbEtnry = c1.Value as CallbackEntry; if (cbEtnry.ItemRemoveCallbackListener != null) { foreach (CallbackInfo cbInfo in cbEtnry.ItemRemoveCallbackListener) { c2.AddCallbackInfo(null, cbInfo); } } if (cbEtnry.ItemUpdateCallbackListener != null) { foreach (CallbackInfo cbInfo in cbEtnry.ItemUpdateCallbackListener) { c2.AddCallbackInfo(cbInfo, null); } } } if (c1 != null && c1.EvictionHint != null) { if (c2.EvictionHint == null) { c2.EvictionHint = c1.EvictionHint; } } return(c2); }
public void Add(AMD_Hello_sayHello cb, int delay) { lock (this) { if (!_done) { // // Add the work item. // CallbackEntry entry = new CallbackEntry(); entry.cb = cb; entry.delay = delay; if (_callbacks.Count == 0) { Monitor.Pulse(this); } _callbacks.Add(entry); } else { // // Destroyed, throw exception. // cb.ice_exception(new RequestCanceledException()); } } }
/// <summary> /// Constructor /// </summary> /// <param name="cache"></param> public AsyncClear(Cache cache, CallbackEntry cbEntry, BitSet flagMap, OperationContext operationContext) { _cache = cache; _cbEntry = cbEntry; _flagMap = flagMap; _operationContext = operationContext; }
public static CacheEntry MergeEntries(CacheEntry c1, CacheEntry c2) { if ((c1 != null) && (c1.Value is CallbackEntry)) { CallbackEntry entry = null; entry = c1.Value as CallbackEntry; if (entry.ItemRemoveCallbackListener != null) { foreach (CallbackInfo info in entry.ItemRemoveCallbackListener) { c2.AddCallbackInfo(null, info); } } if (entry.ItemUpdateCallbackListener != null) { foreach (CallbackInfo info2 in entry.ItemUpdateCallbackListener) { c2.AddCallbackInfo(info2, null); } } } if (((c1 != null) && (c1.EvictionHint != null)) && (c2.EvictionHint == null)) { c2.EvictionHint = c1.EvictionHint; } return(c2); }
/// <summary> /// Implementation of message sending. /// </summary> void AsyncProcessor.IAsyncTask.Process() { object result = null; try { _operationContext.Add(OperationContextFieldName.NoGracefulBlock, true); _cache.Insert(_key, _value, _expiryHint, _syncDependency, _evictionHint, _group, _subGroup, _queryInfo, _flag, _operationContext, null); result = NCache.Caching.AsyncOpResult.Success; } catch (Exception e) { if (NCacheLog != null) { NCacheLog.Error("AsyncInsert.Process()", e.Message); } result = e; } finally { CallbackEntry cbEntry = _value as CallbackEntry; if (cbEntry != null && cbEntry.AsyncOperationCompleteCallback != null) { _cache.OnAsyncOperationCompleted(AsyncOpCode.Update, new object[] { _key, cbEntry.AsyncOperationCompleteCallback, result }); } } }
public void Add(AMD_Hello_sayHello cb, int delay) { lock(this) { if(!_done) { // // Add the work item. // CallbackEntry entry = new CallbackEntry(); entry.cb = cb; entry.delay = delay; if(_callbacks.Count == 0) { Monitor.Pulse(this); } _callbacks.Add(entry); } else { // // Destroyed, throw exception. // cb.ice_exception(new RequestCanceledException()); } } }
/// <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); }
/// <summary> /// Updates or Adds the object to the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="lockId"></param> /// <param name="accessType"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method invokes <see cref="handleInsert"/> on the specified node. /// </remarks> protected CacheInsResultWithEntry Clustered_Insert(Address dest, object key, CacheEntry cacheEntry, object lockId, LockAccessType accessType, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("PartCacheBase.Insert", ""); } CacheInsResultWithEntry retVal = new CacheInsResultWithEntry(); try { Function func = new Function((int)OpCodes.Insert, new object[] { key, cacheEntry.CloneWithoutValue(), lockId, accessType, operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; func.ResponseExpected = true; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, false); if (result == null) { return(retVal); } retVal = (CacheInsResultWithEntry)((OperationResponse)result).SerializablePayload; if (retVal.Entry != null) { retVal.Entry.Value = ((OperationResponse)result).UserPayload; } } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
/// <summary> /// Add the object to specfied node in the cluster. /// </summary> /// <param name="dest"></param> /// <param name="key">key of the entry.</param> /// <param name="cacheEntry"></param> /// <param name="operationContext"></param> /// <returns>cache entry.</returns> /// <remarks> /// This method either invokes <see cref="handleAdd"/> on every server-node in the cluster. /// </remarks> protected CacheAddResult Clustered_Add(Address dest, object key, CacheEntry cacheEntry, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("PartCacheBase.Add_1", ""); } CacheAddResult retVal = CacheAddResult.Success; try { Function func = new Function((int)OpCodes.Add, new object[] { key, cacheEntry.CloneWithoutValue(), operationContext }); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST); if (result == null) { return(retVal); } if (result is CacheAddResult) { retVal = (CacheAddResult)result; } else if (result is System.Exception) { throw (Exception)result; } } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
/// <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); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _removeResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; try { CallbackEntry cbEntry = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); nCache.Cache.Delete(cmdInfo.Key, cmdInfo.FlagMap, cbEntry, cmdInfo.LockId, cmdInfo.LockAccessType, operationContext); //PROTOBUF:RESPONSE Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.DeleteResponse removeResponse = new Alachisoft.NCache.Common.Protobuf.DeleteResponse(); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.DELETE; response.deleteResponse = removeResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add( Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } finally { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RemCmd.Exec", "cmd executed on cache"); } } }
/// <summary> /// Removes all entries from the cluster. /// </summary> /// <remarks> /// This method invokes <see cref="handleClear"/> on every server node in the cluster. /// </remarks> protected void Clustered_Clear(CallbackEntry cbEntry, bool excludeSelf, OperationContext operationContext) { try { Function func = new Function((int)OpCodes.Clear, new object[] { cbEntry, operationContext }, excludeSelf); Cluster.BroadcastToServers(func, GroupRequest.GET_ALL, false); } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { _removeBulkResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } //TODO byte[] data = null; try { NCache nCache = clientManager.CmdExecuter as NCache; CallbackEntry cbEnrty = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient)) { operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient); } nCache.Cache.Delete(cmdInfo.Keys, cmdInfo.FlagMap, cbEnrty, operationContext); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.BulkDeleteResponse bulkDeleteResponse = new Alachisoft.NCache.Common.Protobuf.BulkDeleteResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.intendedRecipient = cmdInfo.IntendedRecipient; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.DELETE_BULK; response.bulkDeleteResponse = bulkDeleteResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { _removeBulkResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } }
/// <summary> /// Add the object to the cluster. Does load balancing as well. /// </summary> /// <param name="key">key of the entry.</param> /// <returns>cache entry.</returns> /// <remarks> /// This method either invokes <see cref="handleAdd"/> on one of the server nodes in the cluster, /// or invokes <see cref="Local_Add"/> locally. /// </remarks> protected CacheAddResult Clustered_Add(ArrayList dests, object key, CacheEntry cacheEntry, OperationContext operationContext) { CacheAddResult result = CacheAddResult.Failure; try { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RepCacheBase.Add", "enter"); } /// Ask every server to add the object, except myself. Function func = new Function((int)OpCodes.Add, new object[] { key, cacheEntry, operationContext }, false, key); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; RspList results = Cluster.BroadcastToMultiple(dests, func, GroupRequest.GET_ALL, _asyncOperation); ClusterHelper.ValidateResponses(results, typeof(CacheAddResult), Name); /// Check if the operation failed on any node. result = ClusterHelper.FindAtomicAddStatusReplicated(results); } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } finally { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("RepCacheBase.Add", "exit"); } } return(result); }
public void Process() { Hashtable result = null; CallbackEntry cbEntry = null; if (((_entries != null) && (_entries[0] != null)) && (_entries[0].Value is CallbackEntry)) { cbEntry = _entries[0].Value as CallbackEntry; } try { result = _parent.WriteThru(_internalCache, _keys as string[], _values, _entries, new Hashtable(), _opCode, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); if (result == null) { result = new Hashtable(_keys.Length); } if (cbEntry != null) { for (int i = 0; i < _keys.Length; i++) { if (!result.ContainsKey(_keys[i])) { result.Add(_keys[i], "1"); } } } } catch (Exception exception) { _internalCache.Context.Logger.Error("WriteBehindTask.Process".GetFormatter(), exception.GetFormatter()); if (cbEntry != null) { for (int j = 0; j < _keys.Length; j++) { result.Add(_keys[j], exception); } } } if (cbEntry != null) { try { _internalCache.NotifyWriteBehindTaskStatus(_opCode, result, cbEntry, _taskId, _providerName, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); } catch { } } }
private object ConvertToUserObject(CompressedValueEntry cmpEntry) { if (cmpEntry.Value is UserBinaryObject) { UserBinaryObject ubObject = cmpEntry.Value as UserBinaryObject; cmpEntry.Value = ubObject.GetFullObject(); } if (cmpEntry.Value is CallbackEntry) { CallbackEntry e = cmpEntry.Value as CallbackEntry; cmpEntry.Value = e.Value; } return(CompactBinaryFormatter.FromByteBuffer((byte[])cmpEntry.Value, CacheId)); }
void IAsyncTask.Process() { object success = null; BitSet flag = new BitSet(); CallbackEntry cbEntry = null; string providerName = null; try { if (_key is object[]) { object[] objArray = (object[])_key; _key = objArray[0]; flag = objArray[1] as BitSet; if (objArray.Length > 2) { cbEntry = objArray[2] as CallbackEntry; } if (objArray.Length == 4) { providerName = objArray[3] as string; } } _cache.Remove(_key as string, flag, cbEntry, null, 0, LockAccessType.IGNORE_LOCK, providerName, _operationContext); success = AsyncOpResult.Success; } catch (Exception exception) { if (this.Logger != null) { this.Logger.Error("AsyncRemove.Process()".GetFormatter(), exception.GetFormatter()); } success = exception; } finally { if ((cbEntry != null) && (cbEntry.AsyncOperationCompleteCallback != null)) { _cache.OnAsyncOperationCompleted(AsyncOpCode.Remove, new object[] { _key, cbEntry.AsyncOperationCompleteCallback, success }); } } }
public void Add(AMD_Hello_sayHello cb, int delay) { #if COMPACT _m.Lock(); try #else lock(this) #endif { if(!_done) { // // Add the work item. // CallbackEntry entry = new CallbackEntry(); entry.cb = cb; entry.delay = delay; if(_callbacks.Count == 0) { #if COMPACT _m.Notify(); #else Monitor.Pulse(this); #endif } _callbacks.Add(entry); } else { // // Destroyed, throw exception. // cb.ice_exception(new RequestCanceledException()); } } #if COMPACT finally { _m.Unlock(); } #endif }
/// <summary> /// Implementation of message sending. /// </summary> void AsyncProcessor.IAsyncTask.Process() { object result = null; BitSet flagMap = new BitSet(); CallbackEntry cbEntry = null; string providerName = null; try { if (_key is object[]) { object[] package = (object[])_key; _key = package[0]; flagMap = package[1] as BitSet; if (package.Length > 2) { cbEntry = package[2] as CallbackEntry; } if (package.Length == 4) { providerName = package[3] as string; } } _operationContext.Add(OperationContextFieldName.NoGracefulBlock, true); _cache.Remove(_key as string, flagMap, cbEntry, null, 0, LockAccessType.IGNORE_LOCK, providerName, _operationContext); result = AsyncOpResult.Success; } catch (Exception e) { if (NCacheLog != null) { NCacheLog.Error("AsyncRemove.Process()", e.Message); } result = e; } finally { if (cbEntry != null && cbEntry.AsyncOperationCompleteCallback != null) { _cache.OnAsyncOperationCompleted(AsyncOpCode.Remove, new object[] { _key, cbEntry.AsyncOperationCompleteCallback, result }); } } }
public void Add(AMD_Hello_sayHello cb, int delay) { #if COMPACT _m.Lock(); try #else lock (this) #endif { if (!_done) { // // Add the work item. // CallbackEntry entry = new CallbackEntry(); entry.cb = cb; entry.delay = delay; if (_callbacks.Count == 0) { #if COMPACT _m.Notify(); #else Monitor.Pulse(this); #endif } _callbacks.Add(entry); } else { // // Destroyed, throw exception. // cb.ice_exception(new RequestCanceledException()); } } #if COMPACT finally { _m.Unlock(); } #endif }
public void Run() { lock (this) { while (!_done) { if (_callbacks.Count == 0) { Monitor.Wait(this); } if (_callbacks.Count != 0) { // // Get next work item. // CallbackEntry entry = (CallbackEntry)_callbacks[0]; // // Wait for the amount of time indicated in delay to // emulate a process that takes a significant period of // time to complete. // Monitor.Wait(this, entry.delay); if (!_done) { // // Print greeting and send response. // _callbacks.RemoveAt(0); Console.Out.WriteLine("Belated Hello World!"); entry.cb.ice_response(); } } } foreach (CallbackEntry e in _callbacks) { e.cb.ice_exception(new RequestCanceledException()); } } }
public void Add(CallbackEntry cb) { lock (this) { if (!_done) { if (_callbacks.Count == 0) { Monitor.Pulse(this); } _callbacks.Add(cb); } else { // // Destroyed, throw exception. // cb.exception(new RequestCanceledException()); } } }
private void GetMessagePayLoad(MessageItem messageItem) { if (messageItem != null) { if (messageItem.Payload is CallbackEntry) { CallbackEntry e = messageItem.Payload as CallbackEntry; messageItem.Payload = e.Value; } if (_perfStatsCollector != null && messageItem.Payload != null && messageItem.Payload is byte[]) { _perfStatsCollector.IncrementAvgItemSize(((byte[])messageItem.Payload).Length); } messageItem.Payload = _cacheImpl.SafeDeserialize(messageItem.Payload, _cacheImpl.Name, messageItem.Flag, _cacheImpl); } }
public void Add(CallbackEntry cb) { lock(this) { if(!_done) { if(_callbacks.Count == 0) { Monitor.Pulse(this); } _callbacks.Add(cb); } else { // // Destroyed, throw exception. // cb.exception(new RequestCanceledException()); } } }
private EPCacheEntry GetEPCacheEntry(Object key, Boolean ignoreLock, OperationContext operationContext) { Object lockId = null; ulong version = 0; DateTime time = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime lockDate = time.Date; BitSet flagMap = new BitSet(); operationContext.Add(OperationContextFieldName.ReaderBitsetEnum, flagMap); operationContext.Add(OperationContextFieldName.DataFormat, DataFormat.Object); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); LockAccessType lockAccessType = LockAccessType.IGNORE_LOCK; if (!ignoreLock) { lockAccessType = LockAccessType.ACQUIRE; } CacheEntry entry = (CacheEntry)_cacheRoot.GetCacheEntry(key, null, null, ref lockId, ref lockDate, EntryProcessorManager.DefaultLockTimeOut, lockAccessType, operationContext, ref version); LockHandle handle = null; if (lockId != null) { handle = new LockHandle(lockId.ToString(), lockDate); } if (entry != null) { CallbackEntry callbackEntry = entry.Value as CallbackEntry; object value = callbackEntry != null ? callbackEntry.Value : entry.Value; if (value != null) { entry.Value = _context.CachingSubSystemDataService.GetCacheData(value, entry.Flag); } } return(new EPCacheEntry(entry, handle)); }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; try { CallbackEntry cbEntry = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); nCache.Cache.Clear(cmdInfo.FlagMap, cbEntry, operationContext); Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.ClearResponse clearResponse = new Alachisoft.NCache.Common.Protobuf.ClearResponse(); response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.CLEAR; response.clearResponse = clearResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } catch (Exception exc) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { CommandInfo cmdInfo; try { cmdInfo = ParseCommand(command, clientManager); } catch (Exception exc) { _removeBulkResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); } return; } //TODO byte[] data = null; try { NCache nCache = clientManager.CmdExecuter as NCache; CallbackEntry cbEnrty = null; OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); Hashtable removeResult = (Hashtable)nCache.Cache.Remove(cmdInfo.Keys, cmdInfo.FlagMap, cbEnrty, operationContext); BulkRemoveResponseBuilder.BuildResponse(removeResult, cmdInfo.CommandVersion, cmdInfo.RequestId, _serializedResponsePackets); } catch (Exception exc) { _removeBulkResult = OperationResult.Failure; //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID)); //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); } }
/// <summary> /// Updates or Adds the object to the cluster. /// </summary> /// <param name="key">key of the entry.</param> /// <returns>cache entry.</returns> /// <remarks> /// This method invokes <see cref="handleInsert"/> on the specified node. /// </remarks> protected CacheInsResult Clustered_Insert(Address dest, object key, CacheEntry cacheEntry, OperationContext operationContext) { CacheInsResult retVal = CacheInsResult.Failure; try { Function func = new Function((int)OpCodes.Insert, new object[] { key, cacheEntry, operationContext }, false, key); Array userPayLoad = null; if (cacheEntry.Value is CallbackEntry) { CallbackEntry cbEntry = ((CallbackEntry)cacheEntry.Value); userPayLoad = cbEntry.UserData; } else { userPayLoad = cacheEntry.UserData; } func.UserPayload = userPayLoad; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, _asyncOperation); if (result == null) { return(retVal); } retVal = (CacheInsResult)result; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return(retVal); }
void Update() { if (_callbackEntries != null) { foreach (List <CallbackEntry> entries in _callbackEntries.Values) { for (int i = 0; i < entries.Count;) { CallbackEntry entry = entries[i]; entry.timeRemaining -= Time.deltaTime; if (entry.timeRemaining <= 0.0f) { entries.RemoveAt(i); entry.callback(); } else { ++i; } } } } }
/// <summary> /// Removes all entries from the store. /// </summary> /// <remarks> /// This method invokes <see cref="handleClear"/> on every node in the partition, /// which then fires OnCacheCleared locally. The <see cref="handleClear"/> method on the /// coordinator will also trigger a cluster-wide notification to the clients. /// </remarks> public override void Clear(CallbackEntry cbEntry, OperationContext operationContext) { /// Wait until the object enters the running status _statusLatch.WaitForAny(NodeStatus.Running); if (_internalCache == null) throw new InvalidOperationException(); if (Servers.Count > 1) { Clustered_Clear(cbEntry, false, operationContext); } else { handleClear(Cluster.LocalAddress, new object[] {cbEntry, operationContext}); } }
private Hashtable ClusteredRemove(IList keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PoRCache.RemoveBlk", ""); Hashtable targetNodes = null; Hashtable result = new Hashtable(); Hashtable tmpResult = null; ArrayList totalKeys = new ArrayList(keys); ArrayList totalRemainingKeys = new ArrayList(); Hashtable totalDepKeys = new Hashtable(); Address targetNode = null; do { targetNodes = GetTargetNodes(totalKeys); if (targetNodes != null && targetNodes.Count == 0) { foreach (object key in totalKeys) { result[key] = new OperationFailedException("No target node available to accommodate the data."); } return result; } IDictionaryEnumerator ide = targetNodes.GetEnumerator(); Hashtable keyList = null; //We select one node at a time for Add operation. while (ide.MoveNext()) { targetNode = ide.Key as Address; keyList = (Hashtable)ide.Value; if (targetNode != null && keyList != null) { object[] currentKeys = MiscUtil.GetArrayFromCollection(keyList.Keys); try { if (targetNode.Equals(Cluster.LocalAddress)) { tmpResult = Local_Remove(currentKeys, ir, Cluster.LocalAddress, cbEntry, notify, operationContext); } else { tmpResult = Clustered_Remove(targetNode, currentKeys, ir, cbEntry, notify, operationContext); } } catch (Runtime.Exceptions.SuspectedException se) { if (Context.NCacheLog.IsInfoEnabled) Context.NCacheLog.Info("PartitionedServerCache.Remove()", targetNode + " left while addition"); totalRemainingKeys.AddRange(currentKeys); continue; } catch (Runtime.Exceptions.TimeoutException te) { if (Context.NCacheLog.IsInfoEnabled) Context.NCacheLog.Info("PartitionedServerCache.Remove()", targetNode + " operation timed out"); totalRemainingKeys.AddRange(currentKeys); continue; } if (tmpResult != null) { IDictionaryEnumerator ie = tmpResult.GetEnumerator(); while (ie.MoveNext()) { if (ie.Value is StateTransferException) totalRemainingKeys.Add(ie.Key); else { if (ie.Value is CacheEntry) result[ie.Key] = ie.Value; } } } } } totalKeys = new ArrayList(totalRemainingKeys); totalRemainingKeys.Clear(); } while (totalKeys.Count > 0); if (result.Count > 0) { IDictionaryEnumerator ide = result.GetEnumerator(); while (ide.MoveNext()) { object key = ide.Key; CacheEntry entry = (CacheEntry) ide.Value; // Already fired from LocalCacheBase if (notify) { object value = entry.Value; if (value is CallbackEntry) { RaiseCustomRemoveCalbackNotifier(key, entry, ir); } } } } return result; }
/// <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; }
/// <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; }
/// <summary> /// Removes all entries from the cluster. /// </summary> /// <remarks> /// This method invokes <see cref="handleClear"/> on every server node in the cluster. /// </remarks> protected void Clustered_Clear(CallbackEntry cbEntry, bool excludeSelf, OperationContext operationContext) { try { Function func = new Function((int)OpCodes.Clear, new object[] { cbEntry, operationContext }, excludeSelf); Cluster.BroadcastToServers(func, GroupRequest.GET_ALL); } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } }
/// <summary> /// Remove the object from the cluster. /// </summary> /// <param name="dest"></param> /// <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(Address dest, object key, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, object lockId, LockAccessType accessType, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PartCacheBase.Remove", ""); CacheEntry retVal = null; try { Function func = new Function((int)OpCodes.Remove, new object[] { key, ir, notify, cbEntry, lockId, accessType, operationContext }, false); func.ResponseExpected = true; object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST, false); if (result != null) { retVal = ((OperationResponse)result).SerializablePayload as CacheEntry; if (retVal != null) retVal.Value = ((OperationResponse)result).UserPayload; } } catch (Runtime.Exceptions.SuspectedException se) { throw; } catch (Runtime.Exceptions.TimeoutException te) { throw; } catch (CacheException e) { throw; } catch (Exception e) { throw new GeneralFailureException(e.Message, e); } return retVal; }
/// <summary> /// Removes all entries from the store. /// </summary> public override void Clear(CallbackEntry cbEntry, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Clear", "enter"); Sync.AcquireWriterLock(Timeout.Infinite); try { Internal.Clear(cbEntry, operationContext); #if !CLIENT if (_context.CacheImpl.RequiresReplication) _context.CacheImpl.EnqueueForReplication(null, (int)ClusterCacheBase.OpCodes.Clear, new object[] { cbEntry, operationContext }); #endif } finally { Sync.ReleaseWriterLock(); if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Clear", "exit"); } }
/// <summary> /// Removes all entries from the store. /// </summary> public virtual void Clear(CallbackEntry cbEntry, OperationContext operationContext) { }
/// <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; }
/// <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; }
/// <summary> /// Clears the local cache only. /// </summary> private void Local_Clear(Address src, CallbackEntry cbEntry, OperationContext operationContext) { if (_internalCache != null) { _internalCache.Clear(null, operationContext); UpdateCacheStatistics(); } }
/// <summary> /// Removes all entries from the store. /// </summary> public sealed override void Clear(CallbackEntry cbEntry, OperationContext operationContext) { ClearInternal(); if (IsSelfInternal) { _context.ExpiryMgr.Clear(); if (_context.PerfStatsColl != null) { if (_context.ExpiryMgr != null) _context.PerfStatsColl.SetExpirationIndexSize(_context.ExpiryMgr.IndexInMemorySize); } _context.PerfStatsColl.IncrementCountStats((long)Count); } _stats.UpdateCount(this.Count); _stats.UpdateSessionCount(0); if (_context.PerfStatsColl != null) { _context.PerfStatsColl.SetCacheSize(Size); } }
private Hashtable OptimizedRemove(IList keys, ItemRemoveReason ir, CallbackEntry cbEntry, bool notify, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PoRCache.RemoveBlk", ""); Hashtable result = new Hashtable(); Hashtable totalDepKeys = new Hashtable(); ArrayList remainingKeys = new ArrayList(); try { result = Local_Remove(keys, ir, Cluster.LocalAddress, cbEntry, notify, operationContext); } catch (Exception ex) { for (int i = 0; i < keys.Count; i++) { result[keys[i]] = new OperationFailedException(ex.Message, ex); } } if (result != null) { IDictionaryEnumerator ie = result.GetEnumerator(); while (ie.MoveNext()) { if (ie.Value is StateTransferException) { remainingKeys.Add(ie.Key); } } } if (result.Count > 0) { IDictionaryEnumerator ide = result.GetEnumerator(); while (ide.MoveNext()) { object key = ide.Key; CacheEntry entry = ide.Value as CacheEntry; if (entry != null) { if (notify) { object value = entry.Value; if (value is CallbackEntry) { RaiseCustomRemoveCalbackNotifier(key, entry, ir); } } } } } return result; }
/// <summary> /// Removes all entries from the store. /// </summary> /// <remarks> /// This method invokes <see cref="handleClear"/> on every node in the cluster, /// which then fires OnCacheCleared locally. The <see cref="handleClear"/> method on the /// coordinator will also trigger a cluster-wide notification to the clients. /// </remarks> public override void Clear(CallbackEntry cbEntry, OperationContext operationContext) { /// Wait until the object enters any running status _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running); if (_statusLatch.IsAnyBitsSet(NodeStatus.Initializing)) { if (_stateTransferTask != null) _stateTransferTask.StopProcessing(); _statusLatch.WaitForAny(NodeStatus.Running); } if (_internalCache == null) throw new InvalidOperationException(); if (Cluster.Servers.Count > 1) Clustered_Clear(cbEntry, false, operationContext); else handleClear(Cluster.LocalAddress, new object[] { cbEntry, operationContext }); }
/// <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; }