package com.sentai.demo;

import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class DemoLogProducer {
  private static final Logger LOGGER = LoggerFactory.getLogger(DemoLogProducer.class);
  private final AtomicInteger counter = new AtomicInteger();

  @Scheduled(fixedDelay = 15000L, initialDelay = 5000L)
  public void emitHeartbeat() {
    LOGGER.info("java-demo heartbeat count={} now={}", counter.incrementAndGet(), Instant.now());
  }

  @Scheduled(fixedDelay = 45000L, initialDelay = 12000L)
  public void emitWarning() {
    LOGGER.warn("java-demo warning sample serviceKey=java-demo-app now={}", Instant.now());
  }
}
