Exemplo n.º 1
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            long   requestId;
            string taskId     = "";
            int    callbackId = 0;

            byte[] mapper        = null;
            byte[] reducer       = null;
            byte[] combiner      = null;
            byte[] inputProvider = null;
            int    outputOption  = 0;

            byte[] keyfilter = null;
            string query     = "";

            byte[]    parameters = null;
            int       overload;
            string    exception = null;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            { overload = command.MethodOverload;
              Alachisoft.NCache.Common.Protobuf.MapReduceTaskCommand mapReduceTaskCommand = command.mapReduceTaskCommand;
              overload = command.MethodOverload;
              if (mapReduceTaskCommand.mapper != null)
              {
                  mapper = mapReduceTaskCommand.mapper;
              }
              if (mapReduceTaskCommand.reducer != null)
              {
                  reducer = mapReduceTaskCommand.reducer;
              }
              if (mapReduceTaskCommand.combiner != null)
              {
                  combiner = mapReduceTaskCommand.combiner;
              }

              if (mapReduceTaskCommand.inputProvider != null)
              {
                  inputProvider = mapReduceTaskCommand.inputProvider;
              }

              if (mapReduceTaskCommand.keyFilter != null)
              {
                  keyfilter = mapReduceTaskCommand.keyFilter;
              }
              if (mapReduceTaskCommand.queryParameters != null)
              {
                  parameters = mapReduceTaskCommand.queryParameters;
              }

              requestId    = command.requestID;
              query        = mapReduceTaskCommand.query;
              taskId       = mapReduceTaskCommand.taskId;
              callbackId   = mapReduceTaskCommand.callbackId;
              outputOption = mapReduceTaskCommand.outputOption; }
            catch (Exception ex)
            {
                if (base.immatureId != "-2")
                {
                    _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID));
                }
                return;
            }
            Runtime.MapReduce.MapReduceTask userTask = null;
            Filter filter = null;

            try
            {
                ICommandExecuter tmpVar = clientManager.CmdExecuter;
                NCache           nCache = (NCache)((tmpVar is NCache) ? tmpVar : null);

                userTask = GetMapReduceTask(mapper, combiner, reducer, inputProvider, nCache.Cache.Name);

                filter = GetFilter(keyfilter, query, parameters, nCache.Cache.Name);

                // the Actual Call.
                nCache.Cache.SubmitMapReduceTask(userTask, taskId,
                                                 new Alachisoft.NCache.MapReduce.Notifications.TaskCallbackInfo(clientManager.ClientID, (short)callbackId), filter,
                                                 new Caching.OperationContext(Caching.OperationContextFieldName.OperationType,
                                                                              OperationContextOperationType.CacheOperation));
                stopWatch.Stop();
                //Build response
                Common.Protobuf.Response reponse = new Common.Protobuf.Response();
                reponse.mapReduceTaskResponse = new Common.Protobuf.MapReduceTaskResponse();
                reponse.commandID             = command.commandID;
                reponse.requestId             = Convert.ToInt64(requestId);
                reponse.responseType          = Alachisoft.NCache.Common.Protobuf.Response.Type.MAP_REDUCE_TASK;
                _serializedResponsePackets.Add(ResponseHelper.SerializeResponse(reponse));
            }
            catch (Exception ex)
            {
                exception = ex.ToString();
                _serializedResponsePackets.Add(ResponseHelper.SerializeExceptionResponse(ex, command.requestID, command.commandID));
            }
            finally
            {
                TimeSpan executionTime = stopWatch.Elapsed;
                try
                {
                    if (Alachisoft.NCache.Management.APILogging.APILogManager.APILogManger != null && Alachisoft.NCache.Management.APILogging.APILogManager.EnableLogging)
                    {
                        if (userTask.Mapper is AggregatorMapper)
                        {
                            APILogItemBuilder log = new APILogItemBuilder(MethodsName.Aggregate.ToLower());
                            log.GenerateAggregateTaskAPILogItem(userTask.ToString(), userTask.Mapper.ToString(), query, parameters, filter != null ? filter.KeyFilter.ToString() : null, 0, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                        }
                        else
                        {
                            APILogItemBuilder log = new APILogItemBuilder(MethodsName.ExecuteTask.ToLower());
                            log.GenerateExecuteTaskAPILogItem(userTask.ToString(), filter != null? filter.KeyFilter.ToString():null, query, parameters, overload, exception, executionTime, clientManager.ClientID.ToLower(), clientManager.ClientSocketId.ToString());
                        }
                    }
                }
                catch
                {
                }
            }
        }