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

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;

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

  public static final AtomicLong RUNNING = createRunning();

  public static final AtomicBoolean DISABLED = createDisabled();

  @Inject
  private transient FileCleanup fileCleanup;

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

  @Override
  protected boolean isSomethingToDoInternal() {
    return fileCleanup.isEtwasZuBereinigen();
  }

  @Override
  protected void doSomethingInternal() {
    fileCleanup.bereinige();
  }

  @Override
  public SystemLogQuelle getSystemLogQuelle() {
    return SystemLogQuelle.FILE_CLEANUP;
  }

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

}
