com.xxl.rpc.util.IpUtil Java Examples
The following examples show how to use
com.xxl.rpc.util.IpUtil.
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: XxlJobExecutor.java From microservices-platform with Apache License 2.0 | 6 votes |
public void start() throws Exception { // init logpath XxlJobFileAppender.initLogPath(logPath); // init admin-client initAdminBizList(adminAddresses, accessToken); // init JobLogFileCleanThread JobLogFileCleanThread.getInstance().start(logRetentionDays); // init TriggerCallbackThread TriggerCallbackThread.getInstance().start(); // init executor-server port = port>0?port: NetUtil.findAvailablePort(9777); ip = (ip!=null&&ip.trim().length()>0)?ip: IpUtil.getIp(); initRpcProvider(ip, port, appName, accessToken); }
Example #2
Source File: XxlJobExecutor.java From microservices-platform with Apache License 2.0 | 6 votes |
private void initRpcProvider(String ip, int port, String appName, String accessToken) throws Exception { // init, provider factory String address = IpUtil.getIpPort(ip, port); Map<String, String> serviceRegistryParam = new HashMap<String, String>(); serviceRegistryParam.put("appName", appName); serviceRegistryParam.put("address", address); xxlRpcProviderFactory = new XxlRpcProviderFactory(); xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, serviceRegistryParam); // add services xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl()); // start xxlRpcProviderFactory.start(); }
Example #3
Source File: XxlJobExecutor.java From zuihou-admin-boot with Apache License 2.0 | 6 votes |
public void start() throws Exception { // init logpath XxlJobFileAppender.initLogPath(logPath); // init admin-client initAdminBizList(adminAddresses, accessToken); // init JobLogFileCleanThread JobLogFileCleanThread.getInstance().start(logRetentionDays); // init TriggerCallbackThread TriggerCallbackThread.getInstance().start(); // init executor-server port = port > 0 ? port : NetUtil.findAvailablePort(9999); ip = (ip != null && ip.trim().length() > 0) ? ip : IpUtil.getIp(); initRpcProvider(ip, port, appName, accessToken, registryLazy); }
Example #4
Source File: XxlJobExecutor.java From zuihou-admin-boot with Apache License 2.0 | 6 votes |
private void initRpcProvider(String ip, int port, String appName, String accessToken, long registryLazy) throws Exception { // init invoker factory xxlRpcInvokerFactory = new XxlRpcInvokerFactory(); // init, provider factory String address = IpUtil.getIpPort(ip, port); Map<String, String> serviceRegistryParam = new HashMap<String, String>(); serviceRegistryParam.put("appName", appName); serviceRegistryParam.put("address", address); serviceRegistryParam.put("registryLazy", String.valueOf(registryLazy)); xxlRpcProviderFactory = new XxlRpcProviderFactory(); xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, serviceRegistryParam); // add services xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl()); // start xxlRpcProviderFactory.start(); }
Example #5
Source File: XxlJobExecutor.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
public void start() throws Exception { // init logpath XxlJobFileAppender.initLogPath(logPath); // init admin-client initAdminBizList(adminAddresses, accessToken); // init JobLogFileCleanThread JobLogFileCleanThread.getInstance().start(logRetentionDays); // init TriggerCallbackThread TriggerCallbackThread.getInstance().start(); // init executor-server port = port > 0 ? port : NetUtil.findAvailablePort(9999); ip = (ip != null && ip.trim().length() > 0) ? ip : IpUtil.getIp(); initRpcProvider(ip, port, appName, accessToken, registryLazy); }
Example #6
Source File: XxlJobExecutor.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
private void initRpcProvider(String ip, int port, String appName, String accessToken, long registryLazy) throws Exception { // init invoker factory xxlRpcInvokerFactory = new XxlRpcInvokerFactory(); // init, provider factory String address = IpUtil.getIpPort(ip, port); Map<String, String> serviceRegistryParam = new HashMap<String, String>(); serviceRegistryParam.put("appName", appName); serviceRegistryParam.put("address", address); serviceRegistryParam.put("registryLazy", String.valueOf(registryLazy)); xxlRpcProviderFactory = new XxlRpcProviderFactory(); xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, serviceRegistryParam); // add services xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl()); // start xxlRpcProviderFactory.start(); }
Example #7
Source File: XxlMqBrokerImpl.java From xxl-mq with GNU General Public License v3.0 | 6 votes |
public void initServer() throws Exception { // address, static registry ip = (ip!=null&&ip.trim().length()>0)?ip:IpUtil.getIp(); String address = IpUtil.getIpPort(ip, port); XxlCommonRegistryData xxlCommonRegistryData = new XxlCommonRegistryData(); xxlCommonRegistryData.setKey(IXxlMqBroker.class.getName()); xxlCommonRegistryData.setValue(address); XxlCommonRegistryServiceImpl.staticRegistryData = xxlCommonRegistryData; // init server providerFactory = new XxlRpcProviderFactory(); providerFactory.initConfig(NetEnum.NETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, null, null, null); // add server providerFactory.addService(IXxlMqBroker.class.getName(), null, this); // start server providerFactory.start(); }
Example #8
Source File: XxlJobTrigger.java From microservices-platform with Apache License 2.0 | 4 votes |
/** * @param group job group, registry list may be empty * @param jobInfo * @param finalFailRetryCount * @param triggerType * @param index sharding index * @param total sharding index */ private static void processTrigger(XxlJobGroup group, XxlJobInfo jobInfo, int finalFailRetryCount, TriggerTypeEnum triggerType, int index, int total){ // param ExecutorBlockStrategyEnum blockStrategy = ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), ExecutorBlockStrategyEnum.SERIAL_EXECUTION); // block strategy ExecutorRouteStrategyEnum executorRouteStrategyEnum = ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null); // route strategy String shardingParam = (ExecutorRouteStrategyEnum.SHARDING_BROADCAST==executorRouteStrategyEnum)?String.valueOf(index).concat("/").concat(String.valueOf(total)):null; // 1、save log-id XxlJobLog jobLog = new XxlJobLog(); jobLog.setJobGroup(jobInfo.getJobGroup()); jobLog.setJobId(jobInfo.getId()); jobLog.setTriggerTime(new Date()); XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().save(jobLog); logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId()); // 2、init trigger-param TriggerParam triggerParam = new TriggerParam(); triggerParam.setJobId(jobInfo.getId()); triggerParam.setExecutorHandler(jobInfo.getExecutorHandler()); triggerParam.setExecutorParams(jobInfo.getExecutorParam()); triggerParam.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy()); triggerParam.setExecutorTimeout(jobInfo.getExecutorTimeout()); triggerParam.setLogId(jobLog.getId()); triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime()); triggerParam.setGlueType(jobInfo.getGlueType()); triggerParam.setGlueSource(jobInfo.getGlueSource()); triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime()); triggerParam.setBroadcastIndex(index); triggerParam.setBroadcastTotal(total); // 3、init address String address = null; ReturnT<String> routeAddressResult = null; if (group.getRegistryList()!=null && !group.getRegistryList().isEmpty()) { if (ExecutorRouteStrategyEnum.SHARDING_BROADCAST == executorRouteStrategyEnum) { if (index < group.getRegistryList().size()) { address = group.getRegistryList().get(index); } else { address = group.getRegistryList().get(0); } } else { routeAddressResult = executorRouteStrategyEnum.getRouter().route(triggerParam, group.getRegistryList()); if (routeAddressResult.getCode() == ReturnT.SUCCESS_CODE) { address = routeAddressResult.getContent(); } } } else { routeAddressResult = new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobconf_trigger_address_empty")); } // 4、trigger remote executor ReturnT<String> triggerResult = null; if (address != null) { triggerResult = runExecutor(triggerParam, address); } else { triggerResult = new ReturnT<String>(ReturnT.FAIL_CODE, null); } // 5、collection trigger info StringBuffer triggerMsgSb = new StringBuffer(); triggerMsgSb.append(I18nUtil.getString("jobconf_trigger_type")).append(":").append(triggerType.getTitle()); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_admin_adress")).append(":").append(IpUtil.getIp()); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regtype")).append(":") .append( (group.getAddressType() == 0)?I18nUtil.getString("jobgroup_field_addressType_0"):I18nUtil.getString("jobgroup_field_addressType_1") ); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobconf_trigger_exe_regaddress")).append(":").append(group.getRegistryList()); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorRouteStrategy")).append(":").append(executorRouteStrategyEnum.getTitle()); if (shardingParam != null) { triggerMsgSb.append("("+shardingParam+")"); } triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorBlockStrategy")).append(":").append(blockStrategy.getTitle()); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_timeout")).append(":").append(jobInfo.getExecutorTimeout()); triggerMsgSb.append("<br>").append(I18nUtil.getString("jobinfo_field_executorFailRetryCount")).append(":").append(finalFailRetryCount); triggerMsgSb.append("<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_run") +"<<<<<<<<<<< </span><br>") .append((routeAddressResult!=null&&routeAddressResult.getMsg()!=null)?routeAddressResult.getMsg()+"<br><br>":"").append(triggerResult.getMsg()!=null?triggerResult.getMsg():""); // 6、save log trigger-info jobLog.setExecutorAddress(address); jobLog.setExecutorHandler(jobInfo.getExecutorHandler()); jobLog.setExecutorParam(jobInfo.getExecutorParam()); jobLog.setExecutorShardingParam(shardingParam); jobLog.setExecutorFailRetryCount(finalFailRetryCount); //jobLog.setTriggerTime(); jobLog.setTriggerCode(triggerResult.getCode()); jobLog.setTriggerMsg(triggerMsgSb.toString()); XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().updateTriggerInfo(jobLog); logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId()); }
Example #9
Source File: XxlMqProducer.java From xxl-mq with GNU General Public License v3.0 | 4 votes |
/** * valid message * * @param mqMessage * @return */ public static void validMessage(XxlMqMessage mqMessage){ if (mqMessage == null) { throw new IllegalArgumentException("xxl-mq, XxlMqMessage can not be null."); } // topic if (mqMessage.getTopic()==null || mqMessage.getTopic().trim().length()==0) { throw new IllegalArgumentException("xxl-mq, topic empty."); } if (!(mqMessage.getTopic().length()>=4 && mqMessage.getTopic().length()<=255)) { throw new IllegalArgumentException("xxl-mq, topic length invalid[4~255]."); } // group if (mqMessage.getGroup()==null || mqMessage.getGroup().trim().length()==0) { mqMessage.setGroup(MqConsumer.DEFAULT_GROUP); } if (!(mqMessage.getGroup().length()>=4 && mqMessage.getGroup().length()<=255)) { throw new IllegalArgumentException("xxl-mq, group length invalid[4~255]."); } // data if (mqMessage.getData() == null) { mqMessage.setData(""); } if (mqMessage.getData().length() > 20000) { throw new IllegalArgumentException("xxl-mq, data length invalid[0~60000]."); } // status mqMessage.setStatus(XxlMqMessageStatus.NEW.name()); // retryCount if (mqMessage.getRetryCount() < 0) { mqMessage.setRetryCount(0); } // shardingId if (mqMessage.getShardingId() < 0) { mqMessage.setShardingId(0); } // delayTime if (mqMessage.getEffectTime() == null) { mqMessage.setEffectTime(new Date()); } // timeout if (mqMessage.getTimeout() < 0) { mqMessage.setTimeout(0); } // log String appendLog = LogHelper.makeLog("生产消息", "消息生产者IP=" + IpUtil.getIp() ); mqMessage.setLog(appendLog); }