Search in sources :

Example 1 with ActiveMQRemoteDisconnectException

use of org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException in project activemq-artemis by apache.

the class ProtonClientConnectionManager method connectionDestroyed.

@Override
public void connectionDestroyed(Object connectionID) {
    RemotingConnection connection = connectionMap.remove(connectionID);
    if (connection != null) {
        log.info("Connection " + connection.getRemoteAddress() + " destroyed");
        connection.fail(new ActiveMQRemoteDisconnectException());
    } else {
        log.error("Connection with id " + connectionID + " not found in connectionDestroyed");
    }
}
Also used : ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQProtonRemotingConnection(org.apache.activemq.artemis.protocol.amqp.broker.ActiveMQProtonRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 2 with ActiveMQRemoteDisconnectException

use of org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException in project activemq-artemis by apache.

the class RemotingConnectionImpl method fail.

@Override
public void fail(final ActiveMQException me, String scaleDownTargetNodeID) {
    synchronized (failLock) {
        if (destroyed) {
            return;
        }
        destroyed = true;
    }
    if (!(me instanceof ActiveMQRemoteDisconnectException)) {
        ActiveMQClientLogger.LOGGER.connectionFailureDetected(me.getMessage(), me.getType());
    }
    try {
        transportConnection.forceClose();
    } catch (Throwable e) {
        ActiveMQClientLogger.LOGGER.failedForceClose(e);
    }
    // Then call the listeners
    callFailureListeners(me, scaleDownTargetNodeID);
    callClosingListeners();
    internalClose();
    for (Channel channel : channels.values()) {
        channel.returnBlocking(me);
    }
}
Also used : ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) Channel(org.apache.activemq.artemis.core.protocol.core.Channel)

Example 3 with ActiveMQRemoteDisconnectException

use of org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException in project activemq-artemis by apache.

the class AmqpOutboundConnectionTest method runOutboundConnectionTest.

private void runOutboundConnectionTest(boolean withSecurity, boolean closeFromClient) throws Exception {
    final ActiveMQServer remote;
    try {
        securityEnabled = withSecurity;
        remote = createServer(AMQP_PORT + 1);
    } finally {
        securityEnabled = false;
    }
    Wait.assertTrue(remote::isActive);
    final Map<String, Object> config = new LinkedHashMap<>();
    config.put(TransportConstants.HOST_PROP_NAME, "localhost");
    config.put(TransportConstants.PORT_PROP_NAME, String.valueOf(AMQP_PORT + 1));
    final ClientSASLFactory clientSASLFactory;
    if (withSecurity) {
        clientSASLFactory = availableMechanims -> {
            if (availableMechanims != null && Arrays.asList(availableMechanims).contains("PLAIN")) {
                return new PlainSASLMechanism(fullUser, fullPass);
            } else {
                return null;
            }
        };
    } else {
        clientSASLFactory = null;
    }
    final AtomicBoolean connectionOpened = new AtomicBoolean();
    EventHandler eventHandler = new EventHandler() {

        @Override
        public void onRemoteOpen(Connection connection) throws Exception {
            connectionOpened.set(true);
        }
    };
    ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, "myid", Collections.singletonMap(Symbol.getSymbol("myprop"), "propvalue"), 5000), Optional.of(eventHandler), clientSASLFactory);
    ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server);
    NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager);
    connector.start();
    Object connectionId = connector.createConnection().getID();
    assertNotNull(connectionId);
    RemotingConnection remotingConnection = lifeCycleListener.getConnection(connectionId);
    AtomicReference<ActiveMQException> ex = new AtomicReference<>();
    AtomicBoolean closed = new AtomicBoolean(false);
    remotingConnection.addCloseListener(() -> closed.set(true));
    remotingConnection.addFailureListener(new FailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
            ex.set(exception);
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            ex.set(exception);
        }
    });
    try {
        Wait.assertEquals(1, remote::getConnectionCount);
        Wait.assertTrue(connectionOpened::get);
        if (closeFromClient) {
            lifeCycleListener.stop();
        } else {
            remote.stop();
        }
        Wait.assertEquals(0, remote::getConnectionCount);
        assertTrue(remotingConnection.isDestroyed());
        if (!closeFromClient) {
            assertTrue(ex.get() instanceof ActiveMQRemoteDisconnectException);
        } else {
            assertNull(ex.get());
        }
    } finally {
        if (closeFromClient) {
            remote.stop();
        } else {
            lifeCycleListener.stop();
        }
    }
}
Also used : ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) EventHandler(org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler) ProtonClientProtocolManager(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager) LinkedHashMap(java.util.LinkedHashMap) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSASLFactory(org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASLFactory) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(org.apache.qpid.proton.engine.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProtonClientConnectionManager(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientConnectionManager) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AMQPClientConnectionFactory(org.apache.activemq.artemis.protocol.amqp.client.AMQPClientConnectionFactory) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener)

Example 4 with ActiveMQRemoteDisconnectException

use of org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException in project activemq-artemis by apache.

the class RemotingServiceImpl method connectionDestroyed.

@Override
public void connectionDestroyed(final Object connectionID) {
    if (logger.isTraceEnabled()) {
        logger.trace("Connection removed " + connectionID + " from server " + this.server, new Exception("trace"));
    }
    ConnectionEntry conn = connections.get(connectionID);
    if (conn != null && !conn.connection.isSupportReconnect()) {
        RemotingConnection removedConnection = removeConnection(connectionID);
        if (removedConnection != null) {
            try {
                if (server.hasBrokerPlugins()) {
                    server.callBrokerPlugins(plugin -> plugin.afterDestroyConnection(removedConnection));
                }
            } catch (ActiveMQException t) {
                logger.warn("Error executing afterDestroyConnection plugin method: {}", t.getMessage(), t);
                conn.connection.fail(t);
                return;
            }
        }
        conn.connection.fail(new ActiveMQRemoteDisconnectException());
    }
}
Also used : ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Aggregations

ActiveMQRemoteDisconnectException (org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException)4 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 LinkedHashMap (java.util.LinkedHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)1 FailureListener (org.apache.activemq.artemis.core.remoting.FailureListener)1 NettyConnector (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ActiveMQProtonRemotingConnection (org.apache.activemq.artemis.protocol.amqp.broker.ActiveMQProtonRemotingConnection)1 ProtonProtocolManagerFactory (org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory)1 AMQPClientConnectionFactory (org.apache.activemq.artemis.protocol.amqp.client.AMQPClientConnectionFactory)1 ProtonClientConnectionManager (org.apache.activemq.artemis.protocol.amqp.client.ProtonClientConnectionManager)1 ProtonClientProtocolManager (org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager)1 EventHandler (org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler)1 ClientSASLFactory (org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASLFactory)1 ConnectionEntry (org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)1