1 23 package com.scalagent.joram.mom.dest.mail; 24 25 import java.util.Properties ; 26 27 import org.objectweb.joram.mom.dest.DestinationImpl; 28 import org.objectweb.joram.mom.dest.Queue; 29 import org.objectweb.joram.mom.proxies.ConnectionManager; 30 import org.objectweb.util.monolog.api.BasicLevel; 31 import org.objectweb.util.monolog.api.Logger; 32 33 import fr.dyade.aaa.agent.AgentId; 34 import fr.dyade.aaa.agent.Channel; 35 import fr.dyade.aaa.agent.Debug; 36 import fr.dyade.aaa.agent.Notification; 37 import fr.dyade.aaa.util.Timer; 38 import fr.dyade.aaa.util.TimerTask; 39 40 46 public class JavaMailQueue extends Queue { 47 48 public static Logger logger = 49 Debug.getLogger("com.scalagent.joram.mom.dest.mail.JavaMailQueue"); 50 51 public static final String MAIL_QUEUE_TYPE = "queue.mail"; 52 53 public static String getDestinationType() { 54 return MAIL_QUEUE_TYPE; 55 } 56 57 60 public JavaMailQueue() {} 61 62 68 public DestinationImpl createsImpl(AgentId adminId, Properties prop) { 69 return new JavaMailQueueImpl(getId(), adminId, prop); 70 } 71 72 private transient PopTask poptask; 73 74 83 protected void agentInitialize(boolean firstTime) throws Exception { 84 super.agentInitialize(firstTime); 85 poptask = new PopTask(getId()); 86 poptask.schedule(); 87 } 88 89 public void react(AgentId from, Notification not) throws Exception { 90 if (not instanceof WakeUpPopNot) { 91 if (poptask == null) 92 poptask = new PopTask(getId()); 93 poptask.schedule(); 94 ((JavaMailQueueImpl) destImpl).doPop(); 95 } else { 96 super.react(from, not); 97 } 98 } 99 100 103 private class PopTask extends TimerTask { 104 private AgentId to; 105 106 public PopTask(AgentId to) { 107 this.to = to; 108 } 109 110 111 public void run() { 112 try { 113 Channel.sendTo(to, new WakeUpPopNot()); 114 } catch (Exception e) {} 115 } 116 117 public void schedule() { 118 long period = ((JavaMailQueueImpl) destImpl).getPopPeriod(); 119 120 if (period > 0) { 121 try { 122 Timer timer = ConnectionManager.getTimer(); 123 timer.schedule(this, period); 124 } catch (Exception exc) { 125 if (logger.isLoggable(BasicLevel.ERROR)) 126 logger.log(BasicLevel.ERROR, "--- " + this + " Queue(...)", exc); 127 } 128 } 129 } 130 } 131 } 132 | Popular Tags |