Skip to content

Commit

Permalink
feat(api)!: Rename JsonMessage interface to JsonRecord
Browse files Browse the repository at this point in the history
BREAKING-CHANGE: Rename `JsonMessage` interface to `JsonRecord`.

Co-authored-by: pklaschka <[email protected]>
  • Loading branch information
fussel178 and pklaschka committed Dec 22, 2022
1 parent eb713e6 commit 80cb961
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 230 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Vert.x. JSON (Jackson Codec) is used to encode and decode messages for the event bus.
* <p>
* {@link de.wuespace.telestion.api.message.HeaderInformation} add support for message headers. They can be
* used to include data unrelated to the data itself of a message.
* used to include metadata unrelated to the payload of a message.
* <p>
* It is heavily recommended to use Telestion traits like {@link de.wuespace.telestion.api.verticle.trait.WithEventBus}, it contains different
* helper methods for message serialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.wuespace.telestion.api.verticle;

import de.wuespace.telestion.api.message.JsonMessage;
import de.wuespace.telestion.api.message.JsonRecord;

/**
* The base class for all Telestion Verticle configurations.
* It extends {@link JsonMessage} so all configurations are also valid json classes.
* It extends {@link JsonRecord} so all configurations are also valid json classes.
*
* @author Cedric Bös (@cb0s), Pablo Klaschka (@pklaschka), Jan von Pichowski (@jvpichowski),
* Ludwig Richter (@fussel178)
*/
public interface TelestionConfiguration extends JsonMessage {
public interface TelestionConfiguration extends JsonRecord {
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
package de.wuespace.telestion.api.verticle.trait;

import com.fasterxml.jackson.annotation.JsonProperty;
import de.wuespace.telestion.api.message.JsonMessage;
import de.wuespace.telestion.api.message.JsonRecord;
import io.vertx.core.Future;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;

/**
* A wrapper for a {@link Message Vert.x message} and its body as {@link JsonMessage}.
* A wrapper for a {@link Message Vert.x message} and its body as {@link JsonRecord}.
*
* @param message the {@link Message Vert.x message}
* @param body the decoded body of the {@link Message Vert.x message}
* @param <V> the type of {@link JsonMessage} to map to
* @param <V> the type of {@link JsonRecord} to map to
* @param <T> the type of the body of the {@link Message Vert.x message}
* @see JsonMessage#on(Class, Message)
* @see JsonRecord#on(Class, Message)
*
* @author Ludwig Richter (@fussel178)
*/
public record DecodedMessage<V extends JsonMessage, T extends JsonObject>(
public record DecodedMessage<V extends JsonRecord, T extends JsonObject>(
@JsonProperty V body,
@JsonProperty Message<T> message
) implements JsonMessage {
) implements JsonRecord {

/**
* Returns a {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonMessage}.
* Fails if the {@code messageFuture}'s body cannot be mapped to the {@link JsonMessage} type
* Returns a {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonRecord}.
* Fails if the {@code messageFuture}'s body cannot be mapped to the {@link JsonRecord} type
* or the {@code messageFuture} fails.
*
* @param clazz the class type of the {@link JsonMessage} to map to
* @param clazz the class type of the {@link JsonRecord} to map to
* @param messageFuture the future that returns the received message
* @param <V> the type of {@link JsonMessage} to map to
* @param <V> the type of {@link JsonRecord} to map to
* @param <T> the type of the body of the {@link Message Vert.x message}
* @return a new {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonMessage}
* @see JsonMessage#on(Class, Message)
* @return a new {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonRecord}
* @see JsonRecord#on(Class, Message)
*/
public static <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> compose(
public static <V extends JsonRecord, T extends JsonObject> Future<DecodedMessage<V, T>> compose(
Class<V> clazz,
Future<Message<T>> messageFuture) {
return messageFuture.compose(message -> on(clazz, message));
}

/**
* Return a {@link Future} which succeeds with the {@link Message Vert.x message}'s body as {@link JsonMessage}.
* Fails if the {@link Message Vert.x message}'s body cannot be mapped to the {@link JsonMessage} type.
* Returns a {@link Future} which succeeds with the {@link Message Vert.x message}'s body as {@link JsonRecord}.
* Fails if the {@link Message Vert.x message}'s body cannot be mapped to the {@link JsonRecord} type.
*
* @param clazz the class type of the {@link JsonMessage} to map to
* @param clazz the class type of the {@link JsonRecord} to map to
* @param message the {@link Message Vert.x message}
* @param <V> the type of {@link JsonMessage} to map to
* @param <V> the type of {@link JsonRecord} to map to
* @param <T> the type of the body of the {@link Message Vert.x message}
* @return a new {@link Future} which returns a {@link DecodedMessage} with the message's contents
* @see JsonMessage#on(Class, Message)
* @see JsonRecord#on(Class, Message)
*/
public static <V extends JsonMessage, T extends JsonObject> Future<DecodedMessage<V, T>> on(
public static <V extends JsonRecord, T extends JsonObject> Future<DecodedMessage<V, T>> on(
Class<V> clazz,
Message<T> message) {
return JsonMessage.on(clazz, message).map(decoded -> new DecodedMessage<>(decoded, message));
return JsonRecord.on(clazz, message).map(decoded -> new DecodedMessage<>(decoded, message));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.wuespace.telestion.api.verticle.trait;

import de.wuespace.telestion.api.message.JsonMessage;
import de.wuespace.telestion.api.message.JsonRecord;
import io.vertx.core.eventbus.Message;

/**
Expand All @@ -11,6 +11,6 @@
* @see WithEventBus#register(String, ExtendedMessageHandler, Class)
*/
@FunctionalInterface
public interface ExtendedMessageHandler<V extends JsonMessage, T> {
public interface ExtendedMessageHandler<V extends JsonRecord, T> {
void handle(V body, Message<T> message);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.wuespace.telestion.api.verticle.trait;

import de.wuespace.telestion.api.message.JsonMessage;
import de.wuespace.telestion.api.message.JsonRecord;

/**
* An event handler which accepts the decoded body of the message
Expand All @@ -10,6 +10,6 @@
* @see WithEventBus#register(String, MessageHandler, Class)
*/
@FunctionalInterface
public interface MessageHandler<T extends JsonMessage> {
public interface MessageHandler<T extends JsonRecord> {
void handle(T body);
}
Loading

0 comments on commit 80cb961

Please sign in to comment.