1 23 package org.infoglue.deliver.jobs; 24 25 import java.util.Date ; 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 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 e) 52 { 53 e.printStackTrace(); 54 } 55 56 logger.info("---" + context.getJobDetail().getFullName() + " executing.[" + new Date () + "]"); 57 58 try 59 { 60 Date firstExpireDateTime = CacheController.expireDateTime; 61 logger.info("firstExpireDateTime:" + firstExpireDateTime); 62 Date now = new Date (); 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 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 [] {"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 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 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 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 [] {"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 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 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 |