33import com .danga .MemCached .ErrorHandler ;
44import com .danga .MemCached .MemCachedClient ;
55import com .danga .MemCached .SockIOPool ;
6-
76import com .googlecode .hibernate .memcached .Memcache ;
87import com .googlecode .hibernate .memcached .MemcacheClientFactory ;
98import com .googlecode .hibernate .memcached .PropertiesHelper ;
10-
119import org .hibernate .cache .CacheException ;
1210
1311/**
@@ -33,17 +31,17 @@ public class DangaMemcacheClientFactory implements MemcacheClientFactory {
3331 public static final String PROP_SOCKET_TIMEOUT = PROP_PREFIX + "socketTimeout" ;
3432 public static final String PROP_SOCKET_CONNECT_TIMEOUT = PROP_PREFIX + "socketConnectTimeout" ;
3533
36- public static final boolean DEFAULT_COMPRESS_ENABLE = true ;
37- public static final String DEFAULT_DEFAULT_ENCODING = "UTF-8" ;
38- public static final String DEFAULT_POOL_NAME = "default" ;
39- public static final String DEFAULT_ERROR_HANDLER = "com.googlecode.hibernate.memcached.dangamemcached.SimpleErrorHandler" ;
40- public static final String DEFAULT_SERVERS = "localhost:11211" ;
41- public static final int DEFAULT_INIT_CONN = 1 ;
42- public static final int DEFAULT_MIN_CONN = 1 ;
43- public static final int DEFAULT_MAX_CONN = 10 ;
44- public static final int DEFAULT_MAX_IDLE = 1000 * 60 * 5 ; //5 minutes
45- public static final int DEFAULT_MAINT_SLEEP = 1000 * 30 ; //30 seconds
46- public static final int DEFAULT_SOCKET_TIMEOUT = 1000 * 30 ; //30 seconds
34+ public static final boolean DEFAULT_COMPRESS_ENABLE = true ;
35+ public static final String DEFAULT_DEFAULT_ENCODING = "UTF-8" ;
36+ public static final String DEFAULT_POOL_NAME = "default" ;
37+ public static final String DEFAULT_ERROR_HANDLER = "com.googlecode.hibernate.memcached.dangamemcached.SimpleErrorHandler" ;
38+ public static final String DEFAULT_SERVERS = "localhost:11211" ;
39+ public static final int DEFAULT_INIT_CONN = 1 ;
40+ public static final int DEFAULT_MIN_CONN = 1 ;
41+ public static final int DEFAULT_MAX_CONN = 10 ;
42+ public static final int DEFAULT_MAX_IDLE = 1000 * 60 * 5 ; //5 minutes
43+ public static final int DEFAULT_MAINT_SLEEP = 1000 * 30 ; //30 seconds
44+ public static final int DEFAULT_SOCKET_TIMEOUT = 1000 * 30 ; //30 seconds
4745 public static final int DEFAULT_SOCKET_CONNECT_TIMEOUT = 1000 * 3 ; //3 seconds
4846
4947 private PropertiesHelper properties ;
@@ -55,37 +53,37 @@ public DangaMemcacheClientFactory(PropertiesHelper properties) {
5553 public Memcache createMemcacheClient () throws Exception {
5654 String poolName = getPoolName ();
5755
58- // grab an instance of our connection pool
59- SockIOPool pool = SockIOPool .getInstance ( poolName );
56+ // grab an instance of our connection pool
57+ SockIOPool pool = SockIOPool .getInstance (poolName );
6058
61- // set the servers and the weights
62- pool .setServers ( getServers () );
63- pool .setWeights ( getWeights () );
59+ // set the servers and the weights
60+ pool .setServers (getServers ());
61+ pool .setWeights (getWeights ());
6462
65- // set some basic pool settings
66- pool .setInitConn ( getInitConn () );
67- pool .setMinConn ( getMinConn () );
68- pool .setMaxConn ( getMaxConn () );
69- pool .setMaxIdle ( getMaxIdle () );
63+ // set some basic pool settings
64+ pool .setInitConn (getInitConn ());
65+ pool .setMinConn (getMinConn ());
66+ pool .setMaxConn (getMaxConn ());
67+ pool .setMaxIdle (getMaxIdle ());
7068
71- // set the sleep for the maint thread
72- // it will wake up every x seconds and
73- // maintain the pool size
74- pool .setMaintSleep ( getMaintSleep () );
69+ // set the sleep for the maint thread
70+ // it will wake up every x seconds and
71+ // maintain the pool size
72+ pool .setMaintSleep (getMaintSleep ());
7573
76- // set some TCP settings
77- pool .setNagle ( false );
78- pool .setSocketTO ( getSocketTimeout () );
79- pool .setSocketConnectTO ( getSocketConnectTimeout () );
74+ // set some TCP settings
75+ pool .setNagle (false );
76+ pool .setSocketTO (getSocketTimeout ());
77+ pool .setSocketConnectTO (getSocketConnectTimeout ());
8078
81- // initialize the connection pool
82- pool .initialize ();
79+ // initialize the connection pool
80+ pool .initialize ();
8381
8482 MemCachedClient client =
85- new MemCachedClient (
86- getClassLoader (),
87- getErrorHandler (),
88- poolName );
83+ new MemCachedClient (
84+ getClassLoader (),
85+ getErrorHandler (),
86+ poolName );
8987 client .setCompressEnable (isCompressEnable ());
9088 client .setDefaultEncoding (getDefaultEncoding ());
9189
@@ -109,25 +107,22 @@ public String getPoolName() {
109107 }
110108
111109 public ErrorHandler getErrorHandler () {
112- String errorHandlerName =
113- properties .get (PROP_ERROR_HANDLER , DEFAULT_ERROR_HANDLER );
110+ String errorHandlerName =
111+ properties .get (PROP_ERROR_HANDLER , DEFAULT_ERROR_HANDLER );
114112
115113 ErrorHandler errorHandler ;
116114 try {
117- errorHandler =
118- (ErrorHandler )Class .forName (errorHandlerName ).newInstance ();
119- } catch (ClassNotFoundException e ) {
115+ errorHandler =
116+ (ErrorHandler ) Class .forName (errorHandlerName ).newInstance ();
117+ } catch (ClassNotFoundException e ) {
120118 throw new CacheException (
121119 "Unable to find error handler class [" + errorHandlerName + "]" );
122- } catch (IllegalAccessException e ) {
120+ } catch (IllegalAccessException e ) {
123121 throw new CacheException (
124- "Illegally access error handler class [" + errorHandlerName + "]" );
125- } catch (InstantiationException e ) {
122+ "Illegally accessed error handler class [" + errorHandlerName + "]" );
123+ } catch (InstantiationException e ) {
126124 throw new CacheException (
127125 "Failed to instantiate error handler class [" + errorHandlerName + "]" );
128- } catch (ClassCastException e ) {
129- throw new CacheException (
130- "Invalid error handler class [" + errorHandlerName + "]" );
131126 }
132127
133128 return errorHandler ;
@@ -138,21 +133,21 @@ public String[] getServers() {
138133 }
139134
140135 public Integer [] getWeights () {
141- String [] servers = getServers ();
136+ String [] servers = getServers ();
142137 Integer [] weights = new Integer [servers .length ];
143138 String weightsValue = properties .get (PROP_WEIGHTS );
144139
145140 if (weightsValue == null || "" .equals (weightsValue )) {
146- for (int i = 0 ; i < weights .length ; i ++)
147- weights [i ] = new Integer ( 1 ) ;
141+ for (int i = 0 ; i < weights .length ; i ++)
142+ weights [i ] = 1 ;
148143 } else {
149144 String [] weightsStrings = weightsValue .split (" " );
150145 if (weightsStrings .length == servers .length ) {
151- for (int i = 0 ; i < weights .length ; i ++)
152- weights [i ] = new Integer (weightsStrings [i ]);
146+ for (int i = 0 ; i < weights .length ; i ++)
147+ weights [i ] = new Integer (weightsStrings [i ]);
153148 } else
154149 throw new CacheException (
155- "Count of weight number mismatch count of server" );
150+ "Count of weight number mismatch count of server" );
156151 }
157152
158153 return weights ;
0 commit comments