Search in sources :

Example 1 with WXModule

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();
        }
    }
}
Also used : Entry(java.util.Map.Entry) Destroyable(com.taobao.weex.common.Destroyable) WXModule(com.taobao.weex.common.WXModule)

Example 2 with WXModule

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;
        }
    }
}
Also used : WXDomModule(com.taobao.weex.dom.WXDomModule) WXSDKInstance(com.taobao.weex.WXSDKInstance) WXTimerModule(com.taobao.weex.ui.module.WXTimerModule) WXModule(com.taobao.weex.common.WXModule) WXException(com.taobao.weex.common.WXException)

Example 3 with WXModule

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;
}
Also used : WXModule(com.taobao.weex.common.WXModule) WXException(com.taobao.weex.common.WXException)

Aggregations

WXModule (com.taobao.weex.common.WXModule)3 WXException (com.taobao.weex.common.WXException)2 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 Destroyable (com.taobao.weex.common.Destroyable)1 WXDomModule (com.taobao.weex.dom.WXDomModule)1 WXTimerModule (com.taobao.weex.ui.module.WXTimerModule)1 Entry (java.util.Map.Entry)1