Skip to content

Commit e37e74d

Browse files
committed
tweak to allow compile and run in jdk5 installs, tweak default pool settings, and some other minor bug fixes
1 parent 9e7d27f commit e37e74d

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

src/com/danga/MemCached/MemCachedClient.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ else if ( NOTFOUND.equals( line ) ) {
499499
sock = null;
500500
}
501501

502-
if ( sock != null )
502+
if ( sock != null ) {
503503
sock.close();
504+
sock = null;
505+
}
504506

505507
return false;
506508
}
@@ -855,8 +857,10 @@ else if ( NOTSTORED.equals( line ) ) {
855857
sock = null;
856858
}
857859

858-
if ( sock != null )
860+
if ( sock != null ) {
859861
sock.close();
862+
sock = null;
863+
}
860864

861865
return false;
862866
}
@@ -1180,8 +1184,10 @@ else if ( NOTFOUND.equals( line ) ) {
11801184
sock = null;
11811185
}
11821186

1183-
if ( sock != null )
1187+
if ( sock != null ) {
11841188
sock.close();
1189+
sock = null;
1190+
}
11851191

11861192
return -1;
11871193
}
@@ -1683,8 +1689,10 @@ public boolean flushAll( String[] servers ) {
16831689
sock = null;
16841690
}
16851691

1686-
if ( sock != null )
1692+
if ( sock != null ) {
16871693
sock.close();
1694+
sock = null;
1695+
}
16881696
}
16891697

16901698
return success;
@@ -1897,8 +1905,10 @@ else if ( line.startsWith( ERROR ) || line.startsWith( CLIENT_ERROR ) || line.st
18971905
sock = null;
18981906
}
18991907

1900-
if ( sock != null )
1908+
if ( sock != null ) {
19011909
sock.close();
1910+
sock = null;
1911+
}
19021912
}
19031913

19041914
return statsMaps;

src/com/danga/MemCached/SockIOPool.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
import java.util.HashSet;
3434
import java.util.Date;
3535
import java.util.Arrays;
36+
import java.util.SortedMap;
3637
import java.util.TreeMap;
3738

38-
// java 5 support needs a backported TreeMap library
39-
// one exists at http://backport-jsr166.sourceforge.net/index.php
40-
4139
import java.util.zip.*;
4240
import java.net.*;
4341
import java.io.*;
@@ -156,12 +154,12 @@ public class SockIOPool {
156154
private Map<String,Integer> createShift;
157155

158156
// 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;
162160
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
165163
private long maintSleep = 1000 * 30; // maintenance thread sleep time
166164
private int socketTO = 1000 * 30; // default timeout of socket reads
167165
private int socketConnectTO = 1000 * 3; // default timeout of socket connections
@@ -575,12 +573,14 @@ private long getBucket( String key, Integer hashCode ) {
575573
* @return
576574
*/
577575
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;
578579

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 );
582582

583-
return k;
583+
return ( tmap.isEmpty() ) ? this.consistentBuckets.firstKey() : tmap.firstKey();
584584
}
585585

586586
/**
@@ -890,7 +890,7 @@ public SockIO getSock( String key, Integer hashCode ) {
890890
|| ( buckets != null && buckets.size() == 1 ) ) {
891891

892892
SockIO sock = ( this.hashingAlg == CONSISTENT_HASH )
893-
? getConnection( consistentBuckets.firstEntry().getValue() )
893+
? getConnection( consistentBuckets.get( consistentBuckets.firstKey() ) )
894894
: getConnection( buckets.get( 0 ) );
895895

896896
if ( sock != null && sock.isConnected() ) {

0 commit comments

Comments
 (0)