Search in sources :

Example 1 with IIndexBuildLifeCycleHook

use of com.qlangtech.tis.exec.lifecycle.hook.IIndexBuildLifeCycleHook in project tis by qlangtech.

the class AdapterIndexBuildLifeCycleHook method create.

public static IIndexBuildLifeCycleHook create(ParseResult schemaParse) {
    try {
        List<IIndexBuildLifeCycleHook> indexBuildLifeCycleHooks = new ArrayList<>();
        List<IndexBuildHook> indexBuildHooks = schemaParse.getIndexBuildHooks();
        for (IndexBuildHook buildHook : indexBuildHooks) {
            Class<?> clazz = Class.forName(buildHook.getFullClassName());
            IIndexBuildLifeCycleHook indexBuildHook = (IIndexBuildLifeCycleHook) clazz.newInstance();
            if (indexBuildHook instanceof AdapterIndexBuildLifeCycleHook) {
                ((AdapterIndexBuildLifeCycleHook) indexBuildHook).init(buildHook.getParams());
            }
            indexBuildLifeCycleHooks.add(indexBuildHook);
        }
        return new IIndexBuildLifeCycleHook() {

            @Override
            public void start(IParamContext ctx) {
                try {
                    indexBuildLifeCycleHooks.forEach((e) -> {
                        e.start(ctx);
                    });
                } catch (Throwable e) {
                    logger.error(e.getMessage(), e);
                }
            }

            @Override
            public void buildFaild(IParamContext ctx) {
                try {
                    indexBuildLifeCycleHooks.forEach((e) -> {
                        e.buildFaild(ctx);
                    });
                } catch (Throwable e) {
                    logger.error(e.getMessage(), e);
                }
            }

            @Override
            public void buildSuccess(IParamContext ctx) {
                try {
                    indexBuildLifeCycleHooks.forEach((e) -> {
                        e.buildSuccess(ctx);
                    });
                } catch (Throwable e) {
                    logger.error(e.getMessage(), e);
                }
            }
        };
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IParamContext(com.qlangtech.tis.order.center.IParamContext) ArrayList(java.util.ArrayList) IIndexBuildLifeCycleHook(com.qlangtech.tis.exec.lifecycle.hook.IIndexBuildLifeCycleHook) IndexBuildHook(com.qlangtech.tis.solrdao.extend.IndexBuildHook)

Aggregations

IIndexBuildLifeCycleHook (com.qlangtech.tis.exec.lifecycle.hook.IIndexBuildLifeCycleHook)1 IParamContext (com.qlangtech.tis.order.center.IParamContext)1 IndexBuildHook (com.qlangtech.tis.solrdao.extend.IndexBuildHook)1 ArrayList (java.util.ArrayList)1