All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nimbusds.infinispan.persistence.sql.HikariConfigUtils Maven / Gradle / Ivy

package com.nimbusds.infinispan.persistence.sql;


import java.util.Properties;

import com.codahale.metrics.MetricRegistry;


/**
 * Hikari CP configuration utils.
 */
class HikariConfigUtils {
	
	
	/**
	 * Removes non-Hikari properties to prevent Hikari CP throwing a
	 * configuration exception.
	 *
	 * @param props The properties. Must not be {@code null}.
	 *
	 * @return The conditioned properties.
	 */
	static Properties removeNonHikariProperties(final Properties props) {
		
		Properties out = new Properties();
		
		for (Object key: props.keySet()) {
			if (key.toString().startsWith("sqlStore.")) {
				continue; // skip
			}
			
			out.put(key, props.get(key));
		}
		
		return out;
	}
	
	
	/**
	 * Sets a default poolName property as "cacheName.sqlStore".
	 *
	 * @param props     The Hikari properties. Must not be {@code null}.
	 * @param cacheName The configured Infinispan cache name. Must not be
	 *                  {@code null}.
	 */
	static void setDefaultPoolName(final Properties props, final String cacheName) {
		
		if (props.containsKey("poolName")) {
			return;
		}
		
		props.setProperty("poolName", cacheName + ".sqlStore");
	}
	
	
	/**
	 * Checks if Hikari CP metrics is already registered.
	 *
	 * @param metricRegistry The metric registry. Must not be {@code null}.
	 *
	 * @return If the Hikari CP metrics are already registered.
	 */
	static boolean metricsAlreadyRegistered(final MetricRegistry metricRegistry) {
		
		for (String gaugeName: metricRegistry.getGauges().keySet()) {
			
			// simple test
			if (gaugeName.contains("pool.TotalConnections")) {
				return true;
			}
		}
		
		return false;
	}
	
	
	/**
	 * Prevents public instantiation.
	 */
	private HikariConfigUtils() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy