package de.ivu.elect.business.system.control;

import javax.ejb.Stateless;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.konfiguration.entity.ElectKonfigurationWerte;
import de.ivu.elect.business.konfiguration.entity.KonfigurationLoader;
import de.ivu.elect.jee.startup.PostStartupAsync;

@Stateless
public class BackgroundServiceRetryPostStartup implements PostStartupAsync {

  private static final Logger LOG = LoggerFactory.getLogger(BackgroundServiceRetryPostStartup.class);

  @Inject
  private transient KonfigurationLoader konfigurationLoader;

  @Override
  public void postStartup() {
    Long maxErrorCount = konfigurationLoader.resolveLongValueOptional(ElectKonfigurationWerte.BACKGROUND_SERVICE_MAX_ERROR_COUNT);
    LOG.info("BackgroundServiceRetry: " + maxErrorCount);
    if (maxErrorCount != null && maxErrorCount > 0) {
      BackgroundServiceRetry.MAX_ERROR_COUNT.set(maxErrorCount);
    }
  }
}
