package com.njzscloud.common.sichen.config;

import com.njzscloud.common.sichen.util.TimerUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@ConditionalOnBooleanProperty(prefix = "sichen.timer", name = "enable")
@EnableConfigurationProperties(TimerProperties.class)
public class TimerAutoConfiguration implements DisposableBean {
    public TimerAutoConfiguration(TimerProperties timerProperties) {
        TimerUtil.init(timerProperties.isVirtual(), timerProperties.getPoolName(), timerProperties.getCorePoolSize());
    }

    @Override
    public void destroy() throws Exception {
        TimerUtil.shutdown();
    }
}
