01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package org.quickserver.net.server.impl;
16:
17: import org.apache.commons.pool.*;
18: import org.apache.commons.pool.impl.*;
19: import org.quickserver.util.pool.thread.ClientPool;
20: import org.quickserver.util.pool.ByteBufferObjectFactory;
21: import org.quickserver.util.xmlreader.PoolConfig;
22: import org.quickserver.net.server.PoolManager;
23: import java.util.logging.*;
24:
25: /**
26: * BasicPoolManager class.
27: * @author Akshathkumar Shetty
28: * @since 1.4.5
29: */
30: public class BasicPoolManager implements PoolManager {
31: private static final Logger logger = Logger
32: .getLogger(BasicPoolManager.class.getName());
33:
34: public ObjectPool makeByteBufferPool(PoolableObjectFactory factory,
35: PoolConfig opConfig) {
36: GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
37: bconfig.maxActive = opConfig.getMaxActive();
38: bconfig.maxIdle = opConfig.getMaxIdle();
39: bconfig.testOnReturn = true;
40: bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
41: return new GenericObjectPool(factory, bconfig);
42: }
43:
44: public ObjectPool makeClientPool(PoolableObjectFactory factory,
45: PoolConfig opConfig) {
46: GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
47: bconfig.maxActive = opConfig.getMaxActive();
48: bconfig.maxIdle = opConfig.getMaxIdle();
49: bconfig.testOnReturn = true;
50: bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
51: return new GenericObjectPool(factory, bconfig);
52: }
53:
54: public ObjectPool makeClientHandlerPool(
55: PoolableObjectFactory factory, PoolConfig opConfig) {
56: GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
57: bconfig.maxActive = opConfig.getMaxActive();
58: bconfig.maxIdle = opConfig.getMaxIdle();
59: bconfig.testOnReturn = true;
60: bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
61: return new GenericObjectPool(factory, bconfig);
62: }
63:
64: public ObjectPool makeClientDataPool(PoolableObjectFactory factory,
65: PoolConfig opConfig) {
66: GenericObjectPool.Config bconfig = new GenericObjectPool.Config();
67: bconfig.maxActive = opConfig.getMaxActive();
68: bconfig.maxIdle = opConfig.getMaxIdle();
69: bconfig.testOnReturn = true;
70: bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
71: return new GenericObjectPool(factory, bconfig);
72: }
73:
74: public void initPool(ObjectPool objectPool, PoolConfig opConfig) {
75: int initSize = opConfig.getInitSize();
76: try {
77: while (objectPool.getNumIdle() < initSize)
78: objectPool.addObject();
79: } catch (Exception e) {
80: logger.fine("Error: " + e);
81: }
82: }
83: }
|