1 14 package org.compiere.request; 15 16 import javax.management.*; 17 import org.jboss.system.*; 18 19 25 public class RequestService extends ServiceMBeanSupport 26 implements RequestServiceMBean, Runnable  27 { 28 31 public RequestService() 32 { 33 super(); 34 } 36 40 public String getName() 41 { 42 return NAME; 43 } 45 46 private Thread m_worker = null; 47 48 private RequestProcessorVO[] m_rpVO = null; 49 50 51 private int m_sleepMinutes = 10; 52 53 private volatile int m_count = 0; 54 55 private String m_dataSourceName; 56 57 58 59 60 64 protected void createService() throws Exception  65 { 66 m_worker = new Thread (this, getName()); 67 m_worker.setDaemon(true); 68 m_worker.setPriority(Thread.MIN_PRIORITY); 69 m_rpVO = RequestProcessorVO.get(); 70 } 72 76 protected void startService() throws Exception  77 { 78 m_worker.start(); 79 } 81 85 protected void stopService() throws Exception  86 { 87 m_worker.interrupt(); 88 } 90 94 protected void destroyService() throws Exception  95 { 96 int maxTime = 10000; 97 int waitTime = 1000; while (m_worker.isAlive()) 99 { 100 m_worker.interrupt(); 101 if (maxTime <= 0) 102 break; 103 log.debug("Waiting for Worker"); 104 Thread.sleep(waitTime); 105 maxTime -= waitTime; 106 } 107 m_worker = null; 108 m_rpVO = null; 109 } 111 112 115 public void run() 116 { 117 try 118 { 119 Thread.sleep(60000); } 122 catch (InterruptedException ex) 123 { 124 log.info ("run: " + ex.getMessage()); 125 return; 126 } 127 128 while (!m_worker.isInterrupted()) 129 { 130 try 131 { 132 for (int i = 0; i < m_rpVO.length; i++) 133 { 134 RequestProcessor rp = new RequestProcessor (m_rpVO[i]); 135 if (m_worker.isInterrupted()) 136 break; 137 } 138 if (!m_worker.isInterrupted()) 139 { 140 m_count++; 141 Thread.sleep (m_sleepMinutes * 60000); 144 } 145 } 146 catch (InterruptedException e) 147 { 148 log.info ("run: " + e.getMessage()); 149 return; 150 } 151 } } 154 155 156 160 public void setSleepMinutes (int sleepMinutes) 161 { 162 m_sleepMinutes = sleepMinutes; 163 } 165 169 public int getSleepMinutes () 170 { 171 return m_sleepMinutes; 172 } 174 178 public String getStatistics() 179 { 180 StringBuffer sb = new StringBuffer (); 181 sb.append("ProcessorCount="); 183 if (m_rpVO == null) 184 sb.append("null"); 185 else 186 sb.append(m_rpVO.length); 187 sb.append(",RunCount=").append(m_count); 188 sb.append(";Worker="); 190 if (m_worker == null) 191 sb.append("null"); 192 else if (!m_worker.isAlive()) 193 sb.append("NotAlive"); 194 else if (m_worker.isInterrupted()) 195 sb.append("Interrupted"); 196 else 197 sb.append("Alive"); 198 return sb.toString(); 200 } 202 206 public String getDataSourceName() 207 { 208 return m_dataSourceName; 209 } 211 215 public void setDataSourceName (String dataSourceName) 216 { 217 m_dataSourceName = dataSourceName; 218 } 220 221 222 225 public void runNow() 226 { 227 for (int i = 0; i < m_rpVO.length; i++) 228 { 229 RequestProcessor rp = new RequestProcessor (m_rpVO[i]); 230 } 231 } 233 }
| Popular Tags
|