private void openFiles ( ) throws IOException { LogManager manager = LogManager . getLogManager ( ) ; manager . checkPermission ( ) ; if ( count < 1 ) { throw new IllegalArgumentException ( "file count = " + count ) ; } if ( limit < 0 ) { limit = 0 ; } // We register our own ErrorManager during initialization // so we can record exceptions. InitializationErrorManager em = new InitializationErrorManager ( ) ; setErrorManager ( em ) ; // Create a lock file. This grants us exclusive access // to our set of output files, as long as we are alive. int unique = - 1 ; for ( ; ; ) { unique ++ ; if ( unique > MAX_LOCKS ) { throw new IOException ( "Couldn't get lock for " + pattern ) ; } // Generate a lock file name from the "unique" int. lockFileName = generate ( pattern , 0 , unique ) . toString ( ) + ".lck" ; // Now try to lock that filename. // Because some systems (e.g., Solaris) can only do file locks // between processes (and not within a process), we first check // if we ourself already have the file locked. synchronized ( locks ) { if ( locks . get ( lockFileName ) != null ) { // We already own this lock, for a different FileHandler // object. Try again. continue ; } FileChannel fc ; try { lockStream = new FileOutputStream ( lockFileName ) ; fc = lockStream . getChannel ( ) ; } catch ( IOException ix ) { // We got an IOException while trying to open the file. // Try the next file. continue ; } boolean available ; try { available = fc . tryLock ( ) != null ; // We got the lock OK. } catch ( IOException ix ) { // We got an IOException while trying to get the lock. // This normally indicates that locking is not supported // on the target directory. We have to proceed without // getting a lock. Drop through. available = true ; } if ( available ) { // We got the lock. Remember it. locks . put ( lockFileName , lockFileName ) ; break ; } // We failed to get the lock. Try next file. fc . close ( ) ; } } files = new File [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { files [ i ] = generate ( pattern , i , unique ) ; } // Create the initial log file. if ( append ) { open ( files [ 0 ] , true ) ; } else { rotate ( ) ; } // Did we detect any exceptions during initialization? Exception ex = em . lastException ; if ( ex != null ) { if ( ex instanceof IOException ) { throw ( IOException ) ex ; } else if ( ex instanceof SecurityException ) { throw ( SecurityException ) ex ; } else { throw new IOException ( "Exception: " + ex ) ; } } // Install the normal default ErrorManager. setErrorManager ( new ErrorManager ( ) ) ; }
configured instance variables .