internal ContainsCommand(string key) { base.name = "ContainsCommand"; base.key = key; _containsCommand = new Alachisoft.NCache.Common.Protobuf.ContainsCommand(); _containsCommand.requestId = base.RequestId; _containsCommand.key = key; }
//PROTOBUF private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager) { CommandInfo cmdInfo = new CommandInfo(); Alachisoft.NCache.Common.Protobuf.ContainsCommand containsCommand = command.containsCommand; cmdInfo.Key = containsCommand.key; cmdInfo.RequestId = containsCommand.requestId.ToString(); return(cmdInfo); }
//PROTOBUF public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command) { int overload = 0; string exception = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Keys = new List <string>(); string key = null; NCache nCache = clientManager.CmdExecuter as NCache; try { overload = command.MethodOverload; switch (command.type) { case Common.Protobuf.Command.Type.CONTAINS: Alachisoft.NCache.Common.Protobuf.ContainsCommand containsCommand = command.containsCommand; Keys.Add(containsCommand.key); key = containsCommand.key; RequestId = containsCommand.requestId.ToString(); break; case Common.Protobuf.Command.Type.CONTAINS_BULK: Alachisoft.NCache.Common.Protobuf.ContainsBulkCommand containsBulkCommand = command.containsBulkCommand; FeatureUsageCollector.Instance.GetFeature(FeatureEnum.bulk_operations).UpdateUsageTime(); Keys = containsBulkCommand.keys; RequestId = containsBulkCommand.requestId.ToString(); break; default: throw new Exception("Invalid Command Received in ContainsCommand"); } var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation); CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress); Hashtable exists = nCache.Cache.Contains(Keys, operationContext); stopWatch.Stop(); if (clientManager.ClientVersion >= 5000) { Alachisoft.NCache.Common.Protobuf.ContainBulkResponse containsBulkResponse = new Alachisoft.NCache.Common.Protobuf.ContainBulkResponse(); containsBulkResponse.exists = CompactBinaryFormatter.ToByteBuffer(exists, null); ResponseHelper.SetResponse(containsBulkResponse, command.requestID, command.commandID); _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(containsBulkResponse, Common.Protobuf.Response.Type.CONTAINS_BULK)); } else { Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response(); Alachisoft.NCache.Common.Protobuf.ContainResponse containResponse = new Alachisoft.NCache.Common.Protobuf.ContainResponse(); IDictionary <string, bool> keysPresent = ExtractKeyStatus(exists, Keys); containResponse.exists = keysPresent[key]; response.contain = containResponse; ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.CONTAINS); _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response)); } } catch (Exception exc) { exception = exc.ToString(); _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.Contains.ToLower()); log.GenerateContainsCommandAPILogItem(key, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString()); } } catch { } } if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd executed on cache"); } }