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

            byte[] data = null;

            NCache    nCache = clientManager.CmdExecuter as NCache;
            int       overload;
            string    exception = null;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                overload             = command.MethodOverload;
                serializationContext = nCache.CacheId;
                cmdInfo = ParseCommand(nCache.Cache, command);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID, command.commandID));
                }
                return;
            }

            data = new byte[1];
            try
            {
                bool result = nCache.Cache.AddExpirationHint(cmdInfo.Key, cmdInfo.ExpHint, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                stopWatch.Stop();

                Alachisoft.NCache.Common.Protobuf.Response             response             = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.AddAttributeResponse addAttributeResponse = new Alachisoft.NCache.Common.Protobuf.AddAttributeResponse();
                addAttributeResponse.success  = result;
                response.requestId            = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID            = command.commandID;
                response.responseType         = Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_ATTRIBUTE;
                response.addAttributeResponse = addAttributeResponse;
                _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
            {
                stopWatch.Stop();
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log            = new APILogItemBuilder(MethodsName.SetAttributes.ToLower());
                        Hashtable         expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpHint, null);
                        log.GenerateAddAttributeAPILogItem(cmdInfo.Key, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                    }
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 2
0
        //PROTOBUF

        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            byte[] data = null;

            NCache    nCache = clientManager.CmdExecuter as NCache;
            int       overload;
            string    exception = null;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                overload             = command.MethodOverload;
                serializationContext = nCache.CacheId;
                cmdInfo = ParseCommand(nCache.Cache, command);
            }
            catch (System.Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                }
                return;
            }

            data = new byte[1];
            try
            {
                var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress);
                //PROTOBUF:RESPONSE
                bool result = nCache.Cache.AddExpirationHint(cmdInfo.Key, cmdInfo.ExpHint, operationContext);
                //PROTOBUF:RESPONSE
                stopWatch.Stop();

                AddAttributeResponse addResponse = new AddAttributeResponse();
                addResponse.success = result;
                if (clientManager.ClientVersion >= 5000)
                {
                    ResponseHelper.SetResponse(addResponse, command.requestID, command.commandID);
                    _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(addResponse, Response.Type.ADD_ATTRIBUTE));
                }
                else
                {
                    //PROTOBUF:RESPONSE
                    Response response = new Response();
                    response.addAttributeResponse = addResponse;
                    ResponseHelper.SetResponse(response, command.requestID, command.commandID, Response.Type.ADD_ATTRIBUTE);
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (System.Exception exc)
            {
                //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc));
                //PROTOBUF:RESPONSEexception = exc.ToString();
                exception = exc.ToString();
                //_resultPacket = Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID);
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
            }
            finally
            {
                stopWatch.Stop();
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        APILogItemBuilder log            = new APILogItemBuilder(MethodsName.SetAttributes.ToLower());
                        Hashtable         expirationHint = log.GetDependencyExpirationAndQueryInfo(cmdInfo.ExpHint, null);
                        log.GenerateAddAttributeAPILogItem(cmdInfo.Key, expirationHint["absolute-expiration"] != null ? (long)expirationHint["absolute-expiration"] : -1, expirationHint["dependency"] != null ? expirationHint["dependency"] as ArrayList : null, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString());
                    }
                }
                catch { }
            }
        }