Exemplo n.º 1
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            //TODO
            byte[] data = null;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd parsed");
                }
            }
            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
            {
                bool exists = nCache.Cache.Contains(cmdInfo.Key, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                Alachisoft.NCache.Common.Protobuf.Response        response         = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.ContainResponse containsResponse = new Alachisoft.NCache.Common.Protobuf.ContainResponse();
                response.requestId      = Convert.ToInt64(cmdInfo.RequestId);
                containsResponse.exists = exists;
                response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.CONTAINS;
                response.contain        = containsResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd executed on cache");
            }
        }
Exemplo n.º 2
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            //TODO
            byte[] data = null;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd parsed");

            }
            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
            {
                bool exists = nCache.Cache.Contains(cmdInfo.Key, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.ContainResponse containsResponse = new Alachisoft.NCache.Common.Protobuf.ContainResponse();
                response.requestId = Convert.ToInt64(cmdInfo.RequestId);
                containsResponse.exists = exists;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.CONTAINS;
                response.contain = containsResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd executed on cache");
        }
Exemplo n.º 3
0
        //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");
            }
        }
Exemplo n.º 4
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            int         overload;
            string      exception = null;
            Stopwatch   stopWatch = new Stopwatch();

            stopWatch.Start();
            byte[] data = null;

            try
            {
                overload = command.MethodOverload;
                cmdInfo  = ParseCommand(command, clientManager);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd parsed");
                }
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                }
                return;
            }

            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                bool exists = nCache.Cache.Contains(cmdInfo.Key, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                stopWatch.Stop();
                Alachisoft.NCache.Common.Protobuf.Response        response         = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.ContainResponse containsResponse = new Alachisoft.NCache.Common.Protobuf.ContainResponse();
                response.requestId      = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID      = command.commandID;
                containsResponse.exists = exists;
                response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.CONTAINS;
                response.contain        = containsResponse;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                exception = exc.ToString();
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
            }
            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(cmdInfo.Key, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("ContCmd.Exec", "cmd executed on cache");
            }
        }