KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > jobs > ExpireCacheJob


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.deliver.jobs;
24
25 import java.util.Date JavaDoc;
26
27 import org.apache.log4j.Logger;
28 import org.infoglue.cms.util.CmsPropertyHandler;
29 import org.infoglue.deliver.util.CacheController;
30 import org.infoglue.deliver.util.RequestAnalyser;
31 import org.quartz.Job;
32 import org.quartz.JobExecutionContext;
33 import org.quartz.JobExecutionException;
34
35 /**
36  * @author mattias
37  *
38  * This jobs searches for expiring contents or sitenodes and clears caches if found.
39  */

40
41 public class ExpireCacheJob implements Job
42 {
43     private final static Logger logger = Logger.getLogger(ExpireCacheJob.class.getName());
44
45     public synchronized void execute(JobExecutionContext context) throws JobExecutionException
46     {
47         try
48         {
49             CacheController.evictWaitingCache();
50         }
51         catch (Exception JavaDoc e)
52         {
53             e.printStackTrace();
54         }
55
56         logger.info("---" + context.getJobDetail().getFullName() + " executing.[" + new Date JavaDoc() + "]");
57
58         try
59         {
60             Date JavaDoc firstExpireDateTime = CacheController.expireDateTime;
61             logger.info("firstExpireDateTime:" + firstExpireDateTime);
62             Date JavaDoc now = new Date JavaDoc();
63             
64             if(firstExpireDateTime != null && now.after(firstExpireDateTime))
65             {
66                 logger.info("setting block");
67                 synchronized(RequestAnalyser.getRequestAnalyser())
68                 {
69                     if(RequestAnalyser.getRequestAnalyser().getBlockRequests())
70                     {
71                         logger.warn("evictWaitingCache allready in progress - returning to avoid conflict");
72                         return;
73                     }
74
75                     RequestAnalyser.getRequestAnalyser().setBlockRequests(true);
76                 }
77
78                 try
79                 {
80                     String JavaDoc operatingMode = CmsPropertyHandler.getOperatingMode();
81                     if(operatingMode != null && operatingMode.equalsIgnoreCase("3"))
82                     {
83                         logger.info("Updating all caches as this was a publishing-update");
84                         CacheController.clearCastorCaches();
85         
86                         logger.info("clearing all except page cache as we are in publish mode..");
87                         CacheController.clearCaches(null, null, new String JavaDoc[] {"pageCache", "NavigationCache", "pagePathCache", "userCache", "pageCacheParentSiteNodeCache", "pageCacheLatestSiteNodeVersions", "pageCacheSiteNodeTypeDefinition"});
88                         
89                         logger.info("Recaching all caches as this was a publishing-update");
90                         CacheController.cacheCentralCastorCaches();
91                         
92                         logger.info("Finally clearing page cache as this was a publishing-update");
93                         CacheController.clearCache("pageCache");
94                     }
95                     else
96                     {
97                         logger.info("Updating all caches as this was a publishing-update");
98                         CacheController.clearCastorCaches();
99         
100                         logger.info("clearing all except page cache as we are in publish mode..");
101                         CacheController.clearCaches(null, null, null);
102                     }
103                 }
104                 catch(Exception JavaDoc e)
105                 {
106                     logger.error("An error occurred when we tried to update cache:" + e.getMessage(), e);
107                 }
108                 
109                 logger.info("releasing block");
110                 RequestAnalyser.getRequestAnalyser().setBlockRequests(false);
111             }
112
113             Date JavaDoc firstPublishDateTime = CacheController.publishDateTime;
114             logger.info("firstPublishDateTime:" + firstPublishDateTime);
115             
116             if(firstPublishDateTime != null && now.after(firstPublishDateTime))
117             {
118                 logger.info("setting block");
119                 synchronized(RequestAnalyser.getRequestAnalyser())
120                 {
121                     if(RequestAnalyser.getRequestAnalyser().getBlockRequests())
122                     {
123                         logger.warn("evictWaitingCache allready in progress - returning to avoid conflict");
124                         return;
125                     }
126
127                     RequestAnalyser.getRequestAnalyser().setBlockRequests(true);
128                 }
129                 
130                 try
131                 {
132                     String JavaDoc operatingMode = CmsPropertyHandler.getOperatingMode();
133                     if(operatingMode != null && operatingMode.equalsIgnoreCase("3"))
134                     {
135                         logger.info("Updating all caches as this was a publishing-update");
136                         CacheController.clearCastorCaches();
137         
138                         logger.info("clearing all except page cache as we are in publish mode..");
139                         CacheController.clearCaches(null, null, new String JavaDoc[] {"pageCache", "NavigationCache", "pagePathCache", "userCache", "pageCacheParentSiteNodeCache", "pageCacheLatestSiteNodeVersions", "pageCacheSiteNodeTypeDefinition"});
140                         
141                         logger.info("Recaching all caches as this was a publishing-update");
142                         CacheController.cacheCentralCastorCaches();
143                         
144                         logger.info("Finally clearing page cache as this was a publishing-update");
145                         CacheController.clearCache("pageCache");
146                     }
147                     else
148                     {
149                         logger.info("Updating all caches as this was a publishing-update");
150                         CacheController.clearCastorCaches();
151         
152                         logger.info("clearing all except page cache as we are in publish mode..");
153                         CacheController.clearCaches(null, null, null);
154                     }
155                 }
156                 catch(Exception JavaDoc e)
157                 {
158                     logger.error("An error occurred when we tried to update cache:" + e.getMessage(), e);
159                 }
160
161                 logger.info("releasing block");
162                 RequestAnalyser.getRequestAnalyser().setBlockRequests(false);
163             }
164
165         }
166         catch (Exception JavaDoc e)
167         {
168             logger.error("An error occurred when we tried to update cache:" + e.getMessage(), e);
169         }
170     }
171     
172
173 }
174
Popular Tags