Exemplo n.º 1
0
 public void init(RackContext context) throws Exception {
   this.context = context;
   String jndiName = context.getInitParameter("jms.connection.factory");
   if (jndiName != null && connectionFactory == null) {
     Properties properties = new Properties();
     String jndiProperties = context.getInitParameter("jms.jndi.properties");
     if (jndiProperties != null) {
       properties.load(new ByteArrayInputStream(jndiProperties.getBytes("UTF-8")));
     }
     jndiContext = new InitialContext(properties);
     connectionFactory = (ConnectionFactory) jndiContext.lookup(jndiName);
   }
 }
Exemplo n.º 2
0
 public void destroy() {
   for (Iterator it = queues.entrySet().iterator(); it.hasNext(); ) {
     Map.Entry<String, Connection> entry = (Map.Entry<String, Connection>) it.next();
     try {
       entry.getValue().close();
     } catch (Exception e) {
       context.log("exception while closing connection: " + e.getMessage(), e);
     }
   }
   queues.clear();
   connectionFactory = null;
 }
Exemplo n.º 3
0
 public synchronized void listen(String queueName) {
   Connection conn = queues.get(queueName);
   if (conn == null) {
     try {
       conn = connectionFactory.createConnection();
       Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
       Destination dest = (Destination) lookup(queueName);
       MessageConsumer consumer = session.createConsumer(dest);
       consumer.setMessageListener(new RubyObjectMessageListener(queueName));
       queues.put(queueName, conn);
       conn.start();
     } catch (Exception e) {
       context.log("Unable to listen to '" + queueName + "': " + e.getMessage(), e);
     }
     // } else { ... already listening on that queue
   }
 }