@ Override public void run ( ) { if ( ! stateUpdater . compareAndSet ( this , 1 , 2 ) ) { return ; } if ( forceLogRotation ) { doRotate ( ) ; } else if ( initialRun && Files . exists ( defaultLogFile ) ) { //if there is an existing log file check if it should be rotated long lm = 0 ; try { lm = Files . getLastModifiedTime ( defaultLogFile ) . toMillis ( ) ; } catch ( IOException e ) { UndertowLogger . ROOT_LOGGER . errorRotatingAccessLog ( e ) ; } Calendar c = Calendar . getInstance ( ) ; c . setTimeInMillis ( changeOverPoint ) ; c . add ( Calendar . DATE , - 1 ) ; if ( lm <= c . getTimeInMillis ( ) ) { doRotate ( ) ; } } initialRun = false ; List < String > messages = new ArrayList <> ( ) ; String msg ; //only grab at most 1000 messages at a time for ( int i = 0 ; i < 1000 ; ++ i ) { msg = pendingMessages . poll ( ) ; if ( msg == null ) { break ; } messages . add ( msg ) ; } try { if ( ! messages . isEmpty ( ) ) { writeMessage ( messages ) ; } } finally { stateUpdater . set ( this , 0 ) ; //check to see if there is still more messages //if so then run this again if ( ! pendingMessages . isEmpty ( ) || forceLogRotation ) { if ( stateUpdater . compareAndSet ( this , 0 , 1 ) ) { logWriteExecutor . execute ( this ) ; } } else if ( closed ) { try { if ( writer != null ) { writer . flush ( ) ; writer . close ( ) ; writer = null ; } } catch ( IOException e ) { UndertowLogger . ROOT_LOGGER . errorWritingAccessLog ( e ) ; } } } }
processes all queued log messages