當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。