Ejemplo n.º 1
0
        /// <summary>
        /// Event handler which is called when the application is shutting down.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void ApplicationExit(object sender, EventArgs e)
        {
            XmlConfigurator.Configure();

            StringBuilder stringBuilder = new StringBuilder("Application is shutting down.");

            ShutdownInfo shutdownInfo = ShutdownInfo.GetShutdownInfo();

            if (shutdownInfo != null && !string.IsNullOrEmpty(shutdownInfo.Message))
            {
                stringBuilder.Append(string.Format(" Message:\n{0}", shutdownInfo.Message));
            }

            Log.Info(stringBuilder.ToString());

            Pipeline pipeline = Pipeline.GetPipeline("shutdown");

            pipeline.Invoke(new ShutdownArgs());

            if (OnExit == null)
            {
                return;
            }

            try
            {
                OnExit();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
        public async Task 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.CommandAsync = OnCommand;
                transport.Exception    = OnException;
                transport.Resumed      = OnResumed;
                transport.Interrupted  = OnInterrupted;

                FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport;
                Assert.IsNotNull(failover);
                Assert.IsFalse(failover.Randomize);

                await transport.StartAsync();

                Thread.Sleep(1000);
                Assert.IsTrue(failover.IsConnected);

                ConnectionInfo connection = createConnection();
                await transport.RequestAsync(connection);

                SessionInfo session1 = createSession(connection);
                await transport.RequestAsync(session1);

                SessionInfo session2 = createSession(connection);
                await transport.RequestAsync(session2);

                ConsumerInfo consumer1 = createConsumer(session1);
                await transport.RequestAsync(consumer1);

                ConsumerInfo consumer2 = createConsumer(session1);
                await transport.RequestAsync(consumer2);

                ConsumerInfo consumer3 = createConsumer(session2);
                await transport.RequestAsync(consumer3);

                ProducerInfo producer1 = createProducer(session2);
                await transport.RequestAsync(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);
            }
        }
Ejemplo n.º 3
0
        protected virtual void WriteShutdownInfo(ShutdownInfo command, BinaryWriter dataOut)
        {
            Debug.Assert(!command.ResponseRequired);

            var frame = new StompFrame("DISCONNECT", _encodeHeaders);

            frame.ToStream(dataOut);
        }
        //
        // Write the booleans that this object uses to a BooleanStream
        //
        public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs)
        {
            ShutdownInfo info = (ShutdownInfo)o;

            int rc = base.TightMarshal1(wireFormat, info, bs);

            return(rc + 0);
        }
Ejemplo n.º 5
0
        protected virtual void WriteShutdownInfo(ShutdownInfo command, BinaryWriter dataOut)
        {
            System.Diagnostics.Debug.Assert(!command.ResponseRequired);

            StompFrame frame = new StompFrame("DISCONNECT");

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Ejemplo n.º 6
0
        public void Close()
        {
            lock (myLock)
            {
                if (this.closed)
                {
                    return;
                }

                try
                {
                    Tracer.Info("Closing Connection.");
                    this.closing = true;
                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.DoClose();
                        }
                    }
                    sessions.Clear();

                    if (connected)
                    {
                        DisposeOf(ConnectionId);
                        ShutdownInfo shutdowninfo = new ShutdownInfo();
                        transport.Oneway(shutdowninfo);
                    }

                    Tracer.Info("Disposing of the Transport.");
                    transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Error during connection close: {0}", ex);
                }
                finally
                {
                    this.transport = null;
                    this.closed    = true;
                    this.connected = false;
                    this.closing   = false;
                }
            }
        }
Ejemplo n.º 7
0
        public void Close()
        {
            lock ( _myLock )
            {
                if (_closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.Info("Closing Connection.");
                    _closing.Value = true;
                    lock (_sessions.SyncRoot)
                        foreach (Session session in _sessions)
                        {
                            session.DoClose();
                        }
                    _sessions.Clear();

                    if (_connected.Value)
                    {
                        var shutdowninfo = new ShutdownInfo();
                        Transport.Oneway(shutdowninfo);
                    }

                    Tracer.Info("Disposing of the Transport.");
                    Transport.Stop();
                    Transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Error during connection close: {0}", ex.Message);
                }
                finally
                {
                    Transport        = null;
                    _closed.Value    = true;
                    _connected.Value = false;
                    _closing.Value   = false;
                }
            }
        }
Ejemplo n.º 8
0
        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;

                    if (this.advisoryConsumer != null)
                    {
                        this.advisoryConsumer.Dispose();
                        this.advisoryConsumer = null;
                    }

                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    foreach (ActiveMQTempDestination dest in this.tempDests.Values)
                    {
                        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.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)?randomize=false");

            FailoverTransportFactory factory = new FailoverTransportFactory();

            ITransport transport = factory.CreateTransport(uri);

            Assert.IsNotNull(transport);
            transport.Command   = new CommandHandler(OnCommand);
            transport.Exception = new ExceptionHandler(OnException);

            FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(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(producer1, transport);

            // Remove the Consumers
            disposeOf(consumer1, transport);
            disposeOf(consumer2, transport);
            disposeOf(consumer3, transport);

            // Remove the Session instances.
            disposeOf(session1, transport);
            disposeOf(session2, transport);

            // Indicate that we are done.
            ShutdownInfo shutdown = new ShutdownInfo();

            transport.Oneway(shutdown);

            transport.Stop();
            transport.Dispose();
        }
Ejemplo n.º 10
0
        protected virtual void WriteShutdownInfo(ShutdownInfo command, BinaryWriter dataOut)
        {
            System.Diagnostics.Debug.Assert(!command.ResponseRequired);

            new StompFrame("DISCONNECT").ToStream(dataOut);
        }
Ejemplo n.º 11
0
 protected virtual void WriteShutdownInfo(ShutdownInfo command, StompFrameStream ss)
 {
     ss.WriteCommand(command, "DISCONNECT");
     System.Diagnostics.Debug.Assert(!command.ResponseRequired);
     ss.Flush();
 }
Ejemplo n.º 12
0
        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.Stop();
                    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;
                }
            }
        }
 public virtual Response processShutdownInfo(ShutdownInfo info)
 {
     return(null);
 }
Ejemplo n.º 14
0
 protected virtual void WriteShutdownInfo(ShutdownInfo command, StompFrameStream ss)
 {
     ss.WriteCommand(command, "DISCONNECT");
     ss.Flush();
 }