|
|
@ -14,12 +14,14 @@ import com.iflytop.gd.hardware.command.checker.SupportMethod; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationEventPublisher; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.security.InvalidParameterException; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
|
|
|
|
|
|
@ -28,6 +30,7 @@ import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class HardwareService { |
|
|
|
private final ApplicationEventPublisher eventPublisher; |
|
|
|
private final ApplicationContext applicationContext; |
|
|
|
private final Map<CmdDevice, CommandHandler> cmdHandlers = new HashMap<>(); |
|
|
|
|
|
|
|
ThreadPoolExecutor executor = ThreadUtil.newFixedExecutor(50, "hardware-service", true); |
|
|
@ -35,6 +38,15 @@ public class HardwareService { |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void postInit() { |
|
|
|
Map<String, CommandHandler> handlers = applicationContext.getBeansOfType(CommandHandler.class); |
|
|
|
handlers.values().forEach(this::registerCommandHandler); |
|
|
|
} |
|
|
|
|
|
|
|
void registerCommandHandler(CommandHandler handler) { |
|
|
|
Set<CmdDevice> devices = handler.getSupportedDevices(); |
|
|
|
for (CmdDevice device : devices) { |
|
|
|
cmdHandlers.put(device, handler); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|