package de.ivu.elect.jee.cron;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Nullable;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;


import static java.util.Collections.singletonList;

/**
 *  on 03.01.2017.
 */
public abstract class AbstractSingleCronTimer extends AbstractCronTimer {

  @Nullable
  protected abstract String getCrontab();

  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  public void createTimer(String crontab) {
    createTimer(singletonList(Crontab.forCrontab(crontab)));
  }

  @Override
  protected List<Crontab> getCrontabs() {
    return singletonList(Crontab.forCrontab(getCrontab()));
  }

  @Override
  protected void timeout(Serializable payload) {
    timeout();
  }

  protected abstract void timeout();

}
