Search in sources :

Example 1 with ClassLoaderHook

use of com.alipay.sofa.ark.spi.service.classloader.ClassLoaderHook in project sofa-ark by alipay.

the class BizClassLoader method loadBizClassLoaderHook.

private void loadBizClassLoaderHook() {
    if (!skipLoadHook.get()) {
        synchronized (lock) {
            if (isHookLoaded.compareAndSet(false, true)) {
                bizClassLoaderHook = ArkServiceLoader.loadExtensionFromArkBiz(ClassLoaderHook.class, BIZ_CLASS_LOADER_HOOK, bizIdentity);
                Biz masterBiz = ArkClient.getMasterBiz();
                if (bizClassLoaderHook == null && masterBiz != null && !masterBiz.getIdentity().equals(bizIdentity)) {
                    ClassLoader masterClassLoader = masterBiz.getBizClassLoader();
                    String defaultBizClassloaderHook = System.getProperty(BIZ_CLASS_LOADER_HOOK_DIR);
                    if (!StringUtils.isEmpty(defaultBizClassloaderHook)) {
                        try {
                            bizClassLoaderHook = (ClassLoaderHook<Biz>) masterClassLoader.loadClass(defaultBizClassloaderHook).newInstance();
                        } catch (Exception e) {
                            throw new RuntimeException(String.format("can not find master classloader hook: %s", defaultBizClassloaderHook), e);
                        }
                    }
                }
                skipLoadHook.set(true);
            }
        }
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ClassLoaderHook(com.alipay.sofa.ark.spi.service.classloader.ClassLoaderHook) ArkLoaderException(com.alipay.sofa.ark.exception.ArkLoaderException) IOException(java.io.IOException)

Aggregations

ArkLoaderException (com.alipay.sofa.ark.exception.ArkLoaderException)1 Biz (com.alipay.sofa.ark.spi.model.Biz)1 ClassLoaderHook (com.alipay.sofa.ark.spi.service.classloader.ClassLoaderHook)1 IOException (java.io.IOException)1