Ejemplo n.º 1
0
 // Runs in the scheduler thread.
 State UpdateState()
 {
     lock (_stateMonitor)
     {
         if (!Transitioning)
         {
             throw new InvalidConnectionStateException(_state);
         }
         bool connected = _connection != null;
         if (_state == State.Connecting && connected)
         {
             _log.Info("Changing connection state to Connected");
             _state = State.Connected;
             // LockWithTimeout() might be waiting for _state to become Connected.
             System.Threading.Monitor.PulseAll(_stateMonitor);
             _requestQueue.TryProcess();
         }
         else if (_state == State.Disconnecting && !connected)
         {
             _log.Info("Changing connection state to Disconnected");
             _state = State.Disconnected;
         }
         return(_state);
     }
 }
Ejemplo n.º 2
0
        // Processes the reply to the last request that we sent.
        // It's the caller's responsibility to guarantee that this message is indeed the
        // reply and not some other unrelated message.
        public void OnReply(TimestampedMsg <Req> msg)
        {
            Condition.Requires(msg, "msg").IsNotNull();
            Callback cb;

            lock (_monitor)
            {
                if (_inflight == null)
                {
                    _log.Error("Received response to a request we didn't send: ({0}) {1}", msg.Value.GetType(), msg.Value);
                    return;
                }
                cb        = _inflight;
                _inflight = null;
            }
            _connection.Scheduler.Schedule(() => cb.Done(msg));
            _queue.TryProcess();
        }