Permalink
Browse files

Fix for "Simplified CommonJS Wrapping Running All the Time" and Warmu…

…p support improvements
  • Loading branch information...
1 parent c5772ab commit e12f028bccc3fac623b49f053716f177fd5fb185 @rbackhouse rbackhouse committed Feb 23, 2013
@@ -462,6 +462,7 @@ var define;
}
define = function (id, dependencies, factory) {
+ var simpleCJS = false;
if (!isString(id)) {
factory = dependencies;
dependencies = id;
@@ -473,6 +474,7 @@ var define;
}
var args;
if (!isArray(dependencies)) {
+ simpleCJS = true;
factory = dependencies;
dependencies = [];
} else {
@@ -481,7 +483,7 @@ var define;
modules[id] = {id: id, exports: {}, args: args, deploaded: {}, dependencies: dependencies, config: function() { if (!cfg.config[id]) { cfg.config[id] = {}; } return cfg.config[id]; }};
if (isFunction(factory)) {
var scancjs = cfg ? cfg.scanCJSRequires : false;
- if (scancjs) {
+ if (scancjs && simpleCJS) {
factory.toString().replace(commentRegExp, "").replace(cjsRequireRegExp, function (match, dep) {
modules[id].dependencies.push("~#"+dep);
});
@@ -212,6 +212,10 @@ public void handleHeadRequest(HttpServletRequest request, HttpServletResponse re
@SuppressWarnings("unchecked")
Map<String, Object> pageConfig = (Map<String, Object>)JSONParser.parse(new StringReader(configString));
String key = JSAnalysisDataImpl.getKey(modules, exclude, pageConfig);
+ if (jsOptimizer.analysisInProcess(key)) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
JSAnalysisData analysisData = jsOptimizer.getAnalysisData(key);
if (analysisData != null) {
String checksum = analysisData.getChecksum();
@@ -18,7 +18,7 @@
public abstract class CachingJSOptimizer implements JSOptimizer {
private static Logger logger = Logger.getLogger("org.dojotoolkit.optimizer");
protected Map<String, JSAnalysisDataImpl> cache = null;
- protected Map<String, Object> lockMap = null;
+ protected Map<String, Lock> lockMap = null;
protected File tempDir = null;
protected ResourceLoader resourceLoader = null;
@@ -28,7 +28,7 @@ public CachingJSOptimizer(File tempDir, ResourceLoader resourceLoader) {
this.tempDir = tempDir;
this.resourceLoader = resourceLoader;
cache = Collections.synchronizedMap(new HashMap<String, JSAnalysisDataImpl>());
- lockMap = new HashMap<String, Object>();
+ lockMap = new HashMap<String, Lock>();
}
public JSAnalysisData getAnalysisData(String[] modules) throws IOException {
@@ -46,11 +46,11 @@ public JSAnalysisData getAnalysisData(String[] modules, JSAnalysisData[] exclude
public JSAnalysisData getAnalysisData(String[] modules, JSAnalysisData[] exclude, Map<String, Object> pageConfig) throws IOException {
String key = JSAnalysisDataImpl.getKey(modules, exclude, pageConfig);
logger.logp(Level.FINE, getClass().getName(), "getAnalysisData", "modules ["+key+"] in");
- Object lock = null;
+ Lock lock = null;
synchronized (lockMap) {
lock = lockMap.get(key);
if (lock == null) {
- lock = new Object();
+ lock = new Lock(false);
lockMap.put(key, lock);
}
}
@@ -81,9 +81,14 @@ public JSAnalysisData getAnalysisData(String[] modules, JSAnalysisData[] exclude
}
logger.logp(Level.FINE, getClass().getName(), "getAnalysisData", "creating Analysis Data for modules["+moduleList+"] stale["+stale+"] key["+key+"] excluded["+excludeList+"]");
}
- jsAnalysisData = _getAnalysisData(modules, exclude, pageConfig);
- jsAnalysisData.save(tempDir);
- cache.put(key, jsAnalysisData);
+ lock.locked = true;
+ try {
+ jsAnalysisData = _getAnalysisData(modules, exclude, pageConfig);
+ jsAnalysisData.save(tempDir);
+ cache.put(key, jsAnalysisData);
+ } finally {
+ lock.locked = false;
+ }
}
logger.logp(Level.FINE, getClass().getName(), "getAnalysisData", "modules ["+key+"] out lock");
}
@@ -94,11 +99,11 @@ public JSAnalysisData getAnalysisData(String[] modules, JSAnalysisData[] exclude
public JSAnalysisData getAnalysisData(String key) throws UnsupportedOperationException {
logger.logp(Level.FINE, getClass().getName(), "getAnalysisData", "modules ["+key+"] in");
- Object lock = null;
+ Lock lock = null;
synchronized (lockMap) {
lock = lockMap.get(key);
if (lock == null) {
- lock = new Object();
+ lock = new Lock(false);
lockMap.put(key, lock);
}
}
@@ -113,5 +118,28 @@ public JSAnalysisData getAnalysisData(String key) throws UnsupportedOperationExc
return jsAnalysisData;
}
+ public boolean analysisInProcess(String key) {
+ Lock lock = null;
+ synchronized (lockMap) {
+ lock = lockMap.get(key);
+ if (lock == null) {
+ return false;
+ }
+ }
+ return lock.isLocked();
+ }
+
protected abstract JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[] exclude, Map<String, Object> config) throws IOException;
+
+ private class Lock {
+ boolean locked = false;
+
+ public Lock(boolean locked) {
+ this.locked = locked;
+ }
+
+ boolean isLocked() {
+ return locked;
+ }
+ }
}
@@ -52,4 +52,10 @@
* @throws IOException
*/
Map<String, Object> getConfig();
+ /**
+ * @param key String value that can be used to identify what this analyisData is for
+ * @return boolean indicates if an analysis is in process for the given key
+ * @throws UnsupportedOperationException if optimizer does not support retrieval by key.
+ */
+ boolean analysisInProcess(String key);
}

0 comments on commit e12f028

Please sign in to comment.