Apache Mina FTP サーバーイベント
バージョン 5.2 で追加された ApacheMinaFtplet
は、特定の Apache Mina FTP サーバーイベントをリッスンし、ApplicationListener
Bean、@EventListener
Bean メソッド、またはイベント受信チャネルアダプターで受信できる ApplicationEvent
として公開します。
現在、サポートされているイベントは次のとおりです。
SessionOpenedEvent
- クライアントセッションが開かれましたDirectoryCreatedEvent
- ディレクトリが作成されましたFileWrittenEvent
- ファイルが書き込まれたPathMovedEvent
- ファイルまたはディレクトリの名前が変更されましたPathRemovedEvent
- ファイルまたはディレクトリが削除されましたSessionClosedEvent
- クライアントが切断されました
これらはそれぞれ ApacheMinaFtpEvent
のサブクラスです。すべてのイベント型を受信するように単一のリスナーを設定できます。各イベントの source
プロパティは FtpSession
であり、そこからクライアントアドレスなどの情報を取得できます。抽象イベントには、便利な getSession()
メソッドが用意されています。
セッションのオープン / クローズ以外のイベントには、コマンドや引数などのプロパティを持つ別のプロパティ FtpRequest
があります。
リスナー(Spring Bean である必要があります)でサーバーを構成するには、サーバーファクトリに追加します。
FtpServerFactory serverFactory = new FtpServerFactory();
...
ListenerFactory factory = new ListenerFactory();
...
serverFactory.addListener("default", factory.createListener());
serverFactory.setFtplets(new HashMap<>(Collections.singletonMap("springFtplet", apacheMinaFtpletBean)));
server = serverFactory.createServer();
server.start();
Spring Integration イベントアダプターを使用してこれらのイベントを消費するには:
@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
ApplicationEventListeningMessageProducer producer =
new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ApacheMinaFtpEvent.class);
producer.setOutputChannel(eventChannel());
return producer;
}