From c67ee979cdbf128520194831d7f4a890c4a68da3 Mon Sep 17 00:00:00 2001 From: Josh Long Date: Sat, 21 Aug 2010 02:21:14 +0000 Subject: [PATCH] cleaning up file adapter support, removing deprecated FileListFilter* hierarchy --- ...eFileSystemSynchronizingMessageSource.java | 5 +- .../config/FileListFilterFactoryBean.java | 13 +-- .../FileReadingMessageSourceFactoryBean.java | 52 ++++++++---- .../entries/CompositeEntryListFilter.java | 5 +- .../integration/file/entries/EntryNamer.java | 2 +- .../file/filters/AbstractFileListFilter.java | 54 ------------ .../filters/AcceptOnceFileListFilter.java | 71 ---------------- .../file/filters/CompositeFileListFilter.java | 82 ------------------- .../file/filters/FileListFilter.java | 36 -------- .../PatternMatchingFileListFilter.java | 49 ----------- .../AbstractEventDrivenFileMonitor.java | 6 +- .../file/CompositeFileListFilterTests.java | 3 +- .../PatternMatchingFileListFilterTests.java | 2 +- 13 files changed, 53 insertions(+), 327 deletions(-) delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/filters/CompositeFileListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java delete mode 100644 spring-integration-file/src/main/java/org/springframework/integration/file/filters/PatternMatchingFileListFilter.java diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java index bac4b1370e..5b10d86056 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/AbstractInboundRemoteFileSystemSynchronizingMessageSource.java @@ -7,6 +7,7 @@ import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.file.entries.*; import java.io.File; +import java.util.Arrays; import java.util.regex.Pattern; @@ -76,7 +77,9 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource< private EntryListFilter buildFilter() { FileEntryNamer fileEntryNamer = new FileEntryNamer(); Pattern completePattern = Pattern.compile("^.*(?(new AcceptOnceEntryFileListFilter(), new PatternMatchingEntryListFilter(fileEntryNamer, completePattern)); + return new CompositeEntryListFilter( + Arrays.asList( + new AcceptOnceEntryFileListFilter(), new PatternMatchingEntryListFilter(fileEntryNamer, completePattern))); } @Override diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileListFilterFactoryBean.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileListFilterFactoryBean.java index 6cd13164c0..21f4ec9a58 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileListFilterFactoryBean.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileListFilterFactoryBean.java @@ -77,7 +77,7 @@ public class FileListFilterFactoryBean implements FactoryBean flf=null; + EntryListFilter flf ; if ((this.filterReference != null) && (this.filenamePattern != null)) { throw new IllegalArgumentException("The 'filter' reference and " + "'filename-pattern' attributes are mutually exclusive."); @@ -99,12 +99,12 @@ public class FileListFilterFactoryBean implements FactoryBean(); - } else { // preventDuplicates is either TRUE or NULL + } else { // preventDuplicates is either TRUE or NULL flf = new AcceptOnceEntryFileListFilter(); } // finally, it might be that they simply want a {@link CompositeEntryListFilter} - if ((this.filterReferences != null) && (this.filterReferences.size() > 0) ) { + if ((this.filterReferences != null) && (this.filterReferences.size() > 0)) { CompositeEntryListFilter flfc = new CompositeEntryListFilter(); for (EntryListFilter ff : filterReferences) @@ -112,14 +112,17 @@ public class FileListFilterFactoryBean implements FactoryBean(); + + if (flf == null) { + flf = new CompositeEntryListFilter(); + } this.fileListFilter = flf; } private CompositeEntryListFilter createCompositeWithAcceptOnceFilter(EntryListFilter otherFilter) { CompositeEntryListFilter compositeFilter = new CompositeEntryListFilter(); - compositeFilter.addFilter(new AcceptOnceEntryFileListFilter() ); + compositeFilter.addFilter(new AcceptOnceEntryFileListFilter()); compositeFilter.addFilter(otherFilter); return compositeFilter; diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileReadingMessageSourceFactoryBean.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileReadingMessageSourceFactoryBean.java index aa0c41b79e..00932172ad 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileReadingMessageSourceFactoryBean.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileReadingMessageSourceFactoryBean.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.integration.file.config; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.FactoryBean; + import org.springframework.integration.file.DirectoryScanner; import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.integration.file.entries.CompositeEntryListFilter; @@ -26,64 +27,65 @@ import org.springframework.integration.file.entries.EntryListFilter; import org.springframework.integration.file.locking.AbstractFileLockerFilter; import java.io.File; + +import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; + /** * @author Mark Fisher * @author Iwein Fuld * @since 1.0.3 */ public class FileReadingMessageSourceFactoryBean implements FactoryBean { - private static Log logger = LogFactory.getLog(FileReadingMessageSourceFactoryBean.class); - private volatile FileReadingMessageSource source; - private volatile File directory; - private volatile EntryListFilter filter; - private volatile AbstractFileLockerFilter locker; - private volatile Comparator comparator; - private volatile DirectoryScanner scanner; - private volatile Boolean scanEachPoll; - private volatile Boolean autoCreateDirectory; - private volatile Integer queueSize; - private final Object initializationMonitor = new Object(); + @SuppressWarnings("unused") public void setDirectory(File directory) { this.directory = directory; } + @SuppressWarnings("unused") public void setComparator(Comparator comparator) { this.comparator = comparator; } + @SuppressWarnings("unused") public void setScanner(DirectoryScanner scanner) { this.scanner = scanner; } + @SuppressWarnings("unused") public void setFilter(EntryListFilter filter) { - if (filter instanceof AbstractFileLockerFilter && this.locker == null) { + if (filter instanceof AbstractFileLockerFilter && (this.locker == null)) { this.setLocker((AbstractFileLockerFilter) filter); } + this.filter = filter; } + @SuppressWarnings("unused") public void setScanEachPoll(Boolean scanEachPoll) { this.scanEachPoll = scanEachPoll; } + @SuppressWarnings("unused") public void setAutoCreateDirectory(Boolean autoCreateDirectory) { this.autoCreateDirectory = autoCreateDirectory; } + @SuppressWarnings("unused") public void setQueueSize(Integer queueSize) { this.queueSize = queueSize; } @@ -96,6 +98,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean(this.filter, this.locker)); + CompositeEntryListFilter fileCompositeEntryListFilter = new CompositeEntryListFilter(); + + for (EntryListFilter filter : Arrays.asList(this.filter, this.locker)) + fileCompositeEntryListFilter.addFilter(filter); + + this.source.setFilter(fileCompositeEntryListFilter); this.source.setLocker(locker); } } + if (this.scanEachPoll != null) { this.source.setScanEachPoll(this.scanEachPoll); } + if (this.autoCreateDirectory != null) { this.source.setAutoCreateDirectory(this.autoCreateDirectory); } + this.source.afterPropertiesSet(); } } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java index 8ba156a376..117a1649d3 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/CompositeEntryListFilter.java @@ -16,7 +16,6 @@ package org.springframework.integration.file.entries; import org.springframework.beans.factory.InitializingBean; - import org.springframework.util.Assert; import java.util.*; @@ -25,8 +24,8 @@ import java.util.*; public class CompositeEntryListFilter implements EntryListFilter { private final Set> fileFilters; - public CompositeEntryListFilter(EntryListFilter... fileFilters) { - this.fileFilters = new LinkedHashSet>(Arrays.asList(fileFilters)); + public CompositeEntryListFilter() { + this.fileFilters = new LinkedHashSet>(); } public CompositeEntryListFilter(Collection> fileFilters) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryNamer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryNamer.java index fde16e3a34..bc32b29e19 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryNamer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/entries/EntryNamer.java @@ -16,7 +16,7 @@ package org.springframework.integration.file.entries; /** - * Responsible for coercing a String identification out of the {@link T} entry. + * Responsible for coercing a String identification out of the T entry. * @param the type of entry (there's an implementation for FTP, SFTP, and plain-old java.io.Files) * * @author Josh Long diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java deleted file mode 100644 index c38d35d153..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.filters; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * A convenience base class for any {@link FileListFilter} whose criteria can be - * evaluated against each File in isolation. If the entire List of files is - * required for evaluation, implement the FileListFilter interface directly. - * - * @author Mark Fisher - * @author Iwein Fuld - */ -@Deprecated -public abstract class AbstractFileListFilter implements FileListFilter { - - /** - * {@inheritDoc} - */ - public final List filterFiles(File[] files) { - List accepted = new ArrayList(); - if (files != null) { - for (File file : files) { - if (this.accept(file)) { - accepted.add(file); - } - } - } - return accepted; - } - - /** - * Subclasses must implement this method. - */ - protected abstract boolean accept(File file); - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java deleted file mode 100644 index 9cd914ec7c..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.file.filters; - -import java.io.File; -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - - -/** - * {@link FileListFilter} that passes files only one time. This can - * conveniently be used to prevent duplication of files, as is done in - * {@link org.springframework.integration.file.FileReadingMessageSource}. - *

- * This implementation is thread safe. - * - * @author Iwein Fuld - * @since 1.0.0 - */ -@Deprecated -public class AcceptOnceFileListFilter extends AbstractFileListFilter { - private final Queue seen; - private final Object monitor = new Object(); - - /** - * Creates an AcceptOnceFileFilter that is based on a bounded queue. If the - * queue overflows, files that fall out will be passed through this filter - * again if passed to the {@link #filterFiles(File[])} method. - * - * @param maxCapacity the maximum number of Files to maintain in the 'seen' - * queue. - */ - public AcceptOnceFileListFilter(int maxCapacity) { - this.seen = new LinkedBlockingQueue(maxCapacity); - } - - /** - * Creates an AcceptOnceFileFilter based on an unbounded queue. - */ - public AcceptOnceFileListFilter() { - this.seen = new LinkedBlockingQueue(); - } - - protected boolean accept(File pathname) { - synchronized (this.monitor) { - if (seen.contains(pathname)) { - return false; - } - - if (!seen.offer(pathname)) { - seen.poll(); - seen.add(pathname); - } - - return true; - } - } -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/CompositeFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/CompositeFileListFilter.java deleted file mode 100644 index c97ed0e12b..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/CompositeFileListFilter.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2002-2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.file.filters; - -import org.springframework.util.Assert; - -import java.io.File; -import java.io.FileFilter; -import java.util.*; - - -/** - * Composition that delegates to multiple {@link FileFilter}s. The composition is AND based, meaning that a file must - * pass through each filter's {@link #filterFiles(java.io.File[])} method in order to be accepted by the composite. - * - * @author Iwein Fuld - * @author Mark Fisher - */ -@Deprecated -public class CompositeFileListFilter implements FileListFilter { - private final Set fileFilters; - - public CompositeFileListFilter(FileListFilter... fileFilters) { - this.fileFilters = new LinkedHashSet(Arrays.asList(fileFilters)); - } - - public CompositeFileListFilter(Collection fileFilters) { - this.fileFilters = new LinkedHashSet(fileFilters); - } - - /** - * {@inheritDoc} - *

- * This implementation delegates to a collection of filters and returns only files that pass all the filters. - */ - public List filterFiles(File[] files) { - Assert.notNull(files, "'files' should not be null"); - - List leftOver = Arrays.asList(files); - - for (FileListFilter fileFilter : this.fileFilters) { - leftOver = fileFilter.filterFiles(leftOver.toArray(new File[]{})); - } - - return leftOver; - } - - /** - * @param filters one or more new filters to add - * @return this CompositeFileFilter instance with the added filters - */ - /* public CompositeFileListFilter addFilter(FileListFilter... filters) { - return addFilters(Arrays.asList(filters)); - }*/ - - /** - * Not thread safe. Only a single thread may add filters at a time. - *

- * Add the new filters to this CompositeFileFilter while maintaining the existing filters. - * - * @param filtersToAdd a list of filters to add - * @return this CompositeFileFilter instance with the added filters - */ -/* public CompositeFileListFilter addFilters(Collection filtersToAdd) { - this.fileFilters.addAll(filtersToAdd); - - return this; - }*/ -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java deleted file mode 100644 index 3a77093669..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/FileListFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.filters; - -import java.io.File; -import java.util.List; - -/** - * Strategy interface for filtering a group of files. - * - * @author Iwein Fuld - */ -@Deprecated -public interface FileListFilter { - - /** - * Filters out files and returns the files that are left in a list, or an - * empty list when a null is passed in. - */ - List filterFiles(File[] files); - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/PatternMatchingFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/PatternMatchingFileListFilter.java deleted file mode 100644 index 786477c454..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/PatternMatchingFileListFilter.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.file.filters; - -import java.io.File; -import java.util.regex.Pattern; - -import org.springframework.util.Assert; - -/** - * A {@link FileListFilter} implementation that matches against a {@link Pattern}. - * - * @author Mark Fisher - */ -@Deprecated -public class PatternMatchingFileListFilter extends AbstractFileListFilter { - - private final Pattern pattern; - - - /** - * Create a filter for the given pattern. - */ - public PatternMatchingFileListFilter(Pattern pattern) { - Assert.notNull(pattern, "pattern must not be null"); - this.pattern = pattern; - } - - - protected boolean accept(File file) { - return (file != null) - && this.pattern.matcher(file.getName()).matches(); - } - -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/AbstractEventDrivenFileMonitor.java b/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/AbstractEventDrivenFileMonitor.java index 4d47ca5186..69e8e610c4 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/AbstractEventDrivenFileMonitor.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/monitors/AbstractEventDrivenFileMonitor.java @@ -20,11 +20,7 @@ import java.util.concurrent.LinkedBlockingQueue; * or Java 7's NIO.2 WaterService or other third party implementations. *

* In the meantime, this provides us with a base class for building event driven file adapters quickly. The two cases I see are: - *

- *

    - *
  1. - *
  2. - *
+ * * * @author Josh Long */ diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java index bb0e28edf3..32c5bd7d64 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/CompositeFileListFilterTests.java @@ -44,7 +44,8 @@ public class CompositeFileListFilterTests { @Test public void forwardedToFilters() throws Exception { - CompositeEntryListFilter compositeFileFilter = new CompositeEntryListFilter(fileFilterMock1, fileFilterMock2); + CompositeEntryListFilter compositeFileFilter = new CompositeEntryListFilter(); + compositeFileFilter .addFilter(fileFilterMock1);compositeFileFilter.addFilter( fileFilterMock2); List returnedFiles = Arrays.asList( fileMock); when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles); when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java index 431b221665..dab0cd2ec0 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java @@ -72,7 +72,7 @@ public class PatternMatchingFileListFilterTests { } - @Test + @Test @SuppressWarnings("unchecked") public void patternEditorInContext() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "patternMatchingFileListFilterTests.xml", this.getClass());