我在config xml中定义了一个工作的sftp入站通道适配器(显然通过注释定义它在Spring中尚未完全正常运行)。
我想要做的是覆盖synchronizeToLocalDirectory方法,以便可以在JMX的帮助下手动激活它。
使用@Component实例化类,但是我的类中的synchronizeToLocalDirectory永远不会被调用,因为它与Spring通过config xml调用的实际bean是分开的。
有没有办法将两者配对,以便每次调用我的synchronizeToLocalDirectory方法?
我的入站文件同步器:
@Component
@ManagedResource(objectName = "bean:name=InboundFileProcessor", description = "Synchronizes to the Local Directory",
log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200,
persistLocation = "Spring", persistName = "FTP")
public class MyFtpInboundFileSynchronizer extends AbstractInboundFileSynchronizer<LsEntry> {
private static final Logger logger = LoggerFactory.getLogger(MyFtpInboundFileSynchronizer.class);
@Inject
private MultiMarkupFilter multiMarkupFilter;
@Inject
public MyFtpInboundFileSynchronizer(SessionFactory<LsEntry> ftpSessionFactory) {
super(ftpSessionFactory);
setRemoteDirectory(((FtpSessionFactory) ftpSessionFactory).getFtpSessionProperties().getRemoteDirectory());
setFilter(multiMarkupFilter);
}
public void init() {
}
@Override
protected boolean isFile(LsEntry lsEntry) {
if (lsEntry != null && !lsEntry.getAttrs().isDir()
&& !lsEntry.getFilename().equals(".")
&& !lsEntry.getFilename().equals("..")) {
logger.debug("Downloading file" + lsEntry.getFilename());
return true;
} else {
return false;
}
}
@Override
protected String getFilename(LsEntry file) {
return (file != null ? file.getFilename() : null);
}
@Override
public void synchronizeToLocalDirectory(File localDirectory) {
logger.debug("Starting synchronizeToLocalDirectory");
super.synchronizeToLocalDirectory(localDirectory);
logger.debug("Ending synchronizeToLocalDirectory");
}
@ManagedOperation(description = "synchronize To Local Directory")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "localDirectory", description = "The Local Directory") })
public void synchronizeToLocalDirectory(String localDirectory) {
File localDirFile = new File(localDirectory);
if (localDirFile.exists() && localDirFile.isDirectory()) {
synchronizeToLocalDirectory(new File(localDirectory));
}
}
}
int-sftp:入站通道适配器定义:
<int:annotation-config/>
<int-sftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel" session-factory="${sessionFactory}"
auto-create-local-directory="${autoCreateLocalDirectory}"
delete-remote-files="${deleteRemoteFiles}" filter="${filter}"
remote-directory="${remoteDirectory}"
remote-file-separator="${remoteFileSeparator}"
local-directory="${localDirectory}">
<int:poller max-messages-per-poll="-1"
fixed-rate="${ftpPollInterval}" id="poller" error-channel="errorChannel" >
</int:poller>
</int-sftp:inbound-channel-adapter>
<int:channel id="ftpChannel"/>
<int:channel id="errorChannel"/>