private void Init(AmqpTcpEndpoint endpoint) { m_delegate = new Connection(m_factory, false, m_factory.CreateFrameHandler(endpoint), this.ClientProvidedName); AutorecoveringConnection self = this; EventHandler <ShutdownEventArgs> recoveryListener = (_, args) => { lock (recoveryLockTarget) { if (ShouldTriggerConnectionRecovery(args)) { try { self.BeginAutomaticRecovery(); } catch (Exception e) { // TODO: logging #if NETFX_CORE System.Diagnostics.Debug.WriteLine( #else Console.WriteLine( #endif "BeginAutomaticRecovery() failed: {0}", e); } } } }; lock (m_eventLock) { ConnectionShutdown += recoveryListener; if (!m_recordedShutdownEventHandlers.Contains(recoveryListener)) { m_recordedShutdownEventHandlers.Add(recoveryListener); } } }
/// <summary> /// Create a connection using a list of hostnames. The first reachable /// hostname will be used initially. Subsequent hostname picks are determined /// by the <see cref="IHostnameSelector" /> configured. /// </summary> /// <param name="hostnames"> /// List of hostnames to use for the initial /// connection and recovery. /// </param> /// <returns>Open connection</returns> /// <exception cref="BrokerUnreachableException"> /// When no hostname was reachable. /// </exception> public IConnection CreateConnection(IList<string> hostnames) { IConnection conn; try { if (AutomaticRecoveryEnabled) { var autorecoveringConnection = new AutorecoveringConnection(this); autorecoveringConnection.Init(hostnames); conn = autorecoveringConnection; } else { IProtocol protocol = Protocols.DefaultProtocol; conn = protocol.CreateConnection(this, false, CreateFrameHandler()); } } catch (Exception e) { throw new BrokerUnreachableException(e); } return conn; }
public AutorecoveringModel(AutorecoveringConnection conn, RecoveryAwareModel _delegate) { m_connection = conn; m_delegate = _delegate; }
public void AutomaticallyRecover(AutorecoveringConnection conn, IConnection connDelegate) { m_connection = conn; RecoveryAwareModel defunctModel = m_delegate; m_delegate = conn.CreateNonRecoveringModel(); m_delegate.InheritOffsetFrom(defunctModel); RecoverModelShutdownHandlers(); RecoverState(); RecoverBasicReturnHandlers(); RecoverBasicAckHandlers(); RecoverBasicNackHandlers(); RecoverCallbackExceptionHandlers(); RunRecoveryEventHandlers(); }
public IConnection CreateConnection(ConnectionFactory factory, IFrameHandler frameHandler, bool automaticRecoveryEnabled, string clientProvidedName) { var ac = new AutorecoveringConnection(factory, clientProvidedName); ac.Init(); return ac; }
public IConnection CreateConnection(ConnectionFactory factory, IFrameHandler frameHandler, bool automaticRecoveryEnabled) { var ac = new AutorecoveringConnection(factory, null); ac.Init(); return ac; }
protected void WaitForRecovery(AutorecoveringConnection conn) { Wait(PrepareForRecovery(conn)); }
protected void RestartServerAndWaitForRecovery(AutorecoveringConnection conn) { ManualResetEvent sl = PrepareForShutdown(conn); ManualResetEvent rl = PrepareForRecovery(conn); RestartRabbitMQ(); Wait(sl); Wait(rl); }
protected ManualResetEvent PrepareForRecovery(AutorecoveringConnection conn) { var latch = new ManualResetEvent(false); conn.Recovery += (source, ea) => latch.Set(); return latch; }
protected void CloseAndWaitForShutdown(AutorecoveringConnection conn) { ManualResetEvent sl = PrepareForShutdown(conn); CloseConnection(conn); Wait(sl); }
protected void CloseAllAndWaitForRecovery(AutorecoveringConnection conn) { ManualResetEvent rl = PrepareForRecovery(conn); CloseAllConnections(); Wait(rl); }
protected void AssertRecordedQueues(AutorecoveringConnection c, int n) { Assert.AreEqual(n, c.RecordedQueues.Count); }