src/main/java/de/uapcore/lightpit/ModuleManager.java

changeset 30
fb30f7b78f9b
parent 29
27a0fdd7bca7
child 31
58f78f0142e8
equal deleted inserted replaced
29:27a0fdd7bca7 30:fb30f7b78f9b
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 * 27 *
28 */ 28 */
29 package de.uapcore.lightpit; 29 package de.uapcore.lightpit;
30 30
31 import de.uapcore.lightpit.entities.CoreDAOFactory; 31 import de.uapcore.lightpit.dao.CoreDAOFactory;
32 import de.uapcore.lightpit.dao.ModuleDao;
32 import de.uapcore.lightpit.entities.Module; 33 import de.uapcore.lightpit.entities.Module;
33 import de.uapcore.lightpit.entities.ModuleDao; 34 import org.slf4j.Logger;
34 import java.sql.Connection; 35 import org.slf4j.LoggerFactory;
35 import java.sql.SQLException; 36
36 import java.util.Collections;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Optional;
41 import java.util.concurrent.atomic.AtomicBoolean;
42 import java.util.stream.Collectors;
43 import javax.servlet.Registration; 37 import javax.servlet.Registration;
44 import javax.servlet.ServletContext; 38 import javax.servlet.ServletContext;
45 import javax.servlet.ServletContextEvent; 39 import javax.servlet.ServletContextEvent;
46 import javax.servlet.ServletContextListener; 40 import javax.servlet.ServletContextListener;
47 import javax.servlet.annotation.WebListener; 41 import javax.servlet.annotation.WebListener;
48 import org.slf4j.Logger; 42 import java.sql.Connection;
49 import org.slf4j.LoggerFactory; 43 import java.sql.SQLException;
44 import java.util.*;
45 import java.util.concurrent.atomic.AtomicBoolean;
46 import java.util.stream.Collectors;
50 47
51 /** 48 /**
52 * Scans registered servlets for LightPIT modules. 49 * Scans registered servlets for LightPIT modules.
53 */ 50 */
54 @WebListener 51 @WebListener
142 // TODO: implement dependency resolver 139 // TODO: implement dependency resolver
143 140
144 dirty.set(true); 141 dirty.set(true);
145 LOG.info("Modules loaded."); 142 LOG.info("Modules loaded.");
146 } 143 }
147 144
148 /** 145 /**
149 * Synchronizes module information with the database. 146 * Synchronizes module information with the database.
150 * 147 * <p>
151 * This must be called from the {@link AbstractLightPITServlet}. 148 * This must be called from the {@link AbstractLightPITServlet}.
152 * Admittedly the call will perform the synchronization once after reload 149 * Admittedly the call will perform the synchronization once after reload
153 * and be a no-op, afterwards. 150 * and be a no-op, afterwards.
154 * However, we since the DatabaseFacade might be loaded after the module 151 * However, since the DatabaseFacade might be loaded after the module
155 * manager, we must defer the synchronization to the first request 152 * manager, we must defer the synchronization to the first request
156 * handled by the Servlet. 153 * handled by the Servlet.
157 * 154 *
158 * @param db interface to the database 155 * @param db interface to the database
159 */ 156 */
160 public void syncWithDatabase(DatabaseFacade db) { 157 public void syncWithDatabase(DatabaseFacade db) {
161 if (dirty.compareAndSet(true, false)) { 158 if (dirty.compareAndSet(true, false)) {
162 if (db.getDataSource().isPresent()) { 159 if (db.getDataSource().isPresent()) {

mercurial