1 50 package org.apache.avalon.excalibur.pool; 51 52 60 public class ValidatedResourceLimitingPool 61 extends ResourceLimitingPool 62 { 63 66 70 private boolean m_needsValidation; 71 72 75 91 public ValidatedResourceLimitingPool( final ObjectFactory factory, 92 int max, 93 boolean maxStrict, 94 boolean blocking, 95 long blockTimeout, 96 long trimInterval ) 97 { 98 99 super( factory, max, maxStrict, blocking, blockTimeout, trimInterval ); 100 } 101 102 105 115 public Poolable get() throws Exception 116 { 117 Poolable poolable; 118 boolean needsValidation; 119 120 do 123 { 124 synchronized( m_semaphore ) 125 { 126 m_needsValidation = true; 129 130 poolable = super.get(); 131 132 needsValidation = m_needsValidation; 135 } 136 137 if( needsValidation ) 139 { 140 if( !validatePoolable( poolable ) ) 142 { 143 synchronized( m_semaphore ) 146 { 147 if( getLogger().isDebugEnabled() ) 148 { 149 getLogger().debug( "Removing a " + poolable.getClass().getName() 150 + " from the pool because it failed validation." ); 151 } 152 153 permanentlyRemovePoolable( poolable ); 154 poolable = null; 155 } 156 } 157 } 158 } while( poolable == null ); 159 160 return poolable; 161 } 162 163 166 173 protected Poolable newPoolable() throws Exception 174 { 175 m_needsValidation = false; 177 178 return super.newPoolable(); 179 } 180 181 184 193 protected boolean validatePoolable( Poolable poolable ) throws Exception 194 { 195 if( poolable instanceof Validatable ) 196 { 197 return ( (Validatable)poolable ).validate(); 198 } 199 else 200 { 201 return true; 202 } 203 } 204 } 205 206 | Popular Tags |