1 16 17 package org.apache.jetspeed.portal.expire; 18 19 import org.apache.jetspeed.cache.disk.DiskCacheEntry; 21 import org.apache.jetspeed.cache.disk.DiskCacheUtils; 22 import org.apache.jetspeed.cache.disk.JetspeedDiskCache; 23 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 24 import org.apache.jetspeed.services.logging.JetspeedLogger; 25 26 import java.io.IOException ; 28 import java.io.Serializable ; 29 30 31 37 public class FileWatcher implements Serializable 38 { 39 40 43 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(FileWatcher.class.getName()); 44 45 47 public static final String EXCEPTION_URL_NOT_NULL = 48 "URL can NOT be null here."; 49 50 public static final String EXCEPTION_URL_NOT_IN_CACHE = 51 "The URL you specified within the disk cache does not exist: "; 52 53 54 56 59 private String url = ""; 60 61 64 private long lastModified = 0; 65 66 69 private String parent = ""; 70 71 79 public FileWatcher( String url ) throws IOException { 80 this( url, null ); 81 } 82 83 89 public FileWatcher( String url, 90 String parent ) throws IOException { 91 92 if ( url == null ) { 93 throw new IOException ( EXCEPTION_URL_NOT_NULL ); 94 } 95 96 if ( DiskCacheUtils.isRemote( url ) && 97 DiskCacheUtils.isCached( url ) == false ) { 98 99 throw new IOException ( EXCEPTION_URL_NOT_IN_CACHE + url ); 100 } 101 102 try { 104 this.lastModified = JetspeedDiskCache.getInstance().getEntry( url ). 105 getLastModified(); 106 } catch (Throwable e) 107 { 108 logger.error( "Unable to set last modified on url " + url, e ); 109 } 110 111 this.url = url; 112 this.parent = parent; 113 } 114 115 121 public boolean hasChanged() { 122 123 try { 124 125 if ( this.lastModified == 0 ) { 127 128 DiskCacheEntry entry = JetspeedDiskCache.getInstance().getEntry( url ); 129 130 this.lastModified = entry.getLastModified(); 131 132 return false; 133 134 } 135 136 long recent = JetspeedDiskCache.getInstance() 139 .getEntry( url ).getLastModified(); 140 141 if ( recent == 0 || 143 this.lastModified < recent ) { 144 145 if ( logger.isInfoEnabled() ) 146 { 147 String message = ""; 148 149 if ( this.parent != null ) { 150 message = this.parent + ": "; 151 } 152 153 message += "REFRESH: Expiring Portlet because it's URL has been modified on disk -> " + url; 154 155 logger.info( message ); 156 } 157 return true; 158 } 159 160 } catch ( IOException e ) { 161 logger.error("Exception", e ); 162 return false; 163 } 164 165 return false; 167 168 } 169 170 } 171 | Popular Tags |