Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.

Commit ddb8bda

Browse files
fussel178Ludwig Richter
authored andcommitted
feat(api): Update request methods in WithEventBus trait
1 parent 2d28b89 commit ddb8bda

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

modules/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/DecodedMessage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import de.wuespace.telestion.api.message.JsonMessage;
55
import io.vertx.core.eventbus.Message;
6+
import io.vertx.core.json.JsonObject;
67

7-
public record DecodedMessage<V extends JsonMessage, T>(
8+
public record DecodedMessage<V extends JsonMessage, T extends JsonObject>(
89
@JsonProperty V body,
910
@JsonProperty Message<T> message
10-
) implements JsonMessage {
11+
) implements JsonMessage {
1112
}

modules/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/WithEventBus.java

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
public interface WithEventBus extends Verticle {
3434
/* PUBLISH */
35+
3536
/**
3637
* @see io.vertx.core.eventbus.EventBus#publish(String, Object, DeliveryOptions)
3738
*/
@@ -61,6 +62,7 @@ default void publish(String address, JsonMessage message) {
6162
}
6263

6364
/* SEND */
65+
6466
/**
6567
* @see io.vertx.core.eventbus.EventBus#send(String, Object, DeliveryOptions)
6668
*/
@@ -90,69 +92,83 @@ default void send(String address, JsonMessage message) {
9092
}
9193

9294
/* REQUEST */
95+
9396
/**
94-
* @param responseType the type of the response to map to
9597
* @see io.vertx.core.eventbus.EventBus#request(String, Object, DeliveryOptions)
9698
*/
97-
default <V extends JsonMessage, T> Future<DecodedMessage<V, T>> request(
98-
String address, Object request, DeliveryOptions options, Class<V> responseType) {
99-
return getVertx().eventBus().<T>request(address, request, options)
100-
.map(raw -> new DecodedMessage<>(JsonMessage.from(raw.body(), responseType), raw));
99+
default <T> Future<Message<T>> request(String address, Object request, DeliveryOptions options) {
100+
return getVertx().eventBus().request(address, request, options);
101101
}
102102

103-
default <V extends JsonMessage, T> Future<DecodedMessage<V, T>> request(
104-
String address, JsonMessage request, DeliveryOptions options, Class<V> responseType) {
105-
return request(address, request.json(), options, responseType);
103+
/**
104+
* @see io.vertx.core.eventbus.EventBus#request(String, Object)
105+
*/
106+
default <T> Future<Message<T>> request(String address, Object request) {
107+
return getVertx().eventBus().request(address, request);
108+
}
109+
110+
/**
111+
* @param responseType the type of the response to map to
112+
* @see io.vertx.core.eventbus.EventBus#request(String, Object, DeliveryOptions)
113+
*/
114+
default <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> request(
115+
String address, Object request, DeliveryOptions options, Class<V> responseType
116+
) {
117+
return this.<T>request(address, request, options)
118+
.map(raw -> new DecodedMessage<>(raw.body().mapTo(responseType), raw));
106119
}
107120

108121
/**
109122
* @param responseType the type of the response to map to
110123
* @see io.vertx.core.eventbus.EventBus#request(String, Object)
111124
*/
112-
default <V extends JsonMessage, T> Future<DecodedMessage<V, T>> request(
113-
String address, Object request, Class<V> responseType) {
114-
return getVertx().eventBus().<T>request(address, request)
115-
.map(raw -> new DecodedMessage<>(((JsonObject) raw.body()).mapTo(responseType), raw));
125+
default <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> request(
126+
String address, Object request, Class<V> responseType
127+
) {
128+
return this.<T>request(address, request)
129+
.map(raw -> new DecodedMessage<>(raw.body().mapTo(responseType), raw));
116130
}
117131

118-
default <V extends JsonMessage, T> Future<DecodedMessage<V, T>> request(
119-
String address, JsonMessage request, Class<V> responseType) {
132+
/**
133+
* @param responseType the type of the response to map to
134+
* @see io.vertx.core.eventbus.EventBus#request(String, Object, DeliveryOptions)
135+
*/
136+
default <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> request(
137+
String address, JsonMessage request, DeliveryOptions options, Class<V> responseType
138+
) {
139+
return request(address, request.json(), options, responseType);
140+
}
141+
142+
/**
143+
* @param responseType the type of the response to map to
144+
* @see io.vertx.core.eventbus.EventBus#request(String, Object)
145+
*/
146+
default <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> request(
147+
String address, JsonMessage request, Class<V> responseType
148+
) {
120149
return request(address, request.json(), responseType);
121150
}
122151

123152
/* REGISTER/CONSUME */
153+
124154
/**
125-
* Registers a handler onto an eventbus channel.
126-
*
127-
* @param address the eventbus address name
128-
* @param handler the handler that gets called when a new message arrives at the specified eventbus address
129155
* @see io.vertx.core.eventbus.EventBus#consumer(String, Handler)
130156
*/
131157
default <T> void register(String address, Handler<Message<T>> handler) {
132158
getVertx().eventBus().consumer(address, handler);
133159
}
134160

135161
/**
136-
* Registers a handler onto an eventbus channel.
137-
* The received messages are mapped to the specified json type before handing over to the handler.
138-
*
139-
* @param address the eventbus address name
140-
* @param handler the handler that gets called when a new message arrives at the specified eventbus address
141-
* @param type the json type to map to
162+
* @param type the type of received message to map to
142163
* @see io.vertx.core.eventbus.EventBus#consumer(String, Handler)
143164
*/
144165
default <V extends JsonMessage> void register(String address, MessageHandler<V> handler, Class<V> type) {
145166
register(address, message -> JsonMessage.on(type, message, handler::handle));
146167
}
147168

148169
/**
149-
* Registers a handler onto an eventbus channel.
150-
* The received messages are mapped to the specified json type before handing over to the handler.
151-
* The handler gets the plain message object received from the eventbus, too.
152-
*
153-
* @param address the eventbus address name
154-
* @param handler the handler that gets called when a new message arrives at the specified eventbus address
155-
* @param type the json type to map to
170+
* @param type the type of received message to map to
171+
* @see io.vertx.core.eventbus.EventBus#consumer(String, Handler)
156172
*/
157173
default <V extends JsonMessage, T> void register(String address, ExtendedMessageHandler<V, T> handler, Class<V> type) {
158174
this.<T>register(address, message -> JsonMessage.on(type, message, body -> handler.handle(body, message)));

0 commit comments

Comments
 (0)