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

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import javax.ejb.DependsOn;
import javax.ejb.Singleton;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.inject.Inject;

import de.ivu.elect.business.system.control.AbstractElectBackgroundService;
import de.ivu.elect.business.system.entity.SystemLogQuelle;


import static de.ivu.elect.business.system.entity.SystemLogQuelle.STATISTIK_LAUF;

@Singleton
@DependsOn("DbInit")
// https://issues.jboss.org/browse/EJBTHREE-2070 (keine Transaktion)
@TransactionManagement(TransactionManagementType.BEAN)
public class StatistikLaufBackgroundService extends AbstractElectBackgroundService {

  public static final AtomicLong RUNNING = createRunning();

  public static final AtomicBoolean DISABLED = createDisabled();

  @Inject
  private transient StatistikLaufBerechner statistikLaufBerechner;

  @Override
  protected boolean isSomethingToDoInternal() {
    return statistikLaufBerechner.isSomethingToDo();
  }

  @Override
  protected void doSomethingInternal() {
    statistikLaufBerechner.berechne();
  }

  @Override
  public SystemLogQuelle getSystemLogQuelle() {
    return STATISTIK_LAUF;
  }


  @Override
  protected AtomicBoolean getDisabledInternal() {
    return DISABLED;
  }

  @Override
  protected AtomicLong getRunning() {
    return RUNNING;
  }
}
