1 17 18 package org.apache.avalon.cornerstone.blocks.threads; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.apache.avalon.cornerstone.services.threads.ThreadManager; 24 25 import org.apache.excalibur.thread.ThreadPool; 26 27 import org.apache.avalon.framework.configuration.Configurable; 28 import org.apache.avalon.framework.configuration.Configuration; 29 import org.apache.avalon.framework.configuration.ConfigurationException; 30 import org.apache.avalon.framework.logger.AbstractLogEnabled; 31 32 37 public abstract class AbstractThreadManager 38 extends AbstractLogEnabled 39 implements ThreadManager, Configurable 40 { 41 private HashMap m_threadPools = new HashMap (); 43 44 51 public void configure( final Configuration configuration ) 52 throws ConfigurationException 53 { 54 final Configuration[] groups = configuration.getChildren( "thread-group" ); 55 for( int i = 0; i < groups.length; i++ ) 56 { 57 configureThreadPool( m_threadPools, groups[ i ] ); 58 } 59 } 60 61 protected abstract void configureThreadPool( final Map threadPools, 62 final Configuration configuration ) 63 throws ConfigurationException; 64 65 73 public ThreadPool getThreadPool( final String name ) 74 throws IllegalArgumentException 75 { 76 final ThreadPool threadPool = (ThreadPool)m_threadPools.get( name ); 77 78 if( null == threadPool ) 79 { 80 final String message = "Unable to locate ThreadPool named " + name; 81 throw new IllegalArgumentException ( message ); 82 } 83 84 return threadPool; 85 } 86 87 92 public ThreadPool getDefaultThreadPool() 93 { 94 return getThreadPool( "default" ); 95 } 96 } 97 | Popular Tags |