1 17 18 package org.apache.sandesha.server; 19 20 import org.apache.axis.components.logger.LogFactory; 21 import org.apache.axis.components.threadpool.ThreadPool; 22 import org.apache.commons.logging.Log; 23 import org.apache.sandesha.Constants; 24 25 import java.util.Collections ; 26 import java.util.Map ; 27 28 35 36 public class ThreadPoolInvokeStrategy implements InvokeStrategy { 37 private static final Log log = LogFactory.getLog(ThreadPoolInvokeStrategy.class.getName()); 38 private Map params = Collections.EMPTY_MAP; 39 private ThreadPool tPool; 40 41 46 public void start() { 47 final int numberOfThreads = getThreadPoolSize(); 48 tPool = new ThreadPool(numberOfThreads); 49 for (int i = 0; i < numberOfThreads; i++) { 50 RMRunnableInvoker rmWorker = new RMRunnableInvoker(new RMInvokerWork()); 51 tPool.addWorker(rmWorker); 52 } 53 } 54 55 58 public void stop() { 59 tPool.shutdown(); 60 } 61 62 67 protected int getThreadPoolSize() { 68 int threadSize = Constants.INVOKER_THREADS; 69 String value = (String ) getParams().get(Constants.THREAD_POOL_SIZE); 70 if (value != null && value.length() > 0) { 71 try { 72 threadSize = Integer.parseInt(value); 73 } catch (NumberFormatException nfe) { 74 } 76 } 77 return threadSize; 78 } 79 80 83 public void addParams(Map aParams) { 84 params = aParams; 85 } 86 87 protected Map getParams() { 88 return params; 89 } 90 91 96 protected class RMRunnableInvoker implements Runnable { 97 private RMInvokerWork rmInvokerWork; 98 99 public RMRunnableInvoker(RMInvokerWork aRMInvokerWork) { 100 rmInvokerWork = aRMInvokerWork; 101 } 102 103 public void run() { 104 while (true) { 105 try { 106 Thread.sleep(Constants.RMINVOKER_SLEEP_TIME); 107 getRMInvokerWorker().executeInvoke(); 108 } catch (InterruptedException ex) { 109 log.error(ex); 110 } catch (Exception e) { 111 log.error(e); 112 } 113 } 114 } 115 116 119 protected RMInvokerWork getRMInvokerWorker() { 120 return rmInvokerWork; 121 } 122 } 123 } 124 | Popular Tags |