Beispiel #1
0
        //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");
        }
Beispiel #2
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd parsed");
                }
            }
            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.SerializeExceptionResponse(arEx, command.requestID));
                }
                return;
            }
            catch (Exception exc)
            {
                _getResult = OperationResult.Failure;
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }

            try
            {
                object               lockId         = cmdInfo.LockId;
                DateTime             lockDate       = new DateTime();
                NCache               nCache         = clientManager.CmdExecuter as NCache;
                CompressedValueEntry flagValueEntry = null;

                flagValueEntry = nCache.Cache.Get(cmdInfo.Key, cmdInfo.FlagMap, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

                UserBinaryObject ubObj = (flagValueEntry == null) ? null : (UserBinaryObject)flagValueEntry.Value;

                Alachisoft.NCache.Common.Protobuf.Response    response    = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetResponse getResponse = new Alachisoft.NCache.Common.Protobuf.GetResponse();
                response.requestId    = Convert.ToInt64(cmdInfo.RequestId);
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET;
                if (lockId != null)
                {
                    getResponse.lockId = lockId.ToString();
                }
                getResponse.lockTime = lockDate.Ticks;

                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)
            {
                _getResult = OperationResult.Failure;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd executed on cache");
            }
        }
Beispiel #3
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

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

            }
            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.SerializeExceptionResponse(arEx, command.requestID));
                return;
            }
            catch (Exception exc)
            {
                _getResult = OperationResult.Failure;
                if (!base.immatureId.Equals("-2"))
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                return;
            }

            try
            {
                object lockId = cmdInfo.LockId;
                DateTime lockDate = new DateTime();
                NCache nCache = clientManager.CmdExecuter as NCache;
                CompressedValueEntry flagValueEntry = null;

                flagValueEntry = nCache.Cache.Get(cmdInfo.Key, cmdInfo.FlagMap, ref lockId, ref lockDate, cmdInfo.LockTimeout, cmdInfo.LockAccessType, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

                UserBinaryObject ubObj = (flagValueEntry == null) ? null : (UserBinaryObject)flagValueEntry.Value;

                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetResponse getResponse = new Alachisoft.NCache.Common.Protobuf.GetResponse();
                response.requestId = Convert.ToInt64(cmdInfo.RequestId);
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET;
                if (lockId != null)
                {
                    getResponse.lockId = lockId.ToString();
                }
                getResponse.lockTime = lockDate.Ticks;

                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)
            {
                _getResult = OperationResult.Failure;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("GetCmd.Exec", "cmd executed on cache");
        }