package com.njzscloud.common.localizer.config;


import com.njzscloud.common.localizer.DeviceStore;
import com.njzscloud.common.localizer.htzj.Htzj;
import com.njzscloud.common.localizer.jt808.JT808;
import com.njzscloud.common.localizer.tuqiang.Tuqiang;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;

public class LocalizerInitializer {
    private final LocalizerProperties properties;

    public LocalizerInitializer(LocalizerProperties properties) {
        this.properties = properties;
    }

    public void init() {
        Htzj.init();
        Tuqiang.init();
        JT808.run(properties.getPort(), properties.getBossThreads(), properties.getWorkerThreads());
    }

    private void destroy() {
        JT808.stop();
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReady() {
        DeviceStore.init();
    }
}
