INT-1614 synchronize method now accepts the loacl directory as an argument rather than having its own direct reference

This commit is contained in:
Mark Fisher
2010-11-19 09:10:31 -05:00
parent e177797aef
commit 2c2d2fd38a
8 changed files with 13 additions and 36 deletions

View File

@@ -47,11 +47,6 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> implements I
*/
protected boolean shouldDeleteSourceFile;
/**
* The directory to which we write our synchronizations.
*/
private volatile Resource localDirectory;
/**
* An {@link FileListFilter} that runs against the <emphasis>remote</emphasis> file system view.
*/
@@ -63,14 +58,6 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> implements I
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;
}
@@ -110,7 +97,7 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> implements I
/**
* This is the callback where the subclasses must synchronize.
*/
protected abstract void syncRemoteToLocalFileSystem();
protected abstract void syncRemoteToLocalFileSystem(Resource localDirectory);
/**

View File

@@ -123,15 +123,6 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
}
}
/**
* Make sure the remote files get here.
*/
this.synchronizer.setLocalDirectory(this.localDirectory);
//this.synchronizer.setTaskScheduler(this.getTaskScheduler());
//this.synchronizer.setBeanFactory(this.getBeanFactory());
//this.synchronizer.setPhase(this.getPhase());
//this.synchronizer.setBeanName(this.getComponentName());
/**
* Forwards files once they ultimately appear in the {@link #localDirectory}.
*/
@@ -139,7 +130,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
this.fileSource.setFilter(this.buildFilter());
this.fileSource.setDirectory(this.localDirectory.getFile());
this.fileSource.afterPropertiesSet();
//this.synchronizer.afterPropertiesSet();
this.synchronizer.afterPropertiesSet();
}
catch (RuntimeException e) {
throw e;
@@ -160,7 +151,7 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
Assert.state(this.synchronizer != null, "synchronizer must not be null");
Message<File> message = this.fileSource.receive();
if (message == null) {
this.synchronizer.syncRemoteToLocalFileSystem();
this.synchronizer.syncRemoteToLocalFileSystem(this.localDirectory);
message = this.fileSource.receive();
}
return message;

View File

@@ -128,7 +128,6 @@ class FtpInboundSynchronizingMessageSourceFactoryBean
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, this.clientFactory);
FtpInboundRemoteFileSystemSynchronizer synchronizer = new FtpInboundRemoteFileSystemSynchronizer();
synchronizer.setClientPool(queuedFtpClientPool);
synchronizer.setLocalDirectory(this.localDirectoryResource);
synchronizer.setShouldDeleteSourceFile(ackRemoteDir);
synchronizer.setFilter(compositeFilter);
messageSource.setRemotePredicate(compositeFilter);

View File

@@ -62,7 +62,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
}
@Override
protected void syncRemoteToLocalFileSystem() {
protected void syncRemoteToLocalFileSystem(Resource localDirectory) {
try {
FTPClient client = this.clientPool.getClient();
Assert.state(client != null,
@@ -73,7 +73,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
try {
for (FTPFile ftpFile : fileList) {
if ((ftpFile != null) && ftpFile.isFile()) {
copyFileToLocalDirectory(client, ftpFile, this.getLocalDirectory());
copyFileToLocalDirectory(client, ftpFile, localDirectory);
}
}
}

View File

@@ -29,6 +29,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.ftp.client.DefaultFtpClientFactory;
import org.springframework.integration.ftp.client.QueuedFtpClientPool;
@@ -48,9 +49,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTest {
file.delete();
}
FtpInboundRemoteFileSystemSynchronizer syncronizer = new FtpInboundRemoteFileSystemSynchronizer();
syncronizer.setLocalDirectory(new FileSystemResource(System.getProperty("java.io.tmpdir")));
FileListFilter filter = new FtpPatternMatchingFileListFilter("foo.txt");
//
syncronizer.setFilter(filter);
DefaultFtpClientFactory factory = mock(DefaultFtpClientFactory.class);
@@ -71,7 +70,8 @@ public class FtpInboundRemoteFileSystemSynchronizerTest {
syncronizer.setShouldDeleteSourceFile(true);
syncronizer.afterPropertiesSet();
syncronizer.syncRemoteToLocalFileSystem();
Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
syncronizer.syncRemoteToLocalFileSystem(localDirectory);
verify(ftpClient, times(1)).retrieveFile(Mockito.anyString(), Mockito.any(OutputStream.class));
verify(ftpClient, times(1)).deleteFile(Mockito.anyString());

View File

@@ -59,7 +59,6 @@ public class SftpInboundChannelAdapterParser extends AbstractPollingInboundChann
"org.springframework.integration.sftp.inbound.SftpInboundSynchronizer");
synchronizerBuilder.addConstructorArgReference(sessionPollName);
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "remote-directory", "remotePath");
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "local-directory");
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "auto-delete-remote-files-on-sync", "shouldDeleteSourceFile");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(synchronizerBuilder, element, "filter");
BeanDefinitionBuilder messageSourceBuilder = BeanDefinitionBuilder.rootBeanDefinition(

View File

@@ -118,7 +118,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
@Override
@SuppressWarnings("unchecked")
protected void syncRemoteToLocalFileSystem() {
protected void syncRemoteToLocalFileSystem(Resource localDirectory) {
SftpSession session = null;
try {
session = sessionPool.getSession();
@@ -132,7 +132,7 @@ public class SftpInboundSynchronizer extends AbstractInboundRemoteFileSystemSych
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.getLocalDirectory());
copyFromRemoteToLocalDirectory(session, lsEntry, localDirectory);
}
}
}

View File

@@ -29,6 +29,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.sftp.session.SftpSession;
import org.springframework.integration.sftp.session.SftpSessionPool;
@@ -51,7 +52,6 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
}
SftpSessionPool sessionPool = mock(SftpSessionPool.class);
SftpInboundSynchronizer syncronizer = new SftpInboundSynchronizer(sessionPool);
syncronizer.setLocalDirectory(new FileSystemResource(System.getProperty("java.io.tmpdir")));
syncronizer.setRemotePath("foo/bar");
FileListFilter filter = mock(FileListFilter.class);
@@ -79,7 +79,8 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
syncronizer.setShouldDeleteSourceFile(true);
syncronizer.afterPropertiesSet();
syncronizer.syncRemoteToLocalFileSystem();
Resource localDirectory = new FileSystemResource(System.getProperty("java.io.tmpdir"));
syncronizer.syncRemoteToLocalFileSystem(localDirectory);
verify(sessionPool, times(1)).getSession();
verify(sftpSession, atLeast(1)).getChannel();