Beispiel #1
0
        void Reconnect()
        {
            if (_connectionLock.TryEnterWriteLock((int)_reconnectDelay.TotalMilliseconds / 2))
            {
                try
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Disconnecting connection handler.");
                    }
                    _connectionHandler.Disconnect();

                    if (_reconnectDelay > TimeSpan.Zero)
                    {
                        Thread.Sleep(_reconnectDelay);
                    }

                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Re-connecting connection handler...");
                    }
                    _connectionHandler.Connect();
                }
                catch (Exception)
                {
                    _log.Warn("Failed to reconnect, deferring to connection policy for reconnection");
                    _connectionHandler.ForceReconnect(_reconnectDelay);
                }
                finally
                {
                    _connectionLock.ExitWriteLock();
                }
            }
            else
            {
                try
                {
                    _connectionLock.EnterReadLock();
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Waiting for reconnect in another thread.");
                    }
                }
                finally
                {
                    _connectionLock.ExitReadLock();
                }
            }
        }