1 46 50 package org.mr.kernel.services.queues; 51 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 55 63 public class QueueDispatcher extends Thread { 64 65 public static final String QUEUE_DISPATCHER_SLEEP_TIME_CONFIG_KEY = "agent.service.queue.dipatch_sleep"; 66 67 AbstractQueueService service; 68 private Log log; 69 private boolean stop = false; 70 71 public QueueDispatcher(AbstractQueueService service){ 72 this.service =service; 73 log=LogFactory.getLog("QueueDispatcher"); 74 } 75 76 77 78 public void run(){ 79 this.setName("QueueDispatcher_4_"+service.getServiceName()); 81 if(log.isDebugEnabled()){ 82 log.debug("Starting QueueDispatcher, thread name QueueDispatcher_4_"+service.getServiceName()); 83 } 84 while(service.isActive() && !stop){ 85 try { 86 service.doDequeue(); 87 } catch (Exception e) { 88 if(!stop){ 89 if(log.isErrorEnabled()){ 90 log.error("Error in queue dispatcher. " , e); 91 } 92 }else{ 93 break; 94 } 95 96 } 97 } } 100 protected synchronized void stopIt() { 101 this.stop = true; 102 this.interrupt(); 103 } 104 } 105 | Popular Tags |