package com.platform.listener;

import com.platform.common.exception.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 *
 * 监听目录文件的变化
 *
 *@author yikaihong
 */
@Component
@Order(Integer.MAX_VALUE)
public class VideoFileApplicationContext implements ApplicationListener<ContextRefreshedEvent>{


    @Autowired
    private VideoFileListener listener;

    @Autowired
    private VideoFileProperties videoFileProperties;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        VideoFileMonitor monitor = new VideoFileMonitor(videoFileProperties.getInterval());
        monitor.monitor(videoFileProperties.getListenerPath(),listener);
        try {
            monitor.start();
        } catch (Exception e) {
            throw new RRException("视频文件监控出错!");
        }
    }

}