1 22 package org.jboss.ejb.txtimer; 23 24 26 import org.jboss.logging.Logger; 27 import org.jboss.system.ServiceMBeanSupport; 28 29 import javax.ejb.Timer ; 30 31 39 public class FixedDelayRetryPolicy extends ServiceMBeanSupport implements FixedDelayRetryPolicyMBean 40 { 41 private static Logger log = Logger.getLogger(FixedDelayRetryPolicy.class); 43 44 private long delay = 100; 46 47 53 public long getDelay() 54 { 55 return this.delay; 56 } 57 58 64 public void setDelay(long delay) 65 { 66 this.delay = delay; 67 } 68 69 76 public void retryTimeout(TimedObjectInvoker invoker, Timer timer) 77 { 78 if (timer instanceof TimerImpl) 80 { 81 TimerImpl txTimer = (TimerImpl)timer; 82 83 long periode = txTimer.getPeriode(); 84 if (0 < periode && periode / 2 < delay) 85 log.warn("A delay of " + delay + " ms might not be appropriate for a timer periode of " + periode + " ms"); 86 } 87 88 new RetryThread(invoker, timer).start(); 89 } 90 91 95 private class RetryThread extends Thread 96 { 97 private TimedObjectInvoker invoker; 98 private Timer timer; 99 100 public RetryThread(TimedObjectInvoker invoker, Timer timer) 101 { 102 this.invoker = invoker; 103 this.timer = timer; 104 } 105 106 public void run() 107 { 108 try 109 { 110 Thread.sleep(delay); 111 log.debug("Retry ejbTimeout: " + timer); 112 invoker.callTimeout(timer); 113 } 114 catch (Exception ignore) 115 { 116 ignore.printStackTrace(); 117 } 118 } 119 } 120 } 121 | Popular Tags |