From: Arne V. <cob...@us...> - 2004-06-29 09:34:53
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4435/org/jrobin/core Modified Files: RrdDb.java Log Message: JRobin 1.4.0 - Moved RrdOpener to core package - Fixed Javadoc comments - Fixed 0 end timestamp Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** RrdDb.java 9 Jun 2004 12:10:29 -0000 1.20 --- RrdDb.java 29 Jun 2004 09:34:38 -0000 1.21 *************** *** 552,555 **** --- 552,598 ---- /** + * Finds the archive that best matches to the start time (time period being start-time until now) + * and requested resolution. + * @param consolFun Consolidation function of the datasource. + * @param startTime Start time of the time period in seconds. + * @param resolution Requested fetch resolution. + * @return Reference to the best matching archive. + * @throws IOException Thrown in case of I/O related error. + */ + public Archive findStartMatchArchive( String consolFun, long startTime, long resolution ) throws IOException { + long arcStep, diff; + int fallBackIndex = 0; + int arcIndex = -1; + long minDiff = Long.MAX_VALUE; + long fallBackDiff = Long.MAX_VALUE; + + for ( int i = 0; i < archives.length; i++ ) + { + if ( archives[i].getConsolFun().equals(consolFun) ) + { + arcStep = archives[i].getArcStep(); + diff = Math.abs( resolution - arcStep ); + + // Now compare start time, see if this archive encompasses the requested interval + if ( startTime >= archives[i].getStartTime() ) + { + if ( diff == 0 ) // Best possible match either way + return archives[i]; + else if ( diff < minDiff ) { + minDiff = diff; + arcIndex = i; + } + } + else if ( diff < fallBackDiff ) { + fallBackDiff = diff; + fallBackIndex = i; + } + } + } + + return ( arcIndex >= 0 ? archives[arcIndex] : archives[fallBackIndex] ); + } + + /** * <p>Returns string representing complete internal RRD state. The returned * string can be printed to <code>stdout</code> and/or used for debugging purposes.</p> |