
package de.ivu.elect.jee.startup;

import javax.annotation.PostConstruct;
import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.inject.Inject;

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

@Startup
@Singleton
@DependsOn("StartupSingleton")
//https://issues.jboss.org/browse/EJBTHREE-2070 (keine Transaktion)
@TransactionManagement(TransactionManagementType.BEAN)
public class PostStartupSingleton {

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

  @Inject
  private transient PostStartupFinder postStartupFinder;

  @Inject
  private transient PostStartupAsyncRunner postStartupAsyncRunner;

  @PostConstruct
  public void init() {
    LOG.info("Post startup");
    for (PostStartup postStartup : postStartupFinder.getPostStartups()) {
      postStartup.postStartup();
    }
    LOG.info("Post startup - starte async timer");
    postStartupAsyncRunner.createTimer();
    LOG.info("startup done");
  }
}
