KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > servlets > InitServlet


1 package com.dotmarketing.servlets;
2
3 import java.io.File JavaDoc;
4 import java.util.Date JavaDoc;
5 import java.util.concurrent.Executors JavaDoc;
6 import java.util.concurrent.ScheduledExecutorService JavaDoc;
7 import java.util.concurrent.TimeUnit JavaDoc;
8
9 import javax.servlet.ServletConfig JavaDoc;
10 import javax.servlet.ServletException JavaDoc;
11 import javax.servlet.http.HttpServlet JavaDoc;
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 JavaDoc {
37     private static final long serialVersionUID = 1L;
38
39     private final ScheduledExecutorService JavaDoc 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 JavaDoc startupDate;
48     /**
49      * Description of the Method
50      */

51     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
52
53         
54         
55         startupDate = new java.util.Date JavaDoc();
56         // Config class Initialization
57
Config.initializeConfig();
58         com.dotmarketing.util.Config.setMyApp(config.getServletContext());
59         
60         
61         String JavaDoc _dbType=DbConnectionFactory.getDBType();
62         String JavaDoc _dailect = DotHibernate.getDialect();
63         String JavaDoc _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         // Set up the database
76
DotCMSInitDb.InitializeDb();
77
78         // Sets reservedFolderNames
79
Config.setReservedFolders();
80
81         // set the application context for use all over the site
82
Logger.debug(this, "");
83         Logger.debug(this, "InitServlet: Setting Application Context!!!!!!");
84
85         // creates the velocity folders to make sure they are there
86
String JavaDoc velocityRootPath = Config.getStringProperty("VELOCITY_ROOT");
87         if (velocityRootPath.startsWith("/WEB-INF")) {
88             velocityRootPath = Config.CONTEXT.getRealPath(velocityRootPath);
89         }
90  
91         new java.io.File JavaDoc(velocityRootPath + File.separator + "live").mkdirs();
92         new java.io.File JavaDoc(velocityRootPath + File.separator + "working").mkdirs();
93
94         // deletes all menues that have been generated
95
RefreshMenus.deleteMenus();
96
97         Logger.debug(this, "Lazy Mapping = " + Config.getBooleanProperty("LAZY_ASSET_MAPPING"));
98         if (!Config.getBooleanProperty("LAZY_ASSET_MAPPING", true)) {
99             // maps all live pages and file uri's into a hashmap
100
PublishFactory.publishAllLiveAssets();
101
102             // maps all working pages and file uri's into a hashmap
103
PreviewFactory.mapAllWorkingAssets();
104
105             // maps all permission for live pages into a hashmap
106
Logger.debug(this, "Before calling PermissionFactory");
107             PermissionFactory.mapAllPermissions();
108
109         }
110
111         // maps all virtual links in memory
112
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         // Initializing spellchecker dicts
122
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 JavaDoc 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         // Fire up the cron thread
137
CronThread c = new CronThread("CronThread");
138         c.start();
139
140         //### Initializing the periodic tasks ###
141
//initializing content review
142
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         //Initializing distributed content indexation
152
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         //Checking and initializing the indexs
165
LuceneUtils.checkAndInitialiazeCurrentIndex ();
166         
167         //Initializing content reindexation
168
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         //Adding the shutdown hook
181
Runtime.getRuntime().addShutdownHook(new ShutdownHookThread ());
182
183         DotHibernate.closeSession();
184
185        
186         /*
187          * Delete the files out of the temp dir (this gets huge)
188          */

189         
190         deleteFiles( new File JavaDoc(SystemUtils.JAVA_IO_TMPDIR));
191
192         
193     }
194
195     protected void deleteFiles(java.io.File JavaDoc directory) {
196         if (directory.isDirectory()) {
197             // get all files for this directory
198
java.io.File JavaDoc[] files = directory.listFiles();
199             for (int i = 0; i < files.length; i++) {
200                 // deletes all files on the directory
201
((java.io.File JavaDoc) files[i]).delete();
202             }
203         }
204     }
205
206     public static Date JavaDoc getStartupDate() {
207         return startupDate;
208     }
209
210     /*
211      *
212      * Tests the hibernate mapping / database structure
213      */

214
215     /*
216      * private static void runInodeTests(){ /* INODE TABLES category file_asset
217      * file_upload contentlet containers entity folder identifier host template
218      * htmlpage links workflow_ mailing_list subscriber campaign recipient click
219      * user_proxy virtual_link event recurance event_registration banner
220      * structure field
221      *
222      *
223      *
224      *
225      *
226      *
227      * Inode i = null; i = InodeFactory.getInode(1, Category.class); i =
228      * InodeFactory.getInode(1, File.class); i = InodeFactory.getInode(1,
229      * Contentlet.class); i = InodeFactory.getInode(1, Container.class); i =
230      * InodeFactory.getInode(1, Entity.class); i = InodeFactory.getInode(1,
231      * Folder.class); i = InodeFactory.getInode(1, Identifier.class); i =
232      * InodeFactory.getInode(1, Host.class); i = InodeFactory.getInode(1,
233      * Template.class); i = InodeFactory.getInode(1, HTMLPage.class); i =
234      * InodeFactory.getInode(1, Link.class); i = InodeFactory.getInode(1,
235      * WorkflowMessage.class); i = InodeFactory.getInode(1, MailingList.class);
236      * i = InodeFactory.getInode(1, Subscriber.class); i =
237      * InodeFactory.getInode(1, Campaign.class); i = InodeFactory.getInode(1,
238      * Recipient.class); i = InodeFactory.getInode(1, Click.class); i =
239      * InodeFactory.getInode(1, UserProxy.class); i = InodeFactory.getInode(1,
240      * VirtualLink.class); i = InodeFactory.getInode(1, Event.class); i =
241      * InodeFactory.getInode(1, Recurance.class); i = InodeFactory.getInode(1,
242      * EventRegistration.class); i = InodeFactory.getInode(1, Banner.class); i =
243      * InodeFactory.getInode(1, Structure.class); i = InodeFactory.getInode(1,
244      * Field.class); }
245      */

246
247 }
248
Popular Tags