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;
}