INT-1614 encapsulation
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.springframework.integration.file.synchronization;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.file.filters.AcceptAllFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
|
||||
/**
|
||||
@@ -48,23 +50,27 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> implements I
|
||||
/**
|
||||
* The directory to which we write our synchronizations.
|
||||
*/
|
||||
protected volatile Resource localDirectory;
|
||||
private volatile Resource localDirectory;
|
||||
|
||||
/**
|
||||
* An {@link FileListFilter} that runs against the <emphasis>remote</emphasis> file system view.
|
||||
*/
|
||||
protected volatile FileListFilter<F> filter = new AcceptAllFileListFilter<F>();
|
||||
private volatile FileListFilter<F> filter;
|
||||
|
||||
/**
|
||||
* The {@link EntryAcknowledgmentStrategy} implementation.
|
||||
*/
|
||||
protected EntryAcknowledgmentStrategy<F> entryAcknowledgmentStrategy;
|
||||
private EntryAcknowledgmentStrategy<F> entryAcknowledgmentStrategy;
|
||||
|
||||
|
||||
public void setLocalDirectory(Resource localDirectory) {
|
||||
this.localDirectory = localDirectory;
|
||||
}
|
||||
|
||||
protected Resource getLocalDirectory() {
|
||||
return this.localDirectory;
|
||||
}
|
||||
|
||||
public void setFilter(FileListFilter<F> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
@@ -91,12 +97,16 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> implements I
|
||||
* @throws Exception
|
||||
* escape hatch exception, let the adapter deal with it.
|
||||
*/
|
||||
protected void acknowledge(Object usefulContextOrClientData, F file) throws Exception {
|
||||
protected final void acknowledge(Object usefulContextOrClientData, F file) throws Exception {
|
||||
if (this.entryAcknowledgmentStrategy != null) {
|
||||
this.entryAcknowledgmentStrategy.acknowledge(usefulContextOrClientData, file);
|
||||
}
|
||||
}
|
||||
|
||||
protected final List<F> filterFiles(F[] files) {
|
||||
return (this.filter != null) ? this.filter.filterFiles(files) : Arrays.asList(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the callback where the subclasses must synchronize.
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(this.clientPool, "clientPool must not be null");
|
||||
if (this.shouldDeleteSourceFile) {
|
||||
this.entryAcknowledgmentStrategy = new DeletionEntryAcknowledgmentStrategy();
|
||||
this.setEntryAcknowledgmentStrategy(new DeletionEntryAcknowledgmentStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,11 +69,11 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
|
||||
FtpClientPool.class.getSimpleName() +
|
||||
" returned a 'null' client. " +
|
||||
"This is most likely a bug in the pool implementation.");
|
||||
Collection<FTPFile> fileList = this.filter.filterFiles(client.listFiles());
|
||||
Collection<FTPFile> fileList = this.filterFiles(client.listFiles());
|
||||
try {
|
||||
for (FTPFile ftpFile : fileList) {
|
||||
if ((ftpFile != null) && ftpFile.isFile()) {
|
||||
copyFileToLocalDirectory(client, ftpFile, this.localDirectory);
|
||||
copyFileToLocalDirectory(client, ftpFile, this.getLocalDirectory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(this.remotePath, "'remotePath' must not be null");
|
||||
if (this.shouldDeleteSourceFile) {
|
||||
this.entryAcknowledgmentStrategy = new DeletionEntryAcknowledgmentStrategy();
|
||||
this.setEntryAcknowledgmentStrategy(new DeletionEntryAcknowledgmentStrategy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
|
||||
Collection<ChannelSftp.LsEntry> beforeFilter = channelSftp.ls(remotePath);
|
||||
ChannelSftp.LsEntry[] entries = (beforeFilter == null) ? new ChannelSftp.LsEntry[0] :
|
||||
beforeFilter.toArray(new ChannelSftp.LsEntry[beforeFilter.size()]);
|
||||
Collection<ChannelSftp.LsEntry> files = this.filter.filterFiles(entries);
|
||||
Collection<ChannelSftp.LsEntry> files = this.filterFiles(entries);
|
||||
for (ChannelSftp.LsEntry lsEntry : files) {
|
||||
if ((lsEntry != null) && !lsEntry.getAttrs().isDir() && !lsEntry.getAttrs().isLink()) {
|
||||
copyFromRemoteToLocalDirectory(session, lsEntry, this.localDirectory);
|
||||
copyFromRemoteToLocalDirectory(session, lsEntry, this.getLocalDirectory());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
|
||||
IOUtils.closeQuietly(in);
|
||||
IOUtils.closeQuietly(fileOutputStream);
|
||||
}
|
||||
if (tmpLocalTarget.renameTo(localFile) && this.entryAcknowledgmentStrategy != null) {
|
||||
if (tmpLocalTarget.renameTo(localFile)) {
|
||||
this.acknowledge(sftpSession, entry);
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user