1 23 24 package org.objectweb.clif.probe.util; 25 26 27 34 abstract public class AbstractInsert 35 extends AbstractDumbInsert 36 { 37 38 39 43 44 public void start() 45 { 46 synchronized(activity_lock) 47 { 48 started = true; 49 activity_lock.notify(); 50 } 51 } 52 53 54 public void stop() 55 { 56 synchronized (activity_lock) 57 { 58 stopped = true; 59 poller.interrupt(); 60 } 61 if (suspended) 62 { 63 resume(); 64 } 65 synchronized (activity_lock) 66 { 67 if (started && ! terminated) 68 { 69 try 70 { 71 activity_lock.wait(); 72 } 73 catch (InterruptedException ex) 74 { 75 } 76 } 77 } 78 } 79 80 81 public void suspend() 82 { 83 synchronized (activity_lock) 84 { 85 suspended = true; 86 poller.interrupt(); 87 } 88 } 89 90 91 public void resume() 92 { 93 synchronized (activity_lock) 94 { 95 suspended = false; 96 activity_lock.notify(); 97 } 98 } 99 100 101 public void join() 102 { 103 synchronized (activity_lock) 104 { 105 if (!terminated) 106 { 107 try 108 { 109 activity_lock.wait(); 110 } 111 catch (InterruptedException ex) 112 { 113 } 114 } 115 } 116 } 117 118 119 123 124 public void run() 125 { 126 try 127 { 128 synchronized (activity_lock) 129 { 130 if (! started) 131 { 132 activity_lock.wait(); 133 } 134 baseTime_ms = System.currentTimeMillis(); 135 } 136 } 137 catch (InterruptedException ex) 138 { 139 } 140 while ( 141 ! stopped 142 && arg_duration_ms > System.currentTimeMillis() - baseTime_ms) 143 { 144 try 145 { 146 synchronized (activity_lock) 147 { 148 if (suspended) 149 { 150 baseTime_ms = System.currentTimeMillis() - baseTime_ms; 151 activity_lock.wait(); 152 baseTime_ms = System.currentTimeMillis() - baseTime_ms; 153 } 154 } 155 synchronized (activity_lock) 156 { 157 if (!stopped 158 && arg_duration_ms > System.currentTimeMillis() - baseTime_ms) 159 { 160 try 161 { 162 dcw.add(doProbe()); 163 } 164 catch (Exception ex) 165 { 166 } 167 } 168 } 169 long time = System.currentTimeMillis(); 170 if (arg_duration_ms > time - baseTime_ms + arg_period_ms) 171 { 172 Thread.currentThread().sleep(arg_period_ms); 173 } 174 else 175 { 176 Thread.currentThread().sleep( 177 arg_duration_ms 178 - time + baseTime_ms); 179 } 180 } 181 catch (InterruptedException ex) 182 { 183 } 184 } 185 synchronized (activity_lock) 186 { 187 terminated = true; 188 if (! stopped) 189 { 190 bir.completed(); 191 } 192 else 193 { 194 activity_lock.notify(); 195 } 196 } 197 } 198 } 199 | Popular Tags |