From b053ccc525f1ebcb2da88c370dc0ff6688ac6a97 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 3 Jun 2014 20:34:18 +0400 Subject: [PATCH] Useless maps dropped --- src/main/java/org/redisson/Redisson.java | 124 ++---------------- .../java/org/redisson/RedissonAtomicLong.java | 11 +- 2 files changed, 13 insertions(+), 122 deletions(-) diff --git a/src/main/java/org/redisson/Redisson.java b/src/main/java/org/redisson/Redisson.java index e8a80f262..1d0f89c94 100644 --- a/src/main/java/org/redisson/Redisson.java +++ b/src/main/java/org/redisson/Redisson.java @@ -58,19 +58,8 @@ public class Redisson { }; private final ConcurrentMap latchesMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK, listener); - private final ConcurrentMap topicsMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); private final ConcurrentMap locksMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK, listener); - private final ConcurrentMap atomicLongsMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap queuesMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap dequeMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap setsMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap sortedSetMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap listsMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap hyperLogLogMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap bucketMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConcurrentMap mapsMap = new ReferenceMap(ReferenceType.STRONG, ReferenceType.WEAK); - private final ConnectionManager connectionManager; private final Config config; @@ -104,29 +93,11 @@ public class Redisson { } public RBucket getBucket(String name) { - RedissonBucket bucket = bucketMap.get(name); - if (bucket == null) { - bucket = new RedissonBucket(connectionManager, name); - RedissonBucket oldBucket = bucketMap.putIfAbsent(name, bucket); - if (oldBucket != null) { - bucket = oldBucket; - } - } - - return bucket; + return new RedissonBucket(connectionManager, name); } public RHyperLogLog getHyperLogLog(String name) { - RedissonHyperLogLog logLog = hyperLogLogMap.get(name); - if (logLog == null) { - logLog = new RedissonHyperLogLog(connectionManager, name); - RedissonHyperLogLog oldLogLog = hyperLogLogMap.putIfAbsent(name, logLog); - if (oldLogLog != null) { - logLog = oldLogLog; - } - } - - return logLog; + return new RedissonHyperLogLog(connectionManager, name); } /** @@ -136,16 +107,7 @@ public class Redisson { * @return distributed list */ public RList getList(String name) { - RedissonList list = listsMap.get(name); - if (list == null) { - list = new RedissonList(connectionManager, name); - RedissonList oldList = listsMap.putIfAbsent(name, list); - if (oldList != null) { - list = oldList; - } - } - - return list; + return new RedissonList(connectionManager, name); } /** @@ -155,16 +117,7 @@ public class Redisson { * @return distributed map */ public RMap getMap(String name) { - RedissonMap map = mapsMap.get(name); - if (map == null) { - map = new RedissonMap(connectionManager, name); - RedissonMap oldMap = mapsMap.putIfAbsent(name, map); - if (oldMap != null) { - map = oldMap; - } - } - - return map; + return new RedissonMap(connectionManager, name); } /** @@ -194,16 +147,7 @@ public class Redisson { * @return distributed set */ public RSet getSet(String name) { - RedissonSet set = setsMap.get(name); - if (set == null) { - set = new RedissonSet(connectionManager, name); - RedissonSet oldSet = setsMap.putIfAbsent(name, set); - if (oldSet != null) { - set = oldSet; - } - } - - return set; + return new RedissonSet(connectionManager, name); } /** @@ -213,16 +157,7 @@ public class Redisson { * @return distributed set */ public RSortedSet getSortedSet(String name) { - RedissonSortedSet set = sortedSetMap.get(name); - if (set == null) { - set = new RedissonSortedSet(connectionManager, name); - RedissonSortedSet oldSet = sortedSetMap.putIfAbsent(name, set); - if (oldSet != null) { - set = oldSet; - } - } - - return set; + return new RedissonSortedSet(connectionManager, name); } /** @@ -232,17 +167,7 @@ public class Redisson { * @return distributed topic */ public RTopic getTopic(String name) { - RedissonTopic topic = topicsMap.get(name); - if (topic == null) { - topic = new RedissonTopic(connectionManager, name); - RedissonTopic oldTopic = topicsMap.putIfAbsent(name, topic); - if (oldTopic != null) { - topic = oldTopic; - } - } - - return topic; - + return new RedissonTopic(connectionManager, name); } /** @@ -252,16 +177,7 @@ public class Redisson { * @return distributed queue */ public RQueue getQueue(String name) { - RedissonQueue queue = queuesMap.get(name); - if (queue == null) { - queue = new RedissonQueue(connectionManager, name); - RedissonQueue oldQueue = queuesMap.putIfAbsent(name, queue); - if (oldQueue != null) { - queue = oldQueue; - } - } - - return queue; + return new RedissonQueue(connectionManager, name); } /** @@ -271,16 +187,7 @@ public class Redisson { * @return distributed queue */ public RDeque getDeque(String name) { - RedissonDeque queue = dequeMap.get(name); - if (queue == null) { - queue = new RedissonDeque(connectionManager, name); - RedissonDeque oldQueue = dequeMap.putIfAbsent(name, queue); - if (oldQueue != null) { - queue = oldQueue; - } - } - - return queue; + return new RedissonDeque(connectionManager, name); } /** @@ -290,18 +197,7 @@ public class Redisson { * @return distributed "atomic long" */ public RAtomicLong getAtomicLong(String name) { - RedissonAtomicLong atomicLong = atomicLongsMap.get(name); - if (atomicLong == null) { - atomicLong = new RedissonAtomicLong(connectionManager, name); - RedissonAtomicLong oldAtomicLong = atomicLongsMap.putIfAbsent(name, atomicLong); - if (oldAtomicLong != null) { - atomicLong = oldAtomicLong; - } - } - - atomicLong.init(); - return atomicLong; - + return new RedissonAtomicLong(connectionManager, name); } /** diff --git a/src/main/java/org/redisson/RedissonAtomicLong.java b/src/main/java/org/redisson/RedissonAtomicLong.java index 8c5e0812e..936b7e405 100644 --- a/src/main/java/org/redisson/RedissonAtomicLong.java +++ b/src/main/java/org/redisson/RedissonAtomicLong.java @@ -15,8 +15,6 @@ */ package org.redisson; -import java.util.concurrent.atomic.AtomicBoolean; - import org.redisson.connection.ConnectionManager; import org.redisson.core.RAtomicLong; @@ -30,16 +28,13 @@ import com.lambdaworks.redis.RedisConnection; */ public class RedissonAtomicLong extends RedissonExpirable implements RAtomicLong { - private final AtomicBoolean initOnce = new AtomicBoolean(); - RedissonAtomicLong(ConnectionManager connectionManager, String name) { super(connectionManager, name); + // TODO make it async + init(); } - public void init() { - if (!initOnce.compareAndSet(false, true)) { - return; - } + private void init() { RedisConnection conn = connectionManager.connectionWriteOp(); try { conn.setnx(getName(), 0);