use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class ActiveMQXAResourceWrapper method connect.
/**
* Connect to the server if not already done so
*
* @return the connectionFactory XAResource
* @throws Exception for any problem
*/
protected XAResource connect() throws Exception {
// Do we already have a valid connectionFactory?
synchronized (ActiveMQXAResourceWrapper.lock) {
if (delegate != null) {
return delegate;
}
}
for (XARecoveryConfig xaRecoveryConfig : xaRecoveryConfigs) {
if (xaRecoveryConfig == null) {
continue;
}
if (ActiveMQXARecoveryLogger.LOGGER.isDebugEnabled()) {
ActiveMQXARecoveryLogger.LOGGER.debug("Trying to connect recovery on " + xaRecoveryConfig + " of " + Arrays.toString(xaRecoveryConfigs));
}
ClientSession cs = null;
try {
// Manual configuration may still use discovery, so we will keep this
if (xaRecoveryConfig.getDiscoveryConfiguration() != null) {
serverLocator = ActiveMQClient.createServerLocator(false, xaRecoveryConfig.getDiscoveryConfiguration());
} else {
serverLocator = ActiveMQClient.createServerLocator(false, xaRecoveryConfig.getTransportConfig());
}
serverLocator.disableFinalizeCheck();
serverLocator.setProtocolManagerFactory(xaRecoveryConfig.getClientProtocolManager());
csf = serverLocator.createSessionFactory();
if (xaRecoveryConfig.getUsername() == null) {
cs = csf.createSession(true, false, false);
} else {
cs = csf.createSession(xaRecoveryConfig.getUsername(), xaRecoveryConfig.getPassword(), true, false, false, false, 1);
}
} catch (Throwable e) {
ActiveMQXARecoveryLogger.LOGGER.xaRecoverAutoConnectionError(e, xaRecoveryConfig);
if (ActiveMQXARecoveryLogger.LOGGER.isDebugEnabled()) {
ActiveMQXARecoveryLogger.LOGGER.debug(e.getMessage(), e);
}
try {
if (cs != null)
cs.close();
if (serverLocator != null)
serverLocator.close();
} catch (Throwable ignored) {
if (ActiveMQXARecoveryLogger.LOGGER.isTraceEnabled()) {
ActiveMQXARecoveryLogger.LOGGER.trace(e.getMessage(), ignored);
}
}
continue;
}
cs.addFailureListener(this);
synchronized (ActiveMQXAResourceWrapper.lock) {
delegate = cs;
}
return delegate;
}
ActiveMQXARecoveryLogger.LOGGER.recoveryConnectFailed(Arrays.toString(xaRecoveryConfigs));
throw new ActiveMQNotConnectedException();
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
List<TransportConfiguration> connectorConfigs = new ArrayList<>();
connectorConfigs.add(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jmsServer.createConnectionFactory("cffoo", false, JMSFactoryType.CF, registerConnectors(server, connectorConfigs), null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, 0, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/cffoo");
cf = (ConnectionFactory) namingContext.lookup("/cffoo");
Connection conn = cf.createConnection();
Queue queue = createQueue("testQueue");
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue);
MessageConsumer cons = session.createConsumer(queue);
conn.start();
prod.send(session.createMessage());
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) ((ActiveMQSession) session).getCoreSession()).getConnection();
connection.fail(new ActiveMQNotConnectedException());
try {
prod.send(session.createMessage());
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
session.close();
conn.close();
} finally {
try {
conn.close();
} catch (Throwable igonred) {
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class JMSReconnectTest method testReconnectOrReattachSameNode.
private void testReconnectOrReattachSameNode(boolean reattach) throws Exception {
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
jbcf.setReconnectAttempts(-1);
if (reattach) {
jbcf.setConfirmationWindowSize(1024 * 1024);
}
// Note we set consumer window size to a value so we can verify that consumer credit re-sending
// works properly on failover
// The value is small enough that credits will have to be resent several time
final int numMessages = 10;
final int bodySize = 1000;
jbcf.setConsumerWindowSize(numMessages * bodySize / 10);
Connection conn = jbcf.createConnection();
MyExceptionListener listener = new MyExceptionListener();
conn.setExceptionListener(listener);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
RemotingConnection coreConn = ((ClientSessionInternal) coreSession).getConnection();
SimpleString jmsQueueName = new SimpleString("myqueue");
coreSession.createQueue(jmsQueueName, RoutingType.ANYCAST, jmsQueueName, null, true);
Queue queue = sess.createQueue("myqueue");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
MessageConsumer consumer = sess.createConsumer(queue);
byte[] body = RandomUtil.randomBytes(bodySize);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = sess.createBytesMessage();
bm.writeBytes(body);
producer.send(bm);
}
conn.start();
Thread.sleep(2000);
ActiveMQException me = new ActiveMQNotConnectedException();
coreConn.fail(me);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = (BytesMessage) consumer.receive(1000);
Assert.assertNotNull(bm);
Assert.assertEquals(body.length, bm.getBodyLength());
}
TextMessage tm = (TextMessage) consumer.receiveNoWait();
Assert.assertNull(tm);
conn.close();
Assert.assertNotNull(listener.e);
Assert.assertTrue(me == listener.e.getCause());
}
use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.
the class BindingsClusterTest method crash.
private void crash() throws Exception {
/*
* Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
* so the bridge's failure listener needs to get something other than a DISCONNECTED message. In this case we
* simulate a NOT_CONNECTED exception.
*/
final CountDownLatch latch = new CountDownLatch(1);
ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
RemotingConnection forwardingConnection = getForwardingConnection(bridge);
forwardingConnection.addFailureListener(new FailureListener() {
@Override
public void connectionFailed(ActiveMQException exception, boolean failedOver) {
latch.countDown();
}
@Override
public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
connectionFailed(me, failedOver);
}
});
forwardingConnection.fail(new ActiveMQNotConnectedException());
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
if (crash) {
jmsServer2.stop();
}
}
Aggregations