refactoring

pull/2637/head
Nikita Koksharov 5 years ago
parent 539b87b88c
commit 4a48668cc2

@ -26,7 +26,6 @@ import org.redisson.misc.RedissonPromise;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.*;
@ -41,20 +40,6 @@ import java.util.function.Supplier;
*/
public class RedissonPriorityQueue<V> extends RedissonList<V> implements RPriorityQueue<V> {
private static class NaturalComparator<V> implements Comparator<V>, Serializable {
private static final long serialVersionUID = 7207038068494060240L;
static final NaturalComparator NATURAL_ORDER = new NaturalComparator();
public int compare(V c1, V c2) {
Comparable<Object> c1co = (Comparable<Object>) c1;
Comparable<Object> c2co = (Comparable<Object>) c2;
return c1co.compareTo(c2co);
}
}
public static class BinarySearchResult<V> {
private V value;
@ -82,7 +67,7 @@ public class RedissonPriorityQueue<V> extends RedissonList<V> implements RPriori
}
private Comparator<? super V> comparator = NaturalComparator.NATURAL_ORDER;
private Comparator comparator = Comparator.naturalOrder();
CommandExecutor commandExecutor;

@ -51,20 +51,6 @@ import io.netty.buffer.ByteBuf;
*/
public class RedissonSortedSet<V> extends RedissonObject implements RSortedSet<V> {
private static class NaturalComparator<V> implements Comparator<V>, Serializable {
private static final long serialVersionUID = 7207038068494060240L;
static final NaturalComparator NATURAL_ORDER = new NaturalComparator();
public int compare(V c1, V c2) {
Comparable<Object> c1co = (Comparable<Object>) c1;
Comparable<Object> c2co = (Comparable<Object>) c2;
return c1co.compareTo(c2co);
}
}
public static class BinarySearchResult<V> {
private V value;
@ -92,7 +78,7 @@ public class RedissonSortedSet<V> extends RedissonObject implements RSortedSet<V
}
private Comparator<? super V> comparator = NaturalComparator.NATURAL_ORDER;
private Comparator comparator = Comparator.naturalOrder();
CommandExecutor commandExecutor;

@ -115,13 +115,13 @@ public abstract class LocalCacheListener {
}
if (options.getEvictionPolicy() == EvictionPolicy.NONE) {
return new NoneCacheMap<CacheKey, CacheValue>(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
return new NoneCacheMap<>(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
}
if (options.getEvictionPolicy() == EvictionPolicy.LRU) {
return new LRUCacheMap<CacheKey, CacheValue>(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
return new LRUCacheMap<>(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
}
if (options.getEvictionPolicy() == EvictionPolicy.LFU) {
return new LFUCacheMap<CacheKey, CacheValue>(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
return new LFUCacheMap<>(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
}
if (options.getEvictionPolicy() == EvictionPolicy.SOFT) {
return ReferenceCacheMap.soft(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis());
@ -255,7 +255,6 @@ public abstract class LocalCacheListener {
}
RSemaphore semaphore = getClearSemaphore(id);
semaphore.expireAsync(60, TimeUnit.SECONDS);
semaphore.tryAcquireAsync(res.intValue(), 50, TimeUnit.SECONDS).onComplete((r, ex) -> {
if (ex != null) {
result.tryFailure(ex);
@ -350,6 +349,7 @@ public abstract class LocalCacheListener {
private RSemaphore getClearSemaphore(byte[] requestId) {
String id = ByteBufUtil.hexDump(requestId);
RSemaphore semaphore = new RedissonSemaphore(commandExecutor, name + ":clear:" + id);
semaphore.expireAsync(60, TimeUnit.SECONDS);
return semaphore;
}

@ -2,6 +2,7 @@ package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
@ -14,6 +15,37 @@ import org.redisson.api.RPriorityQueue;
public class RedissonPriorityQueueTest extends BaseTest {
public static class Entry implements Comparable<Entry>, Serializable {
private String key;
private Integer value;
public Entry(String key, Integer value) {
this.key = key;
this.value = value;
}
@Override
public int compareTo(Entry o) {
return key.compareTo(o.key);
}
}
@Test
public void testComparable() {
RPriorityQueue<Entry> queue = redisson.getPriorityQueue("anyQueue");
queue.add(new Entry("b", 1));
queue.add(new Entry("c", 1));
queue.add(new Entry("a", 1));
// Entry [a:1]
Entry e = queue.poll();
assertThat(e.key).isEqualTo("a");
Entry e1 = queue.poll();
assertThat(e1.key).isEqualTo("b");
}
@Test
public void testPollLastAndOfferFirstTo() {
RPriorityQueue<Integer> queue1 = redisson.getPriorityQueue("deque1");

Loading…
Cancel
Save