From: Bogumil Zebek Date: Tue, 21 Apr 2020 12:26:56 +0000 (+0200) Subject: Remove deprecated method X-Git-Tag: 1.0.0~9^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=37622e3c6acaf455a9a4a5874f190e8ff17a693e;p=integration%2Fsimulators%2Fpnf-simulator.git Remove deprecated method Once deprecated, classes, and interfaces, and their members should be avoided, rather than used, inherited or extended. Deprecation is a warning that the class or interface has been superseded, and will eventually be removed. The deprecation period allows you to make a smooth transition away from the aging, soon-to-be-retired technology. Issue-ID: INT-1517 Signed-off-by: Zebek Bogumil Change-Id: I985959d614c6f2544b0515ed52d6343f194e4720 --- diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java index 1b99220..6bd8390 100644 --- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java +++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.core.ConsumerFactory; import org.springframework.stereotype.Service; +import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -53,7 +54,7 @@ public class StoreService { String clientId = Long.toString(Instant.now().getEpochSecond()); try (Consumer consumer = consumerFactory.createConsumer(clientId, clientId)) { consumer.subscribe(TOPICS_TO_SUBSCRIBE); - ConsumerRecords consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS); + ConsumerRecords consumerRecords = pollConsumerRecords(consumer); consumerRecords.forEach( consumerRecord -> messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value()))); @@ -65,7 +66,7 @@ public class StoreService { List getLastMessages(long offset) { List messages = new ArrayList<>(); try (Consumer consumer = createConsumer(offset)) { - ConsumerRecords consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS); + ConsumerRecords consumerRecords = pollConsumerRecords(consumer); consumerRecords.forEach(consumerRecord -> messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value()))); } @@ -82,10 +83,14 @@ public class StoreService { private void seekConsumerTo(Consumer consumer, long offsetFromLastIndex) { consumer.seekToEnd(consumer.assignment()); - consumer.poll(CONSUMING_DURATION_IN_MS); + pollConsumerRecords(consumer); TopicPartition topicPartition = consumer.assignment().iterator().next(); long topicCurrentSize = consumer.position(topicPartition); long indexToSeek = offsetFromLastIndex > topicCurrentSize ? 0 : topicCurrentSize - offsetFromLastIndex; consumer.seek(topicPartition, indexToSeek); } + + private ConsumerRecords pollConsumerRecords(Consumer consumer) { + return consumer.poll(Duration.ofMillis(CONSUMING_DURATION_IN_MS)); + } }