diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java index 4ef3475..1c10736 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java @@ -2,7 +2,7 @@ package org.sadtech.vkbot.listener.data; import com.google.gson.JsonObject; -import java.util.List; +import java.util.Queue; public interface ResponsibleData { @@ -12,6 +12,6 @@ public interface ResponsibleData { void cleanAll(); - List getJsonObjects(); + Queue getJsonObjects(); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java index 6fca8a2..1630991 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java @@ -4,17 +4,17 @@ import com.google.gson.JsonObject; import org.sadtech.vkbot.listener.data.ResponsibleData; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; @Component public class ResponseDataVk implements ResponsibleData { - private List jsonObjects = new ArrayList(); + private Queue jsonObjects = new ConcurrentLinkedQueue(); @Override public void add(JsonObject jsonObject) { - jsonObjects.add(jsonObject); + jsonObjects.offer(jsonObject); } @Override @@ -27,7 +27,7 @@ public class ResponseDataVk implements ResponsibleData { jsonObjects.clear(); } - public List getJsonObjects() { + public Queue getJsonObjects() { return jsonObjects; } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java index c120a03..a4f4a58 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java @@ -5,6 +5,7 @@ import lombok.extern.log4j.Log4j; import org.sadtech.vkbot.listener.Observable; import org.sadtech.vkbot.listener.Observer; import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -17,21 +18,18 @@ public class DispetcherHandler implements Observable { private ResponsibleData date; private List observers = new ArrayList(); - private List objects; public DispetcherHandler(ResponsibleData date) { this.date = date; } - @Scheduled(fixedRate = 5000) + @Async public void packaging() { - - objects = new ArrayList(date.getJsonObjects()); - date.cleanAll(); - for (JsonObject object : objects) { - log.info(object); + while (true) { + if (date.getJsonObjects().peek() != null) { + log.info(date.getJsonObjects().poll()); + } } - } @Override