Beispiel #1
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            int       overload;
            string    exception = null;
            Stopwatch stopWatch = new Stopwatch();
            int       count     = 0;

            stopWatch.Start();

            try
            {
                try
                {
                    overload = command.MethodOverload;
                    cmdInfo  = ParseCommand(command, clientManager);
                    if (ServerMonitor.MonitorActivity)
                    {
                        ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd parsed");
                    }
                }
                catch (Exception exc)
                {
                    _getBulkResult = OperationResult.Failure;
                    if (!base.immatureId.Equals("-2"))
                    {
                        //PROTOBUF:RESPONSE
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                    }
                    return;
                }

                byte[] data = null;

                NCache     nCache    = clientManager.CmdExecuter as NCache;
                HashVector getResult = null;

                try
                {
                    OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                    operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                    if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient))
                    {
                        operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient);
                    }

                    operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout);
                    operationContext.CancellationToken = CancellationToken;
                    getResult = (HashVector)nCache.Cache.GetBulk(cmdInfo.Keys, cmdInfo.FlagMap, operationContext);
                    stopWatch.Stop();

                    count = getResult.Count;
                    BulkGetResponseBuilder.BuildResponse(getResult, cmdInfo.CommandVersion, cmdInfo.RequestId, _serializedResponsePackets, cmdInfo.IntendedRecipient, command.commandID, clientManager, nCache.Cache);
                }
                catch (OperationCanceledException ex)
                {
                    exception = ex.ToString();
                    Dispose();
                }
                catch (Exception exc)
                {
                    _getBulkResult = OperationResult.Failure;
                    exception      = exc.ToString();
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                }
                finally
                {
                    TimeSpan executionTime = stopWatch.Elapsed;
                    if (getResult != null)
                    {
                        foreach (CompressedValueEntry compressedValueEntry in getResult.Values)
                        {
                            MiscUtil.ReturnEntryToPool(compressedValueEntry.Entry, clientManager.CacheTransactionalPool);
                            MiscUtil.ReturnCompressedEntryToPool(compressedValueEntry, clientManager.CacheTransactionalPool);
                        }
                    }
                    try
                    {
                        if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                        {
                            APILogItemBuilder log = new APILogItemBuilder(MethodsName.GetBulk.ToLower());
                            log.GenerateBulkGetAPILogItem(cmdInfo.Keys.Length, cmdInfo.providerName, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString(), count);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            finally
            {
                cmdInfo.FlagMap.MarkFree(NCModulesConstants.SocketServer);
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd executed on cache");
            }
        }
Beispiel #2
0
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            int    overload;
            string exception = null;
            int    count     = 0;

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            try
            {
                overload = command.MethodOverload;
                cmdInfo  = ParseCommand(command, clientManager);

                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd parsed");
                }
            }
            catch (Exception exc)
            {
                _getBulkCacheItemResult = OperationResult.Failure;
                if (!base.immatureId.Equals("-2"))
                {
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
                }
                return;
            }

            NCache            nCache        = clientManager.CmdExecuter as NCache;
            List <CacheEntry> pooledEntries = null;

            try
            {
                OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                operationContext.Add(OperationContextFieldName.ClientLastViewId, cmdInfo.ClientLastViewId);
                CommandsUtil.PopulateClientIdInContext(ref operationContext, clientManager.ClientAddress);
                if (!string.IsNullOrEmpty(cmdInfo.IntendedRecipient))
                {
                    operationContext.Add(OperationContextFieldName.IntendedRecipient, cmdInfo.IntendedRecipient);
                }

                operationContext.Add(OperationContextFieldName.ClientOperationTimeout, clientManager.RequestTimeout);
                operationContext.Add(OperationContextFieldName.GenerateQueryInfo, true);
                operationContext.CancellationToken = CancellationToken;

                IDictionary getResult = (IDictionary)nCache.Cache.GetBulkCacheItems(cmdInfo.Keys, cmdInfo.FlagMap, operationContext);

                count = getResult.Count;
                stopWatch.Stop();


                Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse bulkGetCacheItemResponse = new Alachisoft.NCache.Common.Protobuf.BulkGetCacheItemResponse();

                IDictionaryEnumerator enu = getResult.GetEnumerator();
                while (enu.MoveNext())
                {
                    CacheEntry cacheEntry = null;
                    try
                    {
                        var keyCacheItem = new Alachisoft.NCache.Common.Protobuf.KeyCacheItemPair();

                        keyCacheItem.key = (string)enu.Key;

                        cacheEntry = (CacheEntry)enu.Value;
                        if (cacheEntry != null)
                        {
                            if (cacheEntry.IsFromPool)
                            {
                                if (pooledEntries == null)
                                {
                                    pooledEntries = new List <CacheEntry>();
                                }
                                pooledEntries.Add(cacheEntry);
                            }
                            keyCacheItem.cacheItem = PopulateResponse(cacheEntry, clientManager, nCache.Cache);

                            keyCacheItem.cacheItem.itemType = MiscUtil.EntryTypeToProtoItemType(cacheEntry.Type);

                            bulkGetCacheItemResponse.KeyCacheItemPairs.Add(keyCacheItem);
                        }
                        else
                        {
                            bulkGetCacheItemResponse.KeyCacheItemPairs.Add(null);
                        }
                    }
                    finally
                    {
                        if (cacheEntry != null)
                        {
                            cacheEntry.MarkFree(NCModulesConstants.Global);
                        }
                    }
                }
                if (clientManager.ClientVersion >= 5000)
                {
                    ResponseHelper.SetResponse(bulkGetCacheItemResponse, command.requestID, command.commandID);
                    _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(bulkGetCacheItemResponse, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM));
                }
                else
                {
                    Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                    ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.BULK_GET_CACHEITEM);
                    response.bulkGetCacheItem = bulkGetCacheItemResponse;
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (OperationCanceledException ex)
            {
                exception = ex.ToString();
                Dispose();
            }
            catch (System.Exception exc)
            {
                _getBulkCacheItemResult = OperationResult.Failure;
                exception = exc.ToString();
                //PROTOBUF:RESPONSE
                _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.GetBulk.ToLower());
                        log.GenerateBulkGetAPILogItem(cmdInfo.Keys.Length, cmdInfo.providerName, overload, exception, executionTime, clientManager.ClientID, clientManager.ClientSocketId.ToString(), count);
                    }

                    if (pooledEntries != null && pooledEntries.Count > 0)
                    {
                        MiscUtil.ReturnEntriesToPool(pooledEntries, clientManager.CacheTransactionalPool);
                    }
                }
                catch
                {
                }
                try
                {
                    cmdInfo.FlagMap?.MarkFree(NCModulesConstants.SocketServer);
                }
                catch
                {
                }
            }
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("BulkGetCmd.Exec", "cmd executed on cache");
            }
        }