| | |
| | | import java.util.List; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Profile; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import com.battery.device.api.NoopDeviceAdapterFactory; |
| | | import com.battery.device.bts.BtsDeviceAdapterFactory; |
| | | import com.battery.device.api.registry.DeviceAdapterRegistry; |
| | | import com.battery.device.neware.NewareMysqlAdapterFactory; |
| | | |
| | | /** 装配单进程设备适配器运行时。 */ |
| | | /** |
| | | * 装配单进程设备适配器运行时。 |
| | | * |
| | | * <p>注册表按存储形态持有全部可用实现;实例按 {@code t_device_adapter} 配置或代码装配注册。 |
| | | * 同一进程内可并存多个来源实例,取数按通道身份里的适配器编码解析到各自实例。 |
| | | * 某个类型是否真的有实例可用只由配置决定,因此这里不再按 profile 收窄可注册的类型。 |
| | | */ |
| | | @Configuration |
| | | @EnableScheduling |
| | | public class DeviceAdapterRuntimeConfig |
| | | { |
| | | @Bean(destroyMethod = "close") |
| | | @Profile("!dev-simulator & !bts") |
| | | public DeviceAdapterRegistry noopDeviceAdapterRegistry() |
| | | { |
| | | return new DeviceAdapterRegistry(List.of(new NoopDeviceAdapterFactory())); |
| | | } |
| | | |
| | | @Bean(destroyMethod = "close") |
| | | @Profile({ "dev-simulator", "bts" }) |
| | | public DeviceAdapterRegistry deviceAdapterRegistry() |
| | | { |
| | | return new DeviceAdapterRegistry(List.of(new BtsDeviceAdapterFactory())); |
| | | return new DeviceAdapterRegistry(List.of(new NoopDeviceAdapterFactory(), new BtsDeviceAdapterFactory(), |
| | | new NewareMysqlAdapterFactory())); |
| | | } |
| | | |
| | | } |