refaturing message system, step 3: making use of queue
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -4,5 +4,5 @@ package de.srsoftware.umbrella.core.api;
|
||||
import de.srsoftware.umbrella.core.model.Envelope;
|
||||
|
||||
public interface PostBox {
|
||||
public void send(Envelope envelope);
|
||||
public void send(Envelope<?> envelope);
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@ import java.util.stream.Collectors;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Envelope<T> {
|
||||
private final Message<T> message;
|
||||
public class Envelope<T extends Message<?>> {
|
||||
private final T message;
|
||||
private final Set<User> receivers;
|
||||
private final LocalDateTime time;
|
||||
|
||||
public Envelope(Message<T> message, User receiver){
|
||||
public Envelope(T message, User receiver){
|
||||
this(message,new HashSet<>(Set.of(receiver)));
|
||||
}
|
||||
|
||||
public Envelope(Message<T> message, HashSet<User> receivers) {
|
||||
public Envelope(T message, HashSet<User> receivers) {
|
||||
this.message = message;
|
||||
this.receivers = receivers;
|
||||
time = LocalDateTime.now();
|
||||
@@ -38,7 +38,7 @@ public class Envelope<T> {
|
||||
* @return
|
||||
* @throws UmbrellaException
|
||||
*/
|
||||
public static Envelope from(JSONObject json) throws UmbrellaException {
|
||||
public static Envelope<TranslatedMessage> from(JSONObject json) throws UmbrellaException {
|
||||
if (!json.has(RECEIVERS)) throw missingField(RECEIVERS);
|
||||
var message = TranslatedMessage.from(json);
|
||||
var obj = json.get(RECEIVERS);
|
||||
@@ -49,12 +49,12 @@ public class Envelope<T> {
|
||||
if (!(o instanceof JSONObject receiverData)) throw invalidField("entries of "+ RECEIVERS, t(JSONOBJECT));
|
||||
receivers.add(User.of(receiverData));
|
||||
}
|
||||
return new Envelope(message,receivers);
|
||||
return new Envelope<>(message,receivers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof Envelope envelope)) return false;
|
||||
if (!(o instanceof Envelope<?> envelope)) return false;
|
||||
return message.equals(envelope.message) && time.equals(envelope.time);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class Envelope<T> {
|
||||
return receivers.contains(receiver);
|
||||
}
|
||||
|
||||
public Message<T> message(){
|
||||
public T message(){
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user