List of usage examples for javax.jms TemporaryQueue delete
void delete() throws JMSException;
From source file:org.apache.james.queue.activemq.ActiveMQMailQueue.java
/** * Try to use ActiveMQ StatisticsPlugin to get size and if that fails * fallback to {@link JMSMailQueue#getSize()} *//*w w w . j a va 2 s. c o m*/ @Override public long getSize() throws MailQueueException { Connection connection = null; Session session = null; MessageConsumer consumer = null; MessageProducer producer = null; TemporaryQueue replyTo = null; long size = -1; try { connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); replyTo = session.createTemporaryQueue(); consumer = session.createConsumer(replyTo); Queue myQueue = session.createQueue(queuename); producer = session.createProducer(null); String queueName = "ActiveMQ.Statistics.Destination." + myQueue.getQueueName(); Queue query = session.createQueue(queueName); Message msg = session.createMessage(); msg.setJMSReplyTo(replyTo); producer.send(query, msg); MapMessage reply = (MapMessage) consumer.receive(2000); if (reply != null && reply.itemExists("size")) { try { size = reply.getLong("size"); return size; } catch (NumberFormatException e) { // if we hit this we can't calculate the size so just catch // it } } } catch (Exception e) { throw new MailQueueException("Unable to remove mails", e); } finally { if (consumer != null) { try { consumer.close(); } catch (JMSException e1) { e1.printStackTrace(); // ignore on rollback } } if (producer != null) { try { producer.close(); } catch (JMSException e1) { // ignore on rollback } } if (replyTo != null) { try { // we need to delete the temporary queue to be sure we will // free up memory if thats not done and a pool is used // its possible that we will register a new mbean in jmx for // every TemporaryQueue which will never get unregistered replyTo.delete(); } catch (JMSException e) { } } try { if (session != null) session.close(); } catch (JMSException e1) { // ignore here } try { if (connection != null) connection.close(); } catch (JMSException e1) { // ignore here } } // if we came to this point we should just fallback to super method return super.getSize(); }
From source file:nl.nn.adapterframework.jms.MessagingSource.java
private void deleteDynamicQueue(Queue queue) throws IfsaException { if (queue != null) { try {//from w w w . j a v a2s . com if (!(queue instanceof TemporaryQueue)) { throw new IfsaException("Queue [" + queue.getQueueName() + "] is not a TemporaryQueue"); } TemporaryQueue tqueue = (TemporaryQueue) queue; tqueue.delete(); } catch (JMSException e) { throw new IfsaException("cannot delete temporary queue", e); } } }
From source file:org.grouter.common.jms.QueueListenerDestination.java
/** * <br>/*from ww w.ja v a 2 s . c o m*/ */ public void sendReplyToTemporaryDestination(Message request) { TemporaryQueue replyQueue = null; QueueSender tempsender = null; String temporaryDestinationName = null; try { if (request.getJMSReplyTo() == null) { throw new IllegalStateException("The sender of this message has not entered a JMSReplyTo field - " + "impossible to send reply on temporary destination!!"); } temporaryDestinationName = request.getJMSReplyTo().toString(); request.setJMSCorrelationID(temporaryDestinationName); replyQueue = (TemporaryQueue) request.getJMSReplyTo(); tempsender = queueSession.createSender(replyQueue); tempsender.send(request); logger.debug("Created a tempsender and sent reply to " + replyQueue); } catch (JMSException ex) { //ignore logger.warn("Failed sending reply on temporary destination : " + temporaryDestinationName); } finally { try { if (tempsender != null) { tempsender.close(); } if (replyQueue != null) { replyQueue.delete(); } } catch (JMSException ex1) { //ignore } } }