Пример #1
0
            public void ReceiveMessage(IChannelMessage message)
            {
                try
                {
                    IRequest request = message as IRequest;
                    if (request != null)
                    {
                        if (_threadPool != null)
                        {
                            _threadPool.ExecuteTask(new RequestDeliverTask(message, _requestListener));
                        }
                        else
                        {
                            _requestListener.OnRequest(request);
                        }
                    }
                    else
                    {
                        IResponse response = message as IResponse;

                        if (_responseListener != null)
                        {
                            _responseListener.ReceiveMessage(message);
                        }
                        //if(response != null)
                        //    _threadPool.ExecuteTask(new ResponseDeliverTask(message, _responseListener));
                    }
                }
                catch (Exception ex)
                {
                    if (LoggerManager.Instance.ServerLogger != null && LoggerManager.Instance.ServerLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.ServerLogger.Error("DualChannelListener.RecieveMessage", ex.Message);
                    }
                }
            }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        private void Run()
        {
            while (true)
            {
                try
                {
                    //receive data size for the response
                    if (_connection != null)
                    {
                        _connection.Receive(_sizeBuffer, DATA_SIZE_BUFFER_LENGTH);

                        int rspLength = Convert.ToInt32(UTF8Encoding.UTF8.GetString(_sizeBuffer, 0, _sizeBuffer.Length));

                        if (rspLength > 0)
                        {
                            byte[] dataBuffer = new byte[rspLength];
                            _connection.Receive(dataBuffer, rspLength);

                            //deserialize the message
                            IChannelMessage message = null;
                            if (_formatter != null)
                            {
                                message = _formatter.Deserialize(dataBuffer) as IChannelMessage;
                            }

                            message.Channel = this;
                            message.Source  = GetSourceAddress();
                            if (_eventListener != null)
                            {
                                _eventListener.ReceiveMessage(message);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch (ThreadAbortException) { break; }
                catch (ThreadInterruptedException) { break; }
                catch (ConnectionException ce)
                {
                    if (_traceProvider != null && _forcedDisconnected)
                    {
                        _traceProvider.TraceError(Name + ".Run", ce.ToString());
                    }
                    if (_eventListener != null & !_forcedDisconnected)
                    {
                        _eventListener.ChannelDisconnected(ce.Message);
                    }
                    break;
                }
                catch (Exception e)
                {
                    if (_traceProvider != null)
                    {
                        _traceProvider.TraceError(Name + ".Run", e.ToString());
                    }
                    break;
                    //new ChannelException();
                }
            }
        }