yeg
6 天以前 a04222c873e5e55f48c8d33b5c0bc46fa524ac8d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.battery.business.service.impl;
 
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.battery.business.service.IDeviceAdapterService;
 
/**
 * 在单采集进程内恢复启用实例,并按各自周期执行只读发现。
 * 不限定 profile:真实来源的发现与接收要在非开发 profile 下运行。
 */
@Component
public class DeviceAdapterRuntimeCoordinator
{
    private final IDeviceAdapterService service;
 
    public DeviceAdapterRuntimeCoordinator(IDeviceAdapterService service) { this.service = service; }
 
    /** 应用就绪时恢复已启用的适配器实例;不限定 profile,真实来源也要在非开发 profile 下运行。 */
    @EventListener(ApplicationReadyEvent.class)
    public void restoreEnabledAdapters() { service.synchronizeEnabledAdapters(); }
 
    /** 每约 1 秒检查一次到期实例并执行只读发现,实际取数节奏由各实例自己的轮询周期决定。 */
    @Scheduled(fixedDelay = 1000)
    public void pollDueAdapters() { service.pollDueAdapters(); }
}