AlerterDataQueue.java 738 B

123456789101112131415161718192021222324252627282930313233
  1. package com.usthe.alert;
  2. import com.usthe.common.entity.alerter.Alert;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.stereotype.Component;
  5. import java.util.concurrent.LinkedBlockingQueue;
  6. import java.util.concurrent.TimeUnit;
  7. /**
  8. * 采集数据队列
  9. * @author tom
  10. * @date 2021/11/24 17:58
  11. */
  12. @Component
  13. @Slf4j
  14. public class AlerterDataQueue {
  15. private final LinkedBlockingQueue<Alert> alertDataQueue;
  16. public AlerterDataQueue() {
  17. alertDataQueue = new LinkedBlockingQueue<>();
  18. }
  19. public void addAlertData(Alert alert) {
  20. alertDataQueue.offer(alert);
  21. }
  22. public Alert pollAlertData() throws InterruptedException {
  23. return alertDataQueue.poll(2, TimeUnit.SECONDS);
  24. }
  25. }