Skip to content

Commit a2eda83

Browse files
committed
revert some of newer features
1 parent 3f9e24c commit a2eda83

File tree

6 files changed

+140
-304
lines changed

6 files changed

+140
-304
lines changed

src/com/danga/MemCached/CacheTask.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public CacheTask( String cmd, byte[] val ) {
3030
this.val = val;
3131
}
3232

33+
public String getCmd() {
34+
return this.cmd;
35+
}
36+
3337
public void setSocket( SockIOPool.SockIO socket ) {
3438
this.socket = socket;
3539
}

src/com/danga/MemCached/MemCacheThreadPoolExecutor.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111

1212
import java.util.concurrent.*;
1313
import java.util.*;
14+
import org.apache.log4j.Logger;
1415

1516
public class MemCacheThreadPoolExecutor extends ThreadPoolExecutor {
1617

18+
// logger
19+
private static Logger log =
20+
Logger.getLogger( MemCacheThreadPoolExecutor.class.getName() );
21+
1722
private String poolName;
1823
private String host;
1924
private SockIOPool.SockIO socket;
@@ -61,34 +66,40 @@ public MemCacheThreadPoolExecutor( int corePoolSize, int maximumPoolSize,
6166
}
6267

6368
protected void beforeExecute( Thread t, Runnable r ) {
64-
super.beforeExecute( t, r );
6569

6670
// make sure we have a valid connected socket
6771
// if not, then get a new connection
68-
if ( socketOnDemand
69-
|| socket == null
70-
|| !socket.isConnected() )
71-
socket = SockIOPool.getInstance( poolName ).getConnection( host );
72-
73-
((CacheTask)r).setSocket( socket );
72+
if ( socketOnDemand || this.socket == null || !this.socket.isConnected() ) {
73+
((CacheTask)r).setSocket( SockIOPool.getInstance( poolName ).getConnection( host ) );
74+
}
75+
else {
76+
((CacheTask)r).setSocket( this.socket );
77+
}
7478

79+
super.beforeExecute( t, r );
7580
}
7681

7782
protected void afterExecute( Runnable r, Throwable t ) {
7883
super.afterExecute( r, t );
7984

80-
socket = ((CacheTask)r).getSocket();
8185
if ( socketOnDemand ) {
8286
// return to pool
83-
if ( socket != null )
84-
socket.close();
87+
if ( ((CacheTask)r).getSocket() != null )
88+
((CacheTask)r).getSocket().close();
8589
}
8690
else {
8791
// freshen the socket so we have it around
88-
if ( socket != null )
89-
socket.touch();
92+
if ( this.socket != null )
93+
this.socket.touch();
9094
else
9195
this.socket = null;
9296
}
9397
}
98+
99+
protected void terminated() {
100+
if ( this.socket != null && this.socket.isConnected() )
101+
this.socket.close();
102+
103+
super.terminated();
104+
}
94105
}

0 commit comments

Comments
 (0)