Skip to content

Commit a4d9237

Browse files
committed
Replace AbstractVerticle -> VerticleBase
1 parent 6366d46 commit a4d9237

File tree

6 files changed

+151
-153
lines changed

6 files changed

+151
-153
lines changed

src/main/java/examples/RedisExamples.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package examples;
22

3-
import io.vertx.core.AbstractVerticle;
4-
import io.vertx.core.Future;
5-
import io.vertx.core.Promise;
6-
import io.vertx.core.Vertx;
3+
import io.vertx.core.*;
74
import io.vertx.core.net.NetClientOptions;
85
import io.vertx.core.net.PemTrustOptions;
96
import io.vertx.core.tracing.TracingPolicy;
@@ -151,7 +148,7 @@ public void example9(Vertx vertx) {
151148

152149
public void example10() {
153150

154-
class RedisVerticle extends AbstractVerticle {
151+
class RedisVerticle extends VerticleBase {
155152

156153
private static final int MAX_RECONNECT_RETRIES = 16;
157154

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

163160
@Override
164-
public void start() {
165-
createRedisClient()
161+
public Future<?> start() {
162+
return createRedisClient()
166163
.onSuccess(conn -> {
167164
// connected to redis!
168165
});

src/test/java/io/vertx/tests/redis/client/CommandGenerator.java

+122-114
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.vertx.tests.redis.client;
22

3-
import io.vertx.core.AbstractVerticle;
3+
import io.vertx.core.Future;
4+
import io.vertx.core.VerticleBase;
45
import io.vertx.core.Vertx;
56
import io.vertx.redis.client.Redis;
67
import io.vertx.redis.client.Response;
@@ -14,19 +15,26 @@
1415
import static io.vertx.redis.client.Command.COMMAND;
1516
import static io.vertx.redis.client.Request.cmd;
1617

17-
public class CommandGenerator extends AbstractVerticle {
18+
public class CommandGenerator extends VerticleBase {
1819

1920
public static void main(String[] args) {
20-
Vertx.vertx().deployVerticle(new CommandGenerator());
21+
Vertx vertx = Vertx.vertx();
22+
try {
23+
vertx
24+
.deployVerticle(new CommandGenerator())
25+
.await();
26+
} finally {
27+
vertx.close();
28+
}
2129
}
2230

2331
@Override
24-
public void start() {
32+
public Future<?> start() {
2533
Redis client = Redis.createClient(vertx);
2634

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

29-
client.send(cmd(COMMAND).arg("DOCS"))
37+
return client.send(cmd(COMMAND).arg("DOCS"))
3038
.compose(resp -> {
3139
for (String key : resp.getKeys()) {
3240
Response doc = resp.get(key);
@@ -60,141 +68,141 @@ public void start() {
6068
}
6169

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

68-
res.forEach(cmd -> {
69-
String commandName = cmd.get(0).toString();
73+
if (ar.succeeded()) {
7074

71-
Boolean ro = null;
72-
boolean getkeys = false;
75+
Response res = ar.result();
7376

74-
for (Response flag : cmd.get(2)) {
75-
if ("readonly".equalsIgnoreCase(flag.toString())) {
76-
ro = true;
77-
}
78-
if ("write".equalsIgnoreCase(flag.toString())) {
79-
ro = false;
80-
}
81-
}
77+
List<String> commands = new ArrayList<>();
78+
Map<String, String> commandInstantiation = new HashMap<>();
79+
Map<String, String> knownCommands = new HashMap<>();
8280

83-
String keyLocator = null;
81+
res.forEach(cmd -> {
82+
String commandName = cmd.get(0).toString();
8483

85-
if (cmd.get(8).size() > 0) {
84+
Boolean ro = null;
85+
boolean getkeys = false;
8686

87-
for (Response hint : cmd.get(8)) {
88-
String beginSearch = null;
89-
String findKeys = null;
90-
Boolean flagRO = null;
87+
for (Response flag : cmd.get(2)) {
88+
if ("readonly".equalsIgnoreCase(flag.toString())) {
89+
ro = true;
90+
}
91+
if ("write".equalsIgnoreCase(flag.toString())) {
92+
ro = false;
93+
}
94+
}
9195

92-
if (hint.size() > 0) {
93-
if (hint.containsKey("flags")) {
94-
for (Response flag : hint.get("flags")) {
95-
if ("RO".equalsIgnoreCase(flag.toString())) {
96-
flagRO = true;
97-
break;
98-
}
99-
if ("RW".equalsIgnoreCase(flag.toString()) || "OW".equalsIgnoreCase(flag.toString()) || "RM".equalsIgnoreCase(flag.toString())) {
100-
flagRO = false;
101-
break;
96+
String keyLocator = null;
97+
98+
if (cmd.get(8).size() > 0) {
99+
100+
for (Response hint : cmd.get(8)) {
101+
String beginSearch = null;
102+
String findKeys = null;
103+
Boolean flagRO = null;
104+
105+
if (hint.size() > 0) {
106+
if (hint.containsKey("flags")) {
107+
for (Response flag : hint.get("flags")) {
108+
if ("RO".equalsIgnoreCase(flag.toString())) {
109+
flagRO = true;
110+
break;
111+
}
112+
if ("RW".equalsIgnoreCase(flag.toString()) || "OW".equalsIgnoreCase(flag.toString()) || "RM".equalsIgnoreCase(flag.toString())) {
113+
flagRO = false;
114+
break;
115+
}
102116
}
103117
}
104-
}
105-
if (hint.containsKey("begin_search")) {
106-
String type = hint.get("begin_search").get("type").toString();
107-
Response spec = hint.get("begin_search").get("spec");
108-
switch (type) {
109-
case "index":
110-
beginSearch = "new BeginSearchIndex(" + spec.get("index").toInteger() + ")";
111-
break;
112-
case "keyword":
113-
beginSearch = "new BeginSearchKeyword(\"" + spec.get("keyword").toString() + "\", " + spec.get("startfrom").toInteger() + ")";
114-
break;
115-
case "unknown":
116-
getkeys = true;
117-
System.err.println(cmd);
118-
break;
118+
if (hint.containsKey("begin_search")) {
119+
String type = hint.get("begin_search").get("type").toString();
120+
Response spec = hint.get("begin_search").get("spec");
121+
switch (type) {
122+
case "index":
123+
beginSearch = "new BeginSearchIndex(" + spec.get("index").toInteger() + ")";
124+
break;
125+
case "keyword":
126+
beginSearch = "new BeginSearchKeyword(\"" + spec.get("keyword").toString() + "\", " + spec.get("startfrom").toInteger() + ")";
127+
break;
128+
case "unknown":
129+
getkeys = true;
130+
System.err.println(cmd);
131+
break;
132+
}
119133
}
120-
}
121-
if (hint.containsKey("find_keys")) {
122-
String type = hint.get("find_keys").get("type").toString();
123-
Response spec = hint.get("find_keys").get("spec");
124-
switch (type) {
125-
case "range":
126-
findKeys = "new FindKeysRange(" + spec.get("lastkey").toInteger() + ", " + spec.get("keystep").toInteger() + ", " + spec.get("limit").toInteger() + ")";
127-
break;
128-
case "keynum":
129-
findKeys = "new FindKeysKeynum(" + spec.get("keynumidx").toInteger() + ", " + spec.get("firstkey").toInteger() + ", " + spec.get("keystep").toInteger() + ")";
130-
break;
131-
case "unknown":
132-
getkeys = true;
133-
System.err.println(cmd);
134-
break;
134+
if (hint.containsKey("find_keys")) {
135+
String type = hint.get("find_keys").get("type").toString();
136+
Response spec = hint.get("find_keys").get("spec");
137+
switch (type) {
138+
case "range":
139+
findKeys = "new FindKeysRange(" + spec.get("lastkey").toInteger() + ", " + spec.get("keystep").toInteger() + ", " + spec.get("limit").toInteger() + ")";
140+
break;
141+
case "keynum":
142+
findKeys = "new FindKeysKeynum(" + spec.get("keynumidx").toInteger() + ", " + spec.get("firstkey").toInteger() + ", " + spec.get("keystep").toInteger() + ")";
143+
break;
144+
case "unknown":
145+
getkeys = true;
146+
System.err.println(cmd);
147+
break;
148+
}
135149
}
136150
}
137-
}
138151

139-
if (beginSearch != null && findKeys != null) {
140-
if (keyLocator == null) {
141-
keyLocator = "new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
142-
} else {
143-
keyLocator += ", new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
152+
if (beginSearch != null && findKeys != null) {
153+
if (keyLocator == null) {
154+
keyLocator = "new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
155+
} else {
156+
keyLocator += ", new KeyLocator(" + flagRO + ", " + beginSearch + ", " + findKeys + ")";
157+
}
144158
}
145159
}
146160
}
147-
}
148161

149-
boolean pubSub = false;
162+
boolean pubSub = false;
150163

151-
for (Response flag : cmd.get(2)) {
152-
if ("pubsub".equals(flag.toString())) {
153-
// we exclude PUBSUB / PUBLISH / SPUBLISH from the flag
154-
if ("pubsub".equalsIgnoreCase(commandName)
164+
for (Response flag : cmd.get(2)) {
165+
if ("pubsub".equals(flag.toString())) {
166+
// we exclude PUBSUB / PUBLISH / SPUBLISH from the flag
167+
if ("pubsub".equalsIgnoreCase(commandName)
155168
|| "publish".equalsIgnoreCase(commandName)
156169
|| "spublish".equalsIgnoreCase(commandName)) {
157-
continue;
170+
continue;
171+
}
172+
pubSub = true;
173+
break;
158174
}
159-
pubSub = true;
160-
break;
161175
}
162-
}
163176

164-
commands.add(commandName);
165-
166-
commandInstantiation.put(commandName,
167-
generateCommand(
168-
commandName,
169-
cmd.get(1).toInteger(),
170-
ro,
171-
pubSub,
172-
getkeys,
173-
keyLocator
174-
));
175-
176-
knownCommands.put(commandName, generateCommandMap(commandName));
177-
});
178-
179-
commands.sort(Comparator.comparing(this::toIdentifier));
180-
for (String cmd : commands) {
181-
System.out.print(commandDocs.get(cmd));
182-
System.out.println(commandInstantiation.get(cmd));
183-
}
177+
commands.add(commandName);
178+
179+
commandInstantiation.put(commandName,
180+
generateCommand(
181+
commandName,
182+
cmd.get(1).toInteger(),
183+
ro,
184+
pubSub,
185+
getkeys,
186+
keyLocator
187+
));
188+
189+
knownCommands.put(commandName, generateCommandMap(commandName));
190+
});
191+
192+
commands.sort(Comparator.comparing(this::toIdentifier));
193+
for (String cmd : commands) {
194+
System.out.print(commandDocs.get(cmd));
195+
System.out.println(commandInstantiation.get(cmd));
196+
}
184197

185-
System.out.println();
186-
System.out.println("----------------------------------------------------------------");
187-
System.out.println();
198+
System.out.println();
199+
System.out.println("----------------------------------------------------------------");
200+
System.out.println();
188201

189-
for (String cmd : commands) {
190-
System.out.println(knownCommands.get(cmd));
202+
for (String cmd : commands) {
203+
System.out.println(knownCommands.get(cmd));
204+
}
191205
}
192-
193-
vertx.close();
194-
})
195-
.onFailure(err -> {
196-
err.printStackTrace();
197-
System.exit(1);
198206
});
199207
}
200208

src/test/java/io/vertx/tests/redis/client/RedisClient7Test.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.vertx.tests.redis.client;
22

3-
import io.vertx.core.AbstractVerticle;
4-
import io.vertx.core.DeploymentOptions;
5-
import io.vertx.core.Promise;
6-
import io.vertx.core.ThreadingModel;
3+
import io.vertx.core.*;
74
import io.vertx.core.json.JsonObject;
85
import io.vertx.ext.unit.Async;
96
import io.vertx.ext.unit.TestContext;
@@ -213,9 +210,9 @@ public void perfRegression(TestContext should) {
213210
AtomicInteger count = new AtomicInteger();
214211

215212
rule.vertx()
216-
.deployVerticle(() -> new AbstractVerticle() {
213+
.deployVerticle(() -> new VerticleBase() {
217214
@Override
218-
public void start(Promise<Void> onStart) {
215+
public Future<?> start() throws Exception {
219216
Redis redisClient = Redis.createClient(rule.vertx(), new RedisOptions()
220217
.setConnectionString("redis://" + redis.getHost() + ":" + redis.getPort() + "/0")
221218
.setMaxPoolSize(10)
@@ -234,7 +231,7 @@ public void start(Promise<Void> onStart) {
234231
.onFailure(should::fail);
235232
});
236233

237-
onStart.complete();
234+
return super.start();
238235
}
239236
}, new DeploymentOptions().setInstances(instances).setThreadingModel(ThreadingModel.WORKER))
240237
.onComplete(res -> {

0 commit comments

Comments
 (0)