本文整理汇总了Java中org.apache.commons.pool.BasePoolableObjectFactory类的典型用法代码示例。如果您正苦于以下问题:Java BasePoolableObjectFactory类的具体用法?Java BasePoolableObjectFactory怎么用?Java BasePoolableObjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasePoolableObjectFactory类属于org.apache.commons.pool包,在下文中一共展示了BasePoolableObjectFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstance
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
public static GsonPool getInstance() {
if (instance == null) {
instance = new GsonPool(new BasePoolableObjectFactory() {
@Override
public Object makeObject() throws Exception {
//return new Gson();
//return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
final GsonBuilder gsonb = new GsonBuilder();
final DateSerializer ds = new DateSerializer();
final ColorSerializer cs = new ColorSerializer();
gsonb.registerTypeHierarchyAdapter(Date.class, ds);
gsonb.registerTypeHierarchyAdapter(Color.class, cs);
return gsonb.excludeFieldsWithoutExposeAnnotation().create();
//return new GsonBuilder().serializeNulls().excludeFieldsWithoutExposeAnnotation().create();
}
});
}
return instance;
}
示例2: getInstance
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
public static ActionRunnablePool getInstance() {
if (instance == null) {
instance = new ActionRunnablePool(new BasePoolableObjectFactory() {
@Override
public Object makeObject() throws Exception {
return new ActionTransmit();
}
});
}
return instance;
}
示例3: setupObjectPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
@Override
public void setupObjectPool() {
objectPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<TestObject>() {
@Override
public TestObject makeObject() throws Exception {
return new TestObject(true);
}
});
}
开发者ID:chrishantha,项目名称:microbenchmarks,代码行数:10,代码来源:CommonsPoolSoftReferenceObjectPoolBenchmark.java
示例4: setupObjectPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
@Override
public void setupObjectPool() {
objectPool = new StackObjectPool<>(new BasePoolableObjectFactory<TestObject>() {
@Override
public TestObject makeObject() throws Exception {
return new TestObject(true);
}
}, poolSize, poolSize);
}
示例5: setupObjectPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
@Override
public void setupObjectPool() {
objectPool = new GenericObjectPool<>(new BasePoolableObjectFactory<TestObject>() {
@Override
public TestObject makeObject() throws Exception {
return new TestObject(true);
}
}, poolSize);
}
示例6: PacketPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private PacketPool() {
// Create a logger for this class
log = LogFactory.getLog(getClass());
pool = new StackObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return new Packet(PACKET_LENGTH);
}
});
//debugList = new LinkedList<DebugEntry>();
}
示例7: CodecPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private CodecPool(final CompressionCodec codec){
try {
boolean supportDirectDecompressor = codec instanceof DirectDecompressionCodec;
compressorPool = new GenericObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return codec.createCompressor();
}
}, Integer.MAX_VALUE);
Object com = compressorPool.borrowObject();
if (com != null) {
cPools.put(com.getClass(), compressorPool);
compressorPool.returnObject(com);
}else{
logger.warn("Unable to find compressor for codec {}", codec.getClass().getName());
}
decompressorPool = new GenericObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return codec.createDecompressor();
}
}, Integer.MAX_VALUE);
Object decom = decompressorPool.borrowObject();
if (decom != null) {
dePools.put(decom.getClass(), decompressorPool);
decompressorPool.returnObject(decom);
} else {
logger.warn("Unable to find decompressor for codec {}", codec.getClass().getName());
}
if (supportDirectDecompressor) {
directDecompressorPool = new GenericObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return ((DirectDecompressionCodec) codec).createDirectDecompressor();
}
}, Integer.MAX_VALUE);
Object ddecom = directDecompressorPool.borrowObject();
if (ddecom != null) {
directDePools.put(ddecom.getClass(), directDecompressorPool);
directDecompressorPool.returnObject(ddecom);
} else {
supportDirectDecompressor = false;
logger.warn("Unable to find direct decompressor for codec {}", codec.getClass().getName());
}
} else {
directDecompressorPool = null;
}
this.supportDirectDecompressor = supportDirectDecompressor;
} catch (Exception e) {
throw new DrillRuntimeException(e);
}
}
示例8: ActionRunnablePool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private ActionRunnablePool(BasePoolableObjectFactory basePoolableObjectFactory) {
super(basePoolableObjectFactory);
}
示例9: GsonPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private GsonPool(BasePoolableObjectFactory basePoolableObjectFactory) {
super(basePoolableObjectFactory);
}
示例10: CodecPool
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private CodecPool(final CompressionCodec codec){
try {
boolean supportDirectDecompressor = codec.getClass() == DIRECT_DECOMPRESSION_CODEC_CLASS;
compressorPool = new GenericObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return codec.createCompressor();
}
}, Integer.MAX_VALUE);
Object com = compressorPool.borrowObject();
if (com != null) {
cPools.put(com.getClass(), compressorPool);
compressorPool.returnObject(com);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(BYTE_BUF_IMPL_NOT_FOUND_MSG, "compressor", codec.getClass().getName()));
}
}
decompressorPool = new GenericObjectPool(new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return codec.createDecompressor();
}
}, Integer.MAX_VALUE);
Object decom = decompressorPool.borrowObject();
if (decom != null) {
dePools.put(decom.getClass(), decompressorPool);
decompressorPool.returnObject(decom);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(BYTE_BUF_IMPL_NOT_FOUND_MSG, "decompressor", codec.getClass().getName()));
}
}
if (supportDirectDecompressor) {
directDecompressorPool = new GenericObjectPool(
new BasePoolableObjectFactory() {
public Object makeObject() throws Exception {
return CREATE_DIRECT_DECOMPRESSOR_METHOD.invoke(DIRECT_DECOMPRESSION_CODEC_CLASS);
}
}, Integer.MAX_VALUE);
Object ddecom = directDecompressorPool.borrowObject();
if (ddecom != null) {
directDePools.put(ddecom.getClass(), directDecompressorPool);
directDecompressorPool.returnObject(ddecom);
} else {
supportDirectDecompressor = false;
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(BYTE_BUF_IMPL_NOT_FOUND_MSG, "compressor", codec.getClass().getName()));
}
}
} else {
directDecompressorPool = null;
}
this.supportDirectDecompressor = supportDirectDecompressor;
} catch (Exception e) {
throw new ParquetCompressionCodecException("Error creating compression codec pool.", e);
}
}
示例11: testEvictionSoftMinIdle
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
public void testEvictionSoftMinIdle() throws Exception {
GenericObjectPool pool = null;
class TimeTest extends BasePoolableObjectFactory {
private final long createTime;
public TimeTest() {
createTime = System.currentTimeMillis();
}
public Object makeObject() throws Exception {
return new TimeTest();
}
public long getCreateTime() {
return createTime;
}
}
pool = new GenericObjectPool(new TimeTest());
pool.setMaxIdle(5);
pool.setMaxActive(5);
pool.setNumTestsPerEvictionRun(5);
pool.setMinEvictableIdleTimeMillis(3000L);
pool.setSoftMinEvictableIdleTimeMillis(1000L);
pool.setMinIdle(2);
Object[] active = new Object[5];
Long[] creationTime = new Long[5] ;
for(int i=0;i<5;i++) {
active[i] = pool.borrowObject();
creationTime[i] = new Long(((TimeTest)active[i]).getCreateTime());
}
for(int i=0;i<5;i++) {
pool.returnObject(active[i]);
}
// Soft evict all but minIdle(2)
Thread.sleep(1500L);
pool.evict();
assertEquals("Idle count different than expected.", 2, pool.getNumIdle());
// Hard evict the rest.
Thread.sleep(2000L);
pool.evict();
assertEquals("Idle count different than expected.", 0, pool.getNumIdle());
}
示例12: LumongoIndex
import org.apache.commons.pool.BasePoolableObjectFactory; //导入依赖的package包/类
private LumongoIndex(HazelcastManager hazelcastManger, MongoConfig mongoConfig, ClusterConfig clusterConfig, IndexConfig indexConfig) throws Exception {
this.documentLockHandler = new LockHandler();
this.hazelcastManager = hazelcastManger;
this.mongoConfig = mongoConfig;
this.clusterConfig = clusterConfig;
this.indexConfig = indexConfig;
this.indexName = indexConfig.getIndexName();
this.numberOfSegments = indexConfig.getNumberOfSegments();
this.mongo = new MongoClient(mongoConfig.getServerAddresses());
MongoClient storageMongoClient = new MongoClient(mongoConfig.getServerAddresses());
String rawStorageDb = mongoConfig.getDatabaseName() + "_" + indexName + STORAGE_DB_SUFFIX;
this.documentStorage = new MongoDocumentStorage(storageMongoClient, indexName, rawStorageDb, RESULT_STORAGE_COLLECTION, clusterConfig.isSharded());
this.segmentPool = Executors.newCachedThreadPool(new LumongoThreadFactory(indexName + "-segments"));
this.parsers = new GenericObjectPool<>(new BasePoolableObjectFactory<LumongoMultiFieldQueryParser>() {
@Override
public LumongoMultiFieldQueryParser makeObject() throws Exception {
return new LumongoMultiFieldQueryParser(getPerFieldAnalyzer(), LumongoIndex.this.indexConfig);
}
});
this.indexLock = new ReentrantReadWriteLock(true);
this.segmentMap = new ConcurrentHashMap<>();
this.hazelLockMap = new ConcurrentHashMap<>();
commitTimer = new Timer(indexName + "-CommitTimer", true);
commitTask = new TimerTask() {
@Override
public void run() {
if (LumongoIndex.this.indexConfig.getIndexSettings().getIdleTimeWithoutCommit() != 0) {
doCommit(false);
}
}
};
commitTimer.scheduleAtFixedRate(commitTask, 1000, 1000);
this.lumongoAnalyzerFactory = new LumongoAnalyzerFactory(indexConfig);
}