public void setShardField(String shardField) { if (StringUtils.isNotEmpty(shardField)) { this.shardField = shardField; } }
public static boolean isNotEmpty(String... strs) { if (strs != null) { for (String s : strs) { if (isEmpty(s)) { return false; } } return true; } return false; }
public static String generateJobId() { return StringUtils.generateUUID(); }
protected void initConfig() { String compiler = config.getParameter(ExtConfig.COMPILER); if (StringUtils.isNotEmpty(compiler)) { AbstractCompiler.setCompiler(compiler); } if (StringUtils.isEmpty(config.getIp())) { config.setIp(NetUtils.getLocalHost()); } if (StringUtils.isEmpty(config.getIdentity())) { JobNodeConfigFactory.buildIdentity(config); } NodeFactory.build(node, config); LOGGER.info("Current Node config :{}", config); appContext.setEventCenter(ServiceLoader.load(EventCenter.class, config)); appContext.setCommandBodyWrapper(new CommandBodyWrapper(config)); appContext.setMasterElector(new MasterElector(appContext)); appContext.getMasterElector().addMasterChangeListener(masterChangeListeners); appContext.setRegistryStatMonitor(new RegistryStatMonitor(appContext)); // 订阅的node管理 SubscribedNodeManager subscribedNodeManager = new SubscribedNodeManager(appContext); appContext.setSubscribedNodeManager(subscribedNodeManager); nodeChangeListeners.add(subscribedNodeManager); // 用于master选举的监听器 nodeChangeListeners.add(new MasterElectionListener(appContext)); // 监听自己节点变化(如,当前节点被禁用了) nodeChangeListeners.add(new SelfChangeListener(appContext)); setSpiConfig(); }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
throw t; } catch (Throwable t) { throw new IllegalStateException("Failed to compile class, cause: " + t.getMessage() + ", class: " + className + ", code: " + code + ", stack: " + StringUtils.toString(t));
/** * Capitalize a {@code String}, changing the first letter to * upper case as per {@link Character#toUpperCase(char)}. * No other letters are changed. * @param str the {@code String} to capitalize, may be {@code null} * @return the capitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ public static String capitalize(String str) { return changeFirstCharacterCase(str, true); }
private static String separatedToCamelCase(String value, boolean caseInsensitive) { StringBuilder builder = new StringBuilder(); for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) { field = (caseInsensitive ? field.toLowerCase() : field); builder.append( builder.length() == 0 ? field : StringUtils.capitalize(field)); } for (String suffix : new String[] { "_", "-", "." }) { if (value.endsWith(suffix)) { builder.append(suffix); } } return builder.toString(); } }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
throw t; } catch (Throwable t) { throw new IllegalStateException("Failed to compile class, cause: " + t.getMessage() + ", class: " + className + ", code: " + code + ", stack: " + StringUtils.toString(t));
/** * Uncapitalize a {@code String}, changing the first letter to * lower case as per {@link Character#toLowerCase(char)}. * No other letters are changed. * @param str the {@code String} to uncapitalize, may be {@code null} * @return the uncapitalized {@code String}, or {@code null} if the supplied * string is {@code null} */ public static String uncapitalize(String str) { return changeFirstCharacterCase(str, false); }
private static String separatedToCamelCase(String value, boolean caseInsensitive) { StringBuilder builder = new StringBuilder(); for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) { field = (caseInsensitive ? field.toLowerCase() : field); builder.append( builder.length() == 0 ? field : StringUtils.capitalize(field)); } for (String suffix : new String[] { "_", "-", "." }) { if (value.endsWith(suffix)) { builder.append(suffix); } } return builder.toString(); } }
public void setShardField(String shardField) { if (StringUtils.isNotEmpty(shardField)) { this.shardField = shardField; } }
public String getParam(String key, String defaultValue) { if (params != null) { String value = params.get(key); if (StringUtils.isEmpty(value)) { return defaultValue; } return value; } return null; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public static String generateJobId() { return StringUtils.generateUUID(); }
public static Datastore getDataStore(Config config) { String[] addresses = config.getParameter(ExtConfig.MONGO_ADDRESSES, new String[]{"127.0.0.1:27017"}); String database = config.getParameter(ExtConfig.MONGO_DATABASE, "lts"); String username = config.getParameter(ExtConfig.MONGO_USERNAME); String pwd = config.getParameter(ExtConfig.MONGO_PASSWORD); String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd); Datastore datastore = DATA_STORE_MAP.get(cachedKey); if (datastore == null) { try { synchronized (lock) { datastore = DATA_STORE_MAP.get(cachedKey); if (datastore != null) { return datastore; } Morphia morphia = new Morphia(); MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd); MongoClient mongo = mongoFactoryBean.createInstance(); datastore = morphia.createDatastore(mongo, database); DATA_STORE_MAP.put(cachedKey, datastore); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect mongo failed! addresses: {}, database: {}", addresses, database), e); } } return datastore; }
response.setSuccess(false); response.setCode(ResponseCode.SYSTEM_ERROR); response.setMsg(StringUtils.toString(e)); } finally {