1 17 package org.apache.log.output.io.rotate; 18 19 import java.io.File ; 20 import java.util.Calendar ; 21 import java.util.GregorianCalendar ; 22 23 28 public class RotateStrategyByTimeOfDay 29 implements RotateStrategy 30 { 31 32 private static final long TIME_24_HOURS = 24 * 3600 * 1000; 33 34 35 private long m_currentRotation; 36 37 41 public RotateStrategyByTimeOfDay() 42 { 43 this( 0 ); 44 } 45 46 51 public RotateStrategyByTimeOfDay( final long time ) 52 { 53 final GregorianCalendar cal = new GregorianCalendar (); 55 cal.set( Calendar.MILLISECOND, 0 ); 56 cal.set( Calendar.SECOND, 0 ); 57 cal.set( Calendar.MINUTE, 0 ); 58 cal.set( Calendar.HOUR_OF_DAY, 0 ); 59 m_currentRotation = cal.getTime().getTime() + time; 60 61 if( m_currentRotation > System.currentTimeMillis() ) 63 { 64 m_currentRotation -= TIME_24_HOURS; 65 } 66 } 67 68 71 public void reset() 72 { 73 final long now = System.currentTimeMillis(); 74 75 while( m_currentRotation + TIME_24_HOURS < now ) 78 { 79 m_currentRotation += TIME_24_HOURS; 80 } 81 } 82 83 92 public boolean isRotationNeeded( final String data, final File file ) 93 { 94 final long now = System.currentTimeMillis(); 95 if( m_currentRotation + TIME_24_HOURS < now ) 96 { 97 return true; 99 } 100 else 101 { 102 return false; 103 } 104 } 105 } 106 107 | Popular Tags |