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");
}
}
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);
}
}
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();
}
}
}
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());
}
}
Aggregations