392 lockFileName = generate(pattern, 0, unique).toString() + ".lck"; 393 // Now try to lock that filename. 394 // Because some systems (e.g., Solaris) can only do file locks 395 // between processes (and not within a process), we first check 396 // if we ourself already have the file locked. 397 synchronized(locks) { 398 if (locks.get(lockFileName) != null) { 399 // We already own this lock, for a different FileHandler 400 // object. Try again. 401 continue; 402 } 403 FileChannel fc; 404 try { 405 lockStream = new FileOutputStream(lockFileName); 406 fc = lockStream.getChannel(); 407 } catch (IOException ix) { 408 // We got an IOException while trying to open the file. 409 // Try the next file. 410 continue; 411 } 412 try { 413 FileLock fl = fc.tryLock(); 414 if (fl == null) { 415 // We failed to get the lock. Try next file. 416 continue; 417 } 418 // We got the lock OK. 419 } catch (IOException ix) { 420 // We got an IOException while trying to get the lock. 421 // This normally indicates that locking is not supported 422 // on the target directory. We have to proceed without 423 // getting a lock. Drop through. 424 } 425 // We got the lock. Remember it. 426 locks.put(lockFileName, lockFileName); 427 break; 428 } 429 } 430 431 files = new File[count]; 432 for (int i = 0; i < count; i++) { 433 files[i] = generate(pattern, i, unique); 434 } 435 436 // Create the initial log file. 437 if (append) { 438 open(files[0], true); 439 } else { 440 rotate(); 441 } 442 443 // Did we detect any exceptions during initialization? 444 Exception ex = em.lastException; 445 if (ex != null) { 446 if (ex instanceof IOException) { 447 throw (IOException) ex; 448 } else if (ex instanceof SecurityException) { 449 throw (SecurityException) ex; | 392 lockFileName = generate(pattern, 0, unique).toString() + ".lck"; 393 // Now try to lock that filename. 394 // Because some systems (e.g., Solaris) can only do file locks 395 // between processes (and not within a process), we first check 396 // if we ourself already have the file locked. 397 synchronized(locks) { 398 if (locks.get(lockFileName) != null) { 399 // We already own this lock, for a different FileHandler 400 // object. Try again. 401 continue; 402 } 403 FileChannel fc; 404 try { 405 lockStream = new FileOutputStream(lockFileName); 406 fc = lockStream.getChannel(); 407 } catch (IOException ix) { 408 // We got an IOException while trying to open the file. 409 // Try the next file. 410 continue; 411 } 412 boolean available = false; 413 try { 414 available = fc.tryLock() != null; 415 // We got the lock OK. 416 } catch (IOException ix) { 417 // We got an IOException while trying to get the lock. 418 // This normally indicates that locking is not supported 419 // on the target directory. We have to proceed without 420 // getting a lock. Drop through. 421 available = true; 422 } 423 if (available) { 424 // We got the lock. Remember it. 425 locks.put(lockFileName, lockFileName); 426 break; 427 } 428 429 // We failed to get the lock. Try next file. 430 fc.close(); 431 } 432 } 433 434 files = new File[count]; 435 for (int i = 0; i < count; i++) { 436 files[i] = generate(pattern, i, unique); 437 } 438 439 // Create the initial log file. 440 if (append) { 441 open(files[0], true); 442 } else { 443 rotate(); 444 } 445 446 // Did we detect any exceptions during initialization? 447 Exception ex = em.lastException; 448 if (ex != null) { 449 if (ex instanceof IOException) { 450 throw (IOException) ex; 451 } else if (ex instanceof SecurityException) { 452 throw (SecurityException) ex; |