Refactor EventService to interface and implement EventServiceImpl; update EventsAutoConfiguration to use the new implementation

This commit is contained in:
extio-de
2025-12-21 23:50:42 +01:00
parent bcf44bb8e2
commit eb6d5729b6
3 changed files with 38 additions and 22 deletions

View File

@@ -2,25 +2,12 @@ package de.extio.game_engine.event;
import java.util.function.Consumer;
public class EventService {
private final EventHandlerRegistry registry;
private final EventExecutor executor;
public EventService(final EventHandlerRegistry registry, final EventExecutor executor) {
this.registry = registry;
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);
}
public interface EventService {
void register(Class<? extends Event> eventClass, String consumerId, Consumer<Event> consumer);
void unregister(Class<? extends Event> eventClass, String consumerId);
void fire(Event event);
}

View File

@@ -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);
}
}

View File

@@ -20,7 +20,7 @@ public class EventsAutoConfiguration {
@Bean
EventService eventService(final EventHandlerRegistry registry, final EventExecutor executor) {
final EventService eventService = new EventService(registry, executor);
final EventService eventService = new EventServiceImpl(registry, executor);
return eventService;
}
}