org.cg.eventbus.producer.EventProducerPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.cg.eventbus Show documentation
Show all versions of org.cg.eventbus Show documentation
Simplified messaging programming model with kafka implementation.
/**
*
*/
package org.cg.eventbus.producer;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.apache.commons.pool2.impl.GenericObjectPool;
/**
* @author yanlinwang
*
*/
public class EventProducerPool extends GenericObjectPool>{
public static final String POOL_SIZE = "pool.size";
public static final String IDLE_SIZE = "idle.size";
public EventProducerPool (Class extends AbstractEventProducer> poolType, Configuration conf) throws Exception{
super(new PooledEventProducerFactory(poolType, conf));
this.setMaxIdle(conf.getInt(IDLE_SIZE,GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY));
this.setMaxTotal(conf.getInt(POOL_SIZE,GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY));
this.setTestOnBorrow(true);
this.setTestOnReturn(true);
}
}