config xml で定義された動作中の sftp インバウンド チャネル アダプターがあります (明らかに、アノテーションを介してこれを定義することは、Spring ではまだ完全に機能していません)。
私がやりたいことは、synchronizeToLocalDirectory メソッドをオーバーライドして、JMX の助けを借りて手動でアクティブ化できるようにすることです。
@Component を使用してクラスをインスタンス化しますが、私のクラスの synchronizeToLocalDirectory は決して呼び出されません。これは、構成 xml を介して Spring によって呼び出される実際の Bean とは別のものだからです。
私の synchronizeToLocalDirectory メソッドが毎回呼び出されるように、2 つをペアにする方法はありますか?
My Inbound File Synchronizer :
@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:inbound-channel-adapter 定義:
<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"/>