package com.armundia.core.startup;

import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;

@ApplicationScoped
public class ApplicationStartup {
	public static final Logger log = Logger.getLogger(ApplicationStartup.class.getName());

    @Inject
    private ApLangCacheMaintenance aplang;

    @Inject
    private DominiCacheMaintenance domini;

    @Inject
    private OpzioniCacheMaintenance opzioni;
	
    private static boolean initialized = false;


	public ApplicationStartup() {
		// none
	}

	@PostConstruct
	@Transactional(TxType.MANDATORY)
	public void postConstruct() {
		if (ApplicationStartup.initialized)
			return;
		
		log.info("\n\nAPPLICATION starting...\n");

		// WARNING: keep this order
		opzioni.initialize();
		aplang.initialize();
		domini.initialize();

        //add here other initializations

		log.info("\n\nAPPLICATION started.\n");
		ApplicationStartup.initialized = true;
	}
}
