refactoring

pull/1204/head
Nikita 7 years ago
parent 2e8145046d
commit 2d85018431

@ -92,7 +92,7 @@ public class CommandDecoder extends ReplayingDecoder<State> {
if (data == null) { if (data == null) {
while (in.writerIndex() > in.readerIndex()) { while (in.writerIndex() > in.readerIndex()) {
decode(in, null, null, ctx.channel()); decode(in, null, null, ctx.channel());
} }
} else if (data instanceof CommandData) { } else if (data instanceof CommandData) {
CommandData<Object, Object> cmd = (CommandData<Object, Object>)data; CommandData<Object, Object> cmd = (CommandData<Object, Object>)data;
@ -330,7 +330,7 @@ public class CommandDecoder extends ReplayingDecoder<State> {
if (parts.isEmpty()) { if (parts.isEmpty()) {
return null; return null;
} }
} }
return data.getCommand().getReplayMultiDecoder(); return data.getCommand().getReplayMultiDecoder();
} }
@ -342,8 +342,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
Decoder<Object> decoder = data.getCommand().getReplayDecoder(); Decoder<Object> decoder = data.getCommand().getReplayDecoder();
if (parts != null) { if (parts != null) {
MultiDecoder<Object> multiDecoder = data.getCommand().getReplayMultiDecoder(); MultiDecoder<Object> multiDecoder = data.getCommand().getReplayMultiDecoder();
if (multiDecoder.isApplicable(parts.size(), state())) { Decoder<Object> mDecoder = multiDecoder.getDecoder(parts.size(), state());
decoder = multiDecoder; if (mDecoder != null) {
decoder = mDecoder;
} }
} }
if (decoder == null) { if (decoder == null) {

@ -176,11 +176,11 @@ public class CommandPubSubDecoder extends CommandDecoder {
if (data == null && parts != null) { if (data == null && parts != null) {
if (parts.size() == 2 && "message".equals(parts.get(0))) { if (parts.size() == 2 && "message".equals(parts.get(0))) {
String channelName = (String) parts.get(1); String channelName = (String) parts.get(1);
return entries.get(channelName).getDecoder(); return entries.get(channelName).getDecoder().getDecoder(parts.size(), state());
} }
if (parts.size() == 3 && "pmessage".equals(parts.get(0))) { if (parts.size() == 3 && "pmessage".equals(parts.get(0))) {
String patternName = (String) parts.get(1); String patternName = (String) parts.get(1);
return entries.get(patternName).getDecoder(); return entries.get(patternName).getDecoder().getDecoder(parts.size(), state());
} }
} }
return super.selectDecoder(data, parts); return super.selectDecoder(data, parts);

@ -15,11 +15,8 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -34,17 +31,13 @@ public class FlatNestedMultiDecoder<T> extends NestedMultiDecoder {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return firstDecoder.decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
NestedDecoderState ds = getDecoder(state); NestedDecoderState ds = getDecoder(state);
if (paramNum == 0) { if (paramNum == 0) {
ds.resetDecoderIndex(); ds.resetDecoderIndex();
} }
return firstDecoder.isApplicable(paramNum, state);
return firstDecoder.getDecoder(paramNum, state);
} }
} }

@ -15,14 +15,12 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec; import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -31,8 +29,6 @@ import io.netty.buffer.ByteBuf;
*/ */
public class GeoDistanceDecoder implements MultiDecoder<List<Object>> { public class GeoDistanceDecoder implements MultiDecoder<List<Object>> {
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
private final Codec codec; private final Codec codec;
public GeoDistanceDecoder(Codec codec) { public GeoDistanceDecoder(Codec codec) {
@ -41,17 +37,11 @@ public class GeoDistanceDecoder implements MultiDecoder<List<Object>> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
if (pos.get() % 2 == 0) { if (paramNum % 2 == 0) {
return codec.getValueDecoder().decode(buf, state); return codec.getValueDecoder();
} }
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state); return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override
public boolean isApplicable(int paramNum, State state) {
pos.set(paramNum);
return true;
} }
@Override @Override

@ -15,7 +15,6 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -23,8 +22,7 @@ import java.util.Map;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec; import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -33,8 +31,6 @@ import io.netty.buffer.ByteBuf;
*/ */
public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> { public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> {
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
private final Codec codec; private final Codec codec;
public GeoDistanceMapDecoder(Codec codec) { public GeoDistanceMapDecoder(Codec codec) {
@ -43,17 +39,11 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
if (pos.get() % 2 == 0) { if (paramNum % 2 == 0) {
return codec.getValueDecoder().decode(buf, state); return codec.getValueDecoder();
} }
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state); return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override
public boolean isApplicable(int paramNum, State state) {
pos.set(paramNum);
return true;
} }
@Override @Override

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -31,8 +30,8 @@ import io.netty.buffer.ByteBuf;
public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> { public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
throw new UnsupportedOperationException(); return null;
} }
@Override @Override
@ -45,9 +44,4 @@ public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
return result; return result;
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
} }

@ -15,14 +15,12 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.api.GeoPosition; import org.redisson.api.GeoPosition;
import org.redisson.client.codec.DoubleCodec; import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -32,13 +30,8 @@ import io.netty.buffer.ByteBuf;
public class GeoPositionDecoder implements MultiDecoder<GeoPosition> { public class GeoPositionDecoder implements MultiDecoder<GeoPosition> {
@Override @Override
public Double decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return (Double) DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state); return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
} }
@Override @Override

@ -15,15 +15,13 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -39,13 +37,8 @@ public class GeoPositionMapDecoder implements MultiDecoder<Map<Object, Object>>
} }
@Override @Override
public Double decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
throw new UnsupportedOperationException(); return null;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
} }
@Override @Override

@ -15,9 +15,11 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
@ -30,10 +32,18 @@ import io.netty.util.CharsetUtil;
public class KeyValueObjectDecoder implements MultiDecoder<Object> { public class KeyValueObjectDecoder implements MultiDecoder<Object> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
String status = buf.toString(CharsetUtil.UTF_8); if (paramNum == 0) {
buf.skipBytes(1); return new Decoder<Object>() {
return status; @Override
public Object decode(ByteBuf buf, State state) throws IOException {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(1);
return status;
}
};
}
return null;
} }
@Override @Override
@ -44,9 +54,4 @@ public class KeyValueObjectDecoder implements MultiDecoder<Object> {
return new KeyValueMessage(parts.get(0), parts.get(1)); return new KeyValueMessage(parts.get(0), parts.get(1));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
} }

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -28,11 +27,6 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ListFirstObjectDecoder implements MultiDecoder<Object> { public class ListFirstObjectDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public Object decode(List<Object> parts, State state) { public Object decode(List<Object> parts, State state) {
if (!parts.isEmpty()) { if (!parts.isEmpty()) {
@ -42,8 +36,8 @@ public class ListFirstObjectDecoder implements MultiDecoder<Object> {
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -28,19 +27,14 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ListIteratorReplayDecoder implements MultiDecoder<ListIteratorResult<Object>> { public class ListIteratorReplayDecoder implements MultiDecoder<ListIteratorResult<Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public ListIteratorResult<Object> decode(List<Object> parts, State state) { public ListIteratorResult<Object> decode(List<Object> parts, State state) {
return new ListIteratorResult<Object>(parts.get(0), Long.valueOf(parts.get(1).toString())); return new ListIteratorResult<Object>(parts.get(0), Long.valueOf(parts.get(1).toString()));
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -15,12 +15,10 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -90,19 +88,16 @@ public class ListMultiDecoder<T> implements MultiDecoder<Object> {
this.decoders = decoders; this.decoders = decoders;
} }
public Object decode(ByteBuf buf, State state) throws IOException {
int index = getDecoder(state).getIndex();
return decoders[index].decode(buf, state);
}
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) { if (paramNum == 0) {
NestedDecoderState s = getDecoder(state); NestedDecoderState s = getDecoder(state);
s.incIndex(); s.incIndex();
s.resetPartsIndex(); s.resetPartsIndex();
} }
return true;
int index = getDecoder(state).getIndex();
return decoders[index].getDecoder(paramNum, state);
} }
@Override @Override

@ -19,10 +19,9 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -32,8 +31,8 @@ import io.netty.util.CharsetUtil;
public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Object>>> { public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Object>>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return buf.toString(CharsetUtil.UTF_8); return StringCodec.INSTANCE.getValueDecoder();
} }
@Override @Override
@ -43,9 +42,4 @@ public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Ob
return Arrays.asList(res); return Arrays.asList(res);
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -17,10 +17,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -30,8 +29,11 @@ import io.netty.util.CharsetUtil;
public class ListScanResultReplayDecoder implements MultiDecoder<ListScanResult<Object>> { public class ListScanResultReplayDecoder implements MultiDecoder<ListScanResult<Object>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8)); if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
} }
@Override @Override
@ -39,9 +41,4 @@ public class ListScanResultReplayDecoder implements MultiDecoder<ListScanResult<
return new ListScanResult<Object>((Long)parts.get(0), (List<Object>)parts.get(1)); return new ListScanResult<Object>((Long)parts.get(0), (List<Object>)parts.get(1));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
} }

@ -15,13 +15,11 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -31,13 +29,8 @@ import io.netty.buffer.ByteBuf;
public class LongMultiDecoder implements MultiDecoder<Object> { public class LongMultiDecoder implements MultiDecoder<Object> {
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return LongCodec.INSTANCE.getValueDecoder().decode(buf, state); return LongCodec.INSTANCE.getValueDecoder();
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
} }
@Override @Override

@ -15,13 +15,11 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -30,11 +28,6 @@ import io.netty.buffer.ByteBuf;
*/ */
public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheScanResult<Object, Object>> { public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheScanResult<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
throw new UnsupportedOperationException();
}
@Override @Override
public MapCacheScanResult<Object, Object> decode(List<Object> parts, State state) { public MapCacheScanResult<Object, Object> decode(List<Object> parts, State state) {
Long pos = (Long)parts.get(0); Long pos = (Long)parts.get(0);
@ -44,8 +37,8 @@ public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheSca
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -18,10 +18,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -31,8 +30,11 @@ import io.netty.util.CharsetUtil;
public class MapScanResultReplayDecoder implements MultiDecoder<MapScanResult<Object, Object>> { public class MapScanResultReplayDecoder implements MultiDecoder<MapScanResult<Object, Object>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8)); if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
} }
@Override @Override
@ -40,9 +42,4 @@ public class MapScanResultReplayDecoder implements MultiDecoder<MapScanResult<Ob
return new MapScanResult<Object, Object>((Long)parts.get(0), (Map<Object, Object>)parts.get(1)); return new MapScanResult<Object, Object>((Long)parts.get(0), (Map<Object, Object>)parts.get(1));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
} }

@ -26,9 +26,9 @@ import org.redisson.client.protocol.Decoder;
* *
* @param <T> type * @param <T> type
*/ */
public interface MultiDecoder<T> extends Decoder<Object> { public interface MultiDecoder<T> {
boolean isApplicable(int paramNum, State state); Decoder<Object> getDecoder(int paramNum, State state);
T decode(List<Object> parts, State state); T decode(List<Object> parts, State state);

@ -15,12 +15,10 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -102,22 +100,7 @@ public class NestedMultiDecoder<T> implements MultiDecoder<Object> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
NestedDecoderState ds = getDecoder(state);
MultiDecoder<?> decoder = null;
if (ds.getFlipDecoderIndex() == 2) {
decoder = firstDecoder;
}
if (ds.getFlipDecoderIndex() == 1) {
decoder = secondDecoder;
}
return decoder.decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
NestedDecoderState ds = getDecoder(state); NestedDecoderState ds = getDecoder(state);
if (paramNum == 0) { if (paramNum == 0) {
ds.incFlipDecoderIndex(); ds.incFlipDecoderIndex();
@ -137,7 +120,7 @@ public class NestedMultiDecoder<T> implements MultiDecoder<Object> {
decoder = secondDecoder; decoder = secondDecoder;
} }
return decoder.isApplicable(paramNum, state); return decoder.getDecoder(paramNum, state);
} }
protected final NestedDecoderState getDecoder(State state) { protected final NestedDecoderState getDecoder(State state) {

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -29,19 +28,14 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ObjectFirstResultReplayDecoder<T> implements MultiDecoder<T> { public class ObjectFirstResultReplayDecoder<T> implements MultiDecoder<T> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public T decode(List<Object> parts, State state) { public T decode(List<Object> parts, State state) {
return (T) parts.get(0); return (T) parts.get(0);
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -15,13 +15,11 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -32,8 +30,11 @@ import io.netty.util.CharsetUtil;
public class ObjectFirstScoreReplayDecoder implements MultiDecoder<Double> { public class ObjectFirstScoreReplayDecoder implements MultiDecoder<Double> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8)).doubleValue(); if (paramNum % 2 != 0) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
return null;
} }
@Override @Override
@ -41,9 +42,4 @@ public class ObjectFirstScoreReplayDecoder implements MultiDecoder<Double> {
return (Double) parts.get(1); return (Double) parts.get(1);
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
}
} }

@ -15,13 +15,11 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -39,8 +37,8 @@ public class ObjectListDecoder<T> implements MultiDecoder<List<T>> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return codec.getMapKeyDecoder().decode(buf, state); return codec.getMapKeyDecoder();
} }
@Override @Override
@ -48,9 +46,4 @@ public class ObjectListDecoder<T> implements MultiDecoder<List<T>> {
return (List<T>) parts; return (List<T>) parts;
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
} }

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -29,19 +28,13 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ObjectListReplayDecoder<T> implements MultiDecoder<List<T>> { public class ObjectListReplayDecoder<T> implements MultiDecoder<List<T>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public List<T> decode(List<Object> parts, State state) { public List<T> decode(List<Object> parts, State state) {
return (List<T>) parts; return (List<T>) parts;
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -15,15 +15,13 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -42,11 +40,11 @@ public class ObjectMapDecoder implements MultiDecoder<Map<Object, Object>> {
private int pos; private int pos;
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
if (pos++ % 2 == 0) { if (pos++ % 2 == 0) {
return codec.getMapKeyDecoder().decode(buf, state); return codec.getMapKeyDecoder();
} }
return codec.getMapValueDecoder().decode(buf, state); return codec.getMapValueDecoder();
} }
@Override @Override
@ -60,9 +58,4 @@ public class ObjectMapDecoder implements MultiDecoder<Map<Object, Object>> {
return result; return result;
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -22,8 +22,7 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -33,8 +32,8 @@ import io.netty.buffer.ByteBuf;
public class ObjectMapEntryReplayDecoder implements MultiDecoder<Set<Entry<Object, Object>>> { public class ObjectMapEntryReplayDecoder implements MultiDecoder<Set<Entry<Object, Object>>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
throw new UnsupportedOperationException(); return null;
} }
@Override @Override
@ -48,9 +47,4 @@ public class ObjectMapEntryReplayDecoder implements MultiDecoder<Set<Entry<Objec
return result.entrySet(); return result.entrySet();
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
} }

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -30,11 +29,6 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>> { public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public Map<Object, Object> decode(List<Object> parts, State state) { public Map<Object, Object> decode(List<Object> parts, State state) {
Map<Object, Object> result = new LinkedHashMap<Object, Object>(parts.size()/2); Map<Object, Object> result = new LinkedHashMap<Object, Object>(parts.size()/2);
@ -47,8 +41,8 @@ public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>>
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
@ -31,19 +30,14 @@ import io.netty.buffer.ByteBuf;
*/ */
public class ObjectSetReplayDecoder<T> implements MultiDecoder<Set<T>> { public class ObjectSetReplayDecoder<T> implements MultiDecoder<Set<T>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public Set<T> decode(List<Object> parts, State state) { public Set<T> decode(List<Object> parts, State state) {
return new LinkedHashSet(parts); return new LinkedHashSet(parts);
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -15,16 +15,14 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.ScoredEntry; import org.redisson.client.protocol.ScoredEntry;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -34,8 +32,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetReplayDecoder<T> implements MultiDecoder<List<ScoredEntry<T>>> { public class ScoredSortedSetReplayDecoder<T> implements MultiDecoder<List<ScoredEntry<T>>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8)); if (paramNum % 2 != 0) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
return null;
} }
@Override @Override
@ -47,9 +48,4 @@ public class ScoredSortedSetReplayDecoder<T> implements MultiDecoder<List<Scored
return result; return result;
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
}
} }

@ -15,12 +15,9 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.math.BigDecimal; import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -31,13 +28,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetScanDecoder<T> extends ObjectListReplayDecoder<T> { public class ScoredSortedSetScanDecoder<T> extends ObjectListReplayDecoder<T> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8)); if (paramNum % 2 != 0) {
} return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override return super.getDecoder(paramNum, state);
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
} }
} }

@ -17,10 +17,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List; import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -30,8 +29,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetScanReplayDecoder implements MultiDecoder<ListScanResult<Object>> { public class ScoredSortedSetScanReplayDecoder implements MultiDecoder<ListScanResult<Object>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8)); if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
} }
@Override @Override
@ -43,9 +45,4 @@ public class ScoredSortedSetScanReplayDecoder implements MultiDecoder<ListScanRe
return new ListScanResult<Object>((Long)parts.get(0), values); return new ListScanResult<Object>((Long)parts.get(0), values);
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
} }

@ -22,12 +22,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.cluster.ClusterSlotRange; import org.redisson.cluster.ClusterSlotRange;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -36,8 +35,8 @@ import io.netty.util.CharsetUtil;
public class SlotsDecoder implements MultiDecoder<Object> { public class SlotsDecoder implements MultiDecoder<Object> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return buf.toString(CharsetUtil.UTF_8); return StringCodec.INSTANCE.getValueDecoder();
} }
@Override @Override
@ -62,9 +61,4 @@ public class SlotsDecoder implements MultiDecoder<Object> {
return parts; return parts;
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -18,10 +18,9 @@ package org.redisson.client.protocol.decoder;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/** /**
* *
@ -31,8 +30,8 @@ import io.netty.util.CharsetUtil;
public class StringListReplayDecoder implements MultiDecoder<List<String>> { public class StringListReplayDecoder implements MultiDecoder<List<String>> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return buf.toString(CharsetUtil.UTF_8); return StringCodec.INSTANCE.getValueDecoder();
} }
@Override @Override
@ -40,9 +39,4 @@ public class StringListReplayDecoder implements MultiDecoder<List<String>> {
return Arrays.asList(Arrays.copyOf(parts.toArray(), parts.size(), String[].class)); return Arrays.asList(Arrays.copyOf(parts.toArray(), parts.size(), String[].class));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -15,15 +15,12 @@
*/ */
package org.redisson.client.protocol.pubsub; package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder; import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class PubSubMessageDecoder implements MultiDecoder<Object> { public class PubSubMessageDecoder implements MultiDecoder<Object> {
private final Decoder<Object> decoder; private final Decoder<Object> decoder;
@ -34,8 +31,8 @@ public class PubSubMessageDecoder implements MultiDecoder<Object> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return decoder.decode(buf, null); return decoder;
} }
@Override @Override
@ -43,9 +40,4 @@ public class PubSubMessageDecoder implements MultiDecoder<Object> {
return new PubSubMessage(parts.get(1).toString(), parts.get(2)); return new PubSubMessage(parts.get(1).toString(), parts.get(2));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -15,15 +15,12 @@
*/ */
package org.redisson.client.protocol.pubsub; package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder; import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class PubSubPatternMessageDecoder implements MultiDecoder<Object> { public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
private final Decoder<Object> decoder; private final Decoder<Object> decoder;
@ -34,8 +31,8 @@ public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return decoder.decode(buf, null); return decoder;
} }
@Override @Override
@ -43,9 +40,4 @@ public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
return new PubSubPatternMessage(parts.get(1).toString(), parts.get(2).toString(), parts.get(3)); return new PubSubPatternMessage(parts.get(1).toString(), parts.get(2).toString(), parts.get(3));
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -15,9 +15,11 @@
*/ */
package org.redisson.client.protocol.pubsub; package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -26,10 +28,16 @@ import io.netty.util.CharsetUtil;
public class PubSubStatusDecoder implements MultiDecoder<Object> { public class PubSubStatusDecoder implements MultiDecoder<Object> {
@Override @Override
public Object decode(ByteBuf buf, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
String status = buf.toString(CharsetUtil.UTF_8); return new Decoder<Object>() {
buf.skipBytes(2);
return status; @Override
public Object decode(ByteBuf buf, State state) throws IOException {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(2);
return status;
}
};
} }
@Override @Override
@ -37,9 +45,4 @@ public class PubSubStatusDecoder implements MultiDecoder<Object> {
return new PubSubStatusMessage(PubSubType.valueOf(parts.get(0).toString().toUpperCase()), parts.get(1).toString()); return new PubSubStatusMessage(PubSubType.valueOf(parts.get(0).toString().toUpperCase()), parts.get(1).toString());
} }
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
} }

@ -19,10 +19,9 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class ListDrainToDecoder<V> implements MultiDecoder<Integer> { public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
private Collection<Object> list; private Collection<Object> list;
@ -31,11 +30,6 @@ public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
this.list = list; this.list = list;
} }
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override @Override
public Integer decode(List<Object> parts, State state) { public Integer decode(List<Object> parts, State state) {
list.addAll(parts); list.addAll(parts);
@ -43,8 +37,8 @@ public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
} }
@Override @Override
public boolean isApplicable(int paramNum, State state) { public Decoder<Object> getDecoder(int paramNum, State state) {
return false; return null;
} }
} }

@ -22,6 +22,7 @@ import java.util.List;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -48,13 +49,8 @@ public class MapCacheGetAllDecoder implements MultiDecoder<List<Object>> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
return LongCodec.INSTANCE.getValueDecoder().decode(buf, state); return null;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
} }
@Override @Override

@ -15,17 +15,15 @@
*/ */
package org.redisson.connection.decoder; package org.redisson.connection.decoder;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder; import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -48,13 +46,8 @@ public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
} }
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Decoder<Object> getDecoder(int paramNum, State state) {
throw new UnsupportedOperationException(); return null;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
} }
@Override @Override

Loading…
Cancel
Save