-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-14907 Implement RESP "cluster shards" command
- Loading branch information
Showing
8 changed files
with
458 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
server/resp/src/main/java/org/infinispan/server/resp/commands/FamilyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.infinispan.server.resp.commands; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.infinispan.server.resp.ByteBufferUtils; | ||
import org.infinispan.server.resp.Resp3Handler; | ||
import org.infinispan.server.resp.RespCommand; | ||
import org.infinispan.server.resp.RespRequestHandler; | ||
import org.infinispan.server.resp.commands.cluster.CLUSTER; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
/** | ||
* An umbrella command. | ||
* <p> | ||
* This command represents a family of commands. Usually, the ones with multiple keywords, for example, | ||
* {@link CLUSTER} or ACL. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public abstract class FamilyCommand extends RespCommand implements Resp3Command { | ||
|
||
public FamilyCommand(int arity, int firstKeyPos, int lastKeyPos, int steps) { | ||
super(arity, firstKeyPos, lastKeyPos, steps); | ||
} | ||
|
||
@Override | ||
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx, List<byte[]> arguments) { | ||
byte[] subCommand = arguments.get(0); | ||
for (RespCommand cmd : getFamilyCommands()) { | ||
if (cmd.match(subCommand)) { | ||
if (cmd instanceof Resp3Command) { | ||
return ((Resp3Command) cmd).perform(handler, ctx, arguments); | ||
} | ||
|
||
if (cmd instanceof AuthResp3Command) { | ||
return ((AuthResp3Command) cmd).perform(handler, ctx, arguments); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
ByteBufferUtils.stringToByteBuf("-ERR unknown command\r\n", handler.allocatorToUse()); | ||
return handler.myStage(); | ||
} | ||
|
||
public abstract RespCommand[] getFamilyCommands(); | ||
} |
41 changes: 41 additions & 0 deletions
41
server/resp/src/main/java/org/infinispan/server/resp/commands/cluster/CLUSTER.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.infinispan.server.resp.commands.cluster; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.infinispan.server.resp.Resp3Handler; | ||
import org.infinispan.server.resp.RespCommand; | ||
import org.infinispan.server.resp.RespErrorUtil; | ||
import org.infinispan.server.resp.RespRequestHandler; | ||
import org.infinispan.server.resp.commands.FamilyCommand; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
public class CLUSTER extends FamilyCommand { | ||
|
||
private static final RespCommand[] CLUSTER_COMMANDS; | ||
|
||
static { | ||
CLUSTER_COMMANDS = new RespCommand[] { | ||
new SHARDS() | ||
}; | ||
} | ||
|
||
public CLUSTER() { | ||
super(-2, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx, List<byte[]> arguments) { | ||
if (arguments.isEmpty()) { | ||
RespErrorUtil.wrongArgumentNumber(this, handler.allocatorToUse()); | ||
return handler.myStage(); | ||
} | ||
return super.perform(handler, ctx, arguments); | ||
} | ||
|
||
@Override | ||
public RespCommand[] getFamilyCommands() { | ||
return CLUSTER_COMMANDS; | ||
} | ||
} |
Oops, something went wrong.