// Path: src/main/java/business/ApplicationContext.java
// public final class ApplicationContext {
// 
//     private final Logger logger = LoggerFactory.getLogger(getClass());
// 
//     private ProductService productService;
// 
//     private CategoryService categoryService;
// 
//     private CustomerService customerService;
// 
//     private CustomerOrderService customerOrderService;
// 
//     private ScheduledExecutorService executorService;
// 
//     public static ApplicationContext INSTANCE = new ApplicationContext();
// 
//     private ApplicationContext() {
// 
//         executorService = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
// 
//         // wire up the business.dao layer "by hand"
//         ProductDao productDao = new ProductDaoJdbc();
// 
//         ProductDaoGuava cachedProductDao = new ProductDaoGuava(productDao);
// 
//         productService = new DefaultProductService();
//         ((DefaultProductService) productService).setProductDao(cachedProductDao);
// 
//         CategoryDao categoryDao = new CategoryDaoJdbc();
// 
//         CategoryDaoGuava cachedCategoryDao = new CategoryDaoGuava(categoryDao);
// 
//         categoryService = new DefaultCategoryService();
//         ((DefaultCategoryService) categoryService).setCategoryDao(cachedCategoryDao);
// 
//         CustomerDao customerDao = new CustomerDaoJdbc();
//         customerService = new DefaultCustomerService();
//         ((DefaultCustomerService) customerService).setCustomerDao(customerDao);
// 
//         CustomerOrderLineItemDao customerOrderLineItemDao = new CustomerOrderLineItemDaoJdbc();
//         CustomerOrderDao customerOrderDao = new CustomerOrderDaoJdbc();
// 
//         customerOrderService = new DefaultCustomerOrderService();
//         DefaultCustomerOrderService service = (DefaultCustomerOrderService) customerOrderService;
//         service.setProductDao(cachedProductDao);
//         service.setCustomerService(customerService);
//         service.setCustomerOrderDao(customerOrderDao);
//         service.setCustomerOrderLineItemDao(customerOrderLineItemDao);
// 
//         executorService.scheduleWithFixedDelay(() -> {
//                 try {
//                     logger.info("Refreshing category and product caches....commencing");
//                     cachedCategoryDao.bulkload();
//                     cachedProductDao.clear();
//                     logger.info("Refreshing category and product caches....complete!");
//                 } catch (Throwable t) {
//                     logger.error("Encountered trouble refreshing category and product caches.", t);
//                 }
//             }, 10, 60, TimeUnit.MINUTES);
//     }
// 
// 
// 
//     public ProductService getProductService() {
//         return productService;
//     }
// 
//     public CategoryService getCategoryService() {
//         return categoryService;
//     }
// 
//     public CustomerService getCustomerService() {
//         return customerService;
//     }
// 
//     public CustomerOrderService getCustomerOrderService() {
//         return customerOrderService;
//     }
// 
//     public void shutdown() {
//         executorService.shutdown();
//     }
// }


import business.ApplicationContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * BSD 3-Clause License
 *
 * Copyright (C) 2018 Steven Atkinson <steven@nowucca.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package controller; /**
 */


public class SimpleAffableBeanContextListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    // Public constructor is required by servlet spec
    public SimpleAffableBeanContextListener() {
    }

    // -------------------------------------------------------
    // ServletContextListener implementation
    // -------------------------------------------------------
    public void contextInitialized(ServletContextEvent sce) {
      /* This method is called when the servlet context is
         initialized(when the Web application is deployed).
         You can initialize servlet context related data here.
      */
        logger.info("Servlet context initializing.");
        // initialize servlet with configuration information
// Path: src/main/java/business/ApplicationContext.java
// public final class ApplicationContext {
// 
//     private final Logger logger = LoggerFactory.getLogger(getClass());
// 
//     private ProductService productService;
// 
//     private CategoryService categoryService;
// 
//     private CustomerService customerService;
// 
//     private CustomerOrderService customerOrderService;
// 
//     private ScheduledExecutorService executorService;
// 
//     public static ApplicationContext INSTANCE = new ApplicationContext();
// 
//     private ApplicationContext() {
// 
//         executorService = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
// 
//         // wire up the business.dao layer "by hand"
//         ProductDao productDao = new ProductDaoJdbc();
// 
//         ProductDaoGuava cachedProductDao = new ProductDaoGuava(productDao);
// 
//         productService = new DefaultProductService();
//         ((DefaultProductService) productService).setProductDao(cachedProductDao);
// 
//         CategoryDao categoryDao = new CategoryDaoJdbc();
// 
//         CategoryDaoGuava cachedCategoryDao = new CategoryDaoGuava(categoryDao);
// 
//         categoryService = new DefaultCategoryService();
//         ((DefaultCategoryService) categoryService).setCategoryDao(cachedCategoryDao);
// 
//         CustomerDao customerDao = new CustomerDaoJdbc();
//         customerService = new DefaultCustomerService();
//         ((DefaultCustomerService) customerService).setCustomerDao(customerDao);
// 
//         CustomerOrderLineItemDao customerOrderLineItemDao = new CustomerOrderLineItemDaoJdbc();
//         CustomerOrderDao customerOrderDao = new CustomerOrderDaoJdbc();
// 
//         customerOrderService = new DefaultCustomerOrderService();
//         DefaultCustomerOrderService service = (DefaultCustomerOrderService) customerOrderService;
//         service.setProductDao(cachedProductDao);
//         service.setCustomerService(customerService);
//         service.setCustomerOrderDao(customerOrderDao);
//         service.setCustomerOrderLineItemDao(customerOrderLineItemDao);
// 
//         executorService.scheduleWithFixedDelay(() -> {
//                 try {
//                     logger.info("Refreshing category and product caches....commencing");
//                     cachedCategoryDao.bulkload();
//                     cachedProductDao.clear();
//                     logger.info("Refreshing category and product caches....complete!");
//                 } catch (Throwable t) {
//                     logger.error("Encountered trouble refreshing category and product caches.", t);
//                 }
//             }, 10, 60, TimeUnit.MINUTES);
//     }
// 
// 
// 
//     public ProductService getProductService() {
//         return productService;
//     }
// 
//     public CategoryService getCategoryService() {
//         return categoryService;
//     }
// 
//     public CustomerService getCustomerService() {
//         return customerService;
//     }
// 
//     public CustomerOrderService getCustomerOrderService() {
//         return customerOrderService;
//     }
// 
//     public void shutdown() {
//         executorService.shutdown();
//     }
// }


// Path: src/main/java/controller/SimpleAffableBeanContextListener.java
import business.ApplicationContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * BSD 3-Clause License
 *
 * Copyright (C) 2018 Steven Atkinson <steven@nowucca.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package controller; /**
 */


public class SimpleAffableBeanContextListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    // Public constructor is required by servlet spec
    public SimpleAffableBeanContextListener() {
    }

    // -------------------------------------------------------
    // ServletContextListener implementation
    // -------------------------------------------------------
    public void contextInitialized(ServletContextEvent sce) {
      /* This method is called when the servlet context is
         initialized(when the Web application is deployed).
         You can initialize servlet context related data here.
      */
        logger.info("Servlet context initializing.");
        // initialize servlet with configuration information
        ApplicationContext applicationContext = ApplicationContext.INSTANCE;