当前位置: 首页>>代码示例>>Java>>正文


Java HikariConfig.setMetricRegistry方法代码示例

本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setMetricRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setMetricRegistry方法的具体用法?Java HikariConfig.setMetricRegistry怎么用?Java HikariConfig.setMetricRegistry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.zaxxer.hikari.HikariConfig的用法示例。


在下文中一共展示了HikariConfig.setMetricRegistry方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDataSourceFromConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:26,代码来源:ConnectionPool.java

示例2: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "shutdown")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource() {
	log.debug("Configuring Datasource");
	if (dataSourcePropertyResolver.getProperty("url") == null
			&& dataSourcePropertyResolver.getProperty("databaseName") == null) {
		log.error(
				"Your database connection pool configuration is incorrect! The application"
						+ " cannot start. Please check your Spring profile, current profiles are: {}",
				Arrays.toString(env.getActiveProfiles()));

		throw new ApplicationContextException("Database connection pool is not configured correctly");
	}
	HikariConfig config = new HikariConfig();
	config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
	if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) {
		config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName"));
		config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName"));
	} else {
		config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url"));
	}
	config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username"));
	config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password"));

	if (metricRegistry != null) {
		config.setMetricRegistry(metricRegistry);
	}
	return new HikariDataSource(config);
}
 
开发者ID:VHAINNOVATIONS,项目名称:BCDS,代码行数:30,代码来源:DatabaseConfiguration.java

示例3: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));

        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    if (metricRegistry != null) {
        config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:31,代码来源:DatabaseConfiguration.java

示例4: build

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> property : this.properties.entrySet()) {
        properties.setProperty(property.getKey(), property.getValue());
    }

    final HikariConfig config = new HikariConfig();
    config.setMetricRegistry(metricRegistry);
    if (healthCheckRegistry != null) {
        config.setHealthCheckRegistry(healthCheckRegistry);
    }

    config.setAutoCommit(autoCommit);
    config.setDataSourceProperties(properties);
    if (datasourceClassName != null) {
        config.setDataSourceClassName(datasourceClassName);
    } else {
        config.setDriverClassName(driverClass);
    }

    config.setMaximumPoolSize(maxSize);
    minSize.ifPresent(config::setMinimumIdle);
    config.setPoolName(name);
    config.setUsername(user);
    config.setPassword(user != null && password == null ? "" : password);
    return new HikariManagedPooledDataSource(config);
}
 
开发者ID:nickbabcock,项目名称:dropwizard-hikaricp-benchmark,代码行数:29,代码来源:HikariDataSourceFactory.java

示例5: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, LeagueProperties leagueProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));

        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    //MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
        config.addDataSourceProperty("cachePrepStmts", leagueProperties.getDatasource().isCachePrepStmts());
        config.addDataSourceProperty("prepStmtCacheSize", leagueProperties.getDatasource().getPrepStmtCacheSize());
        config.addDataSourceProperty("prepStmtCacheSqlLimit", leagueProperties.getDatasource().getPrepStmtCacheSqlLimit());
    }
    if (metricRegistry != null) {
        config.setMetricRegistry(metricRegistry);
    }
    if (healthCheckRegistry != null) {
        config.setHealthCheckRegistry(healthCheckRegistry);
    }
    return new HikariDataSource(config);
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:40,代码来源:DatabaseConfiguration.java

示例6: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));

        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    //MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
        config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
        config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
        config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
    }
    if (metricRegistry != null) {
        config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
}
 
开发者ID:arhs-cube-gameofcode,项目名称:gameofcode,代码行数:37,代码来源:DatabaseConfiguration.java

示例7: DefaultDataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private DefaultDataSource(final Properties properties) {
		log.info(">>>>> Initializing DataSource....");
		HikariConfig config = new HikariConfig();
		ddlResources = ConfigurationHelper.getArraySystemThenEnvProperty(CONFIG_DS_DDL, DEFAULT_DS_DDL, properties);
		config.setMetricRegistry(SharedMetricsRegistry.getInstance());
		config.setDataSourceClassName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_CLASS, DEFAULT_DS_CLASS, properties));
//		config.setDriverClassName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_CLASS, DEFAULT_DS_CLASS, properties));
		config.setJdbcUrl(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_URL, DEFAULT_DS_URL, properties));
		config.addDataSourceProperty("url",ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_URL, DEFAULT_DS_URL, properties));
		config.addDataSourceProperty("user", ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_USER, DEFAULT_DS_USER, properties));
		config.addDataSourceProperty("password", ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_PW, DEFAULT_DS_PW, properties));
		config.setUsername(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_USER, DEFAULT_DS_USER, properties));
		config.setPassword(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_PW, DEFAULT_DS_PW, properties));
//		config.addDataSourceProperty("cachePrepStmts", "" + ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_CACHEDPS, DEFAULT_DS_CACHEDPS, properties));
//		config.addDataSourceProperty("prepStmtCacheSize", "" + ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCACHEDPS, DEFAULT_DS_MAXCACHEDPS, properties));
//		config.addDataSourceProperty("prepStmtCacheSqlLimit", "" + ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCACHEDPS, DEFAULT_DS_MAXCACHEDPS, properties));
		config.setMaximumPoolSize(ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MAXCONNS, DEFAULT_DS_MAXCONNS, properties));
		config.setMinimumIdle(ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_DS_MINCONNS, DEFAULT_DS_MINCONNS, properties));
		config.setConnectionTestQuery(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_TESTSQL, DEFAULT_DS_TESTSQL, properties));
		config.setConnectionTimeout(ConfigurationHelper.getLongSystemThenEnvProperty(CONFIG_DS_CONNTIMEOUT, DEFAULT_DS_CONNTIMEOUT, properties));
		config.setAutoCommit(ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_AUTOCOMMIT, DEFAULT_DS_AUTOCOMMIT, properties));
		config.setRegisterMbeans(ConfigurationHelper.getBooleanSystemThenEnvProperty(CONFIG_DS_MBEANS, DEFAULT_DS_MBEANS, properties));
		config.setPoolName(ConfigurationHelper.getSystemThenEnvProperty(CONFIG_DS_NAME, DEFAULT_DS_NAME, properties));
		config.setThreadFactory(JMXManagedThreadFactory.newThreadFactory("HikariPool-" + config.getPoolName(), true));
		final StringBuilder b = new StringBuilder("\n\t========================\n\tDataSource\n\t========================");
		b.append("\n\tURL:").append(config.getJdbcUrl());
		b.append("\n\tDS Class:").append(config.getDataSourceClassName());
		b.append("\n\tUser:").append(config.getUsername());
		b.append("\n\t========================\n");
		log.info(b.toString());
		schedulerObjectName = JMXHelper.objectName("com.heliosapm.streams.tsdb.listener:service=Scheduler,name=JDBCConnectionPool");
		scheduler = new JMXManagedScheduler(schedulerObjectName, "JDBCConnectionPool", 2, true);
		//config.setScheduledExecutorService(scheduler);
		ds = new HikariDataSource(config);
		sqlWorker = SQLWorker.getInstance(ds);		
		startServers(properties);
		runDDL(properties);
		log.info("<<<<< DataSource Initialized.");
		
	}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:41,代码来源:DefaultDataSource.java

示例8: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    
    if(env.acceptsProfiles("aws")){
    	String url = String.format("jdbc:mysql://%s:%s/%s?useUnicode=true&characterEncoding=utf8", env.getProperty("RDS_HOSTNAME"), env.getProperty("RDS_PORT"),env.getProperty("RDS_DB_NAME"));
    	log.info("Configuring with 'aws' profile. Overriding DataSource config file properties with environment variables. URL used: " + url);
    	dataSourceProperties.setUrl(url);
    	dataSourceProperties.setUsername(env.getProperty("RDS_USERNAME"));
    	dataSourceProperties.setPassword(env.getProperty("RDS_PASSWORD"));
    }
    
    if (dataSourceProperties.getUrl() == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));

        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    //MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourceProperties.getDriverClassName())) {
        config.addDataSourceProperty("cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
        config.addDataSourceProperty("prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
        config.addDataSourceProperty("prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
    }
    if (metricRegistry != null) {
        config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
}
 
开发者ID:jbernach,项目名称:transandalus-backend,代码行数:47,代码来源:DatabaseConfiguration.java


注:本文中的com.zaxxer.hikari.HikariConfig.setMetricRegistry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。