From baa8fdc4f5a673caff7cee34455f8f5e2c819c30 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 15 Jan 2016 11:04:37 -0500 Subject: [PATCH] INT-3574: Polishing Synchronize state clearance when message received while stopped. Make `DefaultFlushPredicate` `static`. --- .../file/FileWritingMessageHandler.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 40f56bbc45..df3eb5e080 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -510,9 +510,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand try { if (state == null || FileWritingMessageHandler.this.flushTask == null) { bos.close(); - if (state != null) { - fileStates.remove(fileToWriteTo.getAbsolutePath()); - } + clearState(fileToWriteTo, state); } else { state.lastWrite = System.currentTimeMillis(); @@ -584,9 +582,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand try { if (state == null || FileWritingMessageHandler.this.flushTask == null) { bos.close(); - if (state != null) { - fileStates.remove(fileToWriteTo.getAbsolutePath()); - } + clearState(fileToWriteTo, state); } else { state.lastWrite = System.currentTimeMillis(); @@ -627,9 +623,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand try { if (state == null || FileWritingMessageHandler.this.flushTask == null) { writer.close(); - if (state != null) { - fileStates.remove(fileToWriteTo.getAbsolutePath()); - } + clearState(fileToWriteTo, state); } else { state.lastWrite = System.currentTimeMillis(); @@ -832,6 +826,12 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand } } + private synchronized void clearState(final File fileToWriteTo, final FileState state) { + if (state != null) { + fileStates.remove(fileToWriteTo.getAbsolutePath()); + } + } + private static final class FileState { @@ -932,7 +932,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand /** * Flushes files where the path matches a pattern, regardless of last write time. */ - private final class DefaultFlushPredicate implements MessageFlushPredicate { + private static final class DefaultFlushPredicate implements MessageFlushPredicate { @Override public boolean shouldFlush(String fileAbsolutePath, long lastWrite, Message triggerMessage) {