private static int checkPermits(int permits) { Assert.isTrue(permits > 0, StringUtils.format("Requested permits ({}) must be positive", permits)); return permits; } }
private static int checkPermits(int permits) { Assert.isTrue(permits > 0, StringUtils.format("Requested permits ({}) must be positive", permits)); return permits; } }
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; }
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; }
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); 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; }
/** * Creates a {@code RateLimiter} with the specified stable throughput, given as * "permits per second" (commonly referred to as <i>QPS</i>, queries per second), and a * <i>warmup period</i>, during which the {@code RateLimiter} smoothly ramps up its rate, * until it reaches its maximum rate at the end of the period (as long as there are enough * requests to saturate it). Similarly, if the {@code RateLimiter} is left <i>unused</i> for * a duration of {@code warmupPeriod}, it will gradually return to its "cold" state, * i.e. it will go through the same warming up process as when it was first created. * <p/> * <p>The returned {@code RateLimiter} is intended for cases where the resource that actually * fulfills the requests (e.g., a remote server) needs "warmup" time, rather than * being immediately accessed at the stable (maximum) rate. * <p/> * <p>The returned {@code RateLimiter} starts in a "cold" state (i.e. the warmup period * will follow), and if it is left unused for long enough, it will return to that state. * * @param permitsPerSecond the rate of the returned {@code RateLimiter}, measured in * how many permits become available per second * @param warmupPeriod the duration of the period where the {@code RateLimiter} ramps up its * rate, before reaching its stable (maximum) rate * @param unit the time unit of the warmupPeriod argument * @throws IllegalArgumentException if {@code permitsPerSecond} is negative or zero or * {@code warmupPeriod} is negative */ public static RateLimiter create(double permitsPerSecond, long warmupPeriod, TimeUnit unit) { Assert.isTrue(warmupPeriod >= 0, com.github.ltsopensource.core.commons.utils.StringUtils.format("warmupPeriod must not be negative: {}", warmupPeriod)); return create(SleepingStopwatch.createFromSystemTimer(), permitsPerSecond, warmupPeriod, unit, 3.0); }
/** * Creates a {@code RateLimiter} with the specified stable throughput, given as * "permits per second" (commonly referred to as <i>QPS</i>, queries per second), and a * <i>warmup period</i>, during which the {@code RateLimiter} smoothly ramps up its rate, * until it reaches its maximum rate at the end of the period (as long as there are enough * requests to saturate it). Similarly, if the {@code RateLimiter} is left <i>unused</i> for * a duration of {@code warmupPeriod}, it will gradually return to its "cold" state, * i.e. it will go through the same warming up process as when it was first created. * <p/> * <p>The returned {@code RateLimiter} is intended for cases where the resource that actually * fulfills the requests (e.g., a remote server) needs "warmup" time, rather than * being immediately accessed at the stable (maximum) rate. * <p/> * <p>The returned {@code RateLimiter} starts in a "cold" state (i.e. the warmup period * will follow), and if it is left unused for long enough, it will return to that state. * * @param permitsPerSecond the rate of the returned {@code RateLimiter}, measured in * how many permits become available per second * @param warmupPeriod the duration of the period where the {@code RateLimiter} ramps up its * rate, before reaching its stable (maximum) rate * @param unit the time unit of the warmupPeriod argument * @throws IllegalArgumentException if {@code permitsPerSecond} is negative or zero or * {@code warmupPeriod} is negative */ public static RateLimiter create(double permitsPerSecond, long warmupPeriod, TimeUnit unit) { Assert.isTrue(warmupPeriod >= 0, com.github.ltsopensource.core.commons.utils.StringUtils.format("warmupPeriod must not be negative: {}", warmupPeriod)); return create(SleepingStopwatch.createFromSystemTimer(), permitsPerSecond, warmupPeriod, unit, 3.0); }
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; }
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; }
private static int checkPermits(int permits) { Assert.isTrue(permits > 0, StringUtils.format("Requested permits ({}) must be positive", permits)); return permits; } }
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; }
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; }
/** * Creates a {@code RateLimiter} with the specified stable throughput, given as * "permits per second" (commonly referred to as <i>QPS</i>, queries per second), and a * <i>warmup period</i>, during which the {@code RateLimiter} smoothly ramps up its rate, * until it reaches its maximum rate at the end of the period (as long as there are enough * requests to saturate it). Similarly, if the {@code RateLimiter} is left <i>unused</i> for * a duration of {@code warmupPeriod}, it will gradually return to its "cold" state, * i.e. it will go through the same warming up process as when it was first created. * <p/> * <p>The returned {@code RateLimiter} is intended for cases where the resource that actually * fulfills the requests (e.g., a remote server) needs "warmup" time, rather than * being immediately accessed at the stable (maximum) rate. * <p/> * <p>The returned {@code RateLimiter} starts in a "cold" state (i.e. the warmup period * will follow), and if it is left unused for long enough, it will return to that state. * * @param permitsPerSecond the rate of the returned {@code RateLimiter}, measured in * how many permits become available per second * @param warmupPeriod the duration of the period where the {@code RateLimiter} ramps up its * rate, before reaching its stable (maximum) rate * @param unit the time unit of the warmupPeriod argument * @throws IllegalArgumentException if {@code permitsPerSecond} is negative or zero or * {@code warmupPeriod} is negative */ public static RateLimiter create(double permitsPerSecond, long warmupPeriod, TimeUnit unit) { Assert.isTrue(warmupPeriod >= 0, com.github.ltsopensource.core.commons.utils.StringUtils.format("warmupPeriod must not be negative: {}", warmupPeriod)); return create(SleepingStopwatch.createFromSystemTimer(), permitsPerSecond, warmupPeriod, unit, 3.0); }
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; }