/// <summary> /// Makes a key and data package form the keys and values of hashtable /// </summary> /// <param name="dic">Hashtable containing the keys and values to be packaged</param> /// <param name="keys">Contains packaged keys after execution</param> /// <param name="data">Contains packaged data after execution</param> /// <param name="currentContext">Current cache</param> internal static Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse PackageKeysValues(IDictionary dic, Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse) { if (dic != null && dic.Count > 0) { if (keyPackageResponse == null) { keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); } ; IDictionaryEnumerator enu = dic.GetEnumerator(); while (enu.MoveNext()) { keyPackageResponse.keys.Add((string)enu.Key); CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value; BitSet flag = cmpEntry.Flag; UserBinaryObject ubObject = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET) as UserBinaryObject; Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value(); value.data.AddRange(ubObject.DataList); keyPackageResponse.flag.Add(cmpEntry.Flag.Data); keyPackageResponse.values.Add(value); keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type)); } } return(keyPackageResponse); }
/// <summary> /// Makes a key and data package form the keys and values of hashtable /// </summary> /// <param name="dic">Hashtable containing the keys and values to be packaged</param> /// <param name="keys">Contains packaged keys after execution</param> /// <param name="data">Contains packaged data after execution</param> /// <param name="currentContext">Current cache</param> internal static IList PackageKeysValues(IDictionary dic) { int estimatedSize = 0; IList ListOfKeyPackageResponse = new ClusteredArrayList(); if (dic != null && dic.Count > 0) { Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); IDictionaryEnumerator enu = dic.GetEnumerator(); while (enu.MoveNext()) { Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value(); CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value; UserBinaryObject ubObject = null; if (cmpEntry != null) { if (cmpEntry.Value is UserBinaryObject) { ubObject = (UserBinaryObject)cmpEntry.Value; } else { var flag = cmpEntry.Flag; ubObject = (UserBinaryObject)Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET); } } //UserBinaryObject ubObject = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref cmpEntry.Flag, LanguageContext.DOTNET) as UserBinaryObject; value.data.AddRange(ubObject.DataList); keyPackageResponse.keys.Add((string)enu.Key); keyPackageResponse.flag.Add(cmpEntry.Flag.Data); keyPackageResponse.values.Add(value); keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type)); // (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)); estimatedSize = estimatedSize + ubObject.Size + (((string)enu.Key).Length * sizeof(Char)); if (estimatedSize >= ServiceConfiguration.ResponseDataSize) //If size is greater than specified size then add it and create new chunck { ListOfKeyPackageResponse.Add(keyPackageResponse); keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); estimatedSize = 0; } } if (estimatedSize != 0) { ListOfKeyPackageResponse.Add(keyPackageResponse); } } else { ListOfKeyPackageResponse.Add(new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse()); } return(ListOfKeyPackageResponse); }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int dataLength = 0; int overload; string exception = null; System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (ArgumentOutOfRangeException arEx) { if (SocketServer.Logger.IsErrorLogsEnabled) { SocketServer.Logger.NCacheLog.Error("GetCommand", "command: " + command + " Error" + arEx); } _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(arEx, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } catch (Exception exc) { _getResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } Alachisoft.NCache.Common.Protobuf.GetResponse getResponse = null; CompressedValueEntry flagValueEntry = null; OperationContext operationContext = null; NCache nCache = clientManager.CmdExecuter as NCache; try { object lockId = cmdInfo.LockId; ulong version = cmdInfo.CacheItemVersion; DateTime lockDate = new DateTime(); operationContext = _operationContext; operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); if (cmdInfo.LockAccessType == LockAccessType.ACQUIRE) { operationContext.Add(OperationContextFieldName.ClientThreadId, clientManager.ClientID); operationContext.Add(OperationContextFieldName.ClientThreadId, cmdInfo.ThreadId); operationContext.Add(OperationContextFieldName.IsRetryOperation, command.isRetryCommand); } flagValueEntry = nCache.Cache.GetGroup(cmdInfo.Key, cmdInfo.FlagMap, null, null, ref version, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext); stopWatch.Stop(); UserBinaryObject ubObj = null; getResponse = _getResponse; if (flagValueEntry != null) { if (flagValueEntry.Value is UserBinaryObject) { ubObj = (UserBinaryObject)flagValueEntry.Value; } else { var flag = flagValueEntry.Flag; ubObj = (UserBinaryObject)nCache.Cache.SocketServerDataService.GetClientData(flagValueEntry.Value, ref flag, LanguageContext.DOTNET); } if (flagValueEntry.Value != null) { getResponse.itemType = MiscUtil.EntryTypeToProtoItemType(flagValueEntry.Type);// (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)flagValueEntry.Type; } } if (ubObj != null) { dataLength = ubObj.Length; } if (clientManager.ClientVersion >= 5000) { if (lockId != null) { getResponse.lockId = lockId.ToString(); } getResponse.requestId = cmdInfo.RequestId; getResponse.commandID = command.commandID; getResponse.lockTime = lockDate.Ticks; getResponse.version = version; if (ubObj == null) { // response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(getResponse, Common.Protobuf.Response.Type.GET)); } else { //_dataPackageArray = ubObj.Data; getResponse.flag = flagValueEntry.Flag.Data; getResponse.data.AddRange(ubObj.DataList); // response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(getResponse, Common.Protobuf.Response.Type.GET)); } } else { Alachisoft.NCache.Common.Protobuf.Response response = Stash.ProtobufResponse; response.requestId = Convert.ToInt64(cmdInfo.RequestId); response.commandID = command.commandID; response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET; if (lockId != null) { getResponse.lockId = lockId.ToString(); } getResponse.lockTime = lockDate.Ticks; getResponse.version = version; if (ubObj == null) { response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } else { getResponse.flag = flagValueEntry.Flag.Data; getResponse.data.AddRange(ubObj.DataList); response.get = getResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } } catch (Exception exc) { exception = exc.ToString(); _getResult = OperationResult.Failure; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { int resutlt = 0; if (getResponse != null) { resutlt = dataLength; } string methodName = null; if (cmdInfo.LockAccessType == LockAccessType.ACQUIRE) { methodName = MethodsName.GET.ToLower(); } else { methodName = MethodsName.GET.ToLower(); } APILogItemBuilder log = new APILogItemBuilder(methodName); log.GenerateGetCommandAPILogItem(cmdInfo.Key, null, null, (long)cmdInfo.CacheItemVersion, cmdInfo.LockAccessType, cmdInfo.LockTimeout, cmdInfo.LockId, cmdInfo.ProviderName, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString(), resutlt); } } catch { } if (flagValueEntry != null) { MiscUtil.ReturnCompressedEntryToPool(flagValueEntry, clientManager.CacheTransactionalPool); MiscUtil.ReturnEntryToPool(flagValueEntry.Entry, clientManager.CacheTransactionalPool); } } //} //if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd executed on cache"); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (System.Exception exc) { if (!base.immatureId.Equals("-2")) { //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, base.immatureId), base.ParsingExceptionMessage(exc)); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; CacheEntry entry = null; try { object lockId = cmdInfo.LockId; DateTime lockDate = new DateTime(); OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); // ReadThruOptions readOptions = new ReadThruOptions(cmdInfo.ReadMode, cmdInfo.ProviderName); //operationContext.Add(OperationContextFieldName.ReadThruOptions, readOptions); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); entry = (CacheEntry)nCache.Cache.GetCacheEntry(cmdInfo.Key, cmdInfo.Group, cmdInfo.SubGroup, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, operationContext, ref cmdInfo.CacheItemVersion); stopWatch.Stop(); GetCacheItemResponse getCacheItemResponse = new GetCacheItemResponse(); getCacheItemResponse.lockId = lockId == null ? string.Empty : lockId.ToString(); getCacheItemResponse.lockTicks = lockDate.Ticks; if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(getCacheItemResponse, command.requestID, command.commandID); if (entry == null) { _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(getCacheItemResponse, Response.Type.GET_CACHE_ITEM)); return; } else { getCacheItemResponse.itemType = MiscUtil.EntryTypeToProtoItemType(entry.Type); } getCacheItemResponse = PopulateResponse(entry, getCacheItemResponse, clientManager, nCache.Cache); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(getCacheItemResponse, Response.Type.GET_CACHE_ITEM)); } else { Response response = new Response(); ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.GET_CACHE_ITEM); if (entry == null) { response.getItem = getCacheItemResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); return; } else { getCacheItemResponse.itemType = MiscUtil.EntryTypeToProtoItemType(entry.Type); } getCacheItemResponse = PopulateResponse(entry, getCacheItemResponse, clientManager, nCache.Cache); response.getItem = getCacheItemResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (System.Exception exc) { exception = exc.ToString(); //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc)); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { int result = 0; if (entry != null) { result = 1; } else { result = 0; } APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetCacheItem.ToLower()); } if (entry != null) { MiscUtil.ReturnEntryToPool(entry, clientManager.CacheTransactionalPool); } } catch { } if (entry != null) { entry.MarkFree(NCModulesConstants.Global); } cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); } }
private Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse PopulateResponse(CacheEntry entry, Alachisoft.NCache.Common.Protobuf.GetCacheItemResponse response, ClientManager clientManager, Caching.Cache cache) { if (entry.ExpirationHint is AggregateExpirationHint) { IList <ExpirationHint> hints = ((AggregateExpirationHint)entry.ExpirationHint).Hints; ///All hints are on same level now. There will be no AggregateExpirationHint within an AggregateExpirationHint for (int i = 0; i < hints.Count; i++) { if (hints[i] is FixedExpiration) { response.absExp = ((FixedExpiration)hints[i]).AbsoluteTime.Ticks; } else if (hints[i] is IdleExpiration) { response.sldExp = ((IdleExpiration)hints[i]).SlidingTime.Ticks; } } } else { if (entry.ExpirationHint is FixedExpiration) { response.absExp = ((FixedExpiration)entry.ExpirationHint).AbsoluteTime.Ticks; } else if (entry.ExpirationHint is IdleExpiration) { response.sldExp = ((IdleExpiration)entry.ExpirationHint).SlidingTime.Ticks; } } response.itemType = MiscUtil.EntryTypeToProtoItemType(entry.Type);// (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType)entry.Type; response.priority = (int)entry.Priority; if (entry.QueryInfo != null) { } if (entry.ExpirationHint != null) { response.hasExpired = entry.ExpirationHint.HasExpired; response.needsResync = entry.ExpirationHint.NeedsReSync; } response.version = entry.Version; response.creationTime = entry.CreationTime.Ticks; response.lastModifiedTime = entry.LastModifiedTime.Ticks; //response.lockId = (entry.LockId != null ? entry.LockId.ToString() : null); //response.lockTicks = entry.LockDate.Ticks; response.ResyncProviderName = entry.ResyncProviderName; object userValue = entry.Value; BitSet flag = entry.Flag; object data = cache.SocketServerDataService.GetClientData(userValue, ref flag, LanguageContext.DOTNET); if (data != null) { response.value.AddRange(((UserBinaryObject)(data)).DataList); } response.flag = flag.Data; return(response); }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); } catch (System.Exception exc) { _removeResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } CompressedValueEntry flagValueEntry = null; NCache nCache = clientManager.CmdExecuter as NCache; if (!cmdInfo.DoAsync) { OperationContext operationContext = null; try { Notifications notification = null; if (cmdInfo.DsItemRemovedId != -1) { notification = new Notifications(clientManager.ClientID, -1, -1, -1, -1, cmdInfo.DsItemRemovedId , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None); //DataFilter not required } operationContext = _operationContext; operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientId, clientManager.ClientID); operationContext.Add(OperationContextFieldName.MethodOverload, overload); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); flagValueEntry = nCache.Cache.Remove(cmdInfo.Key, cmdInfo.FlagMap, notification, cmdInfo.LockId, cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, operationContext); stopWatch.Stop(); UserBinaryObject ubObject = null; if (flagValueEntry != null) { if (flagValueEntry.Value is UserBinaryObject) { ubObject = (UserBinaryObject)flagValueEntry.Value; } else { var flag = flagValueEntry.Flag; ubObject = (flagValueEntry == null) ? null : (UserBinaryObject)nCache.Cache.SocketServerDataService.GetClientData(flagValueEntry.Value, ref flag, LanguageContext.DOTNET); } } //PROTOBUF:RESPONSE RemoveResponse removeResponse = _removeResponse; if (ubObject != null) { removeResponse.value.AddRange(ubObject.DataList); removeResponse.flag = flagValueEntry.Flag.Data; removeResponse.itemType = MiscUtil.EntryTypeToProtoItemType(flagValueEntry.Type); } if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(removeResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(removeResponse, Response.Type.REMOVE)); } else { Response response = Stash.ProtobufResponse; { response.remove = removeResponse; }; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.REMOVE); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (System.Exception exc) { _removeResult = OperationResult.Failure; exception = exc.ToString(); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; if (flagValueEntry != null) { MiscUtil.ReturnEntryToPool(flagValueEntry.Entry, clientManager.CacheTransactionalPool); MiscUtil.ReturnCompressedEntryToPool(flagValueEntry, clientManager.CacheTransactionalPool); } try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.REMOVE.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } else { OperationContext operationContext = null; try { cmdInfo.FlagMap = new BitSet { Data = cmdInfo.FlagMap.Data }; object[] package = null; if (cmdInfo.RequestId != -1 || cmdInfo.DsItemRemovedId != -1) { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, new Notifications(clientManager.ClientID, Convert.ToInt32(cmdInfo.RequestId), -1, -1, (short)(cmdInfo.RequestId == -1 ? -1 : 0), cmdInfo.DsItemRemovedId , Runtime.Events.EventDataFilter.None, Runtime.Events.EventDataFilter.None), cmdInfo.ProviderName }; //DataFilter not required } else { package = new object[] { cmdInfo.Key, cmdInfo.FlagMap, null, cmdInfo.ProviderName }; } operationContext = OperationContext.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer); operationContext.Add(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.RaiseCQNotification, true); operationContext.Add(OperationContextFieldName.MethodOverload, overload); nCache.Cache.RemoveAsync(package, operationContext); stopWatch.Stop(); } finally { operationContext?.MarkFree(NCModulesConstants.SocketServer); TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.RemoveAsync.ToLower()); log.GenerateRemoveAPILogItem(cmdInfo.Key, cmdInfo.FlagMap, cmdInfo.LockId, (long)cmdInfo.Version, cmdInfo.LockAccessType, cmdInfo.ProviderName, cmdInfo.DsItemRemovedId, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } } }
public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload; string exception = null; int count = 0; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { overload = command.MethodOverload; cmdInfo = ParseCommand(command, clientManager); if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd parsed"); } } catch (Exception exc) { _getBulkCacheItemResult = OperationResult.Failure; if (!base.immatureId.Equals("-2")) { //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } return; } NCache nCache = clientManager.CmdExecuter as NCache; List <CacheEntry> pooledEntries = null; try { OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient)) { operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient); } operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout); operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true); operationContext.CancellationToken = CancellationToken; IDictionary getResult = (IDictionary)nCache.Cache.GetBulkCacheItems(cmdInfo.Keys, cmdInfo.FlagMap, operationContext); count = getResult.Count; stopWatch.Stop(); Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse bulkGetCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse(); IDictionaryEnumerator enu = getResult.GetEnumerator(); while (enu.MoveNext()) { CacheEntry cacheEntry = null; try { var keyCacheItem = new Alachisoft.NCache.Common.Protobuf.KeyCacheItemPair(); keyCacheItem.key = (string)enu.Key; cacheEntry = (CacheEntry)enu.Value; if (cacheEntry != null) { if (cacheEntry.IsFromPool) { if (pooledEntries == null) { pooledEntries = new List <CacheEntry>(); } pooledEntries.Add(cacheEntry); } keyCacheItem.cacheItem = PopulateResponse(cacheEntry, clientManager, nCache.Cache); keyCacheItem.cacheItem.itemType = MiscUtil.EntryTypeToProtoItemType(cacheEntry.Type); bulkGetCacheItemResponse.KeyCacheItemPairs.Add(keyCacheItem); } else { bulkGetCacheItemResponse.KeyCacheItemPairs.Add(null); } } finally { if (cacheEntry != null) { cacheEntry.MarkFree(NCModulesConstants.Global); } } } if (clientManager.ClientVersion >= 5000) { ResponseHelper.SetResponse(bulkGetCacheItemResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(bulkGetCacheItemResponse, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM)); } else { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM); response.bulkGetCacheItem = bulkGetCacheItemResponse; _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (OperationCanceledException ex) { exception = ex.ToString(); Dispose(); } catch (System.Exception exc) { _getBulkCacheItemResult = OperationResult.Failure; exception = exc.ToString(); //PROTOBUF:RESPONSE _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion)); } finally { TimeSpan executionTime = stopWatch.Elapsed; try { if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging) { APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetBulk.ToLower()); log.GenerateBulkGetAPILogItem(cmdInfo.Keys.Length, cmdInfo.providerName, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString(), count); } if (pooledEntries != null && pooledEntries.Count > 0) { MiscUtil.ReturnEntriesToPool(pooledEntries, clientManager.CacheTransactionalPool); } } catch { } try { cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer); } catch { } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd executed on cache"); } }