public void Close() { if(!this.closed.Value && !transportFailed.Value) { this.Stop(); } lock(myLock) { if(this.closed.Value) { return; } try { Tracer.Info("Connection.Close(): Closing Connection Now."); this.closing.Value = true; lock(sessions.SyncRoot) { foreach(Session session in sessions) { session.Shutdown(); } } sessions.Clear(); // Connected is true only when we've successfully sent our ConnectionInfo // to the broker, so if we haven't announced ourselves there's no need to // inform the broker of a remove, and if the transport is failed, why bother. if(connected.Value && !transportFailed.Value) { DisposeOf(ConnectionId); ShutdownInfo shutdowninfo = new ShutdownInfo(); transport.Oneway(shutdowninfo); } executor.Shutdown(); Tracer.Info("Connection: Disposing of the Transport."); transport.Dispose(); } catch(Exception ex) { Tracer.ErrorFormat("Error during connection close: {0}", ex); } finally { if(executor != null) { executor.Shutdown(); } this.transport = null; this.closed.Value = true; this.connected.Value = false; this.closing.Value = false; } } }
public void OpenWireCommandsTest() { Uri uri = new Uri("failover:(mock://localhost:61616)?transport.randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); using(ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.Command = OnCommand; transport.Exception = OnException; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); ConnectionInfo connection = createConnection(); transport.Request(connection); SessionInfo session1 = createSession(connection); transport.Request(session1); SessionInfo session2 = createSession(connection); transport.Request(session2); ConsumerInfo consumer1 = createConsumer(session1); transport.Request(consumer1); ConsumerInfo consumer2 = createConsumer(session1); transport.Request(consumer2); ConsumerInfo consumer3 = createConsumer(session2); transport.Request(consumer3); ProducerInfo producer1 = createProducer(session2); transport.Request(producer1); // Remove the Producers disposeOf(transport, producer1); // Remove the Consumers disposeOf(transport, consumer1); disposeOf(transport, consumer2); disposeOf(transport, consumer3); // Remove the Session instances. disposeOf(transport, session1); disposeOf(transport, session2); // Indicate that we are done. ShutdownInfo shutdown = new ShutdownInfo(); transport.Oneway(shutdown); } }
public virtual Response processShutdownInfo(ShutdownInfo info) { return null; }
public void Close() { if(!this.closed.Value && !transportFailed.Value) { this.Stop(); } lock(myLock) { if(this.closed.Value) { return; } try { Tracer.InfoFormat("Connection[{0}]: Closing Connection Now.", this.ConnectionId); this.closing.Value = true; if(this.advisoryConsumer != null) { this.advisoryConsumer.Dispose(); this.advisoryConsumer = null; } lock(sessions.SyncRoot) { foreach(Session session in sessions) { session.Shutdown(); } } sessions.Clear(); if(this.tempDests.Count > 0) { // Make a copy of the destinations to delete, because the act of deleting // them will modify the collection. ActiveMQTempDestination[] tempDestsToDelete = new ActiveMQTempDestination[this.tempDests.Count]; this.tempDests.Values.CopyTo(tempDestsToDelete, 0); foreach(ActiveMQTempDestination dest in tempDestsToDelete) { dest.Delete(); } } // Connected is true only when we've successfully sent our ConnectionInfo // to the broker, so if we haven't announced ourselves there's no need to // inform the broker of a remove, and if the transport is failed, why bother. if(connected.Value && !transportFailed.Value) { DisposeOf(ConnectionId); ShutdownInfo shutdowninfo = new ShutdownInfo(); transport.Oneway(shutdowninfo); } executor.Shutdown(); Tracer.DebugFormat("Connection[{0}]: Disposing of the Transport.", this.ConnectionId); transport.Dispose(); } catch(Exception ex) { Tracer.ErrorFormat("Connection[{0}]: Error during connection close: {1}", ConnectionId, ex); } finally { if(executor != null) { executor.Shutdown(); } this.transport = null; this.closed.Value = true; this.connected.Value = false; this.closing.Value = false; } } }