@@ -175,6 +175,9 @@ public class MemCachedClient {
175175 private static final String ERROR = "ERROR" ; // invalid command name from client
176176 private static final String CLIENT_ERROR = "CLIENT_ERROR" ; // client error in input line - invalid protocol
177177 private static final String SERVER_ERROR = "SERVER_ERROR" ; // server error
178+
179+ // default compression threshold
180+ private static final int COMPRESS_THRESH = 30720 ;
178181
179182 // values for cache flags
180183 //
@@ -189,6 +192,9 @@ public class MemCachedClient {
189192 private long compressThreshold ;
190193 private String defaultEncoding ;
191194
195+ // which pool to use
196+ private String poolName ;
197+
192198 /**
193199 * Creates a new instance of MemCachedClient.
194200 */
@@ -204,16 +210,27 @@ public MemCachedClient() {
204210 private void init () {
205211 this .primitiveAsString = false ;
206212 this .compressEnable = true ;
207- this .compressThreshold = 15360 ;
213+ this .compressThreshold = COMPRESS_THRESH ;
208214 this .defaultEncoding = "UTF-8" ;
215+ this .poolName = "default" ;
216+ }
217+
218+ /**
219+ * Sets the pool that this instance of the client will use.
220+ * The pool must already be initialized or none of this will work.
221+ *
222+ * @param poolName name of the pool to use
223+ */
224+ public void setPoolName ( String poolName ) {
225+ this .poolName = poolName ;
209226 }
210227
211228 /**
212229 * Enables storing primitive types as their String values.
213230 *
214231 * @param primitiveAsString if true, then store all primitives as their string value.
215232 */
216- public void setPrimitiveAsString (boolean primitiveAsString ) {
233+ public void setPrimitiveAsString ( boolean primitiveAsString ) {
217234 this .primitiveAsString = primitiveAsString ;
218235 }
219236
@@ -306,7 +323,7 @@ public boolean delete(String key, Date expiry) {
306323 public boolean delete (String key , Integer hashCode , Date expiry ) {
307324
308325 // get SockIO obj from hash or from key
309- SockIOPool .SockIO sock = SockIOPool .getInstance ().getSock (key , hashCode );
326+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock (key , hashCode );
310327
311328 // return false if unable to get SockIO obj
312329 if (sock == null )
@@ -527,7 +544,7 @@ public boolean replace(String key, Object value, Date expiry, Integer hashCode)
527544 private boolean set (String cmdname , String key , Object value , Date expiry , Integer hashCode , boolean asString ) {
528545
529546 // get SockIO obj
530- SockIOPool .SockIO sock = SockIOPool .getInstance ().getSock (key , hashCode );
547+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock (key , hashCode );
531548
532549 if (sock == null )
533550 return false ;
@@ -719,7 +736,7 @@ public long getCounter(String key) {
719736 public long getCounter (String key , Integer hashCode ) {
720737 long counter = -1 ;
721738 try {
722- counter = (( Long )get ( key , hashCode , true )). longValue ( );
739+ counter = Long . parseLong ( ( String )get ( key , hashCode , true ) );
723740 }
724741 catch (Exception ex ) {
725742 // not found or error getting out
@@ -813,7 +830,7 @@ public long decr(String key, long inc, Integer hashCode) {
813830 private long incrdecr (String cmdname , String key , long inc , Integer hashCode ) {
814831
815832 // get SockIO obj for given cache key
816- SockIOPool .SockIO sock = SockIOPool .getInstance ().getSock (key , hashCode );
833+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock (key , hashCode );
817834
818835 if (sock == null )
819836 return -1 ;
@@ -911,7 +928,7 @@ public Object get( String key, Integer hashCode ) {
911928 public Object get ( String key , Integer hashCode , boolean asString ) {
912929
913930 // get SockIO obj using cache key
914- SockIOPool .SockIO sock = SockIOPool .getInstance ().getSock (key , hashCode );
931+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock (key , hashCode );
915932
916933 if (sock == null )
917934 return null ;
@@ -1061,7 +1078,7 @@ public Map getMulti( String[] keys, Integer[] hashCodes, boolean asString ) {
10611078 hash = hashCodes [i ];
10621079
10631080 // get SockIO obj from cache key
1064- SockIOPool .SockIO sock = SockIOPool .getInstance ().getSock (keys [i ], hash );
1081+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock (keys [i ], hash );
10651082
10661083 if (sock == null )
10671084 continue ;
@@ -1083,7 +1100,7 @@ public Map getMulti( String[] keys, Integer[] hashCodes, boolean asString ) {
10831100 for (Iterator i = sockKeys .keySet ().iterator (); i .hasNext ();) {
10841101 // get SockIO obj from hostname
10851102 String host = (String ) i .next ();
1086- SockIOPool .SockIO sock = SockIOPool .getInstance ().getConnection (host );
1103+ SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getConnection (host );
10871104
10881105 try {
10891106 String cmd = "get" + (StringBuffer ) sockKeys .get ( host ) + "\r \n " ;
@@ -1243,7 +1260,7 @@ public boolean flushAll() {
12431260 public boolean flushAll (String [] servers ) {
12441261
12451262 // get SockIOPool instance
1246- SockIOPool pool = SockIOPool .getInstance ();
1263+ SockIOPool pool = SockIOPool .getInstance ( poolName );
12471264
12481265 // return false if unable to get SockIO obj
12491266 if (pool == null ) {
@@ -1335,7 +1352,7 @@ public Map stats() {
13351352 public Map stats (String [] servers ) {
13361353
13371354 // get SockIOPool instance
1338- SockIOPool pool = SockIOPool .getInstance ();
1355+ SockIOPool pool = SockIOPool .getInstance ( poolName );
13391356
13401357 // return false if unable to get SockIO obj
13411358 if (pool == null ) {
0 commit comments