org.apache.activemq.artemis.api.core.ActiveMQException

Here are the examples of the java api class org.apache.activemq.artemis.api.core.ActiveMQException taken from open source projects.

1. ActiveMQChannelHandler#exceptionCaught()

Project: activemq-artemis
File: ActiveMQChannelHandler.java
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
    if (!active) {
        return;
    }
    // We don't want to log this - since it is normal for this to happen during failover/reconnect
    // and we don't want to spew out stack traces in that event
    // The user has access to this exeception anyway via the ActiveMQException initial cause
    ActiveMQException me = ActiveMQClientMessageBundle.BUNDLE.nettyError();
    me.initCause(cause);
    synchronized (listener) {
        try {
            listener.connectionException(channelId(ctx.channel()), me);
            active = false;
        } catch (Exception ex) {
            ActiveMQClientLogger.LOGGER.errorCallingLifeCycleListener(ex);
        }
    }
}

2. PagingTest#validateExceptionOnSending()

Project: activemq-artemis
File: PagingTest.java
/**
    * This method validates if sending a message will throw an exception
    */
private void validateExceptionOnSending(ClientProducer producer, ClientMessage message) {
    ActiveMQException expected = null;
    try {
        // after the address is full this send should fail (since the address full policy is FAIL)
        producer.send(message);
    } catch (ActiveMQException e) {
        expected = e;
    }
    assertNotNull(expected);
    assertEquals(ActiveMQExceptionType.ADDRESS_FULL, expected.getType());
}

3. ClientSessionFactoryImpl#connectionDestroyed()

Project: activemq-artemis
File: ClientSessionFactoryImpl.java
@Override
public void connectionDestroyed(final Object connectionID) {
    // The exception has to be created in the same thread where it's being called
    // as to avoid a different stack trace cause
    final ActiveMQException ex = ActiveMQClientMessageBundle.BUNDLE.channelDisconnected();
    // It has to use the same executor as the disconnect message is being sent through
    closeExecutor.execute(new Runnable() {

        @Override
        public void run() {
            handleConnectionFailure(connectionID, ex);
        }
    });
}

4. JMSExceptionHelperTest#doConvertException()

Project: activemq-artemis
File: JMSExceptionHelperTest.java
private void doConvertException(final ActiveMQExceptionType errorCode, final Class<? extends Throwable> expectedException) {
    ActiveMQException me = new ActiveMQException(errorCode);
    Exception e = JMSExceptionHelper.convertFromActiveMQException(me);
    Assert.assertNotNull(e);
    Assert.assertTrue(e.getClass().isAssignableFrom(expectedException));
}

5. JMSReconnectTest#testReconnectOrReattachSameNode()

Project: activemq-artemis
File: JMSReconnectTest.java
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(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue");
    coreSession.createQueue(jmsQueueName, 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());
}