提交 31ed9869 编写于 作者: N Nikita Koksharov

refactoring

上级 0041487e
......@@ -15,18 +15,17 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.cluster.ClusterNodeInfo;
import org.redisson.cluster.ClusterSlotRange;
import org.redisson.cluster.ClusterNodeInfo.Flag;
import org.redisson.cluster.ClusterSlotRange;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
......@@ -84,7 +83,7 @@ public class ClusterNodesDecoder implements Decoder<List<ClusterNodeInfo>> {
if (params.length > 8) {
for (int i = 0; i < params.length - 8; i++) {
String slots = params[i + 8];
if (slots.indexOf("-<-") != -1 || slots.indexOf("->-") != -1) {
if (slots.contains("-<-") || slots.contains("->-")) {
continue;
}
......
......@@ -22,6 +22,8 @@ import java.util.Set;
import org.redisson.misc.RedisURI;
import static org.redisson.connection.MasterSlaveConnectionManager.MAX_SLOT;
/**
*
* @author Nikita Koksharov
......@@ -39,7 +41,7 @@ public class ClusterPartition {
private final Set<RedisURI> slaveAddresses = new HashSet<>();
private final Set<RedisURI> failedSlaves = new HashSet<>();
private final BitSet slots = new BitSet();
private final BitSet slots = new BitSet(MAX_SLOT);
private final Set<ClusterSlotRange> slotRanges = new HashSet<ClusterSlotRange>();
private ClusterPartition parent;
......@@ -86,17 +88,13 @@ public class ClusterPartition {
public void addSlotRanges(Set<ClusterSlotRange> ranges) {
for (ClusterSlotRange clusterSlotRange : ranges) {
for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) {
slots.set(i);
}
slots.set(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1);
}
slotRanges.addAll(ranges);
}
public void removeSlotRanges(Set<ClusterSlotRange> ranges) {
for (ClusterSlotRange clusterSlotRange : ranges) {
for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) {
slots.clear(i);
}
slots.clear(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1);
}
slotRanges.removeAll(ranges);
}
......@@ -105,7 +103,7 @@ public class ClusterPartition {
}
public Iterable<Integer> getSlots() {
return (Iterable<Integer>) slots.stream()::iterator;
return slots.stream()::iterator;
}
public BitSet slots() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册