package com.gyee.wisdom.dataadapter.websocket.listener;

import com.gyee.wisdom.dataadapter.websocket.PublishConfig;
import com.gyee.wisdom.dataadapter.websocket.PublishServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.messaging.simp.broker.BrokerAvailabilityEvent;
import org.springframework.stereotype.Component;

@Component
public class BrokerAvailabilityEventListener implements
        ApplicationListener<BrokerAvailabilityEvent> {
    @Value("${websocket_start:false}")
    private String websocketIsStart;
    @Autowired
    private PublishConfig publishConfig;

    @Autowired
    private PublishServer publishServer;

    @Override
    public void onApplicationEvent(BrokerAvailabilityEvent event) {
        System.out.println("BrokerAvailabilityEvent  rised!");
        System.out.println("listener: " + event.toString());
        publishServer.init(publishConfig.getRtdbScanInterval(), publishConfig.getPublishInterval());
        if (Boolean.valueOf(websocketIsStart)) {
            publishServer.start();
        }

    }

}