Remove RJC driver due to lack of Redis 2.6 support

DATAREDIS-185
This commit is contained in:
Jennifer Hickey
2013-06-05 15:12:22 -07:00
parent 66139f9fae
commit dffa1de6d1
25 changed files with 8 additions and 3822 deletions

View File

@@ -1,117 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List;
import org.idevlab.rjc.ds.RedisConnection;
import org.idevlab.rjc.message.RedisNodeSubscriber;
import org.idevlab.rjc.protocol.Protocol.Command;
/**
* Basic decorator suppressing close() calls to the underlying connection.
* Used for reusing arbitrary connections with {@link RedisNodeSubscriber} without
* resorting to connection pooling.
*
* @author Costin Leau
*/
class CloseSuppressingRjcConnection implements RedisConnection {
private final RedisConnection delegate;
/**
* Constructs a new <code>CloseSuppressingRjcConnection</code> instance.
*
* @param delegate
*/
CloseSuppressingRjcConnection(RedisConnection delegate) {
this.delegate = delegate;
}
public void close() {
// no-op
}
public void connect() throws UnknownHostException, IOException {
delegate.connect();
}
public List<Object> getAll() {
return delegate.getAll();
}
public String getBulkReply() {
return delegate.getBulkReply();
}
public String getHost() {
return delegate.getHost();
}
public Long getIntegerReply() {
return delegate.getIntegerReply();
}
public List<String> getMultiBulkReply() {
return delegate.getMultiBulkReply();
}
public List<Object> getObjectMultiBulkReply() {
return delegate.getObjectMultiBulkReply();
}
public Object getOne() {
return delegate.getOne();
}
public int getPort() {
return delegate.getPort();
}
public String getStatusCodeReply() {
return delegate.getStatusCodeReply();
}
public int getTimeout() {
return delegate.getTimeout();
}
public boolean isConnected() {
return delegate.isConnected();
}
public void rollbackTimeout() {
delegate.rollbackTimeout();
}
public void sendCommand(Command arg0, byte[]... arg1) {
delegate.sendCommand(arg0, arg1);
}
public void sendCommand(Command arg0, String... arg1) {
delegate.sendCommand(arg0, arg1);
}
public void sendCommand(Command arg0) {
delegate.sendCommand(arg0);
}
public void setTimeoutInfinite() {
delegate.setTimeoutInfinite();
}
}

View File

@@ -1,221 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.idevlab.rjc.ds.DataSource;
import org.idevlab.rjc.ds.PoolableDataSource;
import org.idevlab.rjc.ds.SimpleDataSource;
import org.idevlab.rjc.message.RedisNodeSubscriber;
import org.idevlab.rjc.protocol.Protocol;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.util.Assert;
/**
* Connection factory creating <a href="http://github.com/e-mzungu/rjc/">rjc</a> based connections.
*
* @author Costin Leau
*/
public class RjcConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
private final static Log log = LogFactory.getLog(RjcConnectionFactory.class);
private String hostName = "localhost";
private int port = Protocol.DEFAULT_PORT;
private int timeout = Protocol.DEFAULT_TIMEOUT;
private String password;
private boolean usePool = true;
private int dbIndex = 0;
private DataSource dataSource;
private DataSource subscriptionDataSource;
/**
* Constructs a new <code>RjcConnectionFactory</code> instance
* with default settings (default connection pooling, no shard information).
*/
public RjcConnectionFactory() {
}
public void afterPropertiesSet() {
if (usePool) {
PoolableDataSource pool = new PoolableDataSource();
pool.setHost(hostName);
pool.setPort(port);
pool.setPassword(password);
pool.setTimeout(timeout);
pool.init();
dataSource = pool;
}
else {
dataSource = new SimpleDataSource(hostName, port, timeout, password);
}
subscriptionDataSource = new SimpleDataSource(hostName, port, timeout, password);
}
public void destroy() {
if (usePool && dataSource != null) {
try {
((PoolableDataSource) dataSource).close();
} catch (Exception ex) {
log.warn("Cannot properly close Rjc pool", ex);
}
dataSource = null;
}
}
public RedisConnection getConnection() {
return postProcessConnection(new RjcConnection(dataSource.getConnection(), dbIndex,
new RedisNodeSubscriber(subscriptionDataSource)));
}
/**
* Post process a newly retrieved connection. Useful for decorating or executing
* initialization commands on a new connection.
* This implementation simply returns the connection.
*
* @param connection
* @return processed connection
*/
protected RjcConnection postProcessConnection(RjcConnection connection) {
return connection;
}
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return RjcUtils.convertRjcAccessException(ex);
}
/**
* Returns the Redis hostName.
*
* @return Returns the hostName
*/
public String getHostName() {
return hostName;
}
/**
* Sets the Redis hostName.
*
* @param hostName The hostName to set.
*/
public void setHostName(String hostName) {
this.hostName = hostName;
}
/**
* Returns the password used for authenticating with the Redis server.
*
* @return password for authentication
*/
public String getPassword() {
return password;
}
/**
* Sets the password used for authenticating with the Redis server.
*
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the port used to connect to the Redis instance.
*
* @return Redis port.
*/
public int getPort() {
return port;
}
/**
* Sets the port used to connect to the Redis instance.
*
* @param port Redis port
*/
public void setPort(int port) {
this.port = port;
}
/**
* Returns the timeout.
*
* @return Returns the timeout
*/
public int getTimeout() {
return timeout;
}
/**
* @param timeout The timeout to set.
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}
/**
* Indicates the use of a connection pool.
*
* @return Returns the use of connection pooling.
*/
public boolean getUsePool() {
return usePool;
}
/**
* Turns on or off the use of connection pooling.
*
* @param usePool The usePool to set.
*/
public void setUsePool(boolean usePool) {
this.usePool = usePool;
}
/**
* Returns the index of the database.
*
* @return Returns the database index
*/
public int getDatabase() {
return dbIndex;
}
/**
* Sets the index of the database used by this connection factory.
* Can be between 0 (default) and 15.
*
* @param index database index
*/
public void setDatabase(int index) {
Assert.isTrue(index >= 0, "invalid DB index (a positive index required)");
this.dbIndex = index;
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import org.idevlab.rjc.message.MessageListener;
import org.idevlab.rjc.message.PMessageListener;
import org.springframework.data.redis.connection.DefaultMessage;
/**
* Message listener adapter for RJC library.
*
* @author Costin Leau
*/
class RjcMessageListener implements MessageListener, PMessageListener {
private final org.springframework.data.redis.connection.MessageListener listener;
RjcMessageListener(org.springframework.data.redis.connection.MessageListener messageListener) {
this.listener = messageListener;
}
public void onMessage(String channel, String message) {
listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), null);
}
public void onMessage(String pattern, String channel, String message) {
listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)),
RjcUtils.encode(pattern));
}
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import org.idevlab.rjc.message.RedisNodeSubscriber;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.util.AbstractSubscription;
/**
* Message subscription on top of RJC.
*
* @author Costin Leau
*/
class RjcSubscription extends AbstractSubscription {
private final RedisNodeSubscriber subscriber;
RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber) {
super(listener);
this.subscriber = subscriber;
subscriber.setMessageListener(new RjcMessageListener(listener));
subscriber.setPMessageListener(new RjcMessageListener(listener));
}
protected void doClose() {
if(!getChannels().isEmpty() || !getPatterns().isEmpty()) {
subscriber.close();
}
}
protected void doPsubscribe(byte[]... patterns) {
subscriber.psubscribe(RjcUtils.decodeMultiple(patterns));
}
protected void doPUnsubscribe(boolean all, byte[]... patterns) {
subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns));
}
protected void doSubscribe(byte[]... channels) {
subscriber.subscribe(RjcUtils.decodeMultiple(channels));
}
protected void doUnsubscribe(boolean all, byte[]... channels) {
subscriber.unsubscribe(RjcUtils.decodeMultiple(channels));
}
}

View File

@@ -1,249 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.idevlab.rjc.Client.LIST_POSITION;
import org.idevlab.rjc.ElementScore;
import org.idevlab.rjc.RedisException;
import org.idevlab.rjc.SortingParams;
import org.idevlab.rjc.ZParams;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.SortParameters.Range;
import org.springframework.data.redis.connection.util.DecodeUtils;
import org.springframework.util.ObjectUtils;
/**
* Helper class featuring methods for RJC connection handling, providing support for exception translation.
*
* @author Costin Leau
*/
public abstract class RjcUtils {
private static final String ONE = "1";
private static final String ZERO = "0";
public static DataAccessException convertRjcAccessException(RuntimeException ex) {
if (ex instanceof RedisException) {
return convertRjcAccessException((RedisException) ex);
}
return new RedisSystemException("Unknown exception", ex);
}
public static DataAccessException convertRjcAccessException(RedisException ex) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
static DataType convertDataType(String type) {
if ("string".equals(type)) {
return DataType.STRING;
}
else if ("list".equals(type)) {
return DataType.LIST;
}
else if ("set".equals(type)) {
return DataType.SET;
}
else if ("zset".equals(type)) {
return DataType.ZSET;
}
else if ("hash".equals(type)) {
return DataType.HASH;
}
else if ("none".equals(type)) {
return DataType.NONE;
}
return null;
}
static String decode(byte[] bytes) {
return DecodeUtils.decode(bytes);
}
static byte[] encode(String string) {
return DecodeUtils.encode(string);
}
static String[] decodeMultiple(byte[]... bytes) {
return DecodeUtils.decodeMultiple(bytes);
}
static String[] flatten(Map<byte[], byte[]> tuple) {
String[] result = new String[tuple.size() * 2];
int index = 0;
for (Map.Entry<byte[], byte[]> entry : tuple.entrySet()) {
result[index++] = decode(entry.getKey());
result[index++] = decode(entry.getValue());
}
return result;
}
static Set<byte[]> convertToSet(Collection<String> keys) {
if (keys == null) {
return null;
}
return DecodeUtils.convertToSet(keys);
}
static List<byte[]> convertToList(Collection<String> keys) {
if (keys == null) {
return null;
}
return DecodeUtils.convertToList(keys);
}
static SortingParams convertSortParams(SortParameters params) {
SortingParams rjcSort = null;
if (params != null) {
rjcSort = new SortingParams();
byte[] byPattern = params.getByPattern();
if (byPattern != null) {
rjcSort.by(DecodeUtils.decode(byPattern));
}
byte[][] getPattern = params.getGetPattern();
if (getPattern != null && getPattern.length > 0) {
for (byte[] bs : getPattern) {
rjcSort.get(DecodeUtils.decode(bs));
}
}
Range limit = params.getLimit();
if (limit != null) {
rjcSort.limit((int) limit.getStart(), (int) limit.getCount());
}
Order order = params.getOrder();
if (order != null && order.equals(Order.DESC)) {
rjcSort.desc();
}
Boolean isAlpha = params.isAlphabetic();
if (isAlpha != null && isAlpha) {
rjcSort.alpha();
}
}
return rjcSort;
}
static Properties info(String string) {
Properties info = new Properties();
StringReader stringReader = new StringReader(string);
try {
info.load(stringReader);
} catch (Exception ex) {
throw new RedisSystemException("Cannot read Redis info", ex);
} finally {
stringReader.close();
}
return info;
}
static String asBit(boolean value) {
return (value ? ONE : ZERO);
}
static LIST_POSITION convertPosition(Position where) {
switch (where) {
case BEFORE:
return LIST_POSITION.BEFORE;
case AFTER:
return LIST_POSITION.AFTER;
}
return null;
}
static ZParams toZParams(Aggregate aggregate, int[] weights) {
return new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
}
static Set<Tuple> convertElementScore(List<ElementScore> tuples) {
Set<Tuple> value = new LinkedHashSet<Tuple>(tuples.size());
for (ElementScore tuple : tuples) {
value.add(new DefaultTuple(encode(tuple.getElement()), Double.valueOf(tuple.getScore())));
}
return value;
}
static Map<byte[], byte[]> encodeMap(Map<String, String> map) {
Map<byte[], byte[]> result = new LinkedHashMap<byte[], byte[]>(map.size());
for (Map.Entry<String, String> entry : map.entrySet()) {
result.put(encode(entry.getKey()), encode(entry.getValue()));
}
return result;
}
static Map<String, String> decodeMap(Map<byte[], byte[]> map) {
Map<String, String> result = new LinkedHashMap<String, String>(map.size());
for (Map.Entry<byte[], byte[]> entry : map.entrySet()) {
result.put(decode(entry.getKey()), decode(entry.getValue()));
}
return result;
}
static Double convert(String zscore) {
return (zscore == null ? null : Double.valueOf(zscore));
}
static String[] addArray(String[] one, String[] two) {
if (ObjectUtils.isEmpty(one)) {
return two;
}
if (ObjectUtils.isEmpty(two)) {
return one;
}
String[] result = Arrays.copyOf(one, one.length + two.length);
System.arraycopy(two, 0, result, one.length, two.length);
return result;
}
static List<Object> maybeConvert(List<Object> result) {
for (int i = 0; i < result.size(); i++) {
Object obj = result.get(i);
if (obj instanceof String) {
result.set(i, encode((String) obj));
}
}
return result;
}
}

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.rjc;
import org.idevlab.rjc.ds.DataSource;
import org.idevlab.rjc.ds.RedisConnection;
/**
* Basic data source that always returns the same connection.
*
* @author Costin Leau
*/
class SingleDataSource implements DataSource {
private final RedisConnection connection;
SingleDataSource(RedisConnection connection) {
this.connection = connection;
}
public RedisConnection getConnection() {
return connection;
}
}

View File

@@ -1,5 +0,0 @@
/**
* Connection package for <a href="https://github.com/e-mzungu/rjc">RJC</a> library.
*/
package org.springframework.data.redis.connection.rjc;