Search in sources :

Example 1 with ManagedGenericKeyedObjectPool

use of com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool in project jmxtrans by jmxtrans.

the class JmxTransModule method getObjectPool.

private <K, V> GenericKeyedObjectPool<K, V> getObjectPool(KeyedPoolableObjectFactory<K, V> factory, String poolName) {
    GenericKeyedObjectPool<K, V> pool = new GenericKeyedObjectPool<>(factory);
    pool.setTestOnBorrow(true);
    pool.setMaxActive(-1);
    pool.setMaxIdle(-1);
    pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
    pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
    try {
        ManagedGenericKeyedObjectPool mbean = new ManagedGenericKeyedObjectPool(pool, poolName);
        ManagementFactory.getPlatformMBeanServer().registerMBean(mbean, mbean.getObjectName());
    } catch (Exception e) {
        log.error("Could not register mbean for pool [{}]", poolName, e);
    }
    return pool;
}
Also used : ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ManagedGenericKeyedObjectPool

use of com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool in project jmxtrans by jmxtrans.

the class StatsDWriter method start.

@Override
public void start() throws LifecycleException {
    try {
        pool = new GenericKeyedObjectPool<>(new DatagramSocketFactory());
        pool.setTestOnBorrow(true);
        pool.setMaxActive(-1);
        pool.setMaxIdle(-1);
        pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
        pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
        this.mbean = new ManagedGenericKeyedObjectPool((GenericKeyedObjectPool) pool, "StatsdConnectionPool");
        ManagementFactory.getPlatformMBeanServer().registerMBean(this.mbean, this.mbean.getObjectName());
    } catch (Exception e) {
        throw new LifecycleException(e);
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) DatagramSocketFactory(com.googlecode.jmxtrans.connections.DatagramSocketFactory) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Aggregations

ManagedGenericKeyedObjectPool (com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool)2 IOException (java.io.IOException)2 GenericKeyedObjectPool (org.apache.commons.pool.impl.GenericKeyedObjectPool)2 DatagramSocketFactory (com.googlecode.jmxtrans.connections.DatagramSocketFactory)1 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)1 ValidationException (com.googlecode.jmxtrans.model.ValidationException)1 FileNotFoundException (java.io.FileNotFoundException)1 SchedulerException (org.quartz.SchedulerException)1