Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your best bet is to have <strong>JMSPublisher</strong> implement <a href="http://download.oracle.com/javaee/1.4/api/javax/jms/Connection.html" rel="nofollow">javax.jms.Exception</a> listener. Implement a <strong><em>connect()</em></strong> method which safely acquires a connection on:</p> <ol> <li>startService</li> <li>onException</li> </ol> <p>A couple of extra points:</p> <ul> <li><p>For code compression, simply acquire the JMS connection factory via resource injection. The connection factory reference will be resolved before <strong>startService</strong> is called and will also act as an implicit <em>depends</em>, making the JMS connection factory a dependency for your service.</p></li> <li><p>Have <strong>JMSPublisher</strong> extend <a href="http://docs.jboss.org/jbossas/javadoc/3.2.7/system/org/jboss/system/ServiceMBeanSupport.html" rel="nofollow">org.jboss.system.ServiceMBeanSupport</a> and implement a token MBean interface (<strong>JMSPublisherMBean</strong>) that extends <a href="http://docs.jboss.org/jbossas/javadoc/3.2.7/system/org/jboss/system/ServiceMBean.html" rel="nofollow">org.jboss.system.ServiceMBean</a>. This will ensure that the dependencies are honoured on service start (and stop).</p></li> </ul> <p><strong>Resource Injected JMS Connection Factory</strong></p> <pre><code>@Resource(mappedName="ConnectionFactory") private javax.jms.ConnectionFactory connectionFactory; private volatile javax.jms.Connection connection; </code></pre> <p><strong>Modified startService()</strong></p> <pre><code>public void startService() { connect(); } </code></pre> <p><strong>Connection Exception Handler</strong></p> <pre><code>public void onException(JMSException je) { connect(); } </code></pre> <p>*<em>Safe Connection Initializer (adding conn.start()) *</em></p> <pre><code>private void synchronized connect() { log.info("Initializing Connection...."); try { if(connection!=null) { try { connection.stop(); } catch (Exception e) {} try { connection.close(); } catch (Exception e) {} } connection = connectionFactory.createConnection(); connection.setExceptionListener(this); connection.start(); } catch (Exception e) { log.error("Failed to intialize JMS connection", e); } } </code></pre> <p>This will not automatically take care of other JMS resources allocated through the lost connection, but if other components are using the connection held by this component, you can publish JMX Notifications from <strong>JMSPublisher</strong> indicating that the connection has been lost and clean up/re-acquire on the notification receipt.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload