Additional interfaces added to all Redisson distributed objects

pull/6/head
Nikita 11 years ago
parent 0336b20aeb
commit 5847d36548

@ -15,16 +15,18 @@
*/
package org.redisson;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import org.redisson.core.RAtomicLong;
import org.redisson.core.RCountDownLatch;
import org.redisson.core.RList;
import org.redisson.core.RLock;
import org.redisson.core.RMap;
import org.redisson.core.RObject;
import org.redisson.core.RQueue;
import org.redisson.core.RSet;
import org.redisson.core.RTopic;
import com.lambdaworks.redis.RedisAsyncConnection;
@ -66,7 +68,7 @@ public class Redisson {
return new Redisson(host, port);
}
public <V> List<V> getList(String name) {
public <V> RList<V> getList(String name) {
RedissonList<V> list = listsMap.get(name);
if (list == null) {
RedisConnection<Object, Object> connection = connect();
@ -82,7 +84,7 @@ public class Redisson {
return list;
}
public <K, V> ConcurrentMap<K, V> getMap(String name) {
public <K, V> RMap<K, V> getMap(String name) {
RedissonMap<K, V> map = mapsMap.get(name);
if (map == null) {
RedisConnection<Object, Object> connection = connect();
@ -98,7 +100,7 @@ public class Redisson {
return map;
}
public Lock getLock(String name) {
public RLock getLock(String name) {
RedissonLock lock = locksMap.get(name);
if (lock == null) {
RedisConnection<Object, Object> connection = connect();
@ -118,7 +120,7 @@ public class Redisson {
return lock;
}
public <V> Set<V> getSet(String name) {
public <V> RSet<V> getSet(String name) {
RedissonSet<V> set = setsMap.get(name);
if (set == null) {
RedisConnection<Object, Object> connection = connect();
@ -155,7 +157,7 @@ public class Redisson {
}
public <V> Queue<V> getQueue(String name) {
public <V> RQueue<V> getQueue(String name) {
RedissonQueue<V> queue = queuesMap.get(name);
if (queue == null) {
RedisConnection<Object, Object> connection = connect();
@ -232,6 +234,15 @@ public class Redisson {
if (robject instanceof RedissonCountDownLatch) {
latchesMap.remove(robject.getName());
}
if (robject instanceof RedissonList) {
listsMap.remove(robject.getName());
}
if (robject instanceof RedissonMap) {
mapsMap.remove(robject.getName());
}
if (robject instanceof RedissonQueue) {
queuesMap.remove(robject.getName());
}
}
public void shutdown() {

@ -22,9 +22,11 @@ import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.redisson.core.RList;
import com.lambdaworks.redis.RedisConnection;
public class RedissonList<V> implements List<V> {
public class RedissonList<V> implements RList<V> {
private int batchSize = 50;
@ -363,8 +365,15 @@ public class RedissonList<V> implements List<V> {
return connection;
}
protected String getName() {
public String getName() {
return name;
}
@Override
public void destroy() {
connection.close();
redisson.remove(this);
}
}

@ -20,16 +20,15 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import org.redisson.core.RObject;
import org.redisson.core.RLock;
import com.lambdaworks.redis.RedisConnection;
import com.lambdaworks.redis.pubsub.RedisPubSubAdapter;
import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
// TODO make it reentrant
public class RedissonLock implements Lock, RObject {
public class RedissonLock implements RLock {
private final Redisson redisson;
private final RedisPubSubConnection<Object, Object> pubSubConnection;

@ -22,10 +22,12 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import org.redisson.core.RMap;
import com.lambdaworks.redis.RedisConnection;
//TODO make keys watching instead of map name
public class RedissonMap<K, V> implements ConcurrentMap<K, V> {
//TODO implement watching by keys instead of map name
public class RedissonMap<K, V> implements RMap<K, V> {
private final RedisConnection<Object, Object> connection;
private final String name;
@ -37,14 +39,10 @@ public class RedissonMap<K, V> implements ConcurrentMap<K, V> {
this.name = name;
}
protected String getName() {
public String getName() {
return name;
}
protected RedisConnection<Object, Object> getConnection() {
return connection;
}
@Override
public int size() {
return connection.hlen(name).intValue();
@ -118,7 +116,7 @@ public class RedissonMap<K, V> implements ConcurrentMap<K, V> {
@Override
public V putIfAbsent(K key, V value) {
while (true) {
Boolean res = getConnection().hsetnx(getName(), key, value);
Boolean res = connection.hsetnx(getName(), key, value);
if (!res) {
V result = get(key);
if (result != null) {
@ -200,4 +198,11 @@ public class RedissonMap<K, V> implements ConcurrentMap<K, V> {
}
}
@Override
public void destroy() {
connection.close();
redisson.remove(this);
}
}

@ -16,11 +16,12 @@
package org.redisson;
import java.util.NoSuchElementException;
import java.util.Queue;
import org.redisson.core.RQueue;
import com.lambdaworks.redis.RedisConnection;
public class RedissonQueue<V> extends RedissonList<V> implements Queue<V> {
public class RedissonQueue<V> extends RedissonList<V> implements RQueue<V> {
RedissonQueue(Redisson redisson, RedisConnection<Object, Object> connection, String name) {
super(redisson, connection, name);

@ -17,11 +17,12 @@ package org.redisson;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.redisson.core.RSet;
import com.lambdaworks.redis.RedisConnection;
public class RedissonSet<V> implements Set<V> {
public class RedissonSet<V> implements RSet<V> {
private final Redisson redisson;
private final RedisConnection<Object, Object> connection;
@ -112,4 +113,16 @@ public class RedissonSet<V> implements Set<V> {
connection.del(name);
}
@Override
public String getName() {
return name;
}
@Override
public void destroy() {
connection.close();
redisson.remove(this);
}
}

@ -0,0 +1,7 @@
package org.redisson.core;
import java.util.List;
public interface RList<V> extends List<V>, RObject {
}

@ -0,0 +1,7 @@
package org.redisson.core;
import java.util.concurrent.locks.Lock;
public interface RLock extends Lock, RObject {
}

@ -0,0 +1,7 @@
package org.redisson.core;
import java.util.concurrent.ConcurrentMap;
public interface RMap<K, V> extends ConcurrentMap<K, V>, RObject {
}

@ -0,0 +1,7 @@
package org.redisson.core;
import java.util.Queue;
public interface RQueue<V> extends Queue<V>, RObject {
}

@ -0,0 +1,7 @@
package org.redisson.core;
import java.util.Set;
public interface RSet<V> extends Set<V>, RObject {
}
Loading…
Cancel
Save