1 18 package org.apache.activemq.tool; 19 20 import org.apache.activemq.ActiveMQConnection; 21 import org.apache.activemq.ActiveMQConnectionFactory; 22 import org.apache.activemq.util.IndentPrinter; 23 24 import javax.jms.Connection ; 25 import javax.jms.Destination ; 26 import javax.jms.JMSException ; 27 import javax.jms.Session ; 28 29 34 public class ToolSupport { 35 36 37 protected Destination destination; 38 protected String subject = "TOOL.DEFAULT"; 39 protected boolean topic = true; 40 protected String user = ActiveMQConnection.DEFAULT_USER; 41 protected String pwd = ActiveMQConnection.DEFAULT_PASSWORD; 42 protected String url = ActiveMQConnection.DEFAULT_BROKER_URL; 43 protected boolean transacted = false; 44 protected boolean durable = false; 45 protected String clientID = getClass().getName(); 46 protected int ackMode = Session.AUTO_ACKNOWLEDGE; 47 protected String consumerName = "James"; 48 49 50 protected Session createSession(Connection connection) throws Exception { 51 if (durable) { 52 connection.setClientID(clientID); 53 } 54 Session session = connection.createSession(transacted, ackMode); 55 if (topic) { 56 destination = session.createTopic(subject); 57 } 58 else { 59 destination = session.createQueue(subject); 60 } 61 return session; 62 } 63 64 protected Connection createConnection() throws JMSException , Exception { 65 ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url); 66 return connectionFactory.createConnection(); 67 } 68 69 protected void close(Connection connection, Session session) throws JMSException { 70 dumpStats(connection); 72 73 if (session != null) { 74 session.close(); 75 } 76 if (connection != null) { 77 connection.close(); 78 } 79 } 80 81 protected void dumpStats(Connection connection) { 82 ActiveMQConnection c = (ActiveMQConnection) connection; 83 c.getConnectionStats().dump(new IndentPrinter()); 84 } 85 } 86 | Popular Tags |