1 16 package org.apache.cocoon.transformation.helpers; 17 18 import java.io.IOException ; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 24 import org.apache.avalon.framework.parameters.Parameters; 25 import org.apache.excalibur.source.Source; 26 import org.apache.excalibur.source.SourceResolver; 27 import org.apache.excalibur.source.SourceValidity; 28 import org.apache.excalibur.source.impl.validity.ExpiresValidity; 29 30 46 public final class IncludeCacheManagerSession { 47 48 49 private long expires; 50 51 52 private boolean purge; 53 54 55 private boolean preemptive; 56 57 58 private boolean parallel; 59 60 61 private IncludeCacheStorageProxy storage; 62 63 64 private Map threadList; 65 66 67 private SourceValidity validity; 68 69 70 private Map sourceList = new HashMap (10); 71 72 77 IncludeCacheManagerSession(Parameters configuration, 78 IncludeCacheStorageProxy proxy) { 79 this.expires = configuration.getParameterAsLong("expires", 0); 80 this.purge = configuration.getParameterAsBoolean("purge", false); 81 this.preemptive = configuration.getParameterAsBoolean("preemptive", false); 82 this.parallel = configuration.getParameterAsBoolean("parallel", false); 83 this.storage = proxy; 84 } 85 86 89 IncludeCacheStorageProxy getCacheStorageProxy() { 90 return this.storage; 91 } 92 93 96 public long getExpires() { 97 return this.expires; 98 } 99 100 public SourceValidity getExpiresValidity() { 101 if ( this.expires > 0 && this.validity == null) { 102 this.validity = new ExpiresValidity( this.expires * 1000 ); } 104 return this.validity; 105 } 106 107 110 public boolean isPurging() { 111 return this.purge; 112 } 113 114 117 public boolean isPreemptive() { 118 return this.preemptive; 119 } 120 121 124 public boolean isParallel() { 125 return this.parallel; 126 } 127 128 133 void add(String uri, Object object) { 134 if ( null == this.threadList ) { 135 this.threadList = new HashMap (10); 136 } 137 this.threadList.put(uri, object); 138 } 139 140 145 Object get(String uri) { 146 if ( null != this.threadList ) { 147 return this.threadList.get( uri ); 148 } 149 return null; 150 } 151 152 155 void setPreemptive(boolean value) { 156 this.preemptive = value; 157 } 158 159 164 public Source resolveURI(String uri, SourceResolver resolver) 165 throws IOException { 166 Source source = (Source)this.sourceList.get(uri); 167 if ( null == source ) { 168 source = resolver.resolveURI( uri ); 169 this.sourceList.put( source.getURI(), source ); 170 } 171 return source; 172 } 173 174 178 void cleanup(SourceResolver resolver) { 179 Iterator iter = this.sourceList.values().iterator(); 180 while ( iter.hasNext() ) { 181 final Source source = (Source) iter.next(); 182 resolver.release( source ); 183 } 184 } 185 186 189 public String toString() { 190 return "CacheManagerSession(" + this.hashCode() + ") -" + 191 " expires: " + this.expires + 192 " parallel: " + this.parallel + 193 " preemptive: " + this.preemptive + 194 " purge: " + this.purge; 195 } 196 } 197 | Popular Tags |