1 23 package com.sun.enterprise.util; 24 25 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManager; 26 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool; 27 import com.sun.corba.ee.spi.orbutil.threadpool.NoSuchThreadPoolException; 28 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolChooser; 29 30 import com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl; 31 import com.sun.corba.ee.impl.orbutil.ORBConstants; 32 33 import com.sun.enterprise.server.ApplicationServer; 34 import com.sun.enterprise.server.ServerContext; 35 36 import com.sun.enterprise.config.ConfigContext; 37 import com.sun.enterprise.config.ConfigException; 38 import com.sun.enterprise.config.ConfigBean; 39 import com.sun.enterprise.config.serverbeans.Server; 40 import com.sun.enterprise.config.serverbeans.IiopService; 41 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 42 import com.sun.enterprise.config.serverbeans.Orb; 43 import com.sun.enterprise.config.serverbeans.Config; 44 import com.sun.enterprise.config.serverbeans.ThreadPools; 45 46 import java.util.HashMap ; 47 import java.util.ArrayList ; 48 import java.util.logging.*; 49 import com.sun.logging.*; 50 51 public class S1ASThreadPoolManager implements ThreadPoolManager { 52 53 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 54 55 private static final int DEFAULT_NUMBER_OF_QUEUES = 0; 56 private static final int DEFAULT_MIN_THREAD_COUNT = 10; 57 private static final int DEFAULT_MAX_THREAD_COUNT = 200; 58 59 private static HashMap idToIndexTable = new HashMap (); 60 private static HashMap indexToIdTable = new HashMap (); 61 private static ArrayList threadpoolList = new ArrayList (); 62 private static String defaultID; 63 64 private static ThreadPoolManager s1asThreadPoolMgr = new S1ASThreadPoolManager(); 65 66 public static ThreadPoolManager getThreadPoolManager() { 67 return s1asThreadPoolMgr; 68 } 69 70 71 S1ASThreadPoolManager() { 72 73 Orb orbBean = null; 74 75 try { 76 ServerContext serverContext = ApplicationServer.getServerContext(); 77 78 ConfigContext configContext = serverContext.getConfigContext(); 79 assert(configContext != null); 80 81 Config config = ServerBeansFactory.getConfigBean(configContext); 83 84 assert(config != null); 85 86 com.sun.enterprise.config.serverbeans.ThreadPools 88 threadpoolsElement = config.getThreadPools(); 89 assert (threadpoolsElement != null); 90 91 com.sun.enterprise.config.serverbeans.ThreadPool[] 92 allThreadpools = threadpoolsElement.getThreadPool(); 93 for (int i = 0; i < allThreadpools.length; i++) { 94 createThreadPools(allThreadpools[i], i); 95 } 96 defaultID = (String )indexToIdTable.get(new Integer (0)); 97 } catch (ConfigException cfe) { 98 _logger.log(Level.SEVERE,"enterprise_util.orbmgr_config_excep", cfe); 99 } catch (NullPointerException npe) { 100 _logger.log(Level.FINE,"Server Context is NULL. Ignoring and proceeding."); 101 } 102 103 104 } 105 106 107 private void createThreadPools(com.sun.enterprise.config.serverbeans.ThreadPool 108 threadpoolBean, int index) { 109 String threadpoolId = null; 110 String minThreadsValue, maxThreadsValue, timeoutValue, numberOfQueuesValue; 111 int minThreads = DEFAULT_MIN_THREAD_COUNT; 112 int maxThreads = DEFAULT_MAX_THREAD_COUNT; 113 int idleTimeoutInSeconds = ORBConstants.DEFAULT_INACTIVITY_TIMEOUT; 114 int numberOfQueues = DEFAULT_NUMBER_OF_QUEUES; 115 116 try { 117 threadpoolId = threadpoolBean.getThreadPoolId(); 118 } catch (NullPointerException npe) { 119 if(_logger.isLoggable(Level.WARNING)) { 120 _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe); 121 } 122 } 123 try { 124 minThreadsValue = threadpoolBean.getMinThreadPoolSize(); 125 minThreads = Integer.parseInt(minThreadsValue); 126 } catch (NullPointerException npe) { 127 if(_logger.isLoggable(Level.WARNING)) { 128 _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe); 129 _logger.log(Level.WARNING, 130 "Using default value for steady-threadpool-size = " + minThreads); 131 } 132 } catch (NumberFormatException nfe) { 133 if(_logger.isLoggable(Level.WARNING)) { 134 _logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe); 135 _logger.log(Level.WARNING, 136 "Using default value for min-threadpool-size = " + minThreads); 137 } 138 } 139 try { 140 maxThreadsValue = threadpoolBean.getMaxThreadPoolSize(); 141 maxThreads = Integer.parseInt(maxThreadsValue); 142 } catch (NullPointerException npe) { 143 if(_logger.isLoggable(Level.WARNING)) { 144 _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe); 145 _logger.log(Level.WARNING, 146 "Using default value for max-threadpool-size = " + maxThreads); 147 } 148 } catch (NumberFormatException nfe) { 149 if(_logger.isLoggable(Level.WARNING)) { 150 _logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe); 151 _logger.log(Level.WARNING, 152 "Using default value for max-threadpool-size = " + maxThreads); 153 } 154 } 155 try { 156 timeoutValue = threadpoolBean.getIdleThreadTimeoutInSeconds(); 157 idleTimeoutInSeconds = Integer.parseInt(timeoutValue); 158 } catch (NullPointerException npe) { 159 if(_logger.isLoggable(Level.WARNING)) { 160 _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe); 161 _logger.log(Level.WARNING, 162 "Using default value for idle-thread-timeout-in-seconds = " + 163 idleTimeoutInSeconds); 164 } 165 } catch (NumberFormatException nfe) { 166 if(_logger.isLoggable(Level.WARNING)) { 167 _logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe); 168 _logger.log(Level.WARNING, 169 "Using default value for idle-thread-timeout-in-seconds = " + 170 idleTimeoutInSeconds); 171 } 172 } 173 174 try { 178 numberOfQueuesValue = threadpoolBean.getNumWorkQueues(); 179 numberOfQueues = Integer.parseInt(numberOfQueuesValue); 180 } catch (NullPointerException npe) { 181 if(_logger.isLoggable(Level.WARNING)) { 182 _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe); 183 _logger.log(Level.WARNING, 184 "Using default value for num-work-queues = " + 185 numberOfQueues); 186 } 187 } catch (NumberFormatException nfe) { 188 if(_logger.isLoggable(Level.WARNING)) { 189 _logger.log(Level.WARNING,"enterprise_util.excep_orbmgr_numfmt",nfe); 190 _logger.log(Level.WARNING, 191 "Using default value for num-work-queues = " + 192 numberOfQueues); 193 } 194 } 195 196 com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool = 198 new ThreadPoolImpl(minThreads, maxThreads, 199 idleTimeoutInSeconds * 1000, threadpoolId); 200 201 202 threadpoolList.add(threadpool); 204 205 idToIndexTable.put(threadpoolId, new Integer (index)); 207 208 indexToIdTable.put(new Integer (index), threadpoolId); 210 211 } 212 213 220 public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool 221 getThreadPool(String id) 222 throws NoSuchThreadPoolException { 223 224 Integer i = (Integer )idToIndexTable.get(id); 225 if (i == null) { 226 throw new NoSuchThreadPoolException(); 227 } 228 try { 229 com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool = 230 (com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool) 231 threadpoolList.get(i.intValue()); 232 return threadpool; 233 } catch (IndexOutOfBoundsException iobe) { 234 throw new NoSuchThreadPoolException(); 235 } 236 } 237 238 246 public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool 247 getThreadPool(int numericIdForThreadpool) 248 throws NoSuchThreadPoolException { 249 250 try { 251 com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool threadpool = 252 (com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool) 253 threadpoolList.get(numericIdForThreadpool); 254 return threadpool; 255 } catch (IndexOutOfBoundsException iobe) { 256 throw new NoSuchThreadPoolException(); 257 } 258 } 259 260 266 public int getThreadPoolNumericId(String id) { 267 Integer i = (Integer )idToIndexTable.get(id); 268 return ((i == null) ? 0 : i.intValue()); 269 } 270 271 275 public String getThreadPoolStringId(int numericIdForThreadpool) { 276 String id = (String )indexToIdTable.get(new Integer (numericIdForThreadpool)); 277 return ((id == null) ? defaultID : id); 278 } 279 280 283 public com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool 284 getDefaultThreadPool() { 285 try { 286 return getThreadPool(0); 287 } catch (NoSuchThreadPoolException nstpe) { 288 if(_logger.isLoggable(Level.WARNING)) { 289 _logger.log(Level.WARNING, "No default ThreadPool defined ", nstpe); 290 } 291 } 292 return null; 293 } 294 295 299 public ThreadPoolChooser getThreadPoolChooser(String componentId) { 300 return null; 304 } 305 306 311 public ThreadPoolChooser getThreadPoolChooser(int componentIndex) { 312 return null; 316 } 317 318 322 public void setThreadPoolChooser(String componentId, ThreadPoolChooser aThreadPoolChooser) { 323 } 327 328 333 public int getThreadPoolChooserNumericId(String componentId) { 334 return 0; 338 } 339 340 341 } 342 343 344 | Popular Tags |