-
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
9 changed files
with
438 additions
and
20 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
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
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.RespErrorUtil; | ||
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) { | ||
if (arguments.isEmpty()) { | ||
RespErrorUtil.wrongArgumentNumber(this, handler.allocator()); | ||
return handler.myStage(); | ||
} | ||
|
||
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.allocator()); | ||
return handler.myStage(); | ||
} | ||
|
||
public abstract RespCommand[] getFamilyCommands(); | ||
} |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
package org.infinispan.server.resp.commands.cluster; | ||
|
||
import org.infinispan.server.resp.RespCommand; | ||
import org.infinispan.server.resp.commands.FamilyCommand; | ||
|
||
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 RespCommand[] getFamilyCommands() { | ||
return CLUSTER_COMMANDS; | ||
} | ||
} |
Oops, something went wrong.