コード例 #1
0
        public void send(AbstractMessageSendExecutor sendExecutor, IClientMessageListenExecutor listenExecutor)
        {
            if (sendExecutor == null)
            {
                return;
            }

            if (listenExecutor != null)
            {
                this.registerListenExecutor(sendExecutor.getMessageType(), listenExecutor);
            }

            try
            {
                Task task = this.currentChannel.WriteAndFlushAsync(sendExecutor.getMessageContext());
                task.Wait();

                if (task.IsCompleted)
                {
                    sendExecutor.success();
                }
                else
                {
                    sendExecutor.failure("server channel error.");
                }
            }
            catch (Exception ex)
            {
                sendExecutor.failure(ex.Message);
            }
        }
コード例 #2
0
 public void registerListenExecutor(ImMessageType messageType, IClientMessageListenExecutor executor)
 {
     if (this.listenExecutors.ContainsKey(messageType))
     {
         this.listenExecutors.Remove(messageType);
     }
     this.listenExecutors.Add(messageType, executor);
 }
コード例 #3
0
        public void listen(ImMessageContext messageContext)
        {
            if (messageContext == null)
            {
                return;
            }

            if (this.clientAckSender != null && messageContext.Response?.ResponseHead?.Isack == true)
            {
                this.clientAckSender(messageContext.Response?.ResponseHead?.Messageid);
            }

            IClientMessageListenExecutor listenExecutor = listenExecutors[messageContext.Type];

            if (listenExecutor != null)
            {
                listenExecutor.execute(messageContext);
                if (listenExecutor.executedAndClose())
                {
                    this.currentChannel.CloseAsync();
                }
            }
        }