Exemplo n.º 1
0
        public MessagePublishCommand(string messageId, byte[] payLoad, long creationTime, long expirationTime,
                                     Hashtable metadata, BitSet flagMap)
        {
            name = "PublishMessageCommand";

            _publishMessageCommand           = new Common.Protobuf.MessagePublishCommand();
            _publishMessageCommand.messageId = messageId;
            key = messageId;
            UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(payLoad);

            _publishMessageCommand.data.AddRange(ubObject.DataList);

            _publishMessageCommand.flag         = flagMap.Data;
            _publishMessageCommand.expiration   = expirationTime;
            _publishMessageCommand.creationTime = creationTime;
            _publishMessageCommand.requestId    = RequestId;
            _publishMessageCommand.isAsync      = isAsync;

            foreach (DictionaryEntry entry in metadata)
            {
                KeyValuePair keyValue = new KeyValuePair();
                keyValue.key   = entry.Key.ToString();
                keyValue.value = entry.Value.ToString();

                _publishMessageCommand.keyValuePair.Add(keyValue);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            int    overload         = 1;
            string exceptionMessage = null;

            NCache nCache = clientManager.CmdExecuter as NCache;

            try
            {
                if (nCache != null)
                {
                    _command = command.messagePublishCommand;
                    var operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                    if (command.commandVersion < 1)
                    {
                        operationContext.Add(OperationContextFieldName.ClientLastViewId, forcedViewId);
                    }
                    else
                    {
                        operationContext.Add(OperationContextFieldName.ClientLastViewId, command.clientLastViewId.ToString(CultureInfo.InvariantCulture));
                    }
                    BitSet flag = BitSet.CreateAndMarkInUse(clientManager.CacheFakePool, NCModulesConstants.SocketServer);
                    flag.Data = ((byte)(byte)_command.flag);
                    try
                    {
                        foreach (KeyValuePair pair in _command.keyValuePair)
                        {
                            _metaData.Add(pair.key, pair.value);
                        }

                        ICollection dataList = _command.data as ICollection;
                        if (dataList != null)
                        {
                            _value = UserBinaryObject.CreateUserBinaryObject(dataList);
                        }
                        else
                        {
                            _value = _command.data;
                        }

                        nCache.Cache.PublishMessage(_command.messageId,
                                                    _value,
                                                    _command.creationTime,
                                                    _command.expiration,
                                                    _metaData,
                                                    flag,
                                                    operationContext
                                                    );
                        stopWatch.Stop();
                    }
                    finally
                    {
                        flag?.MarkFree(NCModulesConstants.SocketServer);
                    }
                    //
                    MessagePublishResponse messagePublishResponse = new MessagePublishResponse();
                    //response.requestId = Convert.ToInt64(_command.requestId);
                    //response.commandID = command.commandID;
                    //response.responseType = Response.Type.MESSAGE_PUBLISH;
                    //_serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(response,Common.Protobuf.Response.Type.MESSAGE_PUBLISH));

                    if (clientManager.ClientVersion >= 5000)
                    {
                        Common.Util.ResponseHelper.SetResponse(messagePublishResponse, command.requestID, command.commandID);
                        _serializedResponsePackets.Add(Common.Util.ResponseHelper.SerializeResponse(messagePublishResponse, Common.Protobuf.Response.Type.MESSAGE_PUBLISH));
                    }
                    else
                    {
                        //PROTOBUF:RESPONSE
                        Response response = new Response();
                        response.messagePublishResponse = messagePublishResponse;
                        Common.Util.ResponseHelper.SetResponse(response, command.requestID, command.commandID, Common.Protobuf.Response.Type.MESSAGE_PUBLISH);
                        _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    }
                }
            }
            catch (System.Exception exc)
            {
                exceptionMessage = exc.ToString();
                _serializedResponsePackets.Add(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.PublishMessageOnTopic);
                        int            size            = _value != null ? ((UserBinaryObject)_value).Size : 0;
                        bool           notifyOnFailure = bool.Parse(_metaData[TopicConstant.NotifyOption] as string);
                        DeliveryOption deliveryOption  = (DeliveryOption)(int.Parse(_metaData[TopicConstant.DeliveryOption] as string));
                        string         topicName       = _metaData[TopicConstant.TopicName] as string;
                        topicName = topicName.Split(TopicConstant.TopicSeperator)[1];

                        log.GeneratePublishTopicMessageAPILogItem(topicName, _command.messageId, size, deliveryOption, notifyOnFailure, _command.expiration, executionTime, clientManager.ClientID, clientManager.ClientIP, overload, exceptionMessage);
                    }
                }
                catch
                {
                }
            }
        }