Refactor EventService to interface and implement EventServiceImpl; update EventsAutoConfiguration to use the new implementation
This commit is contained in:
@@ -2,25 +2,12 @@ package de.extio.game_engine.event;
|
|||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class EventService {
|
public interface EventService {
|
||||||
|
|
||||||
private final EventHandlerRegistry registry;
|
void register(Class<? extends Event> eventClass, String consumerId, Consumer<Event> consumer);
|
||||||
private final EventExecutor executor;
|
|
||||||
|
void unregister(Class<? extends Event> eventClass, String consumerId);
|
||||||
public EventService(final EventHandlerRegistry registry, final EventExecutor executor) {
|
|
||||||
this.registry = registry;
|
void fire(Event event);
|
||||||
this.executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(final Class<? extends Event> eventClass, final String consumerId, final Consumer<Event> consumer) {
|
|
||||||
this.registry.register(eventClass, consumerId, consumer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregister(final Class<? extends Event> eventClass, final String consumerId) {
|
|
||||||
this.registry.unregister(eventClass, consumerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fire(final Event event) {
|
|
||||||
this.executor.submit(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package de.extio.game_engine.event;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class EventServiceImpl implements EventService {
|
||||||
|
|
||||||
|
private final EventHandlerRegistry registry;
|
||||||
|
private final EventExecutor executor;
|
||||||
|
|
||||||
|
public EventServiceImpl(final EventHandlerRegistry registry, final EventExecutor executor) {
|
||||||
|
this.registry = registry;
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final Class<? extends Event> eventClass, final String consumerId, final Consumer<Event> consumer) {
|
||||||
|
this.registry.register(eventClass, consumerId, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unregister(final Class<? extends Event> eventClass, final String consumerId) {
|
||||||
|
this.registry.unregister(eventClass, consumerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fire(final Event event) {
|
||||||
|
this.executor.submit(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ public class EventsAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
EventService eventService(final EventHandlerRegistry registry, final EventExecutor executor) {
|
EventService eventService(final EventHandlerRegistry registry, final EventExecutor executor) {
|
||||||
final EventService eventService = new EventService(registry, executor);
|
final EventService eventService = new EventServiceImpl(registry, executor);
|
||||||
return eventService;
|
return eventService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user