diff --git a/redisson/src/main/java/org/redisson/BaseRemoteService.java b/redisson/src/main/java/org/redisson/BaseRemoteService.java index 5ae6985f3..15f0939a4 100644 --- a/redisson/src/main/java/org/redisson/BaseRemoteService.java +++ b/redisson/src/main/java/org/redisson/BaseRemoteService.java @@ -26,7 +26,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.CancellationException; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; @@ -65,7 +67,6 @@ import io.netty.buffer.ByteBuf; import io.netty.util.Timeout; import io.netty.util.TimerTask; import io.netty.util.concurrent.ScheduledFuture; -import io.netty.util.internal.PlatformDependent; /** * @@ -76,8 +77,8 @@ public abstract class BaseRemoteService { private static final Logger log = LoggerFactory.getLogger(BaseRemoteService.class); - private final Map, String> requestQueueNameCache = PlatformDependent.newConcurrentHashMap(); - private final ConcurrentMap> methodSignaturesCache = PlatformDependent.newConcurrentHashMap(); + private final Map, String> requestQueueNameCache = new ConcurrentHashMap<>(); + private final ConcurrentMap> methodSignaturesCache = new ConcurrentHashMap<>(); protected final Codec codec; protected final RedissonClient redisson; @@ -412,7 +413,7 @@ public abstract class BaseRemoteService { Map> entryResponses = entry.getResponses(); List list = entryResponses.get(requestId); if (list == null) { - list = new ArrayList(3); + list = new ArrayList<>(3); entryResponses.put(requestId, list); } @@ -650,8 +651,7 @@ public abstract class BaseRemoteService { protected RequestId generateRequestId() { byte[] id = new byte[17]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); id[0] = 00; return new RequestId(id); } @@ -679,7 +679,7 @@ public abstract class BaseRemoteService { protected List getMethodSignatures(Method method) { List result = methodSignaturesCache.get(method); if (result == null) { - result = new ArrayList(method.getParameterTypes().length); + result = new ArrayList<>(method.getParameterTypes().length); for (Class t : method.getParameterTypes()) { result.add(t.getName()); } diff --git a/redisson/src/main/java/org/redisson/QueueTransferService.java b/redisson/src/main/java/org/redisson/QueueTransferService.java index de6346e71..8758f8077 100644 --- a/redisson/src/main/java/org/redisson/QueueTransferService.java +++ b/redisson/src/main/java/org/redisson/QueueTransferService.java @@ -15,10 +15,9 @@ */ package org.redisson; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -26,7 +25,7 @@ import io.netty.util.internal.PlatformDependent; */ public class QueueTransferService { - private final ConcurrentMap tasks = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap tasks = new ConcurrentHashMap<>(); public synchronized void schedule(String name, QueueTransferTask task) { QueueTransferTask oldTask = tasks.putIfAbsent(name, task); diff --git a/redisson/src/main/java/org/redisson/Redisson.java b/redisson/src/main/java/org/redisson/Redisson.java index 56b36f0e3..97b7f4530 100755 --- a/redisson/src/main/java/org/redisson/Redisson.java +++ b/redisson/src/main/java/org/redisson/Redisson.java @@ -15,6 +15,7 @@ */ package org.redisson; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -89,8 +90,6 @@ import org.redisson.pubsub.SemaphorePubSub; import org.redisson.remote.ResponseEntry; import org.redisson.transaction.RedissonTransaction; -import io.netty.util.internal.PlatformDependent; - /** * Main infrastructure class allows to get access * to all Redisson objects on top of Redis server. @@ -108,11 +107,11 @@ public class Redisson implements RedissonClient { protected final EvictionScheduler evictionScheduler; protected final ConnectionManager connectionManager; - protected final ConcurrentMap, Class> liveObjectClassCache = PlatformDependent.newConcurrentHashMap(); + protected final ConcurrentMap, Class> liveObjectClassCache = new ConcurrentHashMap<>(); protected final Config config; protected final SemaphorePubSub semaphorePubSub = new SemaphorePubSub(); - protected final ConcurrentMap responses = PlatformDependent.newConcurrentHashMap(); + protected final ConcurrentMap responses = new ConcurrentHashMap<>(); protected Redisson(Config config) { this.config = config; diff --git a/redisson/src/main/java/org/redisson/RedissonDelayedQueue.java b/redisson/src/main/java/org/redisson/RedissonDelayedQueue.java index 4c8e52111..1d17c6636 100644 --- a/redisson/src/main/java/org/redisson/RedissonDelayedQueue.java +++ b/redisson/src/main/java/org/redisson/RedissonDelayedQueue.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.redisson.api.RDelayedQueue; @@ -32,8 +33,6 @@ import org.redisson.client.protocol.RedisCommands; import org.redisson.command.CommandAsyncExecutor; import org.redisson.misc.RedissonPromise; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -96,7 +95,7 @@ public class RedissonDelayedQueue extends RedissonExpirable implements RDelay long delayInMs = timeUnit.toMillis(delay); long timeout = System.currentTimeMillis() + delayInMs; - long randomId = PlatformDependent.threadLocalRandom().nextLong(); + long randomId = ThreadLocalRandom.current().nextLong(); return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID, "local value = struct.pack('dLc0', tonumber(ARGV[2]), string.len(ARGV[3]), ARGV[3]);" + "redis.call('zadd', KEYS[2], ARGV[1], value);" diff --git a/redisson/src/main/java/org/redisson/RedissonExecutorService.java b/redisson/src/main/java/org/redisson/RedissonExecutorService.java index 9b5455a5a..e2da0987c 100644 --- a/redisson/src/main/java/org/redisson/RedissonExecutorService.java +++ b/redisson/src/main/java/org/redisson/RedissonExecutorService.java @@ -33,12 +33,14 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; @@ -90,7 +92,6 @@ import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; -import io.netty.util.internal.PlatformDependent; /** * @@ -136,7 +137,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { private final ScheduledTasksService scheduledRemoteService; private final TasksService executorRemoteService; - private final Map, ClassBody> class2body = PlatformDependent.newConcurrentHashMap(); + private final Map, ClassBody> class2body = new ConcurrentHashMap<>(); private final String name; private final String requestQueueName; @@ -145,8 +146,8 @@ public class RedissonExecutorService implements RScheduledExecutorService { private final String executorId; private final ConcurrentMap responses; - private final ReferenceQueue> referenceDueue = new ReferenceQueue>(); - private final Collection references = Collections.newSetFromMap(PlatformDependent.newConcurrentHashMap()); + private final ReferenceQueue> referenceDueue = new ReferenceQueue<>(); + private final Collection references = Collections.newSetFromMap(new ConcurrentHashMap<>()); public RedissonExecutorService(Codec codec, CommandExecutor commandExecutor, Redisson redisson, String name, QueueTransferService queueTransferService, ConcurrentMap responses, ExecutorOptions options) { @@ -211,8 +212,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { protected String generateRequestId() { byte[] id = new byte[16]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); return ByteBufUtil.hexDump(id); } @@ -580,7 +580,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { throw new NullPointerException("Tasks are not defined"); } - List> result = new ArrayList>(); + List> result = new ArrayList<>(); TasksBatchService executorRemoteService = createBatchService(); RemoteExecutorServiceAsync asyncService = executorRemoteService.get(RemoteExecutorServiceAsync.class, RESULT_OPTIONS); for (Callable task : tasks) { @@ -608,7 +608,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { TasksBatchService executorRemoteService = createBatchService(); RemoteExecutorServiceAsync asyncService = executorRemoteService.get(RemoteExecutorServiceAsync.class, RESULT_OPTIONS); - List> result = new ArrayList>(); + List> result = new ArrayList<>(); for (Callable task : tasks) { check(task); ClassBody classBody = getClassBody(task); @@ -696,7 +696,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { throw new NullPointerException("Tasks are not defined"); } - List> result = new ArrayList>(); + List> result = new ArrayList<>(); TasksBatchService executorRemoteService = createBatchService(); RemoteExecutorServiceAsync asyncService = executorRemoteService.get(RemoteExecutorServiceAsync.class, RESULT_OPTIONS); for (Runnable task : tasks) { @@ -724,7 +724,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { TasksBatchService executorRemoteService = createBatchService(); RemoteExecutorServiceAsync asyncService = executorRemoteService.get(RemoteExecutorServiceAsync.class, RESULT_OPTIONS); - List> result = new ArrayList>(); + List> result = new ArrayList<>(); for (Runnable task : tasks) { check(task); ClassBody classBody = getClassBody(task); @@ -1013,7 +1013,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { throw new NullPointerException(); } - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (Callable callable : tasks) { RExecutorFuture future = submit(callable); futures.add(future); diff --git a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java index 5f4dc9084..b39403fe1 100644 --- a/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java +++ b/redisson/src/main/java/org/redisson/RedissonLiveObjectService.java @@ -34,6 +34,7 @@ import java.util.Queue; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.redisson.api.RCascadeType; @@ -73,9 +74,8 @@ import org.redisson.liveobject.misc.AdvBeanCopy; import org.redisson.liveobject.misc.ClassUtils; import org.redisson.liveobject.misc.Introspectior; import org.redisson.liveobject.resolver.NamingScheme; -import org.redisson.liveobject.resolver.Resolver; +import org.redisson.liveobject.resolver.RIdResolver; -import io.netty.util.internal.PlatformDependent; import jodd.bean.BeanCopy; import jodd.bean.BeanUtil; import net.bytebuddy.ByteBuddy; @@ -90,7 +90,7 @@ import net.bytebuddy.matcher.ElementMatchers; public class RedissonLiveObjectService implements RLiveObjectService { - private static final ConcurrentMap, Resolver> PROVIDER_CACHE = PlatformDependent.newConcurrentHashMap(); + private static final ConcurrentMap>, RIdResolver> PROVIDER_CACHE = new ConcurrentHashMap<>(); private final ConcurrentMap, Class> classCache; private final RedissonClient redisson; private final CommandAsyncExecutor commandExecutor; @@ -120,12 +120,12 @@ public class RedissonLiveObjectService implements RLiveObjectService { String idFieldName = getRIdFieldName(entityClass); RId annotation = ClassUtils.getDeclaredField(entityClass, idFieldName) .getAnnotation(RId.class); - Resolver resolver = getResolver(entityClass, annotation.generator(), annotation); + RIdResolver resolver = getResolver(entityClass, annotation.generator(), annotation); Object id = resolver.resolve(entityClass, annotation, idFieldName, redisson); return id; } - private Resolver getResolver(Class cls, Class resolverClass, Annotation anno) { + private RIdResolver getResolver(Class cls, Class> resolverClass, Annotation anno) { if (!PROVIDER_CACHE.containsKey(resolverClass)) { try { PROVIDER_CACHE.putIfAbsent(resolverClass, resolverClass.newInstance()); diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index 834fab227..9f2eb4d88 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.redisson.api.LocalCachedMapOptions; @@ -67,13 +68,6 @@ import org.redisson.misc.RPromise; import org.redisson.misc.RedissonPromise; import io.netty.buffer.ByteBuf; -import io.netty.util.internal.PlatformDependent; - -/** - * - * @author Nikita Koksharov - * - */ @SuppressWarnings("serial") public class RedissonLocalCachedMap extends RedissonMap implements RLocalCachedMap { @@ -265,8 +259,7 @@ public class RedissonLocalCachedMap extends RedissonMap implements R protected static byte[] generateId() { byte[] id = new byte[16]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); return id; } @@ -274,8 +267,7 @@ public class RedissonLocalCachedMap extends RedissonMap implements R byte[] result = new byte[keyHash.length + 1 + 8]; result[16] = ':'; byte[] id = new byte[8]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); System.arraycopy(keyHash, 0, result, 0, keyHash.length); System.arraycopy(id, 0, result, 17, id.length); diff --git a/redisson/src/main/java/org/redisson/RedissonLock.java b/redisson/src/main/java/org/redisson/RedissonLock.java index 210a1812a..dbe2ab3ec 100644 --- a/redisson/src/main/java/org/redisson/RedissonLock.java +++ b/redisson/src/main/java/org/redisson/RedissonLock.java @@ -18,6 +18,7 @@ package org.redisson; import java.util.Arrays; import java.util.Collections; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -43,7 +44,6 @@ import org.slf4j.LoggerFactory; import io.netty.util.Timeout; import io.netty.util.TimerTask; -import io.netty.util.internal.PlatformDependent; /** * Distributed implementation of {@link java.util.concurrent.locks.Lock} @@ -80,7 +80,7 @@ public class RedissonLock extends RedissonExpirable implements RLock { private static final Logger log = LoggerFactory.getLogger(RedissonLock.class); - private static final ConcurrentMap EXPIRATION_RENEWAL_MAP = PlatformDependent.newConcurrentHashMap(); + private static final ConcurrentMap EXPIRATION_RENEWAL_MAP = new ConcurrentHashMap<>(); protected long internalLockLeaseTime; final UUID id; diff --git a/redisson/src/main/java/org/redisson/RedissonMultiLock.java b/redisson/src/main/java/org/redisson/RedissonMultiLock.java index 75afd3efb..582932021 100644 --- a/redisson/src/main/java/org/redisson/RedissonMultiLock.java +++ b/redisson/src/main/java/org/redisson/RedissonMultiLock.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.ListIterator; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -33,8 +34,6 @@ import org.redisson.misc.RPromise; import org.redisson.misc.RedissonPromise; import org.redisson.misc.TransferListener; -import io.netty.util.internal.ThreadLocalRandom; - /** * Groups multiple independent locks and manages them as one lock. * diff --git a/redisson/src/main/java/org/redisson/RedissonNode.java b/redisson/src/main/java/org/redisson/RedissonNode.java index b6d056f1d..65149bcf0 100644 --- a/redisson/src/main/java/org/redisson/RedissonNode.java +++ b/redisson/src/main/java/org/redisson/RedissonNode.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.util.Map.Entry; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.redisson.api.RExecutorService; @@ -32,7 +33,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBufUtil; -import io.netty.util.internal.PlatformDependent; /** * @@ -75,8 +75,7 @@ public final class RedissonNode { private String generateId() { byte[] id = new byte[8]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); return ByteBufUtil.hexDump(id); } diff --git a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java index cf3df56df..60eaf238d 100644 --- a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java +++ b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java @@ -17,6 +17,7 @@ package org.redisson; import java.util.Arrays; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -33,7 +34,6 @@ import org.redisson.pubsub.SemaphorePubSub; import io.netty.buffer.ByteBufUtil; import io.netty.util.Timeout; import io.netty.util.TimerTask; -import io.netty.util.internal.PlatformDependent; /** * @@ -365,8 +365,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen protected String generateId() { byte[] id = new byte[16]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); return ByteBufUtil.hexDump(id); } diff --git a/redisson/src/main/java/org/redisson/RedissonPriorityBlockingQueue.java b/redisson/src/main/java/org/redisson/RedissonPriorityBlockingQueue.java index ad9fe8952..dc66bd051 100644 --- a/redisson/src/main/java/org/redisson/RedissonPriorityBlockingQueue.java +++ b/redisson/src/main/java/org/redisson/RedissonPriorityBlockingQueue.java @@ -17,6 +17,7 @@ package org.redisson; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.redisson.api.RFuture; @@ -31,8 +32,6 @@ import org.redisson.connection.decoder.ListDrainToDecoder; import org.redisson.misc.RPromise; import org.redisson.misc.RedissonPromise; -import io.netty.util.internal.PlatformDependent; - /** *

Distributed and concurrent implementation of {@link java.util.concurrent.PriorityBlockingQueue}. * @@ -96,7 +95,7 @@ public class RedissonPriorityBlockingQueue extends RedissonPriorityQueue i } } - long del = PlatformDependent.threadLocalRandom().nextInt(2000000); + long del = ThreadLocalRandom.current().nextInt(2000000); if (timeoutInMicro > 0 && remain < 2000000) { del = 0; } diff --git a/redisson/src/main/java/org/redisson/RedissonRemoteService.java b/redisson/src/main/java/org/redisson/RedissonRemoteService.java index a52247c41..740ad6eff 100644 --- a/redisson/src/main/java/org/redisson/RedissonRemoteService.java +++ b/redisson/src/main/java/org/redisson/RedissonRemoteService.java @@ -18,6 +18,7 @@ package org.redisson; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @@ -53,8 +54,6 @@ import org.redisson.remote.ResponseEntry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -87,8 +86,8 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS private static final Logger log = LoggerFactory.getLogger(RedissonRemoteService.class); - private final Map beans = PlatformDependent.newConcurrentHashMap(); - private final Map, Entry> remoteMap = PlatformDependent.newConcurrentHashMap(); + private final Map beans = new ConcurrentHashMap<>(); + private final Map, Entry> remoteMap = new ConcurrentHashMap<>(); public RedissonRemoteService(Codec codec, RedissonClient redisson, String name, CommandExecutor commandExecutor, String executorId, ConcurrentMap responses) { super(codec, redisson, name, commandExecutor, executorId, responses); diff --git a/redisson/src/main/java/org/redisson/api/annotation/RId.java b/redisson/src/main/java/org/redisson/api/annotation/RId.java index abc5f7893..97ffa0d48 100644 --- a/redisson/src/main/java/org/redisson/api/annotation/RId.java +++ b/redisson/src/main/java/org/redisson/api/annotation/RId.java @@ -41,6 +41,6 @@ public @interface RId { * @see UUIDGenerator * @see LongGenerator */ - Class generator() default RequiredIdResolver.class; + Class> generator() default RequiredIdResolver.class; } diff --git a/redisson/src/main/java/org/redisson/cache/AbstractCacheMap.java b/redisson/src/main/java/org/redisson/cache/AbstractCacheMap.java index 3ebb9d01b..7c80fda7e 100644 --- a/redisson/src/main/java/org/redisson/cache/AbstractCacheMap.java +++ b/redisson/src/main/java/org/redisson/cache/AbstractCacheMap.java @@ -23,11 +23,10 @@ import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -38,7 +37,7 @@ import io.netty.util.internal.PlatformDependent; public abstract class AbstractCacheMap implements Cache { final int size; - final ConcurrentMap> map = PlatformDependent.newConcurrentHashMap(); + final ConcurrentMap> map = new ConcurrentHashMap<>(); private final long timeToLiveInMillis; private final long maxIdleInMillis; diff --git a/redisson/src/main/java/org/redisson/client/RedisPubSubConnection.java b/redisson/src/main/java/org/redisson/client/RedisPubSubConnection.java index 7899f2d2b..2ae58eba4 100644 --- a/redisson/src/main/java/org/redisson/client/RedisPubSubConnection.java +++ b/redisson/src/main/java/org/redisson/client/RedisPubSubConnection.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Queue; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import org.redisson.client.codec.Codec; @@ -40,7 +41,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; -import io.netty.util.internal.PlatformDependent; /** * @@ -50,8 +50,8 @@ import io.netty.util.internal.PlatformDependent; public class RedisPubSubConnection extends RedisConnection { final Queue> listeners = new ConcurrentLinkedQueue>(); - final Map channels = PlatformDependent.newConcurrentHashMap(); - final Map patternChannels = PlatformDependent.newConcurrentHashMap(); + final Map channels = new ConcurrentHashMap<>(); + final Map patternChannels = new ConcurrentHashMap<>(); final Set unsubscibedChannels = new HashSet(); final Set punsubscibedChannels = new HashSet(); diff --git a/redisson/src/main/java/org/redisson/client/handler/CommandPubSubDecoder.java b/redisson/src/main/java/org/redisson/client/handler/CommandPubSubDecoder.java index 40b186835..501c4bb67 100644 --- a/redisson/src/main/java/org/redisson/client/handler/CommandPubSubDecoder.java +++ b/redisson/src/main/java/org/redisson/client/handler/CommandPubSubDecoder.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import org.redisson.client.ChannelName; @@ -41,7 +42,6 @@ import org.redisson.misc.LogHelper; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; -import io.netty.util.internal.PlatformDependent; /** * Redis Publish Subscribe protocol decoder @@ -53,8 +53,8 @@ public class CommandPubSubDecoder extends CommandDecoder { private static final Set MESSAGES = new HashSet(Arrays.asList("subscribe", "psubscribe", "punsubscribe", "unsubscribe")); // It is not needed to use concurrent map because responses are coming consecutive - private final Map entries = new HashMap(); - private final Map> commands = PlatformDependent.newConcurrentHashMap(); + private final Map entries = new HashMap<>(); + private final Map> commands = new ConcurrentHashMap<>(); private final boolean keepOrder; diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 84f29adf2..c744799f8 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Queue; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -66,7 +67,6 @@ import io.netty.util.NetUtil; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.ScheduledFuture; -import io.netty.util.internal.PlatformDependent; /** * @@ -77,7 +77,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { private final Logger log = LoggerFactory.getLogger(getClass()); - private final ConcurrentMap lastPartitions = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap lastPartitions = new ConcurrentHashMap<>(); private ScheduledFuture monitorFuture; diff --git a/redisson/src/main/java/org/redisson/codec/DefaultReferenceCodecProvider.java b/redisson/src/main/java/org/redisson/codec/DefaultReferenceCodecProvider.java index c2a8a5fab..f6602036f 100644 --- a/redisson/src/main/java/org/redisson/codec/DefaultReferenceCodecProvider.java +++ b/redisson/src/main/java/org/redisson/codec/DefaultReferenceCodecProvider.java @@ -15,13 +15,14 @@ */ package org.redisson.codec; -import io.netty.util.internal.PlatformDependent; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.redisson.client.codec.Codec; -import org.redisson.config.Config; + import org.redisson.api.RObject; import org.redisson.api.annotation.REntity; import org.redisson.api.annotation.RObjectField; +import org.redisson.client.codec.Codec; +import org.redisson.config.Config; import org.redisson.liveobject.misc.ClassUtils; /** @@ -30,7 +31,7 @@ import org.redisson.liveobject.misc.ClassUtils; */ public class DefaultReferenceCodecProvider implements ReferenceCodecProvider { - private final ConcurrentMap, Codec> codecCache = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap, Codec> codecCache = new ConcurrentHashMap<>(); @Override public T getCodec(Class codecClass) { diff --git a/redisson/src/main/java/org/redisson/command/CommandBatchService.java b/redisson/src/main/java/org/redisson/command/CommandBatchService.java index 49f8e5243..6b201e9fc 100644 --- a/redisson/src/main/java/org/redisson/command/CommandBatchService.java +++ b/redisson/src/main/java/org/redisson/command/CommandBatchService.java @@ -63,7 +63,6 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.util.Timeout; import io.netty.util.TimerTask; -import io.netty.util.internal.PlatformDependent; /** * @@ -123,12 +122,12 @@ public class CommandBatchService extends CommandAsyncService { private AtomicInteger index = new AtomicInteger(); - private ConcurrentMap commands = PlatformDependent.newConcurrentHashMap(); - private ConcurrentMap connections = PlatformDependent.newConcurrentHashMap(); + private ConcurrentMap commands = new ConcurrentHashMap<>(); + private ConcurrentMap connections = new ConcurrentHashMap<>(); private BatchOptions options; - private Map, List> nestedServices = PlatformDependent.newConcurrentHashMap(); + private Map, List> nestedServices = new ConcurrentHashMap<>(); private AtomicBoolean executed = new AtomicBoolean(); diff --git a/redisson/src/main/java/org/redisson/connection/ConnectionEventsHub.java b/redisson/src/main/java/org/redisson/connection/ConnectionEventsHub.java index 89852139f..bd768331c 100644 --- a/redisson/src/main/java/org/redisson/connection/ConnectionEventsHub.java +++ b/redisson/src/main/java/org/redisson/connection/ConnectionEventsHub.java @@ -17,17 +17,15 @@ package org.redisson.connection; import java.net.InetSocketAddress; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import io.netty.util.internal.PlatformDependent; - public class ConnectionEventsHub { public enum Status {CONNECTED, DISCONNECTED}; - private final ConcurrentMap maps = PlatformDependent.newConcurrentHashMap(); - - private final Map listenersMap = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap maps = new ConcurrentHashMap<>(); + private final Map listenersMap = new ConcurrentHashMap<>(); public int addListener(ConnectionListener listener) { int id = System.identityHashCode(listener); diff --git a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java index 72757e4ab..0a38a176d 100644 --- a/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -128,8 +129,8 @@ public class MasterSlaveConnectionManager implements ConnectionManager { protected MasterSlaveServersConfig config; - private final AtomicReferenceArray slot2entry = new AtomicReferenceArray(MAX_SLOT); - private final Map client2entry = PlatformDependent.newConcurrentHashMap(); + private final AtomicReferenceArray slot2entry = new AtomicReferenceArray<>(MAX_SLOT); + private final Map client2entry = new ConcurrentHashMap<>(); private final RPromise shutdownPromise; @@ -149,7 +150,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager { private PublishSubscribeService subscribeService; - private final Map nodeConnections = PlatformDependent.newConcurrentHashMap(); + private final Map nodeConnections = new ConcurrentHashMap<>(); public MasterSlaveConnectionManager(MasterSlaveServersConfig cfg, Config config, UUID id) { this(config, id); diff --git a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java index e1c1f1d80..4db2e6da2 100755 --- a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -56,7 +57,6 @@ import io.netty.resolver.AddressResolver; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.ScheduledFuture; -import io.netty.util.internal.PlatformDependent; /** * @@ -67,10 +67,10 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { private final Logger log = LoggerFactory.getLogger(getClass()); - private final ConcurrentMap sentinels = PlatformDependent.newConcurrentHashMap(); - private final AtomicReference currentMaster = new AtomicReference(); + private final ConcurrentMap sentinels = new ConcurrentHashMap<>(); + private final AtomicReference currentMaster = new AtomicReference<>(); - private final Set disconnectedSlaves = new HashSet(); + private final Set disconnectedSlaves = new HashSet<>(); private ScheduledFuture monitorFuture; private AddressResolver sentinelResolver; @@ -127,7 +127,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { } List> sentinelSentinels = connection.sync(StringCodec.INSTANCE, RedisCommands.SENTINEL_SENTINELS, cfg.getMasterName()); - List> connectionFutures = new ArrayList>(sentinelSentinels.size()); + List> connectionFutures = new ArrayList<>(sentinelSentinels.size()); for (Map map : sentinelSentinels) { if (map.isEmpty()) { continue; @@ -186,7 +186,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { monitorFuture = group.schedule(new Runnable() { @Override public void run() { - List sentinels = new ArrayList(SentinelConnectionManager.this.sentinels.values()); + List sentinels = new ArrayList<>(SentinelConnectionManager.this.sentinels.values()); final AtomicInteger sentinelsCounter = new AtomicInteger(sentinels.size()); FutureListener> commonListener = new FutureListener>() { @@ -336,7 +336,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { } Set currentSlaves = new HashSet(slavesMap.size()); - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (Map map : slavesMap) { if (map.isEmpty()) { continue; @@ -543,7 +543,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { monitorFuture.cancel(true); } - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (RedisClient sentinel : sentinels.values()) { RFuture future = sentinel.shutdownAsync(); futures.add(future); diff --git a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java index e23725a28..8c67466a4 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/LoadBalancerManager.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.redisson.api.NodeType; import org.redisson.api.RFuture; @@ -43,8 +44,6 @@ import org.redisson.misc.URIBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -58,7 +57,7 @@ public class LoadBalancerManager { private final PubSubConnectionPool pubSubConnectionPool; private final SlaveConnectionPool slaveConnectionPool; - private final Map client2Entry = PlatformDependent.newConcurrentHashMap(); + private final Map client2Entry = new ConcurrentHashMap<>(); public LoadBalancerManager(MasterSlaveServersConfig config, ConnectionManager connectionManager, MasterSlaveEntry entry) { this.connectionManager = connectionManager; diff --git a/redisson/src/main/java/org/redisson/connection/balancer/RandomLoadBalancer.java b/redisson/src/main/java/org/redisson/connection/balancer/RandomLoadBalancer.java index 9779f7e04..467af9824 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/RandomLoadBalancer.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/RandomLoadBalancer.java @@ -16,11 +16,10 @@ package org.redisson.connection.balancer; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import org.redisson.connection.ClientConnectionsEntry; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -30,7 +29,7 @@ public class RandomLoadBalancer implements LoadBalancer { @Override public ClientConnectionsEntry getEntry(List clientsCopy) { - int ind = PlatformDependent.threadLocalRandom().nextInt(clientsCopy.size()); + int ind = ThreadLocalRandom.current().nextInt(clientsCopy.size()); return clientsCopy.get(ind); } diff --git a/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java b/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java index fd1442069..44b439790 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java @@ -25,11 +25,10 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.redisson.connection.ClientConnectionsEntry; - -import io.netty.util.internal.PlatformDependent; import org.redisson.misc.URIBuilder; /** @@ -66,7 +65,7 @@ public class WeightedRoundRobinBalancer implements LoadBalancer { private final AtomicInteger index = new AtomicInteger(-1); - private final Map weights = PlatformDependent.newConcurrentHashMap(); + private final Map weights = new ConcurrentHashMap<>(); private final int defaultWeight; @@ -93,7 +92,7 @@ public class WeightedRoundRobinBalancer implements LoadBalancer { } private Set getAddresses(List clients) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (ClientConnectionsEntry entry : clients) { if (entry.isFreezed()) { continue; @@ -108,14 +107,14 @@ public class WeightedRoundRobinBalancer implements LoadBalancer { Set addresses = getAddresses(clients); if (!addresses.equals(weights.keySet())) { - Set newAddresses = new HashSet(addresses); + Set newAddresses = new HashSet<>(addresses); newAddresses.removeAll(weights.keySet()); for (InetSocketAddress addr : newAddresses) { weights.put(addr, new WeightEntry(defaultWeight)); } } - Map weightsCopy = new HashMap(weights); + Map weightsCopy = new HashMap<>(weights); synchronized (this) { @@ -158,7 +157,7 @@ public class WeightedRoundRobinBalancer implements LoadBalancer { } private List findClients(List clients, Map weightsCopy) { - List clientsCopy = new ArrayList(); + List clientsCopy = new ArrayList<>(); for (InetSocketAddress addr : weightsCopy.keySet()) { for (ClientConnectionsEntry clientConnectionsEntry : clients) { if (clientConnectionsEntry.getClient().getAddr().equals(addr) diff --git a/redisson/src/main/java/org/redisson/eviction/EvictionScheduler.java b/redisson/src/main/java/org/redisson/eviction/EvictionScheduler.java index 8bf9f1e51..8e52c4885 100644 --- a/redisson/src/main/java/org/redisson/eviction/EvictionScheduler.java +++ b/redisson/src/main/java/org/redisson/eviction/EvictionScheduler.java @@ -15,12 +15,11 @@ */ package org.redisson.eviction; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.redisson.command.CommandAsyncExecutor; -import io.netty.util.internal.PlatformDependent; - /** * Eviction scheduler. * Deletes expired entries in time interval between 5 seconds to 2 hours. @@ -32,7 +31,7 @@ import io.netty.util.internal.PlatformDependent; */ public class EvictionScheduler { - private final ConcurrentMap tasks = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap tasks = new ConcurrentHashMap<>(); private final CommandAsyncExecutor executor; public EvictionScheduler(CommandAsyncExecutor executor) { diff --git a/redisson/src/main/java/org/redisson/executor/ScheduledTasksService.java b/redisson/src/main/java/org/redisson/executor/ScheduledTasksService.java index cf18fdee4..52f9b7180 100644 --- a/redisson/src/main/java/org/redisson/executor/ScheduledTasksService.java +++ b/redisson/src/main/java/org/redisson/executor/ScheduledTasksService.java @@ -17,6 +17,7 @@ package org.redisson.executor; import java.util.Arrays; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; import org.redisson.RedissonExecutorService; import org.redisson.api.RFuture; @@ -33,8 +34,6 @@ import org.redisson.remote.RemoteServiceRequest; import org.redisson.remote.RequestId; import org.redisson.remote.ResponseEntry; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -136,8 +135,7 @@ public class ScheduledTasksService extends TasksService { protected RequestId generateRequestId() { if (requestId == null) { byte[] id = new byte[17]; - // TODO JDK UPGRADE replace to native ThreadLocalRandom - PlatformDependent.threadLocalRandom().nextBytes(id); + ThreadLocalRandom.current().nextBytes(id); id[0] = 1; return new RequestId(id); } diff --git a/redisson/src/main/java/org/redisson/jcache/JCache.java b/redisson/src/main/java/org/redisson/jcache/JCache.java index 0dae5b9c6..60b96b9ea 100644 --- a/redisson/src/main/java/org/redisson/jcache/JCache.java +++ b/redisson/src/main/java/org/redisson/jcache/JCache.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ThreadLocalRandom; import javax.cache.Cache; import javax.cache.CacheException; @@ -73,7 +74,6 @@ import org.redisson.jcache.configuration.JCacheConfiguration; import org.redisson.misc.Hash; import io.netty.buffer.ByteBuf; -import io.netty.util.internal.PlatformDependent; /** * JCache implementation @@ -241,7 +241,7 @@ public class JCache extends RedissonObject implements Cache { List result = new ArrayList(3); result.add(value); - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); Long syncs = evalWrite(getName(), codec, RedisCommands.EVAL_LONG, "if ARGV[1] == '0' then " + "redis.call('hdel', KEYS[1], ARGV[3]); " @@ -406,7 +406,7 @@ public class JCache extends RedissonObject implements Cache { } private boolean putValueLocked(K key, Object value) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); if (containsKey(key)) { Long updateTimeout = getUpdateTimeout(); @@ -480,7 +480,7 @@ public class JCache extends RedissonObject implements Cache { private boolean putValue(K key, Object value) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); Long creationTimeout = getCreationTimeout(); Long updateTimeout = getUpdateTimeout(); @@ -949,7 +949,7 @@ public class JCache extends RedissonObject implements Cache { } private List getAndPutValueLocked(K key, V value) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); if (containsKey(key)) { Long updateTimeout = getUpdateTimeout(); List result = evalWrite(getName(), codec, RedisCommands.EVAL_LIST, @@ -1021,7 +1021,7 @@ public class JCache extends RedissonObject implements Cache { Long updateTimeout = getUpdateTimeout(); - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); List result = evalWrite(getName(), codec, RedisCommands.EVAL_LIST, "local value = redis.call('hget', KEYS[1], ARGV[4]);" @@ -1351,7 +1351,7 @@ public class JCache extends RedissonObject implements Cache { } private boolean removeValue(K key) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); List res = evalWrite(getName(), codec, RedisCommands.EVAL_LIST, "local value = redis.call('hexists', KEYS[1], ARGV[2]); " @@ -1588,7 +1588,7 @@ public class JCache extends RedissonObject implements Cache { } private V getAndRemoveValue(K key) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); List result = evalWrite(getName(), codec, RedisCommands.EVAL_MAP_VALUE_LIST, "local value = redis.call('hget', KEYS[1], ARGV[2]); " + "if value == false then " @@ -1704,7 +1704,7 @@ public class JCache extends RedissonObject implements Cache { if (res == 1) { Long updateTimeout = getUpdateTimeout(); - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); Long syncs = evalWrite(getName(), codec, RedisCommands.EVAL_LONG, "if ARGV[2] == '0' then " + "redis.call('hdel', KEYS[1], ARGV[4]); " @@ -1745,7 +1745,7 @@ public class JCache extends RedissonObject implements Cache { return -1; } - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); List result = evalWrite(getName(), codec, RedisCommands.EVAL_LIST, "if ARGV[1] == '0' then " + "redis.call('hdel', KEYS[1], ARGV[4]); " @@ -1904,7 +1904,7 @@ public class JCache extends RedissonObject implements Cache { private boolean replaceValueLocked(K key, V value) { if (containsKey(key)) { - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); Long updateTimeout = getUpdateTimeout(); Long syncs = evalWrite(getName(), codec, RedisCommands.EVAL_LONG, "if ARGV[1] == '0' then " @@ -2045,7 +2045,7 @@ public class JCache extends RedissonObject implements Cache { if (oldValue != null) { Long updateTimeout = getUpdateTimeout(); - double syncId = PlatformDependent.threadLocalRandom().nextDouble(); + double syncId = ThreadLocalRandom.current().nextDouble(); Long syncs = evalWrite(getName(), codec, RedisCommands.EVAL_LONG, "if ARGV[1] == '0' then " + "local value = redis.call('hget', KEYS[1], ARGV[3]); " diff --git a/redisson/src/main/java/org/redisson/jcache/JCacheEventCodec.java b/redisson/src/main/java/org/redisson/jcache/JCacheEventCodec.java index 06644c0c0..afe50423d 100644 --- a/redisson/src/main/java/org/redisson/jcache/JCacheEventCodec.java +++ b/redisson/src/main/java/org/redisson/jcache/JCacheEventCodec.java @@ -16,7 +16,6 @@ package org.redisson.jcache; import java.io.IOException; -import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; @@ -63,7 +62,7 @@ public class JCacheEventCodec implements Codec { result.add(value); if (sync) { - double syncId = buf.order(ByteOrder.LITTLE_ENDIAN).readDouble(); + double syncId = buf.readDoubleLE(); result.add(syncId); } diff --git a/redisson/src/main/java/org/redisson/liveobject/resolver/LongGenerator.java b/redisson/src/main/java/org/redisson/liveobject/resolver/LongGenerator.java index 0246e542e..322ae316d 100644 --- a/redisson/src/main/java/org/redisson/liveobject/resolver/LongGenerator.java +++ b/redisson/src/main/java/org/redisson/liveobject/resolver/LongGenerator.java @@ -22,13 +22,12 @@ import org.redisson.api.annotation.RId; * * @author Rui Gu (https://github.com/jackygurui) */ -public class LongGenerator implements RIdResolver { +public class LongGenerator implements RIdResolver { - public static final LongGenerator INSTANCE - = new LongGenerator(); + public static final LongGenerator INSTANCE = new LongGenerator(); @Override - public Long resolve(Class value, RId id, String idFieldName, RedissonClient redisson) { + public Long resolve(Class value, RId id, String idFieldName, RedissonClient redisson) { return redisson.getAtomicLong(this.getClass().getCanonicalName() + "{" + value.getCanonicalName() + "}:" + idFieldName) .incrementAndGet(); diff --git a/redisson/src/main/java/org/redisson/liveobject/resolver/RIdResolver.java b/redisson/src/main/java/org/redisson/liveobject/resolver/RIdResolver.java index 281f3ae26..58892a0b8 100644 --- a/redisson/src/main/java/org/redisson/liveobject/resolver/RIdResolver.java +++ b/redisson/src/main/java/org/redisson/liveobject/resolver/RIdResolver.java @@ -21,10 +21,9 @@ import org.redisson.api.annotation.RId; /** * * @author Rui Gu (https://github.com/jackygurui) - * @param RId annotation to resolve * @param Value type */ -public interface RIdResolver extends Resolver, A, V>{ +public interface RIdResolver { /** * RLiveObjectService instantiate the class and invokes this method to get @@ -32,10 +31,10 @@ public interface RIdResolver extends Resolver, A, V>{ * * @param cls the class of the LiveObject. * @param annotation the RId annotation used in the class. + * @param idFieldName field id * @param redisson instance * @return resolved RId field value. */ - @Override - V resolve(Class cls, A annotation, String idFieldName, RedissonClient redisson); + V resolve(Class cls, RId annotation, String idFieldName, RedissonClient redisson); } diff --git a/redisson/src/main/java/org/redisson/liveobject/resolver/RequiredIdResolver.java b/redisson/src/main/java/org/redisson/liveobject/resolver/RequiredIdResolver.java index e4aef15f8..9e4dbaed1 100644 --- a/redisson/src/main/java/org/redisson/liveobject/resolver/RequiredIdResolver.java +++ b/redisson/src/main/java/org/redisson/liveobject/resolver/RequiredIdResolver.java @@ -23,12 +23,12 @@ import org.redisson.api.annotation.RId; * @author Nikita Koksharov * */ -public class RequiredIdResolver implements RIdResolver { +public class RequiredIdResolver implements RIdResolver { public static final RequiredIdResolver INSTANCE = new RequiredIdResolver(); @Override - public Object resolve(Class cls, RId annotation, String idFieldName, RedissonClient redisson) { + public Object resolve(Class cls, RId annotation, String idFieldName, RedissonClient redisson) { throw new IllegalArgumentException("id value not defined for instance of " + cls); } diff --git a/redisson/src/main/java/org/redisson/liveobject/resolver/Resolver.java b/redisson/src/main/java/org/redisson/liveobject/resolver/Resolver.java deleted file mode 100644 index 79c5cb109..000000000 --- a/redisson/src/main/java/org/redisson/liveobject/resolver/Resolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2013-2019 Nikita Koksharov - * - * 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.redisson.liveobject.resolver; - -import java.lang.annotation.Annotation; - -import org.redisson.api.RedissonClient; - -/** - * A resolver is used to provide value based on contextual parameters - * - * @author Rui Gu (https://github.com/jackygurui) - * @param Field instance type - * @param Annotation to resolve - * @param Value type - */ -public interface Resolver { - - /** - * Used to provide a value instance based on contextual parameters. - * - * Actual behavior may vary depending on implementation - * - * @param value object - * @param annotation object - * @param idFieldName name of field - * @param redisson instance - * @return resolved value - */ - V resolve(T value, A annotation, String idFieldName, RedissonClient redisson); - -} diff --git a/redisson/src/main/java/org/redisson/liveobject/resolver/UUIDGenerator.java b/redisson/src/main/java/org/redisson/liveobject/resolver/UUIDGenerator.java index f2110257c..a3b94c7e8 100644 --- a/redisson/src/main/java/org/redisson/liveobject/resolver/UUIDGenerator.java +++ b/redisson/src/main/java/org/redisson/liveobject/resolver/UUIDGenerator.java @@ -24,7 +24,7 @@ import org.redisson.api.annotation.RId; * * @author Rui Gu (https://github.com/jackygurui) */ -public class UUIDGenerator implements RIdResolver{ +public class UUIDGenerator implements RIdResolver{ public static final UUIDGenerator INSTANCE = new UUIDGenerator(); diff --git a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java index 42244cee7..a68355e46 100644 --- a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java +++ b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribe.java @@ -15,6 +15,7 @@ */ package org.redisson.pubsub; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicReference; @@ -29,8 +30,6 @@ import org.redisson.misc.RPromise; import org.redisson.misc.RedissonPromise; import org.redisson.misc.TransferListener; -import io.netty.util.internal.PlatformDependent; - /** * * @author Nikita Koksharov @@ -38,10 +37,10 @@ import io.netty.util.internal.PlatformDependent; */ abstract class PublishSubscribe> { - private final ConcurrentMap entries = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap entries = new ConcurrentHashMap<>(); - public void unsubscribe(final E entry, final String entryName, final String channelName, final PublishSubscribeService subscribeService) { - final AsyncSemaphore semaphore = subscribeService.getSemaphore(new ChannelName(channelName)); + public void unsubscribe(E entry, String entryName, String channelName, PublishSubscribeService subscribeService) { + AsyncSemaphore semaphore = subscribeService.getSemaphore(new ChannelName(channelName)); semaphore.acquire(new Runnable() { @Override public void run() { @@ -64,10 +63,10 @@ abstract class PublishSubscribe> { return entries.get(entryName); } - public RFuture subscribe(final String entryName, final String channelName, final PublishSubscribeService subscribeService) { - final AtomicReference listenerHolder = new AtomicReference(); - final AsyncSemaphore semaphore = subscribeService.getSemaphore(new ChannelName(channelName)); - final RPromise newPromise = new RedissonPromise() { + public RFuture subscribe(String entryName, String channelName, PublishSubscribeService subscribeService) { + AtomicReference listenerHolder = new AtomicReference(); + AsyncSemaphore semaphore = subscribeService.getSemaphore(new ChannelName(channelName)); + RPromise newPromise = new RedissonPromise() { @Override public boolean cancel(boolean mayInterruptIfRunning) { return semaphore.remove(listenerHolder.get()); @@ -111,7 +110,7 @@ abstract class PublishSubscribe> { protected abstract void onMessage(E value, Long message); - private RedisPubSubListener createListener(final String channelName, final E value) { + private RedisPubSubListener createListener(String channelName, E value) { RedisPubSubListener listener = new BaseRedisPubSubListener() { @Override diff --git a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java index 39d33057f..16e090ae9 100644 --- a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java +++ b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java @@ -17,6 +17,7 @@ package org.redisson.pubsub; import java.util.Collection; import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -41,7 +42,6 @@ import org.slf4j.LoggerFactory; import io.netty.util.Timeout; import io.netty.util.TimerTask; -import io.netty.util.internal.PlatformDependent; /** * @@ -60,7 +60,7 @@ public class PublishSubscribeService { private final AsyncSemaphore freePubSubLock = new AsyncSemaphore(1); - protected final ConcurrentMap name2PubSubConnection = PlatformDependent.newConcurrentHashMap(); + protected final ConcurrentMap name2PubSubConnection = new ConcurrentHashMap<>(); protected final Queue freePubSubConnections = new ConcurrentLinkedQueue(); diff --git a/redisson/src/main/java/org/redisson/transaction/BaseTransactionalMap.java b/redisson/src/main/java/org/redisson/transaction/BaseTransactionalMap.java index df94c3683..397129438 100644 --- a/redisson/src/main/java/org/redisson/transaction/BaseTransactionalMap.java +++ b/redisson/src/main/java/org/redisson/transaction/BaseTransactionalMap.java @@ -641,7 +641,7 @@ public class BaseTransactionalMap { protected RFuture> getAllOperationAsync(Set keys) { RPromise> result = new RedissonPromise<>(); - Set keysToLoad = new HashSet(keys); + Set keysToLoad = new HashSet(); Map map = new HashMap(); for (K key : keys) { HashValue keyHash = toKeyHash(key); @@ -656,6 +656,10 @@ public class BaseTransactionalMap { } } + if (keysToLoad.isEmpty()) { + return RedissonPromise.newSucceededFuture(map); + } + RFuture> future = ((RedissonMap) this.map).getAllOperationAsync(keysToLoad); future.onComplete((res, e) -> { if (e != null) {