Sentinel info decode fixed

pull/282/head
Nikita 9 years ago
parent 90c77f9d1c
commit 557c2e6e31

@ -100,7 +100,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
CommandData<Object, Object> cmd = (CommandData<Object, Object>)data;
try {
// if (state().getSize() > 0) {
// decodeMulti(in, cmd, null, ctx.channel(), currentDecoder, state().getSize(), state().getRespParts());
// List<Object> respParts = new ArrayList<Object>();
// respParts.addAll(state().getRespParts());
// decodeMulti(in, cmd, null, ctx.channel(), currentDecoder, state().getSize(), respParts);
// } else {
decode(in, cmd, null, ctx.channel(), currentDecoder);
// }
@ -189,10 +191,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
handleResult(data, parts, result, false, channel);
} else if (code == '*') {
long size = readLong(in);
// state().setSize(size);
// state().setSizeOnce(size);
List<Object> respParts = new ArrayList<Object>();
// state().setRespParts(respParts);
decodeMulti(in, data, parts, channel, currentDecoder, size, respParts);
} else {
@ -214,10 +215,11 @@ public class CommandDecoder extends ReplayingDecoder<State> {
Object result = decoder.decode(respParts, state());
// store current message index
checkpoint();
if (result instanceof Message) {
// store current message index
checkpoint();
handleMultiResult(data, null, channel, result);
// has next messages?
if (in.writerIndex() > in.readerIndex()) {
@ -225,6 +227,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
}
} else {
handleMultiResult(data, parts, channel, result);
// if (parts != null && !decoder.isApplicable(parts.size(), state())) {
// state().setRespParts(parts);
// }
}
}

@ -29,7 +29,10 @@ public class State {
super();
}
public void setSize(long size) {
public void setSizeOnce(long size) {
if (this.size != 0) {
return;
}
this.size = size;
}
public long getSize() {

@ -148,6 +148,11 @@ public class RedisCommand<R> {
this(name, null, null, reponseDecoder, objectParamIndex);
}
public RedisCommand(String name, String subName, MultiDecoder<R> replayMultiDecoder, ValueType outParamType) {
this(name, subName, replayMultiDecoder, -1);
this.outParamType = outParamType;
}
public RedisCommand(String name, MultiDecoder<R> replayMultiDecoder, ValueType outParamType) {
this(name, replayMultiDecoder, -1);
this.outParamType = outParamType;

@ -29,11 +29,13 @@ import org.redisson.client.protocol.convertor.KeyValueConvertor;
import org.redisson.client.protocol.convertor.TrueReplayConvertor;
import org.redisson.client.protocol.convertor.VoidReplayConvertor;
import org.redisson.client.protocol.decoder.KeyValueObjectDecoder;
import org.redisson.client.protocol.decoder.ListResultReplayDecoder;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.client.protocol.decoder.ListScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.client.protocol.decoder.MapScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.NestedMultiDecoder;
import org.redisson.client.protocol.decoder.NestedMultiDecoder2;
import org.redisson.client.protocol.decoder.ObjectFirstResultReplayDecoder;
import org.redisson.client.protocol.decoder.ObjectListReplayDecoder;
import org.redisson.client.protocol.decoder.ObjectMapReplayDecoder;
@ -43,7 +45,6 @@ import org.redisson.client.protocol.decoder.ScoredSortedSetScanReplayDecoder;
import org.redisson.client.protocol.decoder.StringDataDecoder;
import org.redisson.client.protocol.decoder.StringListReplayDecoder;
import org.redisson.client.protocol.decoder.StringMapDataDecoder;
import org.redisson.client.protocol.decoder.StringMapReplayDecoder;
import org.redisson.client.protocol.decoder.StringReplayDecoder;
import org.redisson.client.protocol.pubsub.PubSubStatusDecoder;
@ -183,7 +184,9 @@ public interface RedisCommands {
RedisStrictCommand<Map<String, String>> CLUSTER_INFO = new RedisStrictCommand<Map<String, String>>("CLUSTER", "INFO", new StringMapDataDecoder());
RedisStrictCommand<List<String>> SENTINEL_GET_MASTER_ADDR_BY_NAME = new RedisStrictCommand<List<String>>("SENTINEL", "GET-MASTER-ADDR-BY-NAME", new StringListReplayDecoder());
RedisStrictCommand<List<Map<String, String>>> SENTINEL_SLAVES = new RedisStrictCommand<List<Map<String, String>>>("SENTINEL", "SLAVES", new StringMapReplayDecoder());
RedisCommand<List<Map<String, String>>> SENTINEL_SLAVES = new RedisCommand<List<Map<String, String>>>("SENTINEL", "SLAVES",
new NestedMultiDecoder2(new ObjectMapReplayDecoder(), new ListResultReplayDecoder()), ValueType.OBJECT
);
RedisStrictCommand<String> INFO_REPLICATION = new RedisStrictCommand<String>("INFO", "replication", new StringDataDecoder());
}

@ -15,9 +15,7 @@
*/
package org.redisson.client.protocol.decoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -26,7 +24,7 @@ import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
public class StringMapReplayDecoder implements MultiDecoder<List<Map<String, String>>> {
public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Object>>> {
@Override
public Object decode(ByteBuf buf, State state) {
@ -34,26 +32,10 @@ public class StringMapReplayDecoder implements MultiDecoder<List<Map<String, Str
}
@Override
public List<Map<String, String>> decode(List<Object> parts, State state) {
// TODO refactor
if (!parts.isEmpty()) {
if (parts.get(0) instanceof List) {
List<Map<String, String>> result = new ArrayList<Map<String, String>>(parts.size());
for (Object object : parts) {
List<Map<String, String>> list = (List<Map<String, String>>) object;
result.addAll(list);
}
return result;
}
}
Map<String, String> result = new HashMap<String, String>(parts.size()/2);
for (int i = 0; i < parts.size(); i++) {
if (i % 2 != 0) {
result.put(parts.get(i-1).toString(), parts.get(i).toString());
}
}
return Collections.singletonList(result);
@SuppressWarnings("unchecked")
public List<Map<Object, Object>> decode(List<Object> parts, State state) {
Map<Object, Object>[] res = parts.toArray(new Map[parts.size()]);
return Arrays.asList(res);
}
@Override

@ -0,0 +1,79 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* 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.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
public class NestedMultiDecoder2<T> implements MultiDecoder<Object> {
private final MultiDecoder<Object> firstDecoder;
private final MultiDecoder<Object> secondDecoder;
public NestedMultiDecoder2(MultiDecoder<Object> firstDecoder, MultiDecoder<Object> secondDecoder) {
this.firstDecoder = firstDecoder;
this.secondDecoder = secondDecoder;
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return firstDecoder.decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
if (paramNum == 0) {
setCounter(state, 0);
}
return firstDecoder.isApplicable(paramNum, state);
}
private Integer getCounter(State state) {
Integer value = state.getDecoderState();
if (value == null) {
return 0;
}
return value;
}
private void setCounter(State state, Integer value) {
state.setDecoderState(value);
}
@Override
public Object decode(List<Object> parts, State state) {
if (getCounter(state) == 2) {
setCounter(state, 0);
}
int counter = getCounter(state);
counter++;
setCounter(state, counter);
MultiDecoder<?> decoder = null;
if (counter == 1) {
decoder = firstDecoder;
}
if (counter == 2) {
decoder = secondDecoder;
}
return decoder.decode(parts, state);
}
}

@ -30,6 +30,7 @@ import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.pubsub.PubSubType;
@ -84,7 +85,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
currentMaster.set(masterHost);
log.info("master: {} added", masterHost);
List<Map<String, String>> sentinelSlaves = connection.sync(RedisCommands.SENTINEL_SLAVES, cfg.getMasterName());
List<Map<String, String>> sentinelSlaves = connection.sync(StringCodec.INSTANCE, RedisCommands.SENTINEL_SLAVES, cfg.getMasterName());
for (Map<String, String> map : sentinelSlaves) {
if (map.isEmpty()) {
continue;

Loading…
Cancel
Save