コード例 #1
0
ファイル: RequestManager.cs プロジェクト: abayaz61/NCache
        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);
                }
            }
        }
コード例 #2
0
ファイル: RequestManager.cs プロジェクト: yongwuhou/NCache
        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);
                    }
                }
            }
        }
コード例 #3
0
ファイル: RequestManager.cs プロジェクト: abayaz61/NCache
        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);
        }
コード例 #4
0
ファイル: RequestManager.cs プロジェクト: abayaz61/NCache
        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);
                }
            }
        }
コード例 #5
0
ファイル: RequestManager.cs プロジェクト: javithalion/NCache
        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;
        }