INT-1614 refactoring FTP and SFTP so that base class receive() calls synchronizer on demand for both (was for SFTP but not FTP).

This commit is contained in:
Mark Fisher
2010-11-19 07:47:54 -05:00
parent 1dc64b2914
commit 45798c5345
5 changed files with 16 additions and 22 deletions

View File

@@ -132,7 +132,7 @@ public abstract class AbstractInboundRemoteFileSystemSychronizer<F> extends Abst
/**
* This is the callback where we need the implementation to do some specific work
*/
protected abstract void syncRemoteToLocalFileSystem() throws Exception;
protected abstract void syncRemoteToLocalFileSystem();
/**

View File

@@ -148,8 +148,18 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
}
}
public Message<File> receive() {
return this.fileSource.receive();
/**
* Polls from the file source. If the result is not null, it will be returned.
* If the result is null, it attempts to sync up with the remote directory to populate the file source.
* Then, it polls the file source again and returns the result, whether or not it is null.
*/
public final Message<File> receive() {
Message<File> message = this.fileSource.receive();
if (message == null) {
this.synchronizer.syncRemoteToLocalFileSystem();
message = this.fileSource.receive();
}
return message;
}
@SuppressWarnings("unchecked")

View File

@@ -89,7 +89,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
throw (RuntimeException)th;
}
else {
throw new MessagingException("Failed to compy file", th);
throw new MessagingException("Failed to copy file", th);
}
}
finally {

View File

@@ -49,12 +49,12 @@ public class FtpInboundRemoteFileSystemSynchronizingMessageSource
@Override
protected void doStart() {
this.synchronizer.start();
//this.synchronizer.start();
}
@Override
protected void doStop() {
this.synchronizer.stop();
//this.synchronizer.stop();
}
}

View File

@@ -16,11 +16,9 @@
package org.springframework.integration.sftp.inbound;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.regex.Pattern;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.synchronization.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
@@ -49,20 +47,6 @@ public class SftpInboundSynchronizingMessageSource
return "sftp:inbound-channel-adapter";
}
public Message<File> receive() {
/*
* Poll from the file source. If the result is not null, return it.
* If the result is null, attempt to sync up with remote directory to populate the file source.
* Then, poll on the file source again and return the result, whether or not it is null.
*/
Message<File> message = this.fileSource.receive();
if (message == null) {
this.synchronizer.syncRemoteToLocalFileSystem();
message = this.fileSource.receive();
}
return message;
}
@Override
protected void onInit() {
try {