Debian Codegraph @

rhino/src/org/mozilla/javascript/commonjs/module/provider/StrongCachingModuleScriptProvider.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.javascript.commonjs.module.provider;
6
7 import java.util.Map;
8 import java.util.concurrent.ConcurrentHashMap;
9
10 import org.mozilla.javascript.commonjs.module.ModuleScript;
11
12 /**
13 * A module script provider that uses a module source provider to load modules
14 * and caches the loaded modules. It strongly references the loaded modules,
15 * thus a module once loaded will not be eligible for garbage collection before
16 * the module provider itself becomes eligible.
17 * @author Attila Szegedi
18 * @version $Id: StrongCachingModuleScriptProvider.java,v 1.3 2011/04/07 20:26:12 hannes%helma.at Exp $
19 */
20 public class StrongCachingModuleScriptProvider extends CachingModuleScriptProviderBase
21 {
22 private static final long serialVersionUID = 1L;
23
24 private final Map<String, CachedModuleScript> modules =
25 new ConcurrentHashMap<String, CachedModuleScript>(16, .75f, getConcurrencyLevel());
26
27 /**
28 * Creates a new module provider with the specified module source provider.
29 * @param moduleSourceProvider provider for modules' source code
30 */
31 public StrongCachingModuleScriptProvider(
32 ModuleSourceProvider moduleSourceProvider)
33 {
34 super(moduleSourceProvider);
35 }
36
37 @Override
38 protected CachedModuleScript getLoadedModule(String moduleId) {
39 return modules.get(moduleId);
40 }
41
42 @Override
43 protected void putLoadedModule(String moduleId, ModuleScript moduleScript,
44 Object validator) {
45 modules.put(moduleId, new CachedModuleScript(moduleScript, validator));
46 }
47 }