@Override
public synchronized TreeLogger loadModule(BrowserChannelServer channel,
String moduleName, String userAgent, String url, String tabKey,
String sessionKey, byte[] userAgentIcon) {
Event moduleInit = SpeedTracerLogger.start(DevModeEventType.MODULE_INIT, "Module Name", moduleName);
ModuleHandle moduleHandle = host.createModuleLogger(moduleName, userAgent,
url, tabKey, sessionKey, channel, userAgentIcon);
TreeLogger logger = moduleHandle.getLogger();
moduleHandleMap.put(channel, moduleHandle);
ModuleSpace moduleSpace = null;
try {
// Attach a new ModuleSpace to make it programmable.
ModuleSpaceHost msh = host.createModuleSpaceHost(moduleHandle, moduleName);
moduleSpace = new ModuleSpaceOOPHM(msh, moduleName, channel);
moduleMap.put(channel, moduleSpace);
moduleSpace.onLoad(logger);
moduleHandle.getLogger().log(TreeLogger.INFO,
"Module " + moduleName + " has been loaded");
} catch (Throwable e) {
// We do catch Throwable intentionally because there are a ton of things
// that can go wrong trying to load a module, including Error-derived
// things like NoClassDefFoundError.
//
moduleHandle.getLogger().log(
TreeLogger.ERROR,
"Failed to load module '" + moduleName + "' from user agent '"
+ userAgent + "' at " + channel.getRemoteEndpoint(), e);
if (moduleSpace != null) {
moduleSpace.dispose();
}
moduleHandle.unload();
moduleMap.remove(channel);
moduleHandleMap.remove(channel);
return null;
} finally {
moduleInit.end();
}
return moduleHandle.getLogger();
}