| 1 | // $Id: CostCalculationEngine.java,v 1.3 2003-08-23 16:53:47 cvs Exp $ |
| 2 | // |
| 3 | package diskCacheV111.pools ; |
| 4 | |
| 5 | import java.lang.reflect.* ; |
| 6 | import java.util.* ; |
| 7 | |
| 8 | public class CostCalculationEngine { |
| 9 | private Class _class = null ; |
| 10 | private Constructor _constructor = null ; |
| 11 | private final static Class [] _classArgs = { diskCacheV111.pools.PoolCostInfo.class } ; |
| 12 | public CostCalculationEngine( String algorithmClass ) |
| 13 | throws |
| 14 | ClassNotFoundException , |
| 15 | NoSuchMethodException { |
| 16 | |
| 17 | _class = Class.forName(algorithmClass) ; |
| 18 | _constructor = _class.getConstructor( _classArgs ) ; |
| 19 | |
| 20 | } |
| 21 | public CostCalculatable getCostCalculatable( PoolCostInfo info ) |
| 22 | throws MissingResourceException { |
| 23 | |
| 24 | Object [] args = { info } ; |
| 25 | long started = System.currentTimeMillis() ; |
| 26 | |
| 27 | try{ |
| 28 | |
| 29 | return (CostCalculatable)_constructor.newInstance( args ) ; |
| 30 | |
| 31 | }catch(Exception ee ){ |
| 32 | throw new |
| 33 | MissingResourceException( "Can't create cost calculator : "+ee , |
| 34 | _class.getName() , info.getPoolName() ) ; |
| 35 | }finally{ |
| 36 | // System.out.println("newInstance(CostCalculatable) : "+ |
| 37 | // (System.currentTimeMillis()-started)); |
| 38 | } |
| 39 | } |
| 40 | } |