Skip to content

Commit

Permalink
Polishing #2173
Browse files Browse the repository at this point in the history
Reintroduce deprecated constructor.

Original pull request: #2174
  • Loading branch information
mp911de committed Nov 23, 2022
1 parent 66506f9 commit 1a394fe
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/main/java/io/lettuce/core/protocol/RedisStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

import io.lettuce.core.internal.LettuceStrings;
Expand Down Expand Up @@ -205,6 +204,7 @@ public Result handle(RedisStateMachine rsm, State state, ByteBuf buffer, Command
Consumer<Exception> errorHandler) {
return behavior.handle(rsm, state, buffer, output, errorHandler);
}

}

enum Result {
Expand All @@ -231,8 +231,6 @@ public String toString() {

private final boolean debugEnabled = logger.isDebugEnabled();

private final AtomicBoolean closed = new AtomicBoolean();

private final Resp2LongProcessor longProcessor = new Resp2LongProcessor();

private ProtocolVersion protocolVersion = null;
Expand All @@ -241,9 +239,18 @@ public String toString() {

/**
* Initialize a new instance.
*
* @deprecated since 6.3, {@link ByteBufAllocator no longer required}.
*/
public RedisStateMachine() {
@Deprecated
public RedisStateMachine(ByteBufAllocator alloc) {
this();
}

/**
* Initialize a new instance.
*/
public RedisStateMachine() {
}

public boolean isDiscoverProtocol() {
Expand Down Expand Up @@ -358,8 +365,8 @@ static State.Result handleSingle(RedisStateMachine rsm, State state, ByteBuf buf
return State.Result.NORMAL_END;
}

static State.Result handleBigNumber(RedisStateMachine rsm, State state, ByteBuf buffer,
CommandOutput<?, ?, ?> output, Consumer<Exception> errorHandler) {
static State.Result handleBigNumber(RedisStateMachine rsm, State state, ByteBuf buffer, CommandOutput<?, ?, ?> output,
Consumer<Exception> errorHandler) {
ByteBuffer bytes;

if ((bytes = rsm.readLine(buffer)) == null) {
Expand Down Expand Up @@ -425,8 +432,8 @@ static State.Result handleFloat(RedisStateMachine rsm, State state, ByteBuf buff
return State.Result.NORMAL_END;
}

static State.Result handleBulkAndVerbatim(RedisStateMachine rsm, State state, ByteBuf buffer,
CommandOutput<?, ?, ?> output, Consumer<Exception> errorHandler) {
static State.Result handleBulkAndVerbatim(RedisStateMachine rsm, State state, ByteBuf buffer, CommandOutput<?, ?, ?> output,
Consumer<Exception> errorHandler) {
int length;
int end;

Expand All @@ -445,8 +452,8 @@ static State.Result handleBulkAndVerbatim(RedisStateMachine rsm, State state, By
return State.Result.NORMAL_END;
}

static State.Result handleBulkError(RedisStateMachine rsm, State state, ByteBuf buffer,
CommandOutput<?, ?, ?> output, Consumer<Exception> errorHandler) {
static State.Result handleBulkError(RedisStateMachine rsm, State state, ByteBuf buffer, CommandOutput<?, ?, ?> output,
Consumer<Exception> errorHandler) {
int length;
int end;

Expand Down Expand Up @@ -479,8 +486,8 @@ static State.Result handleHelloV3(RedisStateMachine rsm, State state, ByteBuf bu
return returnDependStateCount(rsm, state);
}

static State.Result handlePushAndMulti(RedisStateMachine rsm, State state, ByteBuf buffer,
CommandOutput<?, ?, ?> output, Consumer<Exception> errorHandler) {
static State.Result handlePushAndMulti(RedisStateMachine rsm, State state, ByteBuf buffer, CommandOutput<?, ?, ?> output,
Consumer<Exception> errorHandler) {
int end;

if (state.count == NOT_FOUND) {
Expand Down Expand Up @@ -547,8 +554,8 @@ static State.Result returnDependStateCount(RedisStateMachine rsm, State state) {
return State.Result.CONTINUE_LOOP;
}

static State.Result handleVerbatim(RedisStateMachine rsm, State state, ByteBuf buffer,
CommandOutput<?, ?, ?> output, Consumer<Exception> errorHandler) {
static State.Result handleVerbatim(RedisStateMachine rsm, State state, ByteBuf buffer, CommandOutput<?, ?, ?> output,
Consumer<Exception> errorHandler) {
ByteBuffer bytes;

if ((bytes = rsm.readBytes(buffer, state.count)) == null) {
Expand Down Expand Up @@ -588,9 +595,6 @@ public void reset() {
* Close the state machine to free resources.
*/
public void close() {
if (closed.compareAndSet(false, true)) {
// free resources if any
}
}

private int findLineEnd(ByteBuf buffer) {
Expand Down Expand Up @@ -671,7 +675,8 @@ private ByteBuffer readBytes(ByteBuf buffer, int count) {
}

private ByteBuffer readBytes0(ByteBuf buffer, int count) {
final ByteBuffer byteBuffer = buffer.internalNioBuffer(buffer.readerIndex(), count);

ByteBuffer byteBuffer = buffer.internalNioBuffer(buffer.readerIndex(), count);

// advance reader index
buffer.readerIndex(buffer.readerIndex() + count);
Expand Down

0 comments on commit 1a394fe

Please sign in to comment.