1 24 25 package org.objectweb.dream.pump; 26 27 import org.objectweb.dream.PullException; 28 import org.objectweb.dream.PushException; 29 import org.objectweb.dream.message.Message; 30 31 37 public class PumpPeriodicSynchronizedImpl extends PumpSynchronizedImpl 38 implements 39 PumpPeriodicAttributeController 40 { 41 42 46 public static final String PERIOD_INIT_PARAM_NAME = "period"; 47 48 protected long period = -1; 49 50 53 public PumpPeriodicSynchronizedImpl() 54 { 55 pumpTask = new PeriodicPumpTask(); 56 } 57 58 class PeriodicPumpTask extends PumpTask 59 { 60 61 64 public Object execute(Object hints) throws InterruptedException 65 { 66 67 long begin = System.currentTimeMillis(); 68 if (mutexItf != null) 69 { 70 mutexItf.lock(); 71 } 72 try 73 { 74 Message msg = inPullItf.pull(null); 75 if (msg != null || pushNullPolicy) 76 { 77 outPushItf.push(msg, null); 78 } 79 } 80 catch (PullException e) 81 { 82 throw new InterruptedException (e.getLocalizedMessage()); 83 } 84 catch (PushException e) 85 { 86 throw new InterruptedException (e.getLocalizedMessage()); 87 } 88 finally 89 { 90 if (mutexItf != null) 91 { 92 mutexItf.unlock(); 93 } 94 } 95 96 long sleepTime = period - (System.currentTimeMillis() - begin); 97 if (sleepTime > 0) 98 { 99 Thread.sleep(sleepTime); 100 } 101 return EXECUTE_AGAIN; 102 } 103 } 104 105 108 public long getPeriod() 109 { 110 return period; 111 } 112 113 116 public void setPeriod(long period) 117 { 118 if (period < 0) 119 { 120 throw new IllegalArgumentException ("Period value negative"); 121 } 122 this.period = period; 123 } 124 } | Popular Tags |