1 10 11 package org.mule.providers.jms; 12 13 import java.util.Collections ; 14 import java.util.Map ; 15 16 import javax.jms.JMSException ; 17 import javax.jms.Message ; 18 19 import org.apache.commons.collections.map.LRUMap; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.mule.umo.MessagingException; 23 24 27 public class DefaultRedeliveryHandler implements RedeliveryHandler 28 { 29 32 protected static Log logger = LogFactory.getLog(DefaultRedeliveryHandler.class); 33 34 private Map messages = null; 35 36 protected JmsConnector connector; 37 38 public DefaultRedeliveryHandler() 39 { 40 messages = Collections.synchronizedMap(new LRUMap(256)); 41 } 42 43 49 public void setConnector(JmsConnector connector) 50 { 51 this.connector = connector; 52 } 53 54 62 public void handleRedelivery(Message message) throws JMSException , MessagingException 63 { 64 if (connector.getMaxRedelivery() <= 0) 65 { 66 return; 67 } 68 69 String id = message.getJMSMessageID(); 70 Integer i = (Integer )messages.remove(id); 71 if (i == null) 72 { 73 if (logger.isDebugEnabled()) 74 { 75 logger.debug("Message with id: " + id + " has been redelivered for the fist time"); 76 } 77 messages.put(id, new Integer (1)); 78 return; 79 } 80 else if (i.intValue() == connector.getMaxRedelivery()) 81 { 82 if (logger.isDebugEnabled()) 83 { 84 logger.debug("Message with id: " + id + " has been redelivered " + (i.intValue() + 1) 85 + " times, which exceeds the maxRedelivery setting on the connector"); 86 } 87 JmsMessageAdapter adapter = (JmsMessageAdapter)connector.getMessageAdapter(message); 88 throw new MessageRedeliveredException(new org.mule.config.i18n.Message("jms", 11, id, 89 String.valueOf(i.intValue() + 1)), adapter); 90 91 } 92 else 93 { 94 messages.put(id, new Integer (i.intValue() + 1)); 95 if (logger.isDebugEnabled()) 96 { 97 logger.debug("Message with id: " + id + " has been redelivered " + i.intValue() + " times"); 98 } 99 } 100 } 101 } 102 | Popular Tags |