use of com.taobao.weex.common.WXModule in project weex-example by KalicyZhou.
the class WXModuleManager method destroyInstanceModules.
public static void destroyInstanceModules(String instanceId) {
sDomModuleMap.remove(instanceId);
Map<String, WXModule> moduleMap = sInstanceModuleMap.remove(instanceId);
if (moduleMap == null || moduleMap.size() < 1) {
return;
}
Iterator<Entry<String, WXModule>> iterator = moduleMap.entrySet().iterator();
Entry<String, WXModule> entry;
while (iterator.hasNext()) {
entry = iterator.next();
WXModule module = entry.getValue();
if (module instanceof Destroyable) {
((Destroyable) module).destroy();
}
}
}
use of com.taobao.weex.common.WXModule in project weex-example by KalicyZhou.
the class WXModuleManager method callModuleMethod.
static Object callModuleMethod(final String instanceId, String moduleStr, String methodStr, JSONArray args) {
ModuleFactory factory = sModuleFactoryMap.get(moduleStr);
if (factory == null) {
WXLogUtils.e("[WXModuleManager] module factory not found.");
return null;
}
final WXModule wxModule = findModule(instanceId, moduleStr, factory);
if (wxModule == null) {
return null;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
wxModule.mWXSDKInstance = instance;
final Invoker invoker = factory.getMethodInvoker(methodStr);
try {
return instance.getNativeInvokeHelper().invoke(wxModule, invoker, args);
} catch (Exception e) {
WXLogUtils.e("callModuleMethod >>> invoke module:" + moduleStr + ", method:" + methodStr + " failed. ", e);
return null;
} finally {
if (wxModule instanceof WXDomModule || wxModule instanceof WXTimerModule) {
wxModule.mWXSDKInstance = null;
}
}
}
use of com.taobao.weex.common.WXModule in project weex-example by KalicyZhou.
the class WXModuleManager method findModule.
private static WXModule findModule(String instanceId, String moduleStr, ModuleFactory factory) {
// find WXModule
WXModule wxModule = sGlobalModuleMap.get(moduleStr);
//not global module
if (wxModule == null) {
Map<String, WXModule> moduleMap = sInstanceModuleMap.get(instanceId);
if (moduleMap == null) {
moduleMap = new ConcurrentHashMap<>();
sInstanceModuleMap.put(instanceId, moduleMap);
}
// if cannot find the Module, create a new Module and save it
wxModule = moduleMap.get(moduleStr);
if (wxModule == null) {
try {
wxModule = factory.buildInstance();
wxModule.setModuleName(moduleStr);
} catch (Exception e) {
WXLogUtils.e(moduleStr + " module build instace failed.", e);
return null;
}
moduleMap.put(moduleStr, wxModule);
}
}
return wxModule;
}
Aggregations