I am having 3 applications in Tomcat Web server.All 3 apps are using activemq connections to send JMS messages .I want to find only connections from a particular application and close them in java or servlet before undeploy my application from server.
But I checked and stuck with that.I didn't find any methods to find out connections from particular application.
public class ConnFactory {
private static QueueConnectionFactory conFactory;
private static final Class[] SSA = new Class[] { String.class };
public static QueueConnectionFactory getSingleFactory() {
if (conFactory == null) {
try {
conFactory = GetConnectionFactory();
} catch (Exception e) {
System.err.println("Exception in getSingleFactory....");
e.printStackTrace();
}
}
return conFactory;
}
public static QueueConnectionFactory GetConnectionFactory()
throws Exception {
Object o = Class.forName("org.apache.activemq.ActiveMQConnectionFactory", true, ConnFactory.class.getClassLoader()).newInstance();
Method pm = o.getClass().getMethod("setBrokerURL", SSA);
String cfgStr = "keepAlive=true&wireFormat.stackTraceEnabled=true";
String transCfgStr = "maxReconnectAttempts=3&startupMaxReconnectAttempts=3&timeout=10000";
pm.invoke(o, new Object[] { "failover://(tcp://" + "localhost" + ":"
+ "61616" + "?" + cfgStr + ")?" + transCfgStr });
ActiveMQConnectionFactory cd = (ActiveMQConnectionFactory) o;
RedeliveryPolicy rd = cd.getRedeliveryPolicy();
rd.setMaximumRedeliveries(5);
rd.setMaximumRedeliveryDelay(5000);
rd.setInitialRedeliveryDelay(5000);
cd.setRedeliveryPolicy(rd);
QueueConnectionFactory conf = cd;
System.out.println("ConnectionFactory Initialized.......");
return conf;
}
public QueueConnection getConnection() throws Exception {
QueueConnection con = null;
con = getSingleFactory().createQueueConnection();
// con.setClientID("leo1");
return con;
}
public void sendJMSMsg(QueueConnection qConn) throws Exception {
TextMessage message = null;
try {
QueueSession queueSession = qConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue1 = queueSession.createQueue("JQ1");
QueueSender queueSender = queueSession.createSender(queue1);
message = queueSession.createTextMessage();
message.setText("This is message " + (new Date().getTime()));
System.out.println("Sending message: " + message.getText());
queueSender.send(message);
qConn.close();
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
}
}
}