feat(module): Integrate EventService into ModuleService for event management

This commit is contained in:
extio-de
2025-12-26 15:58:09 +01:00
parent 64adf9c9f9
commit b48ac87ae5
4 changed files with 36 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import de.extio.game_engine.event.EventService;
import de.extio.game_engine.renderer.work.RendererWorkingSet;
@AutoConfiguration
@@ -14,8 +15,8 @@ public class ModuleServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
ModuleService moduleService(final ApplicationContext applicationContext, final RendererWorkingSet rendererWorkingSet) {
return new ModuleServiceImpl(applicationContext, rendererWorkingSet);
ModuleService moduleService(final ApplicationContext applicationContext, final RendererWorkingSet rendererWorkingSet, final EventService eventService) {
return new ModuleServiceImpl(applicationContext, rendererWorkingSet, eventService);
}
@Bean

View File

@@ -17,6 +17,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import de.extio.game_engine.event.EventService;
import de.extio.game_engine.renderer.work.RendererWorkingSet;
public class ModuleServiceImpl implements ModuleService, ApplicationListener<ContextRefreshedEvent> {
@@ -30,6 +31,8 @@ public class ModuleServiceImpl implements ModuleService, ApplicationListener<Con
private final Map<String, AbstractModule> modulesByIdMap = new ConcurrentHashMap<>();
private final RendererWorkingSet rendererWorkingSet;
private final EventService eventService;
private List<AbstractModule> modulesAllView = List.of();
@@ -47,9 +50,10 @@ public class ModuleServiceImpl implements ModuleService, ApplicationListener<Con
private final Map<ModuleExecutorCallbacks, List<AbstractModule>> executorCallbackMap = Collections.synchronizedMap(new EnumMap<>(ModuleExecutorCallbacks.class));
public ModuleServiceImpl(ApplicationContext applicationContext, final RendererWorkingSet rendererWorkingSet) {
public ModuleServiceImpl(ApplicationContext applicationContext, final RendererWorkingSet rendererWorkingSet, final EventService eventService) {
this.applicationContext = applicationContext;
this.rendererWorkingSet = rendererWorkingSet;
this.eventService = eventService;
}
@@ -123,6 +127,8 @@ public class ModuleServiceImpl implements ModuleService, ApplicationListener<Con
}
this.invokeSafe(module, m -> m.onUnload());
this.eventService.unregisterAll(module.getId());
if (module instanceof final AbstractClientModule clientModule) {
this.rendererWorkingSet.clear(clientModule.getId());
}
@@ -153,6 +159,7 @@ public class ModuleServiceImpl implements ModuleService, ApplicationListener<Con
.map(m -> (AbstractClientModule) m)
.toList();
}
this.eventService.unregisterAll(module.getId());
if (module instanceof final AbstractClientModule clientModule) {
this.rendererWorkingSet.clear(clientModule.getId());
}
@@ -164,6 +171,7 @@ public class ModuleServiceImpl implements ModuleService, ApplicationListener<Con
}
}
}
this.invokeSafe(module, AbstractModule::onDeactivate);
LOGGER.info("Deactivated {}", id);

View File

@@ -70,7 +70,7 @@ public class Container extends AbstractClientModule implements InitializingBean
@Override
public void onDeactivate() {
this.eventService.unregister(ViewportResizeEvent.class, this.id);
}
protected void onViewportResize(final ViewportResizeEvent event) {