Skip to content

Commit b631ebf

Browse files
committed
fire error handler when no conn returned from pool
1 parent 997f06a commit b631ebf

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/com/danga/MemCached/MemCachedClient.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,11 @@ public boolean delete( String key, Integer hashCode, Date expiry ) {
447447
SockIOPool.SockIO sock = pool.getSock( key, hashCode );
448448

449449
// return false if unable to get SockIO obj
450-
if ( sock == null )
450+
if ( sock == null ) {
451+
if ( errorHandler != null )
452+
errorHandler.handleErrorOnDelete( this, new IOException( "no socket to server available" ), key );
451453
return false;
454+
}
452455

453456
// build command
454457
StringBuilder command = new StringBuilder( "delete " ).append( key );
@@ -702,8 +705,11 @@ private boolean set( String cmdname, String key, Object value, Date expiry, Inte
702705

703706
SockIOPool.SockIO sock = pool.getSock( key, hashCode );
704707

705-
if ( sock == null )
708+
if ( sock == null ) {
709+
if ( errorHandler != null )
710+
errorHandler.handleErrorOnSet( this, new IOException( "no socket to server available" ), key );
706711
return false;
712+
}
707713

708714
if ( expiry == null )
709715
expiry = new Date(0);
@@ -1127,8 +1133,11 @@ private long incrdecr( String cmdname, String key, long inc, Integer hashCode )
11271133

11281134
SockIOPool.SockIO sock = pool.getSock( key, hashCode );
11291135

1130-
if ( sock == null )
1136+
if ( sock == null ) {
1137+
if ( errorHandler != null )
1138+
errorHandler.handleErrorOnSet( this, new IOException( "no socket to server available" ), key );
11311139
return -1;
1140+
}
11321141

11331142
try {
11341143
String cmd = String.format( "%s %s %d\r\n", cmdname, key, inc );
@@ -1265,8 +1274,11 @@ public Object get( String key, Integer hashCode, boolean asString ) {
12651274

12661275
SockIOPool.SockIO sock = pool.getSock( key, hashCode );
12671276

1268-
if ( sock == null )
1277+
if ( sock == null ) {
1278+
if ( errorHandler != null )
1279+
errorHandler.handleErrorOnGet( this, new IOException( "no socket to server available" ), key );
12691280
return null;
1281+
}
12701282

12711283
Map<String,StringBuilder> cmdMap =
12721284
new HashMap<String,StringBuilder>();
@@ -1426,8 +1438,11 @@ public Map<String,Object> getMulti( String[] keys, Integer[] hashCodes, boolean
14261438

14271439
SockIOPool.SockIO sock = pool.getSock( cleanKey, hash );
14281440

1429-
if ( sock == null )
1441+
if ( sock == null ) {
1442+
if ( errorHandler != null )
1443+
errorHandler.handleErrorOnGet( this, new IOException( "no socket to server available" ), key );
14301444
continue;
1445+
}
14311446

14321447
// store in map and list if not already
14331448
if ( !cmdMap.containsKey( sock.getHost() ) )
@@ -1652,6 +1667,8 @@ public boolean flushAll( String[] servers ) {
16521667
if ( sock == null ) {
16531668
log.error( "++++ unable to get connection to : " + servers[i] );
16541669
success = false;
1670+
if ( errorHandler != null )
1671+
errorHandler.handleErrorOnFlush( this, new IOException( "no socket to server available" ) );
16551672
continue;
16561673
}
16571674

@@ -1845,6 +1862,8 @@ private Map stats( String[] servers, String command, String lineStart ) {
18451862
SockIOPool.SockIO sock = pool.getConnection( servers[i] );
18461863
if ( sock == null ) {
18471864
log.error( "++++ unable to get connection to : " + servers[i] );
1865+
if ( errorHandler != null )
1866+
errorHandler.handleErrorOnStats( this, new IOException( "no socket to server available" ) );
18481867
continue;
18491868
}
18501869

0 commit comments

Comments
 (0)