|
33 | 33 | import java.util.HashSet; |
34 | 34 | import java.util.Date; |
35 | 35 | import java.util.Arrays; |
| 36 | +import java.util.SortedMap; |
36 | 37 | import java.util.TreeMap; |
37 | 38 |
|
38 | | -// java 5 support needs a backported TreeMap library |
39 | | -// one exists at http://backport-jsr166.sourceforge.net/index.php |
40 | | - |
41 | 39 | import java.util.zip.*; |
42 | 40 | import java.net.*; |
43 | 41 | import java.io.*; |
@@ -156,12 +154,12 @@ public class SockIOPool { |
156 | 154 | private Map<String,Integer> createShift; |
157 | 155 |
|
158 | 156 | // initial, min and max pool sizes |
159 | | - private int poolMultiplier = 4; |
160 | | - private int initConn = 3; |
161 | | - private int minConn = 3; |
| 157 | + private int poolMultiplier = 3; |
| 158 | + private int initConn = 1; |
| 159 | + private int minConn = 1; |
162 | 160 | private int maxConn = 10; |
163 | | - private long maxIdle = 1000 * 60 * 3; // max idle time for avail sockets |
164 | | - private long maxBusyTime = 1000 * 60 * 5; // max idle time for avail sockets |
| 161 | + private long maxIdle = 1000 * 60 * 5; // max idle time for avail sockets |
| 162 | + private long maxBusyTime = 1000 * 30; // max idle time for avail sockets |
165 | 163 | private long maintSleep = 1000 * 30; // maintenance thread sleep time |
166 | 164 | private int socketTO = 1000 * 30; // default timeout of socket reads |
167 | 165 | private int socketConnectTO = 1000 * 3; // default timeout of socket connections |
@@ -575,12 +573,14 @@ private long getBucket( String key, Integer hashCode ) { |
575 | 573 | * @return |
576 | 574 | */ |
577 | 575 | private Long findPointFor( Long hv ) { |
| 576 | + // this works in java 6, but still want to release support for java5 |
| 577 | + //Long k = this.consistentBuckets.ceilingKey( hv ); |
| 578 | + //return ( k == null ) ? this.consistentBuckets.firstKey() : k; |
578 | 579 |
|
579 | | - Long k = this.consistentBuckets.ceilingKey( hv ); |
580 | | - if ( k == null ) |
581 | | - k = this.consistentBuckets.firstKey(); |
| 580 | + SortedMap<Long,String> tmap = |
| 581 | + this.consistentBuckets.tailMap( hv ); |
582 | 582 |
|
583 | | - return k; |
| 583 | + return ( tmap.isEmpty() ) ? this.consistentBuckets.firstKey() : tmap.firstKey(); |
584 | 584 | } |
585 | 585 |
|
586 | 586 | /** |
@@ -890,7 +890,7 @@ public SockIO getSock( String key, Integer hashCode ) { |
890 | 890 | || ( buckets != null && buckets.size() == 1 ) ) { |
891 | 891 |
|
892 | 892 | SockIO sock = ( this.hashingAlg == CONSISTENT_HASH ) |
893 | | - ? getConnection( consistentBuckets.firstEntry().getValue() ) |
| 893 | + ? getConnection( consistentBuckets.get( consistentBuckets.firstKey() ) ) |
894 | 894 | : getConnection( buckets.get( 0 ) ); |
895 | 895 |
|
896 | 896 | if ( sock != null && sock.isConnected() ) { |
|
0 commit comments