示例#1
0
        /// <summary>
        /// Receives notification of any IO exceptions on the connection.
        ///
        /// <p/>Upon receipt of a connection closed exception or any IOException, the fail-over process is attempted. If the fail-over fails, then
        /// all method listeners and the application connection object are notified of the connection failure exception.
        ///
        /// <p/>All other exception types are propagated to all method listeners.
        /// </summary>
        public void OnException(Exception cause)
        {
            _log.Warn("public void OnException(Exception cause = " + cause + "): called");

            // Ensure that the method listener set cannot be changed whilst this exception is propagated to all listeners. This also
            // ensures that this exception is fully propagated to all listeners, before another one can be processed.
            lock (_lock)
            {
                if (cause is AMQConnectionClosedException || cause is System.IO.IOException)
                {
                    // Try a fail-over because the connection has failed.
                    FailoverState failoverState = AttemptFailover();

                    // Check if the fail-over has failed, in which case notify all method listeners of the exception.
                    // The application connection object is also notified of the failure of the connection with the exception.
                    if (failoverState == FailoverState.FAILED)
                    {
                        _log.Debug("Fail-over has failed. Notifying all method listeners of the exception.");

                        AMQException amqe = new AMQException("Protocol handler error: " + cause, cause);
                        PropagateExceptionToWaiters(amqe);
                        _connection.ExceptionReceived(cause);
                    }
                }
                // Notify all method listeners of the exception.
                else
                {
                    PropagateExceptionToWaiters(cause);
                    _connection.ExceptionReceived(cause);
                }
            }
        }
        private void MakeBrokerConnection(IBrokerInfo brokerDetail)
        {
            try
            {
                _stateManager     = new AMQStateManager();
                _protocolListener = new AMQProtocolListener(this, _stateManager);
                _protocolListener.AddFrameListener(_stateManager);

                /*
                 * // Currently there is only one transport option - BlockingSocket.
                 * String assemblyName = "Apache.Qpid.Client.Transport.Socket.Blocking.dll";
                 * String transportType = "Apache.Qpid.Client.Transport.Socket.Blocking.BlockingSocketTransport";
                 *
                 * // Load the transport assembly dynamically.
                 * _transport = LoadTransportFromAssembly(brokerDetail.getHost(), brokerDetail.getPort(), assemblyName, transportType);
                 */

                _transport = new BlockingSocketTransport();

                // Connect.
                _transport.Connect(brokerDetail, this);
                _protocolWriter  = new ProtocolWriter(_transport.ProtocolWriter, _protocolListener);
                _protocolSession = new AMQProtocolSession(_transport.ProtocolWriter, _transport, this);
                _protocolListener.ProtocolSession = _protocolSession;

                // Now start the connection "handshake".
                _transport.ProtocolWriter.Write(new ProtocolInitiation());

                // Blocks until the connection has been opened.
                _stateManager.AttainState(AMQState.CONNECTION_OPEN);

                _failoverPolicy.attainedConnection();

                // XXX: Again this should be changed to a suitable notify.
                _connected = true;
            }
            catch (AMQException e)
            {
                _lastAMQException = e;
                throw; // rethrow
            }
        }
示例#3
0
        private void MakeBrokerConnection(IBrokerInfo brokerDetail)
        {
            try
            {
                _stateManager = new AMQStateManager();
                _protocolListener = new AMQProtocolListener(this, _stateManager);
                _protocolListener.AddFrameListener(_stateManager);

                /*
                // Currently there is only one transport option - BlockingSocket.
                String assemblyName = "Apache.Qpid.Client.Transport.Socket.Blocking.dll";
                String transportType = "Apache.Qpid.Client.Transport.Socket.Blocking.BlockingSocketTransport";

                // Load the transport assembly dynamically.
                _transport = LoadTransportFromAssembly(brokerDetail.getHost(), brokerDetail.getPort(), assemblyName, transportType);
                */

                _transport = new BlockingSocketTransport();
                
                // Connect.
                _transport.Connect(brokerDetail, this);                
                _protocolWriter = new ProtocolWriter(_transport.ProtocolWriter, _protocolListener);
                _protocolSession = new AMQProtocolSession(_transport.ProtocolWriter, _transport, this);
                _protocolListener.ProtocolSession = _protocolSession;

                // Now start the connection "handshake".
                _transport.ProtocolWriter.Write(new ProtocolInitiation());

                // Blocks until the connection has been opened.
                _stateManager.AttainState(AMQState.CONNECTION_OPEN);

                _failoverPolicy.attainedConnection();

                // XXX: Again this should be changed to a suitable notify.
                _connected = true;
            }
            catch (AMQException e)
            {
                _lastAMQException = e;
                throw; // rethrow
            }
        }
        /// <summary>
        /// Receives notification of any IO exceptions on the connection.
        ///
        /// <p/>Upon receipt of a connection closed exception or any IOException, the fail-over process is attempted. If the fail-over fails, then
        /// all method listeners and the application connection object are notified of the connection failure exception.
        ///
        /// <p/>All other exception types are propagated to all method listeners.
        /// </summary>
        public void OnException(Exception cause)
        {
            _log.Warn("public void OnException(Exception cause = " + cause + "): called");

            // Ensure that the method listener set cannot be changed whilst this exception is propagated to all listeners. This also 
            // ensures that this exception is fully propagated to all listeners, before another one can be processed.
            lock (_lock)
            {
                if (cause is AMQConnectionClosedException || cause is System.IO.IOException)
                {
                    // Try a fail-over because the connection has failed.
                    FailoverState failoverState = AttemptFailover();

                    // Check if the fail-over has failed, in which case notify all method listeners of the exception.
                    // The application connection object is also notified of the failure of the connection with the exception.
                    if (failoverState == FailoverState.FAILED)
                    {
                        _log.Debug("Fail-over has failed. Notifying all method listeners of the exception.");

                        AMQException amqe = new AMQException("Protocol handler error: " + cause, cause);
                        PropagateExceptionToWaiters(amqe);
                        _connection.ExceptionReceived(cause);
                    }
                }
                // Notify all method listeners of the exception.
                else
                {
                    PropagateExceptionToWaiters(cause);
                    _connection.ExceptionReceived(cause);
                }
            }
        }
示例#5
0
 /// <summary>
 /// Close all producers or consumers. This is called either in the error case or when closing the session normally.
 /// <param name="amqe">the exception, may be null to indicate no error has occurred</param>
 ///
 private void CloseProducersAndConsumers(AMQException amqe)
 {
     try
     {
         CloseProducers();
     }
     catch (QpidException e)
     {
         _logger.Error("Error closing session: " + e, e);
     }
     try
     {
         CloseConsumers(amqe);
     }
     catch (QpidException e)
     {
         _logger.Error("Error closing session: " + e, e);
     }
 }
示例#6
0
        /**
         * Called when the server initiates the closure of the session
         * unilaterally.
         * @param e the exception that caused this session to be closed. Null causes the
         */
        public void ClosedWithException(Exception e)
        {
            lock (_connection.FailoverMutex)
            {
                // An AMQException has an error code and message already and will be passed in when closure occurs as a
                // result of a channel close request
                SetClosed();
                AMQException amqe;

                if (e is AMQException)
                {
                    amqe = (AMQException) e;
                }
                else
                {
                    amqe = new AMQException("Closing session forcibly", e);
                }

                _connection.DeregisterSession(_channelId);
                CloseProducersAndConsumers(amqe);
            }
        }