I have a poller that is polling a remote dir in order to sftp the file across but i want to stop it if it doesn't find the file after x amount of attempts. Is there a simple config for this?
ApplicationContext.xml
<int-sftp:inbound-channel-adapter id="sftpInboundAdaptor"
session-factory="sftpSessionFactory"
local-directory="${local.dir}"
auto-create-local-directory="true"
auto-startup="false"
channel="SftpChannel"
remote-directory="${remote.dir}"
filename-pattern="XXXX"
delete-remote-files="false"
charset="UTF-8"
remote-file-separator="/"
local-filename-generator-expression="#this">
<int:poller max-messages-per-poll="1" fixed-rate="30000" >
</int:poller>
</int-sftp:inbound-channel-adapter>
Main.class
private static void sftpFile(String party) throws Exception {
SourcePollingChannelAdapter adapter = (SourcePollingChannelAdapter) applicationContext.getBean("sftpInboundAdaptor");
adapter.start();
SftpDownloader sftpProcessor = (SftpDownloader) applicationContext.getBean("sftpDownloader");
LOGGER.info((fileDownloaded ? "Successful" : "Failed") + " downloading file"");
}
SftpDownloader.class
public boolean receiveFile(String party, String fileType) throws SftpJobException {
if (Constants.1.equals(fileType)) {
return isFile1SftpSuccessful();
} else if (Constants.2.equals(fileType)) {
return isFile2SftpSuccessful(party);
}
return false;
}
private boolean isFile1SftpSuccessful() throws SftpJobException {
return isValidFile((File) SftpChannel.receive().getPayload());
}
private boolean isValidFile(File received) throws SftpJobException{
if (received.length() != 0) {
LOGGER.info("File is: {}", received.toString());
return true;
} else {
throw new SftpJobException("File size is 0, either no file exists an empty file was created. ")
}
}
I seems like it polls indefinitely when i look for the above file (doesn't exist) whereas i'd like to throw an exception if the file wasn't there.