fr.fezlight.eventsystem.models.EventWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-event-system Show documentation
Show all versions of spring-boot-starter-event-system Show documentation
This library is dedicated for Spring Boot application and is an implementation of an event system
integrated with RabbitMQ and Spring-Modulith-Events.
The newest version!
package fr.fezlight.eventsystem.models;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.springframework.modulith.events.Externalized;
import java.util.Objects;
import java.util.StringJoiner;
@Externalized
public class EventWrapper {
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
private final T event;
private final String handlerName;
private Integer retryLeft;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public EventWrapper(@JsonProperty("event") T event,
@JsonProperty("handlerName") String handlerName,
@JsonProperty("retryLeft") Integer retryLeft) {
this.event = Objects.requireNonNull(event, "event cannot be null");
this.handlerName = Objects.requireNonNull(handlerName, "handlerName cannot be null");
this.retryLeft = retryLeft;
}
public static EventWrapperBuilder builder() {
return new EventWrapperBuilder<>();
}
@Override
public String toString() {
return new StringJoiner(", ", EventWrapper.class.getSimpleName() + "[", "]")
.add("event=" + event)
.add("handlerName='" + handlerName + "'")
.add("retryLeft=" + retryLeft)
.toString();
}
public T getEvent() {
return this.event;
}
public String getHandlerName() {
return this.handlerName;
}
public Integer getRetryLeft() {
return this.retryLeft;
}
public void setRetryLeft(Integer retryLeft) {
this.retryLeft = retryLeft;
}
public static class EventWrapperBuilder {
private T event;
private String handlerName;
private Integer retryLeft;
EventWrapperBuilder() {
}
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public EventWrapperBuilder event(T event) {
this.event = event;
return this;
}
public EventWrapperBuilder handlerName(String handlerName) {
this.handlerName = handlerName;
return this;
}
public EventWrapperBuilder retryLeft(Integer retryLeft) {
this.retryLeft = retryLeft;
return this;
}
public EventWrapper build() {
return new EventWrapper<>(this.event, this.handlerName, this.retryLeft);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy