com.xxl.job.core.biz.AdminBiz Java Examples

The following examples show how to use com.xxl.job.core.biz.AdminBiz. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TriggerCallbackThread.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * do callback, will retry if error
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList){
    boolean callbackRet = false;
    // callback, will retry if error
    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult!=null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback finish.");
                callbackRet = true;
                break;
            } else {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback fail, callbackResult:" + callbackResult);
            }
        } catch (Exception e) {
            callbackLog(callbackParamList, "<br>----------- xxl-job job callback error, errorMsg:" + e.getMessage());
        }
    }
    if (!callbackRet) {
        appendFailCallbackFile(callbackParamList);
    }
}
 
Example #2
Source File: TriggerCallbackThread.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
/**
 * do callback, will retry if error
 *
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList) {
    boolean callbackRet = false;
    // callback, will retry if error
    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult != null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback finish.");
                callbackRet = true;
                break;
            } else {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback fail, callbackResult:" + callbackResult);
            }
        } catch (Exception e) {
            callbackLog(callbackParamList, "<br>----------- xxl-job job callback error, errorMsg:" + e.getMessage());
        }
    }
    if (!callbackRet) {
        appendFailCallbackFile(callbackParamList);
    }
}
 
Example #3
Source File: AdminBizTest.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * registry executor remove
 *
 * @throws Exception
 */
@Test
public void registryRemove() throws Exception {
    addressUrl = addressUrl.replace("http://", "");
    AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
            NetEnum.JETTY,
            Serializer.SerializeEnum.HESSIAN.getSerializer(),
            CallType.SYNC,
            LoadBalance.ROUND,
            AdminBiz.class,
            null,
            10000,
            addressUrl,
            accessToken,
            null,
            null).getObject();

    // test executor registry remove
    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registryRemove(registryParam);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

    // stop invoker
    XxlRpcInvokerFactory.getInstance().stop();
}
 
Example #4
Source File: AdminBizTest.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
/**
 * registry executor
 *
 * @throws Exception
 */
@Test
public void registryTest() throws Exception {
    addressUrl = addressUrl.replace("http://", "");
    AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
            NetEnum.JETTY,
            Serializer.SerializeEnum.HESSIAN.getSerializer(),
            CallType.SYNC,
            LoadBalance.ROUND,
            AdminBiz.class,
            null,
            10000,
            addressUrl,
            accessToken,
            null,
            null).getObject();

    // test executor registry
    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registry(registryParam);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

    // stop invoker
    XxlRpcInvokerFactory.getInstance().stop();
}
 
Example #5
Source File: XxlJobExecutor.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
    if (adminAddresses != null && adminAddresses.trim().length() > 0) {
        for (String address : adminAddresses.trim().split(",")) {
            if (address != null && address.trim().length() > 0) {

                String addressUrl = address.concat(AdminBiz.MAPPING);
                if (addressUrl.startsWith("http://")) {
                    addressUrl = addressUrl.replace("http://", "");
                }
                if (addressUrl.startsWith("https://")) {
                    addressUrl = addressUrl.replace("https://", "");
                }

                AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), CallType.SYNC,
                        AdminBiz.class, null, 10000, addressUrl, accessToken, null).getObject();

                if (adminBizList == null) {
                    adminBizList = new ArrayList<AdminBiz>();
                }
                adminBizList.add(adminBiz);
            }
        }
    }
}
 
Example #6
Source File: XxlJobDynamicScheduler.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
private void initRpcProvider(){
    // init
    XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
    xxlRpcProviderFactory.initConfig(
            NetEnum.JETTY,
            Serializer.SerializeEnum.HESSIAN.getSerializer(),
            null,
            0,
            XxlJobAdminConfig.getAdminConfig().getAccessToken(),
            null,
            null);

    // add services
    xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());

    // jetty handler
    jettyServerHandler = new JettyServerHandler(xxlRpcProviderFactory);
}
 
Example #7
Source File: TriggerCallbackThread.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * do callback, will retry if error
 *
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList) {
    boolean callbackRet = false;
    // callback, will retry if error
    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult != null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback finish.");
                callbackRet = true;
                break;
            } else {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback fail, callbackResult:" + callbackResult);
            }
        } catch (Exception e) {
            callbackLog(callbackParamList, "<br>----------- xxl-job job callback error, errorMsg:" + e.getMessage());
        }
    }
    if (!callbackRet) {
        appendFailCallbackFile(callbackParamList);
    }
}
 
Example #8
Source File: XxlJobExecutor.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
    if (adminAddresses != null && adminAddresses.trim().length() > 0) {
        for (String address : adminAddresses.trim().split(",")) {
            if (address != null && address.trim().length() > 0) {

                String addressUrl = address.concat(AdminBiz.MAPPING);
                if (addressUrl.startsWith("http://")) {
                    addressUrl = addressUrl.replace("http://", "");
                }
                if (addressUrl.startsWith("https://")) {
                    addressUrl = addressUrl.replace("https://", "");
                }

                AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), CallType.SYNC,
                        AdminBiz.class, null, 10000, addressUrl, accessToken, null).getObject();

                if (adminBizList == null) {
                    adminBizList = new ArrayList<AdminBiz>();
                }
                adminBizList.add(adminBiz);
            }
        }
    }
}
 
Example #9
Source File: TriggerCallbackThread.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
/**
 * do callback, will retry if error
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList){
    boolean callbackRet = false;
    // callback, will retry if error
    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult!=null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback finish.");
                callbackRet = true;
                break;
            } else {
                callbackLog(callbackParamList, "<br>----------- xxl-job job callback fail, callbackResult:" + callbackResult);
            }
        } catch (Exception e) {
            callbackLog(callbackParamList, "<br>----------- xxl-job job callback error, errorMsg:" + e.getMessage());
        }
    }
    if (!callbackRet) {
        appendFailCallbackFile(callbackParamList);
    }
}
 
Example #10
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    // admin registry monitor run
    // 启动自动注册线程, 获取类型为自动注册的执行器信息,完成机器的自动注册与发现
    JobRegistryMonitorHelper.getInstance().start();

    // admin monitor run
    // 启动失败日志监控线程
    JobFailMonitorHelper.getInstance().start();

    // admin-server(spring-mvc)
    NetComServerFactory.putService(AdminBiz.class, XxlJobDynamicScheduler.adminBiz);
    NetComServerFactory.setAccessToken(accessToken);

    // init i18n
    initI18n();

    // valid
    Assert.notNull(scheduler, "quartz scheduler is null");
    logger.info(">>>>>>>>> init xxl-job admin success.");
}
 
Example #11
Source File: JobApiController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping(AdminBiz.MAPPING)
@PermessionLimit(limit=false)
public void api(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // invoke
    RpcResponse rpcResponse = doInvoke(request);

    // serialize response
    byte[] responseBytes = HessianSerializer.serialize(rpcResponse);

    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    //baseRequest.setHandled(true);

    OutputStream out = response.getOutputStream();
    out.write(responseBytes);
    out.flush();
}
 
Example #12
Source File: TriggerCallbackThread.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * do callback, will retry if error
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList){
    // callback, will retry if error
    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult!=null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackResult = ReturnT.SUCCESS;
                logger.info(">>>>>>>>>>> xxl-job callback success, callbackParamList:{}, callbackResult:{}", new Object[]{callbackParamList, callbackResult});
                break;
            } else {
                logger.info(">>>>>>>>>>> xxl-job callback fail, callbackParamList:{}, callbackResult:{}", new Object[]{callbackParamList, callbackResult});
            }
        } catch (Exception e) {
            logger.error(">>>>>>>>>>> xxl-job callback error, callbackParamList:{}", callbackParamList, e);
            //getInstance().callBackQueue.addAll(callbackParamList);
        }
    }
}
 
Example #13
Source File: AdminBizTest.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * registry executor remove
 *
 * @throws Exception
 */
@Test
public void registryRemove() throws Exception {
    AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);

    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registryRemove(registryParam);

    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

}
 
Example #14
Source File: XxlJobDynamicScheduler.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private void initRpcProvider() {
    // init
    XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
    xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), null, 0, XxlJobAdminConfig.getAdminConfig().getAccessToken(), null, null);

    // add services
    xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());

    // jetty handler
    jettyServerHandler = new JettyServerHandler(xxlRpcProviderFactory);
}
 
Example #15
Source File: XxlJobExecutor.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
    if (adminAddresses!=null && adminAddresses.trim().length()>0) {
        for (String address: adminAddresses.trim().split(",")) {
            if (address!=null && address.trim().length()>0) {

                AdminBiz adminBiz = new AdminBizClient(address.trim(), accessToken);

                if (adminBizList == null) {
                    adminBizList = new ArrayList<AdminBiz>();
                }
                adminBizList.add(adminBiz);
            }
        }
    }
}
 
Example #16
Source File: AdminBizTest.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void callback() throws Exception {
    AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);

    HandleCallbackParam param = new HandleCallbackParam();
    param.setLogId(1);
    param.setExecuteResult(ReturnT.SUCCESS);

    List<HandleCallbackParam> callbackParamList = Arrays.asList(param);

    ReturnT<String> returnT = adminBiz.callback(callbackParamList);

    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
}
 
Example #17
Source File: AdminBizTest.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * registry executor
 *
 * @throws Exception
 */
@Test
public void registry() throws Exception {
    AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);

    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registry(registryParam);

    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
}
 
Example #18
Source File: XxlJobExecutor.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
private static void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
    if (adminAddresses!=null && adminAddresses.trim().length()>0) {
        for (String address: adminAddresses.trim().split(",")) {
            if (address!=null && address.trim().length()>0) {
                String addressUrl = address.concat(AdminBiz.MAPPING);
                AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl, accessToken).getObject();
                if (adminBizList == null) {
                    adminBizList = new ArrayList<AdminBiz>();
                }
                adminBizList.add(adminBiz);
            }
        }
    }
}
 
Example #19
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
   	XxlJobDynamicScheduler.scheduler = applicationContext.getBean("scheduler",Scheduler.class);
	//初始化 全局Dao 配置
	XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(XxlJobLogDao.class);
	XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(XxlJobInfoDao.class);
       XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(XxlJobRegistryDao.class);
       XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(XxlJobGroupDao.class);
       XxlJobDynamicScheduler.adminBiz = applicationContext.getBean(AdminBiz.class);
}
 
Example #20
Source File: XxlJobExecutor.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
    if (adminAddresses!=null && adminAddresses.trim().length()>0) {
        for (String address: adminAddresses.trim().split(",")) {
            if (address!=null && address.trim().length()>0) {

                String addressUrl = address.concat(AdminBiz.MAPPING);

                AdminBiz adminBiz = (AdminBiz) new XxlRpcReferenceBean(
                        NetEnum.JETTY,
                        Serializer.SerializeEnum.HESSIAN.getSerializer(),
                        CallType.SYNC,
                        LoadBalance.ROUND,
                        AdminBiz.class,
                        null,
                        10000,
                        addressUrl,
                        accessToken,
                        null,
                        null
                ).getObject();

                if (adminBizList == null) {
                    adminBizList = new ArrayList<AdminBiz>();
                }
                adminBizList.add(adminBiz);
            }
        }
    }
}
 
Example #21
Source File: XxlJobDynamicScheduler.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
private void initRpcProvider() {
    // init
    XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
    xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), null, 0, XxlJobAdminConfig.getAdminConfig().getAccessToken(), null, null);

    // add services
    xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());

    // jetty handler
    jettyServerHandler = new JettyServerHandler(xxlRpcProviderFactory);
}
 
Example #22
Source File: XxlJobExecutor.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
public static List<AdminBiz> getAdminBizList(){
    return adminBizList;
}
 
Example #23
Source File: ExecutorRegistryThread.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
public void start(final int port, final String ip, final String appName){

        // valid
        if (appName==null || appName.trim().length()==0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        // executor address (generate addredd = ip:port)
        final String executorAddress;
        if (ip != null && ip.trim().length()>0) {
            executorAddress = ip.trim().concat(":").concat(String.valueOf(port));
        } else {
            executorAddress = IpUtil.getIpPort(port);
        }

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
                        for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        logger.error(e.getMessage(), e);
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
                    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }
 
Example #24
Source File: XxlJobExecutor.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
public static List<AdminBiz> getAdminBizList(){
    return adminBizList;
}
 
Example #25
Source File: XxlJobExecutor.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
public static List<AdminBiz> getAdminBizList(){
    return adminBizList;
}
 
Example #26
Source File: ExecutorRegistryThread.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
public void start(final String appName, final String address){

        // valid
        if (appName==null || appName.trim().length()==0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                        for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }

                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        if (!toStop) {
                            logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                        }
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }
 
Example #27
Source File: ExecutorRegistryThread.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
public void start(final String appname, final String address){

        // valid
        if (appname==null || appname.trim().length()==0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appname is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
                        for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.debug(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }

                    }

                    try {
                        if (!toStop) {
                            TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                        }
                    } catch (InterruptedException e) {
                        if (!toStop) {
                            logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                        }
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
                    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            if (!toStop) {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                            }

                        }

                    }
                } catch (Exception e) {
                    if (!toStop) {
                        logger.error(e.getMessage(), e);
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.setName("xxl-job, executor ExecutorRegistryThread");
        registryThread.start();
    }
 
Example #28
Source File: XxlJobExecutor.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public static List<AdminBiz> getAdminBizList() {
    return adminBizList;
}
 
Example #29
Source File: ExecutorRegistryThread.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public void start(final String appName, final String address, final String registryLazy) {

        // valid
        if (appName == null || appName.trim().length() == 0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        REGISTRY_LAZY = Convert.toLong(registryLazy, 10000L);

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // 首次主次延迟 REGISTRY_LAZY 毫秒, 防止尚未启动完成时,注册失败
                if (REGISTRY_LAZY > 0) {
                    try {
                        Thread.sleep(REGISTRY_LAZY);
                    } catch (InterruptedException e) {
                        logger.error(">>>>>>>>>>> xxl-job 首次注册延迟失败, appName:{}, address:{}", new Object[]{appName, address});
                    } finally {
                        REGISTRY_LAZY = 0;
                    }
                }

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                        for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }
 
Example #30
Source File: XxlJobAdminConfig.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public AdminBiz getAdminBiz() {
    return adminBiz;
}