1 22 package org.jboss.resource.adapter.jms.inflow.dlq; 23 24 import java.util.HashMap ; 25 26 import javax.jms.JMSException ; 27 import javax.jms.Message ; 28 29 35 public class GenericDLQHandler extends JBossMQDLQHandler 36 { 37 38 protected HashMap resent = new HashMap (); 39 40 public void messageDelivered(Message msg) 41 { 42 try 43 { 44 String id = msg.getJMSMessageID(); 45 if (id == null) 46 { 47 log.error("Message id is null? " + msg); 48 return; 49 } 50 51 clearResentCounter(id); 52 } 53 catch (Throwable t) 54 { 55 log.warn("Unexpected error processing delivery notification " + msg, t); 56 } 57 } 58 59 protected boolean handleDelivery(Message msg) 60 { 61 boolean handled = super.handleDelivery(msg); 63 if (handled) 64 return true; 65 66 try 67 { 68 if (msg.propertyExists(JMS_JBOSS_REDELIVERY_COUNT)) 69 return false; 70 71 String id = msg.getJMSMessageID(); 72 if (id == null) 73 { 74 log.error("Message id is null? " + msg); 75 return false; 76 } 77 78 int count = 0; 79 80 try 81 { 82 if (msg.propertyExists(PROPERTY_DELIVERY_COUNT)) 83 count = msg.getIntProperty(PROPERTY_DELIVERY_COUNT) - 1; 84 } 85 catch (JMSException ignored) 86 { 87 count = incrementResentCounter(id); 88 } 89 90 if (count > maxResent) 91 { 92 warnDLQ(msg, count, maxResent); 93 clearResentCounter(id); 94 return true; 95 } 96 } 97 catch (Throwable t) 98 { 99 log.warn("Unexpected error checking whether dlq should be used " + msg, t); 100 } 101 102 return false; 103 } 104 105 110 protected int incrementResentCounter(String id) 111 { 112 ResentInfo info; 113 synchronized (resent) 114 { 115 info = (ResentInfo) resent.get(id); 116 if (info == null) 117 { 118 info = new ResentInfo(); 119 resent.put(id, info); 120 } 121 } 122 return ++info.count; 123 } 124 125 130 protected void clearResentCounter(String id) 131 { 132 synchronized (resent) 133 { 134 resent.remove(id); 135 } 136 } 137 138 141 protected static class ResentInfo 142 { 143 int count = 0; 144 } 145 } | Popular Tags |