|
|
|
@ -15,10 +15,6 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
import org.redisson.api.RPriorityDeque;
|
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
@ -28,6 +24,12 @@ import org.redisson.client.protocol.RedisCommands;
|
|
|
|
|
import org.redisson.client.protocol.decoder.ListFirstObjectDecoder;
|
|
|
|
|
import org.redisson.command.CommandExecutor;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Distributed and concurrent implementation of {@link java.util.Queue}
|
|
|
|
|
*
|
|
|
|
@ -48,26 +50,32 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
super(codec, commandExecutor, name, redisson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int addFirstIfExists(V... elements) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int addLastIfExists(V... elements) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> addFirstIfExistsAsync(V... elements) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> addLastIfExistsAsync(V... elements) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Void> addFirstAsync(V e) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Void> addLastAsync(V e) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
@ -118,7 +126,7 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> getLastAsync() {
|
|
|
|
|
return commandExecutor.readAsync(getName(), codec, LRANGE_SINGLE, getName(), -1, -1);
|
|
|
|
|
}
|
|
|
|
@ -150,7 +158,7 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> peekFirstAsync() {
|
|
|
|
|
return getAsync(0);
|
|
|
|
|
}
|
|
|
|
@ -179,7 +187,7 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RFuture<V> pollLastAsync() {
|
|
|
|
|
return pollAsync(RedisCommands.RPOP, getName());
|
|
|
|
|
return wrapLockedAsync(RedisCommands.RPOP, getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -187,7 +195,7 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
return get(pollLastAsync());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> popAsync() {
|
|
|
|
|
return pollAsync();
|
|
|
|
|
}
|
|
|
|
@ -205,8 +213,15 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
public RFuture<Void> pushAsync(V e) {
|
|
|
|
|
throw new UnsupportedOperationException("use add or put method");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> removeAsync(Object o, int count) {
|
|
|
|
|
return wrapLockedAsync(() -> {
|
|
|
|
|
return super.removeAsync(o, count);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> removeFirstOccurrenceAsync(Object o) {
|
|
|
|
|
return removeAsync(o, 1);
|
|
|
|
|
}
|
|
|
|
@ -216,12 +231,12 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
return remove(o, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> removeFirstAsync() {
|
|
|
|
|
return pollAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> removeLastAsync() {
|
|
|
|
|
return pollLastAsync();
|
|
|
|
|
}
|
|
|
|
@ -235,7 +250,7 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> removeLastOccurrenceAsync(Object o) {
|
|
|
|
|
return removeAsync(o, -1);
|
|
|
|
|
}
|
|
|
|
@ -250,4 +265,36 @@ public class RedissonPriorityDeque<V> extends RedissonPriorityQueue<V> implement
|
|
|
|
|
return toStream(descendingIterator());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<List<V>> pollFirstAsync(int limit) {
|
|
|
|
|
return pollAsync(limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<V> pollFirst(int limit) {
|
|
|
|
|
return poll(limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<V> pollLast(int limit) {
|
|
|
|
|
return get(pollLastAsync(limit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<List<V>> pollLastAsync(int limit) {
|
|
|
|
|
return wrapLockedAsync(() -> {
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_LIST,
|
|
|
|
|
"local result = {};"
|
|
|
|
|
+ "for i = 1, ARGV[1], 1 do " +
|
|
|
|
|
"local value = redis.call('rpop', KEYS[1]);" +
|
|
|
|
|
"if value ~= false then " +
|
|
|
|
|
"table.insert(result, value);" +
|
|
|
|
|
"else " +
|
|
|
|
|
"return result;" +
|
|
|
|
|
"end;" +
|
|
|
|
|
"end; " +
|
|
|
|
|
"return result;",
|
|
|
|
|
Collections.singletonList(getName()), limit);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|