@@ -161,7 +161,17 @@ protected final MessageDigest initialValue() {
161161 @ SuppressWarnings ("unused" )
162162 private static int recBufferSize = 128 ;// bufsize
163163
164- private long maxIdle = 1000 ; // max idle time for avail sockets
164+ private long maxWait = 1000 ; // max wait time for avail sockets
165+ private int maxIdle = maxConn ;
166+ private int minIdle = GenericObjectPool .DEFAULT_MIN_IDLE ;
167+ private boolean testOnBorrow = GenericObjectPool .DEFAULT_TEST_ON_BORROW ;
168+ private boolean testOnReturn = GenericObjectPool .DEFAULT_TEST_ON_RETURN ;
169+ private long timeBetweenEvictionRunsMillis = GenericObjectPool .DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS ;
170+ private int numTestsPerEvictionRun = GenericObjectPool .DEFAULT_NUM_TESTS_PER_EVICTION_RUN ;
171+ private long minEvictableIdleTimeMillis = GenericObjectPool .DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS ;
172+ private boolean testWhileIdle = true ;
173+ private long softMinEvictableIdleTimeMillis = GenericObjectPool .DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS ;
174+ private boolean lifo = GenericObjectPool .DEFAULT_LIFO ;
165175
166176 private boolean aliveCheck = false ; // default to not check each connection
167177 // for being alive
@@ -337,7 +347,9 @@ private void populateBuckets() {
337347 } else {
338348 factory = new SchoonerSockIOFactory (servers [i ], isTcp , bufferSize , socketTO , socketConnectTO , nagle );
339349 }
340- gop = new GenericObjectPool (factory , maxConn , GenericObjectPool .WHEN_EXHAUSTED_BLOCK , maxIdle , maxConn );
350+ gop = new GenericObjectPool (factory , maxConn , GenericObjectPool .WHEN_EXHAUSTED_BLOCK , maxWait , maxIdle , minIdle , testOnBorrow ,
351+ testOnReturn , timeBetweenEvictionRunsMillis , numTestsPerEvictionRun , minEvictableIdleTimeMillis , testWhileIdle ,
352+ this .softMinEvictableIdleTimeMillis , this .lifo );
341353 factory .setSockets (gop );
342354 socketPool .put (servers [i ], gop );
343355 }
@@ -382,7 +394,10 @@ private void populateConsistentBuckets() {
382394 } else {
383395 factory = new SchoonerSockIOFactory (servers [i ], isTcp , bufferSize , socketTO , socketConnectTO , nagle );
384396 }
385- gop = new GenericObjectPool (factory , maxConn , GenericObjectPool .WHEN_EXHAUSTED_BLOCK , maxIdle , maxConn );
397+
398+ gop = new GenericObjectPool (factory , maxConn , GenericObjectPool .WHEN_EXHAUSTED_BLOCK , maxWait , maxIdle , minIdle , testOnBorrow ,
399+ testOnReturn , timeBetweenEvictionRunsMillis , numTestsPerEvictionRun , minEvictableIdleTimeMillis , testWhileIdle ,
400+ this .softMinEvictableIdleTimeMillis , this .lifo );
386401 factory .setSockets (gop );
387402 socketPool .put (servers [i ], gop );
388403 }
@@ -758,7 +773,7 @@ public final int getSocketConnectTO() {
758773 * @param maxIdle
759774 * idle time in ms
760775 */
761- public void setMaxIdle (long maxIdle ) {
776+ public void setMaxIdle (int maxIdle ) {
762777 this .maxIdle = maxIdle ;
763778 }
764779
@@ -767,10 +782,89 @@ public void setMaxIdle(long maxIdle) {
767782 *
768783 * @return max idle setting in ms
769784 */
770- public long getMaxIdle () {
785+ public int getMaxIdle () {
771786 return this .maxIdle ;
772787 }
773-
788+
789+ public final long getMaxWait () {
790+ return this .maxWait ;
791+ }
792+
793+ public final void setMaxWait (long maxWait ) {
794+ this .maxWait = maxWait ;
795+ }
796+
797+ public final int getMinIdle () {
798+ return minIdle ;
799+ }
800+
801+ public final void setMinIdle (int minIdle ) {
802+ this .minIdle = minIdle ;
803+ }
804+
805+ public final boolean getTestOnBorrow () {
806+ return testOnBorrow ;
807+ }
808+
809+ public final void setTestOnBorrow (boolean testOnBorrow ) {
810+ this .testOnBorrow = testOnBorrow ;
811+ }
812+
813+ public final boolean getTestOnReturn () {
814+ return testOnReturn ;
815+ }
816+
817+ public final void setTestOnReturn (boolean testOnReturn ) {
818+ this .testOnReturn = testOnReturn ;
819+ }
820+
821+ public final long getTimeBetweenEvictionRunsMillis () {
822+ return this .timeBetweenEvictionRunsMillis ;
823+ }
824+
825+ public final void setTimeBetweenEvictionRunsMillis (long timeBetweenEvictionRunsMillis ) {
826+ this .timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis ;
827+ }
828+
829+ public final int getNumTestsPerEvictionRun () {
830+ return this .numTestsPerEvictionRun ;
831+ }
832+
833+ public final void setNumTestsPerEvictionRun (int numTestsPerEvictionRun ) {
834+ this .numTestsPerEvictionRun = numTestsPerEvictionRun ;
835+ }
836+
837+ public final long getMinEvictableIdleTimeMillis () {
838+ return this .minEvictableIdleTimeMillis ;
839+ }
840+
841+ public final void setMinEvictableIdleTimeMillis (long minEvictableIdleTimeMillis ) {
842+ this .minEvictableIdleTimeMillis = minEvictableIdleTimeMillis ;
843+ }
844+
845+ public final boolean getTestWhileIdle () {
846+ return this .testWhileIdle ;
847+ }
848+
849+ public final void setTestWhileIdle (boolean testWhileIdle ) {
850+ this .testWhileIdle = testWhileIdle ;
851+ }
852+
853+ public final long getSoftMinEvictableIdleTimeMillis (long softMinEvictableIdleTimeMillis ) {
854+ return this .softMinEvictableIdleTimeMillis ;
855+ }
856+
857+ public final void setSoftMinEvictableIdleTimeMillis (long softMinEvictableIdleTimeMillis ) {
858+ this .softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis ;
859+ }
860+
861+ public final boolean getLifo () {
862+ return this .lifo ;
863+ }
864+
865+ public final void setLifo (boolean lifo ) {
866+ this .lifo = lifo ;
867+ }
774868 /**
775869 * Sets the failover flag for the pool.
776870 *
@@ -1479,27 +1573,6 @@ public boolean isConnected() {
14791573 return (sock != null && sock .isConnected ());
14801574 }
14811575
1482- /**
1483- * checks to see that the connection is still working
1484- *
1485- * @return true if still alive
1486- */
1487- public final boolean isAlive () {
1488- if (!isConnected ())
1489- return false ;
1490-
1491- // try to talk to the server w/ a dumb query to ask its version
1492- try {
1493- write ("version\r \n " .getBytes ());
1494- readBuf .clear ();
1495- sockChannel .read (readBuf );
1496- } catch (IOException ex ) {
1497- return false ;
1498- }
1499-
1500- return true ;
1501- }
1502-
15031576 /**
15041577 * read fix length data from server and store it in the readBuf
15051578 *
@@ -1691,7 +1764,7 @@ public void trueClose(boolean addToDeadPool) throws IOException {
16911764 @ Override
16921765 public ByteChannel getByteChannel () {
16931766 // TODO Auto-generated method stub
1694- return null ;
1767+ return sockChannel ;
16951768 }
16961769 }
16971770
0 commit comments