update to srp 0.2 snapshot
except for zset and pubsub ops, the rest of the tests seem to be running
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -14,12 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.redis.connection.sredis;
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Socket;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -29,67 +27,60 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import redis.client.SocketPool;
|
||||
|
||||
/**
|
||||
* Connection factory creating <a href="http://github.com/spullara/redis-protocol">Redis Protocol</a> based connections.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class SRedisConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
|
||||
public class SrpConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
|
||||
|
||||
private final static Log log = LogFactory.getLog(JedisConnectionFactory.class);
|
||||
|
||||
private String hostName = "localhost";
|
||||
private int port = 6379;
|
||||
private SocketPool pool;
|
||||
private BlockingQueue<SrpConnection> trackedConnections = new ArrayBlockingQueue<SrpConnection>(50);
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new <code>SRedisConnectionFactory</code> instance
|
||||
* with default settings.
|
||||
*/
|
||||
public SRedisConnectionFactory() {
|
||||
public SrpConnectionFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>SRedisConnectionFactory</code> instance
|
||||
* with default settings.
|
||||
*/
|
||||
public SRedisConnectionFactory(String host, int port) {
|
||||
public SrpConnectionFactory(String host, int port) {
|
||||
this.hostName = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
pool = new SocketPool(hostName, port);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Field f = ReflectionUtils.findField(SocketPool.class, "queue");
|
||||
ReflectionUtils.makeAccessible(f);
|
||||
Queue<Socket> queue = (Queue<Socket>) ReflectionUtils.getField(f, pool);
|
||||
Socket s = null;
|
||||
SrpConnection con;
|
||||
do {
|
||||
s = queue.poll();
|
||||
if (s != null) {
|
||||
con = trackedConnections.poll();
|
||||
if (con != null && !con.isClosed()) {
|
||||
try {
|
||||
s.close();
|
||||
} catch (IOException ex) {
|
||||
con.close();
|
||||
} catch (Exception ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
} while (s != null);
|
||||
pool = null;
|
||||
} while (con != null);
|
||||
}
|
||||
|
||||
public RedisConnection getConnection() {
|
||||
return new SRedisConnection(pool);
|
||||
return new SrpConnection(hostName, port, trackedConnections);
|
||||
}
|
||||
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
return SRedisUtils.convertSRedisAccessException(ex);
|
||||
return SrpUtils.convertSRedisAccessException(ex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.redis.connection.sredis;
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.util.AbstractSubscription;
|
||||
@@ -26,11 +26,11 @@ import redis.client.RedisClient;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class SRedisSubscription extends AbstractSubscription {
|
||||
class SrpSubscription extends AbstractSubscription {
|
||||
|
||||
private final RedisClient client;
|
||||
|
||||
SRedisSubscription(MessageListener listener, RedisClient client) {
|
||||
SrpSubscription(MessageListener listener, RedisClient client) {
|
||||
super(listener);
|
||||
this.client = client;
|
||||
}
|
||||
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.redis.connection.sredis;
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -38,6 +37,7 @@ import org.springframework.util.Assert;
|
||||
import redis.client.RedisException;
|
||||
import redis.reply.BulkReply;
|
||||
import redis.reply.MultiBulkReply;
|
||||
import redis.reply.Reply;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
@@ -46,7 +46,7 @@ import com.google.common.base.Charsets;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
abstract class SRedisUtils {
|
||||
abstract class SrpUtils {
|
||||
|
||||
private static final byte[] ONE = new byte[] { 1 };
|
||||
private static final byte[] ZERO = new byte[] { 0 };
|
||||
@@ -70,7 +70,7 @@ abstract class SRedisUtils {
|
||||
static Properties info(BulkReply reply) {
|
||||
Properties info = new Properties();
|
||||
// use the same charset as the library
|
||||
StringReader stringReader = new StringReader(new String(reply.bytes, Charsets.UTF_8));
|
||||
StringReader stringReader = new StringReader(new String(reply.data(), Charsets.UTF_8));
|
||||
try {
|
||||
info.load(stringReader);
|
||||
} catch (Exception ex) {
|
||||
@@ -81,17 +81,17 @@ abstract class SRedisUtils {
|
||||
return info;
|
||||
}
|
||||
|
||||
static List<byte[]> toBytesList(Object[] byteArrays) {
|
||||
List<byte[]> list = new ArrayList<byte[]>(byteArrays.length);
|
||||
if (byteArrays.length == 1 && byteArrays[0] == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
for (Object obj : byteArrays) {
|
||||
if (obj instanceof byte[])
|
||||
list.add((byte[]) obj);
|
||||
static List<byte[]> toBytesList(Reply[] replies) {
|
||||
List<byte[]> list = new ArrayList<byte[]>(replies.length);
|
||||
for (Reply reply : replies) {
|
||||
Object data = reply.data();
|
||||
if (data == null) {
|
||||
list.add(null);
|
||||
}
|
||||
else if (data instanceof byte[])
|
||||
list.add((byte[]) data);
|
||||
else
|
||||
throw new IllegalArgumentException("array contains more then just bytes" + obj);
|
||||
throw new IllegalArgumentException("array contains more then just nulls and bytes -> " + data);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -101,7 +101,7 @@ abstract class SRedisUtils {
|
||||
return Arrays.asList(byteArrays);
|
||||
}
|
||||
|
||||
static Set<byte[]> toSet(Object[] byteArrays) {
|
||||
static Set<byte[]> toSet(Reply[] byteArrays) {
|
||||
return new LinkedHashSet<byte[]>(toBytesList(byteArrays));
|
||||
}
|
||||
|
||||
@@ -126,21 +126,21 @@ abstract class SRedisUtils {
|
||||
}
|
||||
|
||||
static Double toDouble(byte[] bytes) {
|
||||
return Double.valueOf(new String(bytes, Charsets.UTF_8));
|
||||
return (bytes == null || bytes.length == 0 ? null : Double.valueOf(new String(bytes, Charsets.UTF_8)));
|
||||
}
|
||||
|
||||
static Long toLong(Object[] byteArrays) {
|
||||
return Long.valueOf(new String((byte[]) byteArrays[0], Charsets.UTF_8));
|
||||
static Long toLong(Object[] bytes) {
|
||||
return (bytes == null || bytes.length == 0 ? null : Long.valueOf(new String((byte[]) bytes[0], Charsets.UTF_8)));
|
||||
}
|
||||
|
||||
static Set<Tuple> convertTuple(MultiBulkReply zrange) {
|
||||
Object[] byteArrays = zrange.byteArrays;
|
||||
Reply[] byteArrays = zrange.data();
|
||||
Set<Tuple> tuples = new LinkedHashSet<Tuple>(byteArrays.length / 2 + 1);
|
||||
|
||||
for (int i = 0; i < byteArrays.length; i++) {
|
||||
byte[] value = (byte[]) byteArrays[i];
|
||||
byte[] value = (byte[]) byteArrays[i].data();
|
||||
i++;
|
||||
Double score = toDouble((byte[]) byteArrays[i]);
|
||||
Double score = toDouble((byte[]) byteArrays[i].data());
|
||||
tuples.add(new DefaultTuple(value, score));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Connection package for <a href="https://github.com/spullara/redis-protocol">spullara Redis Protocol</a> library.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.sredis;
|
||||
package org.springframework.data.redis.connection.srp;
|
||||
|
||||
Reference in New Issue
Block a user