Beispiel #1
0
        public override void ProcessCommand(ClientManager clientManager, object cmd, long acknowledgementId, UsageStats stats)
        {
            Common.Protobuf.Command command = cmd as Common.Protobuf.Command;
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "enter");
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "" + command);
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " COMMAND to be executed : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            HPTimeStats milliSecWatch = new HPTimeStats();

            milliSecWatch.BeginSample();

            CommandBase incommingCmd = null;

            switch (command.type)
            {
            case Common.Protobuf.Command.Type.INIT:
                Common.Protobuf.InitCommand initCommand = command.initCommand;
                initCommand.requestId = command.requestID;
                incommingCmd          = new ServiceInitializeCommand(acknowledgementId);
                break;

            case Common.Protobuf.Command.Type.GET_OPTIMAL_SERVER:
                command.getOptimalServerCommand.requestId = command.requestID;
                incommingCmd = new ServiceGetOptimalServerCommand(acknowledgementId);
                break;

            case Common.Protobuf.Command.Type.GET_CACHE_BINDING:
                command.getCacheBindingCommand.requestId = command.requestID;
                incommingCmd = new ServiceCacheBindingCommand(acknowledgementId);
                break;

            case Common.Protobuf.Command.Type.GET_SERVER_MAPPING:
                command.getServerMappingCommand.requestId = command.requestID;
                incommingCmd = new GetServerMappingCommand();
                break;
            }


            if (SocketServer.IsServerCounterEnabled)
            {
                base.PerfStatsCollector.MsecPerCacheOperationBeginSample();
            }
            try
            {
                incommingCmd.ExecuteCommand(clientManager, command);
            }
            catch (Exception ex)
            {
                throw;
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " after executing COMMAND : " + command.type.ToString() + " RequestId :" + command.requestID);
            }


            if (SocketServer.IsServerCounterEnabled)
            {
                base.PerfStatsCollector.MsecPerCacheOperationEndSample();
            }


            if (clientManager != null && incommingCmd.SerializedResponsePackets != null && !clientManager.IsCacheStopped)
            {
                if (SocketServer.IsServerCounterEnabled)
                {
                    base.PerfStatsCollector.IncrementResponsesPerSecStats(1);
                }

                foreach (byte[] reponse in incommingCmd.SerializedResponsePackets)
                {
                    ConnectionManager.AssureSend(clientManager, reponse, Common.Enum.Priority.Normal);
                }
            }

            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "exit");
            }
        }
Beispiel #2
0
        public void ProcessCommand(ClientManager clientManager, object cmd)
        {
            Alachisoft.NCache.Common.Protobuf.Command command = cmd as Alachisoft.NCache.Common.Protobuf.Command;
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "enter");
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "" + command);
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " COMMAND to be executed : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            HPTimeStats milliSecWatch = new HPTimeStats();

            milliSecWatch.BeginSample();

            CommandBase incommingCmd = null;

            switch (command.type)
            {
            case Alachisoft.NCache.Common.Protobuf.Command.Type.INIT:
                Alachisoft.NCache.Common.Protobuf.InitCommand initCommand = command.initCommand;
                initCommand.requestId = command.requestID;
                if (SocketServer.Logger.IsDetailedLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " RequestId :" + command.requestID);
                }
                incommingCmd = new InitializeCommand();
                break;

            // added in server to cater getProductVersion request from client
            case Common.Protobuf.Command.Type.GET_PRODUCT_VERSION:
                command.getProductVersionCommand.requestId = command.requestID;
                incommingCmd = new GetProductVersionCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD:
                command.addCommand.requestId = command.requestID;
                incommingCmd = new AddCommand();
                break;


            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_BULK:
                command.bulkAddCommand.requestId = command.requestID;
                incommingCmd = new BulkAddCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CLEAR:
                command.clearCommand.requestId = command.requestID;
                incommingCmd = new ClearCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.CONTAINS:
                command.containsCommand.requestId = command.requestID;
                incommingCmd = new ContainsCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.COUNT:
                command.countCommand.requestId = command.requestID;
                incommingCmd = new CountCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DISPOSE:
                command.disposeCommand.requestId = command.requestID;
                incommingCmd = new DisposeCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET:
                command.getCommand.requestId = command.requestID;
                incommingCmd = new GetCommand();
                break;


            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_BULK:
                command.bulkGetCommand.requestId = command.requestID;
                incommingCmd = new BulkGetCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_ITEM:
                command.getCacheItemCommand.requestId = command.requestID;
                incommingCmd = new GetCacheItemCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_ENUMERATOR:
                command.getEnumeratorCommand.requestId = command.requestID;
                incommingCmd = new GetEnumeratorCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_NEXT_CHUNK:
                command.getNextChunkCommand.requestId = command.requestID;
                incommingCmd = new GetNextChunkCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_HASHMAP:
                command.getHashmapCommand.requestId = command.requestID;
                incommingCmd = new GetHashmapCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_OPTIMAL_SERVER:
                command.getOptimalServerCommand.requestId = command.requestID;
                incommingCmd = new GetOptimalServerCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_RUNNING_SERVERS:
                command.getRunningServersCommand.requestId = command.requestID;
                incommingCmd = new GetRunningServersCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_LOGGING_INFO:
                command.getLoggingInfoCommand.requestId = command.requestID;
                incommingCmd = new GetLogginInfoCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_TYPEINFO_MAP:
                command.getTypeInfoMapCommand.requestId = command.requestID;
                incommingCmd = new GetTypeInfoMap();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT:
                command.insertCommand.requestId = command.requestID;
                incommingCmd = new InsertCommand();
                break;


            case Alachisoft.NCache.Common.Protobuf.Command.Type.INSERT_BULK:
                command.bulkInsertCommand.requestId = command.requestID;
                incommingCmd = new BulkInsertCommand();
                break;


            case Alachisoft.NCache.Common.Protobuf.Command.Type.ISLOCKED:
                command.isLockedCommand.requestId = command.requestID;
                incommingCmd = new IsLockedCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.LOCK:
                command.lockCommand.requestId = command.requestID;
                incommingCmd = new LockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.LOCK_VERIFY:
                command.lockVerifyCommand.requestId = command.requestID;
                incommingCmd = new VerifyLockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_KEY_NOTIF:
                command.registerKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new RegisterKeyNotifcationCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REGISTER_NOTIF:
                command.registerNotifCommand.requestId = command.requestID;
                incommingCmd = new NotificationRegistered();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE:
                command.removeCommand.requestId = command.requestID;
                incommingCmd = new RemoveCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DELETE:
                command.deleteCommand.requestId = command.requestID;
                incommingCmd = new DeleteCommand();
                break;


            case Alachisoft.NCache.Common.Protobuf.Command.Type.REMOVE_BULK:
                command.bulkRemoveCommand.requestId = command.requestID;
                incommingCmd = new BulkRemoveCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.DELETE_BULK:
                command.bulkDeleteCommand.requestId = command.requestID;
                incommingCmd = new BulkDeleteCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.SEARCH:
                Alachisoft.NCache.Common.Protobuf.SearchCommand searchCommand = command.searchCommand;
                searchCommand.requestId = command.requestID;

                if (searchCommand.searchEntries)
                {
                    incommingCmd = new SearchEnteriesCommand();
                }
                else
                {
                    incommingCmd = new SearchCommand();
                }

                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNLOCK:
                command.unlockCommand.requestId = command.requestID;
                incommingCmd = new UnlockCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.UNREGISTER_KEY_NOTIF:
                command.unRegisterKeyNotifCommand.requestId = command.requestID;
                incommingCmd = new UnRegisterKeyNoticationCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.ADD_ATTRIBUTE:
                command.addAttributeCommand.requestId = command.requestID;
                incommingCmd = new AddAttributeCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_SERVER_MAPPING:
                command.getServerMappingCommand.requestId = command.requestID;
                incommingCmd = new GetServerMappingCommand();
                break;
            }
            if (SocketServer.IsServerCounterEnabled)
            {
                _perfStatsCollector.MsecPerCacheOperationBeginSample();
            }
            ///*****************************************************************/
            ///**/incommingCmd.ExecuteCommand(clientManager, command, value);/**/
            ///*****************************************************************/
            //PROTOBUF
            /*****************************************************************/
            /**/
            incommingCmd.ExecuteCommand(clientManager, command);/**/
            /*****************************************************************/
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " after executing COMMAND : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            if (SocketServer.IsServerCounterEnabled)
            {
                _perfStatsCollector.MsecPerCacheOperationEndSample();
            }

            if (clientManager != null && incommingCmd.SerializedResponsePackets != null && !clientManager.IsCacheStopped)
            {
                if (SocketServer.IsServerCounterEnabled)
                {
                    _perfStatsCollector.IncrementResponsesPerSecStats(1);
                }

                foreach (byte[] reponse in incommingCmd.SerializedResponsePackets)
                {
                    ConnectionManager.AssureSend(clientManager, reponse, Alachisoft.NCache.Common.Enum.Priority.Normal);
                }
            }

            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "exit");
            }
        }
        public override void ProcessCommand(ClientManager clientManager, object cmd, short cmdType, long acknowledgementId, UsageStats stats, bool waitforResponse)
        {
            Alachisoft.NCache.Common.Protobuf.Command command = cmd as Alachisoft.NCache.Common.Protobuf.Command;
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "enter");
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "" + command);
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " COMMAND to be executed : " + command.type.ToString() + " RequestId :" + command.requestID);
            }

            bool clientDisposed = false;

            CommandBase incommingCmd    = null;
            bool        isUnsafeCommand = false;

            switch (command.type)
            {
            case Alachisoft.NCache.Common.Protobuf.Command.Type.INIT:
                Alachisoft.NCache.Common.Protobuf.InitCommand initCommand = command.initCommand;
                initCommand.requestId = command.requestID;
                if (SocketServer.Logger.IsDetailedLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " RequestId :" + command.requestID);
                }
                incommingCmd = new ServiceInitializeCommand(base.RequestLogger.RequestLoggingEnabled, acknowledgementId);
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_OPTIMAL_SERVER:
                command.getOptimalServerCommand.requestId = command.requestID;
                incommingCmd = new ServiceGetOptimalServerCommand(acknowledgementId);
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_BINDING:
                command.getCacheBindingCommand.requestId = command.requestID;
                incommingCmd = new ServiceCacheBindingCommand(acknowledgementId);
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_SERVER_MAPPING:
                command.getServerMappingCommand.requestId = command.requestID;
                incommingCmd = new GetServerMappingCommand();
                break;

            case Alachisoft.NCache.Common.Protobuf.Command.Type.GET_CACHE_MANAGEMENT_PORT:
                command.getCacheManagementPortCommand.requestId = command.requestID;
                incommingCmd = new GetCacheManagementPortCommand();
                break;
            }


            if (SocketServer.IsServerCounterEnabled)
            {
                base.PerfStatsCollector.MsecPerCacheOperationBeginSample();
            }
            try
            {
                if (isUnsafeCommand && clientManager.SupportAcknowledgement)
                {
                    if (clientDisposed)
                    {
                        base.RequestLogger.RemoveClientAccount(clientManager.ClientID);
                    }
                    else
                    {
                        base.RequestLogger.RegisterRequest(clientManager.ClientID, command.requestID, command.commandID,
                                                           acknowledgementId);
                    }
                }
                incommingCmd.ExecuteCommand(clientManager, command);
            }
            catch (Exception ex)
            {
                if (isUnsafeCommand && clientManager.SupportAcknowledgement)
                {
                    base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID,
                                                     Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null);
                }
                throw;
            }
            if (SocketServer.Logger.IsDetailedLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Info("ConnectionManager.ReceiveCallback", clientManager.ToString() + " after executing COMMAND : " + command.type.ToString() + " RequestId :" + command.requestID);
            }


            if (SocketServer.IsServerCounterEnabled)
            {
                base.PerfStatsCollector.MsecPerCacheOperationEndSample();
            }


#if SERVER
            if (clientManager != null && incommingCmd.OperationResult == OperationResult.Success)
            {
                if (clientManager.CmdExecuter != null)
                {
                    clientManager.CmdExecuter.UpdateSocketServerStats(new SocketServerStats(clientManager.ClientsRequests, clientManager.ClientsBytesSent, clientManager.ClientsBytesRecieved));
                }
            }
#endif
            if (isUnsafeCommand && clientManager.SupportAcknowledgement)
            {
                if (clientManager != null && clientManager.IsDisposed &&
                    incommingCmd.OperationResult == OperationResult.Failure)
                {
                    base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID, Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_WITH_ERROR, null);
                }
                else
                {
                    base.RequestLogger.UpdateRequest(clientManager.ClientID, command.requestID, command.commandID,
                                                     Alachisoft.NCache.Common.Enum.RequestStatus.RECEIVED_AND_EXECUTED, incommingCmd.SerializedResponsePackets);
                }
            }


            if (clientManager != null && incommingCmd.SerializedResponsePackets != null && !clientManager.IsCacheStopped)
            {
                if (SocketServer.IsServerCounterEnabled)
                {
                    base.PerfStatsCollector.IncrementResponsesPerSecStats(1);
                }

                foreach (IList reponse in incommingCmd.SerializedResponsePackets)
                {
                    ConnectionManager.AssureSendSync(clientManager, reponse);
                }
            }

            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("CmdMgr.PrsCmd", "exit");
            }
        }