1 50 package org.apache.avalon.excalibur.pool; 51 52 import org.apache.avalon.framework.activity.Initializable; 53 import org.apache.avalon.framework.thread.ThreadSafe; 54 55 64 public class HardResourceLimitingPool 65 extends SoftResourceLimitingPool 66 implements ThreadSafe, Initializable 67 { 68 public HardResourceLimitingPool( final ObjectFactory factory, final PoolController controller ) 69 throws Exception 70 { 71 this( factory, controller, DEFAULT_POOL_SIZE, DEFAULT_POOL_SIZE ); 72 } 73 74 public HardResourceLimitingPool( final ObjectFactory factory, final PoolController controller, int max ) 75 throws Exception 76 { 77 this( factory, controller, controller.grow(), max ); 78 } 79 80 public HardResourceLimitingPool( final ObjectFactory factory, final PoolController controller, int initial, int max ) 81 throws Exception 82 { 83 super( factory, controller, initial, max ); 84 } 85 86 public HardResourceLimitingPool( final ObjectFactory factory ) 87 throws Exception 88 { 89 this( factory, null ); 90 } 91 92 public HardResourceLimitingPool( final ObjectFactory factory, 93 final int initial, 94 final int maximum ) 95 throws Exception 96 { 97 this( factory, null, initial, maximum ); 98 } 99 100 public HardResourceLimitingPool( final ObjectFactory factory, final int initial ) 101 throws Exception 102 { 103 this( factory, initial, initial ); 104 } 105 106 public HardResourceLimitingPool( final Class clazz, final int initial, final int maximum ) 107 throws NoSuchMethodException , Exception 108 { 109 this( new DefaultObjectFactory( clazz ), initial, maximum ); 110 } 111 112 public HardResourceLimitingPool( final Class clazz, final int initial ) 113 throws NoSuchMethodException , Exception 114 { 115 this( clazz, initial, initial ); 116 } 117 118 public void initialize() 119 { 120 try 121 { 122 super.initialize(); 123 } 124 catch( final Exception e ) 125 { 126 if( getLogger().isDebugEnabled() ) 127 { 128 getLogger().debug( "Caught init exception", e ); 129 } 130 } 131 } 132 133 protected Poolable newPoolable() throws Exception 134 { 135 if( this.size() < m_max ) 136 { 137 return super.newPoolable(); 138 } 139 140 throw new InstantiationException ( "Ran out of resources to instantiate" ); 141 } 142 143 protected void internalGrow( int amount ) 144 throws Exception 145 { 146 super.internalGrow( ( ( this.size() + amount ) < m_max ) ? amount : m_max - this.size() ); 147 } 148 } 149 | Popular Tags |