preparing message bus
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
public class Event {
|
||||
public enum Type{
|
||||
CREATE,
|
||||
UPDATE,
|
||||
DELETE
|
||||
}
|
||||
|
||||
private UmbrellaUser initiator;
|
||||
private String realm;
|
||||
private Object payload;
|
||||
private Type type;
|
||||
|
||||
public Event(UmbrellaUser initiator, String realm, Object payload, Type type){
|
||||
this.initiator = initiator;
|
||||
this.realm = realm;
|
||||
this.payload = payload;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
public interface EventListener {
|
||||
public void onEvent(Event event);
|
||||
void onEvent(Event event);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MessageApi implements EventListener{
|
||||
|
||||
private static final System.Logger LOG = System.getLogger(MessageApi.class.getSimpleName());
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
LOG.log(System.Logger.Level.DEBUG,"received {0}",event.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,13 @@ public class MessageBus {
|
||||
private MessageBus(){}
|
||||
|
||||
public void dispatch(Event event){
|
||||
listeners.parallelStream().forEach(l -> l.onEvent(event));
|
||||
new Thread(() -> { // TODO: use thread pool
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
listeners.parallelStream().forEach(l -> l.onEvent(event));
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void drop(EventListener listener){
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.umbrella.messagebus;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.TASK;
|
||||
|
||||
public class TaskEvent extends Event{
|
||||
public TaskEvent(UmbrellaUser initiator,Object payload, Type type){
|
||||
super(initiator,TASK,payload, type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user