1 package com.dotmarketing.servlets; 2 3 import java.io.File ; 4 import java.util.Date ; 5 import java.util.concurrent.Executors ; 6 import java.util.concurrent.ScheduledExecutorService ; 7 import java.util.concurrent.TimeUnit ; 8 9 import javax.servlet.ServletConfig ; 10 import javax.servlet.ServletException ; 11 import javax.servlet.http.HttpServlet ; 12 13 import org.apache.commons.lang.SystemUtils; 14 15 import com.dotmarketing.cache.VirtualLinksCache; 16 import com.dotmarketing.cms.factories.PublicCompanyFactory; 17 import com.dotmarketing.db.DbConnectionFactory; 18 import com.dotmarketing.db.DotCMSInitDb; 19 import com.dotmarketing.db.DotHibernate; 20 import com.dotmarketing.factories.PermissionFactory; 21 import com.dotmarketing.factories.PreviewFactory; 22 import com.dotmarketing.factories.PublishFactory; 23 import com.dotmarketing.menubuilders.RefreshMenus; 24 import com.dotmarketing.portlets.languagesmanager.factories.LanguageFactory; 25 import com.dotmarketing.portlets.languagesmanager.model.Language; 26 import com.dotmarketing.threads.ContentIndexationThread; 27 import com.dotmarketing.threads.ContentReindexerThread; 28 import com.dotmarketing.threads.ContentReviewThread; 29 import com.dotmarketing.threads.CronThread; 30 import com.dotmarketing.threads.ShutdownHookThread; 31 import com.dotmarketing.util.Config; 32 import com.dotmarketing.util.DotSpellChecker; 33 import com.dotmarketing.util.Logger; 34 import com.dotmarketing.util.LuceneUtils; 35 36 public class InitServlet extends HttpServlet { 37 private static final long serialVersionUID = 1L; 38 39 private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(Config 40 .getIntProperty("EXEC_NUM_OF_THREAD")); 41 42 public void destroy() { 43 System.out.println("dotCMS shutting down"); 44 System.gc(); 45 } 46 47 public static Date startupDate; 48 51 public void init(ServletConfig config) throws ServletException { 52 53 54 55 startupDate = new java.util.Date (); 56 Config.initializeConfig(); 58 com.dotmarketing.util.Config.setMyApp(config.getServletContext()); 59 60 61 String _dbType=DbConnectionFactory.getDBType(); 62 String _dailect = DotHibernate.getDialect(); 63 String _companyId=PublicCompanyFactory.getDefaultCompanyId(); 64 System.out.println(""); 65 System.out.println(" Initializing dotCMS"); 66 System.out.println(" Using database: " + _dbType); 67 System.out.println(" Using dialect : " + _dailect); 68 System.out.println(" Company Name : " + _companyId); 69 System.out.println(""); 70 71 72 73 74 75 DotCMSInitDb.InitializeDb(); 77 78 Config.setReservedFolders(); 80 81 Logger.debug(this, ""); 83 Logger.debug(this, "InitServlet: Setting Application Context!!!!!!"); 84 85 String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT"); 87 if (velocityRootPath.startsWith("/WEB-INF")) { 88 velocityRootPath = Config.CONTEXT.getRealPath(velocityRootPath); 89 } 90 91 new java.io.File (velocityRootPath + File.separator + "live").mkdirs(); 92 new java.io.File (velocityRootPath + File.separator + "working").mkdirs(); 93 94 RefreshMenus.deleteMenus(); 96 97 Logger.debug(this, "Lazy Mapping = " + Config.getBooleanProperty("LAZY_ASSET_MAPPING")); 98 if (!Config.getBooleanProperty("LAZY_ASSET_MAPPING", true)) { 99 PublishFactory.publishAllLiveAssets(); 101 102 PreviewFactory.mapAllWorkingAssets(); 104 105 Logger.debug(this, "Before calling PermissionFactory"); 107 PermissionFactory.mapAllPermissions(); 108 109 } 110 111 VirtualLinksCache.mapAllVirtualLinks(); 113 114 Language language = LanguageFactory.getDefaultLanguage(); 115 116 if (language.getId() == 0) { 117 Logger.debug(this, "Creating Default Language"); 118 LanguageFactory.createDefaultLanguage(); 119 } 120 121 if (Config.getBooleanProperty("INIT_DICTS_AT_STARTUP")) { 123 Logger.info(this, "Calling Initializing SpellChecker Dictionaries Rutine"); 124 try { 125 DotSpellChecker.initializeDicts(false, false); 126 } catch (Exception e) { 127 Logger.error(this, "Error encountered initializing spellchecker dicts!!", e); 128 } 129 } else { 130 Logger 131 .info( 132 this, 133 "Intialization of spell checker dictionaries at startup is off. Check INIT_DICTS_AT_STARTUP global variable to enable it."); 134 } 135 136 CronThread c = new CronThread("CronThread"); 138 c.start(); 139 140 if (Config.getBooleanProperty("ENABLE_CONTENT_REVIEW_THREAD")) { 143 Logger.info(this, "Enabling content review schedule every: " + Config 144 .getIntProperty("EXEC_CONTENT_REVIEW_DELAY") + " seconds."); 145 scheduler.scheduleWithFixedDelay(new ContentReviewThread(), Config.getIntProperty("EXEC_INIT_DELAY"), Config 146 .getIntProperty("EXEC_CONTENT_REVIEW_DELAY"), TimeUnit.SECONDS); 147 } else { 148 Logger.info(this, "Content review schedule disabled on this server"); 149 } 150 151 if(Config.getBooleanProperty("DIST_INDEXATION_ENABLED",false)) 153 { 154 int initDelay = Config.getIntProperty("DIST_INDEXATION_INIT_DELAY"); 155 int reviewDelay = Config.getIntProperty("DIST_INDEXATION_CONTENT_REVIEW_DELAY"); 156 Logger.info(this, "Enabling content distributed indexation schedule every: " + reviewDelay + " seconds. Starting in " + initDelay + " seconds."); 157 scheduler.scheduleWithFixedDelay(new ContentIndexationThread(),initDelay,reviewDelay,TimeUnit.SECONDS); 158 } 159 else 160 { 161 Logger.info(this,"Content indexation schedule disabled on this server"); 162 } 163 164 LuceneUtils.checkAndInitialiazeCurrentIndex (); 166 167 if(Config.getBooleanProperty("ENABLE_CONTENT_REINDEXATION_THREAD",false)) 169 { 170 int initDelay = Config.getIntProperty("EXEC_CONTENT_REINDEXATION_INIT_DELAY"); 171 int reviewDelay = Config.getIntProperty("EXEC_CONTENT_REINDEXATION_DELAY"); 172 Logger.info(this, "Enabling automatic content reindexation schedule every: " + reviewDelay + " seconds. Starting in " + initDelay + " seconds."); 173 scheduler.scheduleWithFixedDelay(new ContentReindexerThread(),initDelay,reviewDelay,TimeUnit.SECONDS); 174 } 175 else 176 { 177 Logger.info(this,"Automatic content reindexation schedule disabled on this server"); 178 } 179 180 Runtime.getRuntime().addShutdownHook(new ShutdownHookThread ()); 182 183 DotHibernate.closeSession(); 184 185 186 189 190 deleteFiles( new File (SystemUtils.JAVA_IO_TMPDIR)); 191 192 193 } 194 195 protected void deleteFiles(java.io.File directory) { 196 if (directory.isDirectory()) { 197 java.io.File [] files = directory.listFiles(); 199 for (int i = 0; i < files.length; i++) { 200 ((java.io.File ) files[i]).delete(); 202 } 203 } 204 } 205 206 public static Date getStartupDate() { 207 return startupDate; 208 } 209 210 214 215 246 247 } 248 | Popular Tags |