List of usage examples for org.apache.commons.pool2.impl GenericObjectPool getNumWaiters
@Override public int getNumWaiters()
From source file:com.netflix.spinnaker.kork.jedis.JedisHealthIndicatorFactory.java
public static HealthIndicator build(Pool<Jedis> jedisPool) { try {//from w w w . j a v a2 s .co m final Pool<Jedis> src = jedisPool; final Field poolAccess = Pool.class.getDeclaredField("internalPool"); poolAccess.setAccessible(true); GenericObjectPool<Jedis> internal = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool); return () -> { Jedis jedis = null; Health.Builder health; try { jedis = src.getResource(); if ("PONG".equals(jedis.ping())) { health = Health.up(); } else { health = Health.down(); } } catch (Exception ex) { health = Health.down(ex); } finally { if (jedis != null) jedis.close(); } health.withDetail("maxIdle", internal.getMaxIdle()); health.withDetail("minIdle", internal.getMinIdle()); health.withDetail("numActive", internal.getNumActive()); health.withDetail("numIdle", internal.getNumIdle()); health.withDetail("numWaiters", internal.getNumWaiters()); return health.build(); }; } catch (IllegalAccessException | NoSuchFieldException e) { throw new BeanCreationException("Error creating Redis health indicator", e); } }
From source file:com.netflix.spinnaker.orca.config.RedisConfiguration.java
@Deprecated // rz - Kept for backwards compat with old connection configs @Bean/*from w w w .j a va2 s. co m*/ HealthIndicator redisHealth(@Qualifier("jedisPool") Pool<Jedis> jedisPool) { try { final Pool<Jedis> src = jedisPool; final Field poolAccess = Pool.class.getDeclaredField("internalPool"); poolAccess.setAccessible(true); GenericObjectPool<Jedis> internal = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool); return () -> { Jedis jedis = null; Health.Builder health; try { jedis = src.getResource(); if ("PONG".equals(jedis.ping())) { health = Health.up(); } else { health = Health.down(); } } catch (Exception ex) { health = Health.down(ex); } finally { if (jedis != null) jedis.close(); } health.withDetail("maxIdle", internal.getMaxIdle()); health.withDetail("minIdle", internal.getMinIdle()); health.withDetail("numActive", internal.getNumActive()); health.withDetail("numIdle", internal.getNumIdle()); health.withDetail("numWaiters", internal.getNumWaiters()); return health.build(); }; } catch (IllegalAccessException | NoSuchFieldException e) { throw new BeanCreationException("Error creating Redis health indicator", e); } }
From source file:org.moneta.healthcheck.DbcpConnectionPoolHealthCheck.java
@Override protected Result check() throws Exception { GenericObjectPool<PoolableConnection> pool = (GenericObjectPool<PoolableConnection>) connectionPool; if (pool.getNumWaiters() > maxWaitingConnections) { return Result.unhealthy( "Overloaded connection pool. name=" + poolName + " nbrWaiters=" + pool.getNumWaiters()); }/*w ww .j av a2 s . c o m*/ PoolableConnectionFactory poolFactory = (PoolableConnectionFactory) pool.getFactory(); PoolableConnection conn = null; try { conn = pool.borrowObject(); poolFactory.validateConnection(conn); } catch (Exception e) { return Result .unhealthy("Database connection validation error. error=" + ExceptionUtils.getStackTrace(e)); } finally { DbUtils.closeQuietly(conn); } return Result.healthy(); }