@Override public void run() { Thread thread = Thread.currentThread(); runningThreads.add(thread); File compressedFile = getCompressedFile(rotatedFile); try { unsafeSyncCompress(rotatedFile, compressedFile); callback.onSuccess(policy, dateTime, compressedFile); } catch (Exception error) { String message = String.format( "compression failure {dateTime=%s, rotatedFile=%s, compressedFile=%s}", dateTime, rotatedFile, compressedFile); RuntimeException extendedError = new RuntimeException(message, error); callback.onFailure(policy, dateTime, rotatedFile, extendedError); } finally { runningThreads.remove(thread); } } };
@Override public void rotate(RotationPolicy policy, LocalDateTime dateTime) { boolean acquired = rotationLock.tryLock(); if (!acquired) { config.getCallback().onConflict(policy, dateTime); } else { try { unsafeRotate(policy, dateTime); } catch (Exception error) { String message = String.format("rotation failure {dateTime=%s}", dateTime); RuntimeException extendedError = new RuntimeException(message); config.getCallback().onFailure(policy, dateTime, null, extendedError); } finally { rotationLock.unlock(); } } }
@Override public void run() { // Get file size. LocalDateTime now = config.getClock().now(); File file = config.getFile(); long byteCount; try { byteCount = file.length(); } catch (Exception error) { String message = String.format("failed accessing file size (file=%s)", file); Exception extendedError = new IOException(message, error); config.getCallback().onFailure(SizeBasedRotationPolicy.this, now, file, extendedError); return; } // Rotate if necessary. if (byteCount > maxByteCount) { LOGGER.debug("triggering {byteCount={}}", byteCount); config.getCallback().onTrigger(SizeBasedRotationPolicy.this, now); rotatable.rotate(SizeBasedRotationPolicy.this, now); } } };
String message = String.format("rename failure {file=%s, rotatedFile=%s}", config.getFile(), rotatedFile); IOException error = new IOException(message); config.getCallback().onFailure(policy, dateTime, rotatedFile, error); return;