Skip to content

Commit

Permalink
Replace AbstractVerticle -> VerticleBase
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Oct 22, 2024
1 parent 6366d46 commit a4d9237
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 153 deletions.
11 changes: 4 additions & 7 deletions src/main/java/examples/RedisExamples.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package examples;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.*;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.PemTrustOptions;
import io.vertx.core.tracing.TracingPolicy;
Expand Down Expand Up @@ -151,7 +148,7 @@ public void example9(Vertx vertx) {

public void example10() {

class RedisVerticle extends AbstractVerticle {
class RedisVerticle extends VerticleBase {

private static final int MAX_RECONNECT_RETRIES = 16;

Expand All @@ -161,8 +158,8 @@ class RedisVerticle extends AbstractVerticle {
private final AtomicBoolean CONNECTING = new AtomicBoolean();

@Override
public void start() {
createRedisClient()
public Future<?> start() {
return createRedisClient()
.onSuccess(conn -> {
// connected to redis!
});
Expand Down
236 changes: 122 additions & 114 deletions src/test/java/io/vertx/tests/redis/client/CommandGenerator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.vertx.tests.redis.client;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.VerticleBase;
import io.vertx.core.Vertx;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.Response;
Expand All @@ -14,19 +15,26 @@
import static io.vertx.redis.client.Command.COMMAND;
import static io.vertx.redis.client.Request.cmd;

public class CommandGenerator extends AbstractVerticle {
public class CommandGenerator extends VerticleBase {

public static void main(String[] args) {
Vertx.vertx().deployVerticle(new CommandGenerator());
Vertx vertx = Vertx.vertx();
try {
vertx
.deployVerticle(new CommandGenerator())
.await();
} finally {
vertx.close();
}
}

@Override
public void start() {
public Future<?> start() {
Redis client = Redis.createClient(vertx);

Map<String, String> commandDocs = new HashMap<>();

client.send(cmd(COMMAND).arg("DOCS"))
return client.send(cmd(COMMAND).arg("DOCS"))
.compose(resp -> {
for (String key : resp.getKeys()) {
Response doc = resp.get(key);
Expand Down Expand Up @@ -60,141 +68,141 @@ public void start() {
}

return client.send(cmd(COMMAND).arg("INFO"));
}).onSuccess(res -> {
List<String> commands = new ArrayList<>();
Map<String, String> commandInstantiation = new HashMap<>();
Map<String, String> knownCommands = new HashMap<>();
}).andThen(ar -> {

res.forEach(cmd -> {
String commandName = cmd.get(0).toString();
if (ar.succeeded()) {

Boolean ro = null;
boolean getkeys = false;
Response res = ar.result();

for (Response flag : cmd.get(2)) {
if ("readonly".equalsIgnoreCase(flag.toString())) {
ro = true;
}
if ("write".equalsIgnoreCase(flag.toString())) {
ro = false;
}
}
List<String> commands = new ArrayList<>();
Map<String, String> commandInstantiation = new HashMap<>();
Map<String, String> knownCommands = new HashMap<>();

String keyLocator = null;
res.forEach(cmd -> {
String commandName = cmd.get(0).toString();

if (cmd.get(8).size() > 0) {
Boolean ro = null;
boolean getkeys = false;

for (Response hint : cmd.get(8)) {
String beginSearch = null;
String findKeys = null;
Boolean flagRO = null;
for (Response flag : cmd.get(2)) {
if ("readonly".equalsIgnoreCase(flag.toString())) {
ro = true;
}
if ("write".equalsIgnoreCase(flag.toString())) {
ro = false;
}
}

if (hint.size() > 0) {
if (hint.containsKey("flags")) {
for (Response flag : hint.get("flags")) {
if ("RO".equalsIgnoreCase(flag.toString())) {
flagRO = true;
break;
}
if ("RW".equalsIgnoreCase(flag.toString()) || "OW".equalsIgnoreCase(flag.toString()) || "RM".equalsIgnoreCase(flag.toString())) {
flagRO = false;
break;
String keyLocator = null;

if (cmd.get(8).size() > 0) {

for (Response hint : cmd.get(8)) {
String beginSearch = null;
String findKeys = null;
Boolean flagRO = null;

if (hint.size() > 0) {
if (hint.containsKey("flags")) {
for (Response flag : hint.get("flags")) {
if ("RO".equalsIgnoreCase(flag.toString())) {
flagRO = true;
break;
}
if ("RW".equalsIgnoreCase(flag.toString()) || "OW".equalsIgnoreCase(flag.toString()) || "RM".equalsIgnoreCase(flag.toString())) {
flagRO = false;
break;
}
}
}
}
if (hint.containsKey("begin_search")) {
String type = hint.get("begin_search").get("type").toString();
Response spec = hint.get("begin_search").get("spec");
switch (type) {
case "index":
beginSearch = "new BeginSearchIndex(" + spec.get("index").toInteger() + ")";
break;
case "keyword":
beginSearch = "new BeginSearchKeyword(\"" + spec.get("keyword").toString() + "\", " + spec.get("startfrom").toInteger() + ")";
break;
case "unknown":
getkeys = true;
System.err.println(cmd);
break;
if (hint.containsKey("begin_search")) {
String type = hint.get("begin_search").get("type").toString();
Response spec = hint.get("begin_search").get("spec");
switch (type) {
case "index":
beginSearch = "new BeginSearchIndex(" + spec.get("index").toInteger() + ")";
break;
case "keyword":
beginSearch = "new BeginSearchKeyword(\"" + spec.get("keyword").toString() + "\", " + spec.get("startfrom").toInteger() + ")";
break;
case "unknown":
getkeys = true;
System.err.println(cmd);
break;
}
}
}
if (hint.containsKey("find_keys")) {
String type = hint.get("find_keys").get("type").toString();
Response spec = hint.get("find_keys").get("spec");
switch (type) {
case "range":
findKeys = "new FindKeysRange(" + spec.get("lastkey").toInteger() + ", " + spec.get("keystep").toInteger() + ", " + spec.get("limit").toInteger() + ")";
break;
case "keynum":
findKeys = "new FindKeysKeynum(" + spec.get("keynumidx").toInteger() + ", " + spec.get("firstkey").toInteger() + ", " + spec.get("keystep").toInteger() + ")";
break;
case "unknown":
getkeys = true;
System.err.println(cmd);
break;
if (hint.containsKey("find_keys")) {
String type = hint.get("find_keys").get("type").toString();
Response spec = hint.get("find_keys").get("spec");
switch (type) {
case "range":
findKeys = "new FindKeysRange(" + spec.get("lastkey").toInteger() + ", " + spec.get("keystep").toInteger() + ", " + spec.get("limit").toInteger() + ")";
break;
case "keynum":
findKeys = "new FindKeysKeynum(" + spec.get("keynumidx").toInteger() + ", " + spec.get("firstkey").toInteger() + ", " + spec.get("keystep").toInteger() + ")";
break;
case "unknown":
getkeys = true;
System.err.println(cmd);
break;
}
}
}
}

if (beginSearch != null && findKeys != null) {
if (keyLocator == null) {
keyLocator = "new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
} else {
keyLocator += ", new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
if (beginSearch != null && findKeys != null) {
if (keyLocator == null) {
keyLocator = "new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
} else {
keyLocator += ", new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
}
}
}
}
}

boolean pubSub = false;
boolean pubSub = false;

for (Response flag : cmd.get(2)) {
if ("pubsub".equals(flag.toString())) {
// we exclude PUBSUB / PUBLISH / SPUBLISH from the flag
if ("pubsub".equalsIgnoreCase(commandName)
for (Response flag : cmd.get(2)) {
if ("pubsub".equals(flag.toString())) {
// we exclude PUBSUB / PUBLISH / SPUBLISH from the flag
if ("pubsub".equalsIgnoreCase(commandName)
|| "publish".equalsIgnoreCase(commandName)
|| "spublish".equalsIgnoreCase(commandName)) {
continue;
continue;
}
pubSub = true;
break;
}
pubSub = true;
break;
}
}

commands.add(commandName);

commandInstantiation.put(commandName,
generateCommand(
commandName,
cmd.get(1).toInteger(),
ro,
pubSub,
getkeys,
keyLocator
));

knownCommands.put(commandName, generateCommandMap(commandName));
});

commands.sort(Comparator.comparing(this::toIdentifier));
for (String cmd : commands) {
System.out.print(commandDocs.get(cmd));
System.out.println(commandInstantiation.get(cmd));
}
commands.add(commandName);

commandInstantiation.put(commandName,
generateCommand(
commandName,
cmd.get(1).toInteger(),
ro,
pubSub,
getkeys,
keyLocator
));

knownCommands.put(commandName, generateCommandMap(commandName));
});

commands.sort(Comparator.comparing(this::toIdentifier));
for (String cmd : commands) {
System.out.print(commandDocs.get(cmd));
System.out.println(commandInstantiation.get(cmd));
}

System.out.println();
System.out.println("----------------------------------------------------------------");
System.out.println();
System.out.println();
System.out.println("----------------------------------------------------------------");
System.out.println();

for (String cmd : commands) {
System.out.println(knownCommands.get(cmd));
for (String cmd : commands) {
System.out.println(knownCommands.get(cmd));
}
}

vertx.close();
})
.onFailure(err -> {
err.printStackTrace();
System.exit(1);
});
}

Expand Down
11 changes: 4 additions & 7 deletions src/test/java/io/vertx/tests/redis/client/RedisClient7Test.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.vertx.tests.redis.client;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.core.ThreadingModel;
import io.vertx.core.*;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
Expand Down Expand Up @@ -213,9 +210,9 @@ public void perfRegression(TestContext should) {
AtomicInteger count = new AtomicInteger();

rule.vertx()
.deployVerticle(() -> new AbstractVerticle() {
.deployVerticle(() -> new VerticleBase() {
@Override
public void start(Promise<Void> onStart) {
public Future<?> start() throws Exception {
Redis redisClient = Redis.createClient(rule.vertx(), new RedisOptions()
.setConnectionString("redis://" + redis.getHost() + ":" + redis.getPort() + "/0")
.setMaxPoolSize(10)
Expand All @@ -234,7 +231,7 @@ public void start(Promise<Void> onStart) {
.onFailure(should::fail);
});

onStart.complete();
return super.start();
}
}, new DeploymentOptions().setInstances(instances).setThreadingModel(ThreadingModel.WORKER))
.onComplete(res -> {
Expand Down
Loading

0 comments on commit a4d9237

Please sign in to comment.