private final Map<String,String> typeMap;
private final NavigableMap<String,Content> content;
private final Set<String> attachOnly;
private final Map<String,String> typeMap;
private final NavigableMap<String,Content> content;
private final Set<String> attachOnly;
// when to re-validate from file
// Re validating means comparing the Timestamp on the disk, and seeing it has changed. Cache is not marked
// dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e.
// deployed GUI elements is unnecessary, and wastes time.
// This parameter exists to cover the cases where data can be more volatile, so the user can choose how often the
// File IO will be accessed, based on probability of change. "0", of course, means, check every time.
// when to re-validate from file
// Re validating means comparing the Timestamp on the disk, and seeing it has changed. Cache is not marked
// dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e.
// deployed GUI elements is unnecessary, and wastes time.
// This parameter exists to cover the cases where data can be more volatile, so the user can choose how often the
// File IO will be accessed, based on probability of change. "0", of course, means, check every time.
- private final static String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval";
- private final static String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit
- private final static String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command";
+ private static final String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval";
+ private static final String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit
+ private static final String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command";
// Note: can be null without a problem, but included
// to tie in with existing Logging.
// Note: can be null without a problem, but included
// to tie in with existing Logging.
public long checkInterval; // = 600000L; // only check if not hit in 10 mins by default
public int maxItemSize; // = 512000; // max file 500k
private Timer timer;
public long checkInterval; // = 600000L; // only check if not hit in 10 mins by default
public int maxItemSize; // = 512000; // max file 500k
private Timer timer;
// A command key is set in the Properties, preferably changed on deployment.
// it is compared at the beginning of the path, and if so, it is assumed to issue certain commands
// It's purpose is to protect, to some degree the command, even though it is HTTP, allowing
// local batch files to, for instance, clear caches on resetting of files.
// A command key is set in the Properties, preferably changed on deployment.
// it is compared at the beginning of the path, and if so, it is assumed to issue certain commands
// It's purpose is to protect, to some degree the command, even though it is HTTP, allowing
// local batch files to, for instance, clear caches on resetting of files.
public CachingFileAccess(EnvJAXB env, String ... args) throws IOException {
super(null,"Caching File Access");
public CachingFileAccess(EnvJAXB env, String ... args) throws IOException {
super(null,"Caching File Access");
typeMap.put("html","text/html");
typeMap.put("css","text/css");
typeMap.put("js","text/javascript");
typeMap.put("html","text/html");
typeMap.put("css","text/css");
typeMap.put("js","text/javascript");
typeMap.put("xml","text/xml");
typeMap.put("xsd","text/xml");
attachOnly.add("xsd");
typeMap.put("xml","text/xml");
typeMap.put("xsd","text/xml");
attachOnly.add("xsd");
typeMap.put("jar","application/x-java-applet");
typeMap.put("jnlp", "application/x-java-jnlp-file");
typeMap.put("class", "application/java");
typeMap.put("jar","application/x-java-applet");
typeMap.put("jnlp", "application/x-java-jnlp-file");
typeMap.put("class", "application/java");
timer.schedule(new Cleanup(content,500),60000,60000);
// Property params
timer.schedule(new Cleanup(content,500),60000,60000);
// Property params
- web_path = env.get(env.staticSlot(CFA_WEB_PATH));
- env.init().log("CachingFileAccess path: " + new File(web_path).getCanonicalPath());
+ webPath = env.get(env.staticSlot(CFA_WEB_PATH));
+ env.init().log("CachingFileAccess path: " + new File(webPath).getCanonicalPath());
Object obj;
obj = env.get(env.staticSlot(CFA_CACHE_CHECK_INTERVAL),600000L); // Default is 10 mins
if (obj instanceof Long) {
Object obj;
obj = env.get(env.staticSlot(CFA_CACHE_CHECK_INTERVAL),600000L); // Default is 10 mins
if (obj instanceof Long) {
public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException {
String key = pathParam(req, ":key");
int slash = key.indexOf('/');
public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException {
String key = pathParam(req, ":key");
int slash = key.indexOf('/');
resp.setHeader("Content-Type",typeMap.get("txt"));
if ("clear".equals(key.substring(slash+1))) {
content.clear();
resp.setHeader("Content-Type",typeMap.get("txt"));
if ("clear".equals(key.substring(slash+1))) {
content.clear();
- Content c = load(logT , web_path,key, null, checkInterval);
+ Content c = load(logT , webPath,key, null, checkInterval);
private long date; // date of the actual artifact (i.e. File modified date)
private long access; // last accessed
private long date; // date of the actual artifact (i.e. File modified date)
private long access; // last accessed
public void setHeader(HttpServletResponse resp) {
resp.setStatus(200/*OK_200*/);
resp.setHeader("Content-Type",contentType);
public void setHeader(HttpServletResponse resp) {
resp.setStatus(200/*OK_200*/);
resp.setHeader("Content-Type",contentType);
for (int i=0;i<end;++i) {
Entry<String, Content> entry = scont.get(i).entry;
content.remove(entry.getKey());
for (int i=0;i<end;++i) {
Entry<String, Content> entry = scont.get(i).entry;
content.remove(entry.getKey());