/** * Converts a JMSException from the server to an XAException. if the * JMSException contained a linked XAException that is returned instead. * * @param e JMSException to convert * @return XAException wrapping original exception or its message */ private XAException toXAException(JMSException e) { if (e.getCause() != null && e.getCause() instanceof XAException) { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; if (xae.errorCode == XA_OK) { // detail not unmarshalled see: org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.createThrowable xae.errorCode = parseFromMessageOr(original.getMessage(), XAException.XAER_RMERR); } xae.initCause(original); return xae; } XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
syncSendPacket(removeCommand, closeTimeout); } catch (JMSException e) { if (e.getCause() instanceof RequestTimedOutIOException) {
private boolean shouldReinit(final JMSException ex) { return ex instanceof AlreadyClosedException || ex instanceof javax.jms.IllegalStateException || ex instanceof ConnectionFailedException || ex.getCause() instanceof IOException; }
public synchronized void doStop() throws Exception { if (brokerService != null) { BrokerService temp = brokerService; brokerService = null; try { temp.stop(); } catch (JMSException ignored) { // just a lame exception ActiveMQ likes to throw on shutdown if (!(ignored.getCause() instanceof TransportDisposedIOException)) { throw ignored; } } } }
public synchronized void doFail() { if (brokerService != null) { BrokerService temp = brokerService; brokerService = null; try { temp.stop(); } catch (JMSException ignored) { // just a lame exception ActiveMQ likes to throw on shutdown if (!(ignored.getCause() instanceof TransportDisposedIOException)) { log.warn("Caught while closing due to failure: " + ignored, ignored); } } catch (Exception e) { log.warn("Caught while closing due to failure: " + e, e); } } }
/** * Generate a single line String consisted of the summary of a JMSException * @param e the exception * @return summary of the exception in one line */ static public String exceptionSummary(JMSException e){ Throwable cause = e.getCause(); Exception linked = e.getLinkedException(); return "JMSException: " + e.getMessage() + ", error code: " + e.getErrorCode() + ", linked exception: " + (linked == null ? null : (linked.getClass().getName() + " - " + linked.getMessage())) + ", cause: " + (cause == null ? null : (cause.getClass().getName() + " - " + cause.getMessage())); }
public synchronized void doFail() { if (asyncStartup) { active.set(false); // ActiveMQ AMQPersistenceAdapter can hang, if we are still starting if (asyncStarted.getCount() > 0) { return; } } try { brokerService.stop(); brokerService.waitUntilStopped(); } catch (JMSException ignored) { // just a lame exception ActiveMQ likes to throw on shutdown if (!(ignored.getCause() instanceof TransportDisposedIOException)) { log.warn("Caught while closing due to failure: " + ignored, ignored); } } catch (Exception e) { log.warn("Caught while closing due to failure: " + e, e); } }
/** * Close a message producer. * * @param producer */ public static void closeQuietly(final MessageProducer producer) { if (producer != null) { try { producer.close(); } catch (JMSException je) { if (je.getCause() instanceof InterruptedException) { LOG.trace("ActiveMQ caught and wrapped InterruptedException"); } if (je.getCause() instanceof InterruptedIOException) { LOG.trace("ActiveMQ caught and wrapped InterruptedIOException"); } else { LOG.warnDebug(je, "While closing producer"); } } } }
/** * Close a session. * * @param session */ public static void closeQuietly(final Session session) { if (session != null) { try { session.close(); } catch (JMSException je) { if (je.getCause() instanceof InterruptedException) { LOG.trace("ActiveMQ caught and wrapped InterruptedException"); } if (je.getCause() instanceof InterruptedIOException) { LOG.trace("ActiveMQ caught and wrapped InterruptedIOException"); } else { LOG.warnDebug(je, "While closing session"); } } } }
/** * Close a connection. * * @param connection */ public static void closeQuietly(final Connection connection) { if (connection != null) { try { connection.close(); } catch (JMSException je) { if (je.getCause() instanceof InterruptedException) { LOG.trace("ActiveMQ caught and wrapped InterruptedException"); } if (je.getCause() instanceof InterruptedIOException) { LOG.trace("ActiveMQ caught and wrapped InterruptedIOException"); } else { LOG.warnDebug(je, "While closing connection"); } } } } }
private Destination createWanTopic(String topicName) throws JMSException { Connection conn = null; Session session = null; try { conn = jmsTemplate.getConnectionFactory().createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); return session.createTopic(topicName); } catch (JMSException jmsEx) { jmsEx.printStackTrace(); if (jmsEx.getCause() instanceof ConnectException) { System.out.println("Connection to broker could not be established. Check if JMS Broker is running."); } throw jmsEx; } finally { try { if (session != null) session.close(); if (conn != null) conn.close(); } catch (JMSException ignore) { // ok. } } }
/** * Converts a JMSException from the server to an XAException. if the * JMSException contained a linked XAException that is returned instead. * * @param e JMSException to convert * @return XAException wrapping original exception or its message */ private XAException toXAException(JMSException e) { if (e.getCause() != null && e.getCause() instanceof XAException) { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; xae.initCause(original); return xae; } XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
/** * Close a message consumer. * * @param consumer */ public static void closeQuietly(final MessageConsumer consumer) { if (consumer != null) { try { consumer.close(); } catch (JMSException je) { if (je.getCause() instanceof InterruptedException) { LOG.trace("ActiveMQ caught and wrapped InterruptedException"); } if (je.getCause() instanceof InterruptedIOException) { LOG.trace("ActiveMQ caught and wrapped InterruptedIOException"); } else { LOG.warnDebug(je, "While closing consumer"); } } } }
/** * Converts a JMSException from the server to an XAException. if the * JMSException contained a linked XAException that is returned instead. * * @param e JMSException to convert * @return XAException wrapping original exception or its message */ private XAException toXAException(JMSException e) { if (e.getCause() != null && e.getCause() instanceof XAException) { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; if (xae.errorCode == XA_OK) { // detail not unmarshalled see: org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.createThrowable xae.errorCode = parseFromMessageOr(original.getMessage(), XAException.XAER_RMERR); } xae.initCause(original); return xae; } XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
@Override public void onMessage(final Message message) { try { if (message instanceof ObjectMessage) { final SysEvent ev = (SysEvent)((ObjectMessage)message).getObject(); action(ev); } } catch (final NotificationException ne) { ne.printStackTrace(); } catch (final JMSException je) { final Throwable t = je.getCause(); if (t instanceof InvalidClassException) { /* Probably an old message - just ignore it. */ warn("Ignoring message of unknown class"); } error(je); } }
/** * Converts a JMSException from the server to an XAException. if the * JMSException contained a linked XAException that is returned instead. * * @param e JMSException to convert * @return XAException wrapping original exception or its message */ private XAException toXAException(JMSException e) { if (e.getCause() != null && e.getCause() instanceof XAException) { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; if (xae.errorCode == XA_OK) { // detail not unmarshalled see: org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.createThrowable xae.errorCode = parseFromMessageOr(original.getMessage(), XAException.XAER_RMERR); } xae.initCause(original); return xae; } XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
/** * Converts a JMSException from the server to an XAException. if the * JMSException contained a linked XAException that is returned instead. * * @param e JMSException to convert * @return XAException wrapping original exception or its message */ private XAException toXAException(JMSException e) { if (e.getCause() != null && e.getCause() instanceof XAException) { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; if (xae.errorCode == XA_OK) { // detail not unmarshalled see: org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.createThrowable xae.errorCode = parseFromMessageOr(original.getMessage(), XAException.XAER_RMERR); } xae.initCause(original); return xae; } XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
/** * Wraps a {@link JmsExceptionThrowingBiConsumer} returning a BiConsumer by converting thrown {@link JMSException}s * to {@link JMSRuntimeException}s. * * @param throwingConsumer the JmsExceptionThrowingBiConsumer that throws {@link JMSException} * @return a BiConsumer that throws {@link JMSRuntimeException} */ static BiConsumer<Message, String> wrap(final JmsExceptionThrowingBiConsumer throwingConsumer) { return (m, v) -> { try { throwingConsumer.accept(m, v); } catch (final JMSException jmsException) { throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(), jmsException.getCause()); } }; } }
/** * Wraps a {@link JmsExceptionThrowingBiConsumer} returning a BiConsumer by converting thrown {@link JMSException}s * to {@link JMSRuntimeException}s. * * @param throwingConsumer the JmsExceptionThrowingBiConsumer that throws {@link JMSException} * @return a BiConsumer that throws {@link JMSRuntimeException} */ static BiConsumer<Message, String> wrap(final JmsExceptionThrowingBiConsumer throwingConsumer) { return (m, v) -> { try { throwingConsumer.accept(m, v); } catch (final JMSException jmsException) { throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(), jmsException.getCause()); } }; } }