1 46 package org.mr.kernel.services; 47 48 import java.util.Timer ; 49 import java.util.TimerTask ; 50 import java.util.logging.Logger ; 51 52 import org.apache.commons.logging.LogFactory; 53 import org.mr.MantaAgent; 54 import org.mr.MantaAgentConstants; 55 import org.mr.core.protocol.MantaBusMessage; 56 57 64 public class DeadLetterHandler { 65 private static Timer timer = new Timer (); 66 private static ServiceProducer serviceProducer = null; 67 68 final public synchronized static void HandleDeadMessage(MantaBusMessage msg){ 69 if(serviceProducer == null){ 70 MantaService ms = MantaAgent.getInstance().getService( 71 "deadLetter",MantaService.SERVICE_TYPE_TOPIC); 72 73 serviceProducer = ServiceProducer.createNew(ms); 74 } 75 msg.setValidUntil(Long.MAX_VALUE); 77 msg.setDeliveryMode(MantaAgentConstants.NON_PERSISTENT); 78 msg.setSource(serviceProducer); 79 80 final MantaBusMessage dead = msg; 81 82 TimerTask timerTask = new TimerTask (){ 83 public void run(){ 84 try { 85 MantaAgent.getInstance().publish(dead, (ServiceProducer) dead.getSource()); 86 LogFactory.getLog("QueueDispatcher").info("DeadLetterHandler sent message to 'deadLetter' topic msg="+dead); 87 } catch (Exception e) { 88 Logger.getLogger("DeadLetterHandler").warning("DeadLetterHandler failed "+dead); 89 } 90 } 91 }; 92 93 timer.schedule(timerTask, 2); 94 } 95 96 } 97 | Popular Tags |