Exemplo n.º 1
0
        public void ChannelError(object error)
        {
            Hashtable requestClone = null;

            lock (_lock)
            {
                requestClone = _requests.Clone() as Hashtable;
            }
            IDictionaryEnumerator ide = requestClone.GetEnumerator();

            while (ide.MoveNext())
            {
                RequestResponsePair reqRspPair = ide.Value as RequestResponsePair;

                if (!reqRspPair.RequestSentOverChannel)
                {
                    continue;
                }

                lock (reqRspPair)
                {
                    reqRspPair.Response = error;
                    System.Threading.Monitor.PulseAll(reqRspPair);
                }
            }
        }
Exemplo n.º 2
0
        public void ChannelDisconnected(string serverIp, string reason)
        {
            Hashtable requestClone = null;

            lock (_lock)
            {
                requestClone = _requests.Clone() as Hashtable;
            }
            IDictionaryEnumerator ide = requestClone.GetEnumerator();

            while (ide.MoveNext())
            {
                RequestResponsePair reqRspPair = ide.Value as RequestResponsePair;

                if (!reqRspPair.RequestSentOverChannel)
                {
                    continue;
                }

                lock (reqRspPair)
                {
                    if (_resendRequestOnChannelDisconnect)
                    {
                        //resend the request when channel is disconnected
                        try
                        {
                            if (_channel != null)
                            {
                                _channel.SendMessage(reqRspPair.Request);
                            }
                        }
                        catch (ChannelException ce)
                        {
                            lock (reqRspPair)
                            {
                                reqRspPair.ChannelException = ce;
                                System.Threading.Monitor.PulseAll(reqRspPair);
                            }
                        }
                    }
                    else
                    {
                        lock (reqRspPair)
                        {
                            reqRspPair.ChannelException = new ChannelException(reason);
                            System.Threading.Monitor.PulseAll(reqRspPair);
                        }
                    }

                    if (_channelDisconnectedListener != null)
                    {
                        _channelDisconnectedListener.ChannelDisconnected(serverIp, reason);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public object SendRequest(IRequest request)
        {
            object response = null;

            request.RequestId = GenerateRequestId();
            bool lockReacquired             = false;
            RequestResponsePair reqRespPair = new RequestResponsePair();

            lock (_lock)
            {
                reqRespPair.Request = request;

                if (!_requests.Contains(request.RequestId))
                {
                    _requests.Add(request.RequestId, reqRespPair);
                }
            }


            try
            {
                lock (reqRespPair)
                {
                    _channel.SendMessage(request);
                    reqRespPair.RequestSentOverChannel = true;
                    lockReacquired = System.Threading.Monitor.Wait(reqRespPair, _requestTimeout);
                }
            }
            catch (ChannelException e)
            {
                throw;
            }
            finally
            {
                lock (_lock)
                {
                    _requests.Remove(request.RequestId);
                }
            }


            if (!lockReacquired)
            {
                throw new Runtime.Exceptions.TimeoutException("Request has timedout. Did not receive response from " + _channel.Server);
            }

            if (reqRespPair.ChannelException != null)
            {
                throw reqRespPair.ChannelException;
            }

            response = reqRespPair.Response;

            return(response);
        }
Exemplo n.º 4
0
        public void ReceiveResponse(IResponse response)
        {
            IResponse           protoResponse   = response;
            RequestResponsePair reqResponsePair = _requests[protoResponse.RequestId] as RequestResponsePair;

            lock (reqResponsePair)
            {
                if (reqResponsePair != null)
                {
                    reqResponsePair.Response = protoResponse;
                    System.Threading.Monitor.Pulse(reqResponsePair);
                }
            }
        }
Exemplo n.º 5
0
        public object SendRequest(IRequest request)
        {
            object response = null;

            request.RequestId = GenerateRequestId();
            bool lockReacquired = false;
            RequestResponsePair reqRespPair = new RequestResponsePair();

            lock (_lock)
            {
                reqRespPair.Request = request;

                if (!_requests.Contains(request.RequestId))
                {
                    _requests.Add(request.RequestId, reqRespPair);
                }
            }

            lock (reqRespPair)
            {
                try
                {
                    _channel.SendMessage(request);
                    reqRespPair.RequestSentOverChannel = true;
                    lockReacquired = System.Threading.Monitor.Wait(reqRespPair, _requestTimeout);
                }
                catch (ChannelException e)
                {
                    throw;
                }
                finally
                {
                    lock (_lock)
                    {
                        _requests.Remove(request.RequestId);
                    }
                }
            }

            if (!lockReacquired)
                throw new Runtime.Exceptions.TimeoutException("Request has timedout. Did not receive response from " + _channel.Server );

            if (reqRespPair.ChannelException != null)
                throw reqRespPair.ChannelException;

            response = reqRespPair.Response;

            return response;
        }