yeg
2026-09-05 f522c9ffa487e3710d691e8b98df8c4f0cfafd43
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.battery.business.runtime;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Profile;
import com.battery.device.simulator.BtsDevelopmentSimulator;
import com.battery.device.api.registry.DeviceAdapterRegistry;
import com.battery.business.service.impl.DeviceDiscoveryPersistenceService;
import com.battery.business.service.impl.DeviceDiscoveryPersistenceService.DiscoverySource;
 
/** 轮询代码固定装配的 dev-sim;该运行时不依赖数据库适配器记录。 */
@Component
@Profile("dev-simulator")
public class DevelopmentSimulatorDiscoveryScheduler
{
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DevelopmentSimulatorDiscoveryScheduler.class);
    private final DeviceAdapterRegistry registry;
    private final DeviceDiscoveryPersistenceService persistence;
    public DevelopmentSimulatorDiscoveryScheduler(DeviceAdapterRegistry registry,
            DeviceDiscoveryPersistenceService persistence)
    {
        this.registry = registry;
        this.persistence = persistence;
    }
 
    /** 注册表已包含固定开发适配器时,将一轮检测柜观测写入 Redis 候选。 */
    @Scheduled(fixedDelay = BtsDevelopmentSimulator.POLL_INTERVAL_MS)
    public void discover()
    {
        if (!registry.contains(BtsDevelopmentSimulator.ADAPTER_CODE)) return;
        try
        {
            persistence.discoverForReception(registry, new DiscoverySource(BtsDevelopmentSimulator.ADAPTER_CODE, null,
                    BtsDevelopmentSimulator.ADAPTER_NAME, BtsDevelopmentSimulator.POLL_INTERVAL_MS));
        }
        catch (RuntimeException exception)
        {
            persistence.markUnavailable(BtsDevelopmentSimulator.ADAPTER_CODE);
            log.warn("模拟设备观测失败,已清除过期实时值:{}", exception.getMessage());
        }
    }
}