use of org.redisson.client.RedisOutOfMemoryException in project redisson by redisson.
the class CommandDecoder method decode.
private void decode(ByteBuf in, CommandData<Object, Object> data, List<Object> parts, Channel channel) throws IOException {
int code = in.readByte();
if (code == '+') {
ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r'));
try {
String result = rb.toString(CharsetUtil.UTF_8);
in.skipBytes(2);
handleResult(data, parts, result, false, channel);
} finally {
rb.release();
}
} else if (code == '-') {
ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r'));
try {
String error = rb.toString(CharsetUtil.UTF_8);
in.skipBytes(2);
if (error.startsWith("MOVED")) {
String[] errorParts = error.split(" ");
int slot = Integer.valueOf(errorParts[1]);
String addr = errorParts[2];
data.tryFailure(new RedisMovedException(slot, addr));
} else if (error.startsWith("ASK")) {
String[] errorParts = error.split(" ");
int slot = Integer.valueOf(errorParts[1]);
String addr = errorParts[2];
data.tryFailure(new RedisAskException(slot, addr));
} else if (error.startsWith("TRYAGAIN")) {
data.tryFailure(new RedisTryAgainException(error + ". channel: " + channel + " data: " + data));
} else if (error.startsWith("LOADING")) {
data.tryFailure(new RedisLoadingException(error + ". channel: " + channel + " data: " + data));
} else if (error.startsWith("OOM")) {
data.tryFailure(new RedisOutOfMemoryException(error.split("OOM ")[1] + ". channel: " + channel + " data: " + data));
} else if (error.contains("-OOM ")) {
data.tryFailure(new RedisOutOfMemoryException(error.split("-OOM ")[1] + ". channel: " + channel + " data: " + data));
} else {
if (data != null) {
data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + data));
} else {
log.error("Error: {} channel: {} data: {}", error, channel, data);
}
}
} finally {
rb.release();
}
} else if (code == ':') {
Long result = readLong(in);
handleResult(data, parts, result, false, channel);
} else if (code == '$') {
ByteBuf buf = readBytes(in);
Object result = null;
if (buf != null) {
Decoder<Object> decoder = selectDecoder(data, parts);
result = decoder.decode(buf, state());
}
handleResult(data, parts, result, false, channel);
} else if (code == '*') {
int level = state().incLevel();
long size = readLong(in);
List<Object> respParts;
if (state().getLevels().size() - 1 >= level) {
StateLevel stateLevel = state().getLevels().get(level);
respParts = stateLevel.getParts();
size = stateLevel.getSize();
} else {
respParts = new ArrayList<Object>();
if (state().isMakeCheckpoint()) {
state().addLevel(new StateLevel(size, respParts));
}
}
decodeList(in, data, parts, channel, size, respParts);
} else {
String dataStr = in.toString(0, in.writerIndex(), CharsetUtil.UTF_8);
throw new IllegalStateException("Can't decode replay: " + dataStr);
}
}
Aggregations