Permalink
Browse files

a

  • Loading branch information...
1 parent 355dd86 commit 369a963837b3ac96b17ce85a7222f4d42806680c @arden committed Aug 25, 2010
View
Binary file not shown.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=074da0ae
-build.xml.script.CRC32=b102c1a2
-build.xml.stylesheet.CRC32=28e38971@1.38.1.45
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=074da0ae
-nbproject/build-impl.xml.script.CRC32=93195a2d
-nbproject/build-impl.xml.stylesheet.CRC32=78c6a6ee@1.38.1.45
+build.xml.data.CRC32=074da0ae
+build.xml.script.CRC32=b102c1a2
+build.xml.stylesheet.CRC32=28e38971@1.38.1.45
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=074da0ae
+nbproject/build-impl.xml.script.CRC32=7397afa4
+nbproject/build-impl.xml.stylesheet.CRC32=f33e10ff@1.38.2.45
No changes.
@@ -1,2 +1,6 @@
compile.on.save=true
+do.depend=false
+do.jar=true
+javac.debug=true
+javadoc.preview=true
user.properties.file=C:\\Users\\arden\\.netbeans\\6.9\\build.properties
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
@@ -1,9 +1,9 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
-annotation.processing.processor.options=
-annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=jredis-auto-connect
+application.vendor=arden
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
@@ -24,14 +24,17 @@ debug.test.classpath=\
dist.dir=dist
dist.jar=${dist.dir}/jredis-auto-connect.jar
dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
excludes=
+file.reference.commons-pool-1.5.4.jar=lib/commons-pool-1.5.4.jar
file.reference.jrails-1.0.jar=lib\\jrails-1.0.jar
file.reference.jredis-core-all-1.0-rc1-jar-with-dependencies.jar=lib\\jredis-core-all-1.0-rc1-jar-with-dependencies.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.jrails-1.0.jar}:\
- ${file.reference.jredis-core-all-1.0-rc1-jar-with-dependencies.jar}
+ ${file.reference.jredis-core-all-1.0-rc1-jar-with-dependencies.jar}:\
+ ${file.reference.commons-pool-1.5.4.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
@@ -4,30 +4,46 @@
*/
package com.tujiao.jredis;
-import com.jrails.commons.utils.PropertiesUtils;
-import com.jrails.modules.spring.ServiceLocator;
+import com.tujiao.jredis.pool.RedisPoolableObjectFactory;
import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
import org.jredis.connector.ConnectionSpec;
import org.jredis.JRedis;
import org.jredis.ri.alphazero.JRedisClient;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.impl.SoftReferenceObjectPool;
/**
*
* @author arden
*/
public class RedisClient implements Runnable {
- private static String host = "121.11.69.53";
+ private static String host = "localhost";
private static int port = 6379;
private static JRedis jredis = null;
private static final int retryConnectTimes = 3;
+ private static PoolableObjectFactory factory = new RedisPoolableObjectFactory();
+ public static SoftReferenceObjectPool pool = new SoftReferenceObjectPool(factory);
static {
+// try {
+// // 启动自动重连功能
+// RedisReconnect.start();
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+ }
+
+ public static JRedis getRedis() {
+ Object o;
try {
- // 启动自动重连功能
- RedisReconnect.start();
- } catch (Exception e) {
- e.printStackTrace();
+ o = pool.borrowObject();
+ if (o instanceof JRedis) {
+ return (JRedis)o;
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
+ return null;
}
public static JRedis getRedisClient() {
@@ -0,0 +1,69 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.tujiao.jredis.pool;
+
+import com.paojiao.redis.RedisClient;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.jredis.JRedis;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ *
+ * @author arden
+ */
+public class RedisPoolableObjectFactory implements PoolableObjectFactory {
+ private static Logger logger = LoggerFactory.getLogger(RedisPoolableObjectFactory.class);
+
+ @Override
+ public void activateObject(Object o) throws Exception {
+ logger.debug("Activating Object " + o);
+ }
+
+ @Override
+ public void destroyObject(Object o) throws Exception {
+ logger.debug("DestroyObject Object " + o);
+ }
+
+ @Override
+ public Object makeObject() throws Exception {
+ JRedis jredis = RedisClient.connect();
+ logger.debug("正在创建JRedis对象:" + jredis);
+ return jredis;
+ }
+
+ @Override
+ public void passivateObject(Object o) throws Exception {
+ logger.debug("Passivating Object " + o);
+ }
+
+ @Override
+ public boolean validateObject(Object o) {
+ JRedis jredis = null;
+ boolean result = true;
+ try {
+ if (o instanceof JRedis) {
+ jredis = (JRedis)o;
+ jredis.ping();
+ logger.debug("----:jredis:" + jredis);
+ //RedisClient.pool.returnObject(jredis);
+ }
+ } catch (Exception e) {
+ result = false;
+ try {
+ if (jredis != null) {
+ jredis.quit();
+ }
+ } catch (Exception ex) {
+ //ex.printStackTrace();
+ }
+ //e.printStackTrace();
+ }
+ logger.debug("Validating Object " + o + " : " + result);
+ return result;
+ }
+
+}

0 comments on commit 369a963

Please sign in to comment.