1 50 package org.apache.avalon.excalibur.pool; 51 52 59 public class SoftResourceLimitingPool 60 extends DefaultPool 61 implements Resizable 62 { 63 66 public SoftResourceLimitingPool( final ObjectFactory factory ) 67 throws Exception 68 { 69 this( factory, AbstractPool.DEFAULT_POOL_SIZE / 2 ); 70 } 71 72 76 public SoftResourceLimitingPool( final ObjectFactory factory, 77 final int min ) 78 throws Exception 79 { 80 this( factory, null, min, min * 2 ); 81 } 82 83 87 public SoftResourceLimitingPool( final ObjectFactory factory, 88 final int min, 89 final int max ) throws Exception 90 { 91 this( factory, null, min, max ); 92 } 93 94 98 public SoftResourceLimitingPool( final ObjectFactory factory, 99 final PoolController controller, 100 final int min, 101 final int max ) 102 throws Exception 103 { 104 super( factory, controller, min, max ); 105 } 106 107 public SoftResourceLimitingPool( final Class clazz, final int initial, final int maximum ) 108 throws NoSuchMethodException , Exception 109 { 110 this( new DefaultObjectFactory( clazz ), initial, maximum ); 111 } 112 113 public SoftResourceLimitingPool( final Class clazz, final int initial ) 114 throws NoSuchMethodException , Exception 115 { 116 this( clazz, initial, initial ); 117 } 118 119 public void initialize() 120 throws Exception 121 { 122 this.grow( this.m_min ); 123 124 this.m_initialized = true; 125 } 126 127 public void grow( final int amount ) 128 { 129 try 130 { 131 m_mutex.acquire(); 132 133 this.internalGrow( amount ); 134 } 135 catch( final InterruptedException ie ) 136 { 137 if( getLogger().isWarnEnabled() ) 138 { 139 getLogger().warn( "Interrupted while waiting on lock", ie ); 140 } 141 } 142 catch( final Exception e ) 143 { 144 if( getLogger().isWarnEnabled() ) 145 { 146 getLogger().warn( "Could not grow the pool properly, an exception was caught", e ); 147 } 148 } 149 finally 150 { 151 m_mutex.release(); 152 } 153 } 154 155 public void shrink( final int amount ) 156 { 157 try 158 { 159 m_mutex.acquire(); 160 161 this.internalShrink( amount ); 162 } 163 catch( final InterruptedException ie ) 164 { 165 if( getLogger().isWarnEnabled() ) 166 { 167 getLogger().warn( "Interrupted while waiting on lock", ie ); 168 } 169 } 170 catch( final Exception e ) 171 { 172 if( getLogger().isWarnEnabled() ) 173 { 174 getLogger().warn( "Could not shrink the pool properly, an exception was caught", e ); 175 } 176 } 177 finally 178 { 179 m_mutex.release(); 180 } 181 } 182 } 183 | Popular Tags |