Skip to content

Commit 716eb62

Browse files
committed
Eagerly initialise the processor to get the reference tests passing
1 parent 35df99e commit 716eb62

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
quarkus.arc.selected-alternatives=io.a2a.server.apps.common.TestHttpClient
2+
3+
# Debug logging for event processing and request handling
4+
quarkus.log.category."io.a2a.server.events".level=DEBUG
5+
quarkus.log.category."io.a2a.server.requesthandlers".level=DEBUG
6+
quarkus.log.category."io.a2a.server.tasks".level=DEBUG

server-common/src/main/java/io/a2a/server/events/MainEventBusProcessor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* This architecture ensures clients never receive events before they're persisted,
3131
* eliminating race conditions and enabling reliable event replay.
3232
* </p>
33+
* <p>
34+
* <b>Note:</b> This bean is eagerly initialized by {@link MainEventBusProcessorInitializer}
35+
* to ensure the background thread starts automatically when the application starts.
36+
* </p>
3337
*/
3438
@ApplicationScoped
3539
public class MainEventBusProcessor implements Runnable {
@@ -79,6 +83,14 @@ void start() {
7983
LOGGER.info("MainEventBusProcessor started");
8084
}
8185

86+
/**
87+
* No-op method to force CDI proxy resolution and ensure @PostConstruct has been called.
88+
* Called by MainEventBusProcessorInitializer during application startup.
89+
*/
90+
public void ensureStarted() {
91+
// Method intentionally empty - just forces proxy resolution
92+
}
93+
8294
@PreDestroy
8395
void stop() {
8496
LOGGER.info("MainEventBusProcessor stopping...");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.a2a.server.events;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.enterprise.context.Initialized;
5+
import jakarta.enterprise.event.Observes;
6+
import jakarta.inject.Inject;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
/**
11+
* Portable CDI initializer for MainEventBusProcessor.
12+
* <p>
13+
* This bean observes the ApplicationScoped initialization event and injects
14+
* MainEventBusProcessor, which triggers its eager creation and starts the background thread.
15+
* </p>
16+
* <p>
17+
* This approach is portable across all Jakarta CDI implementations (Weld, OpenWebBeans, Quarkus, etc.)
18+
* and ensures MainEventBusProcessor starts automatically when the application starts.
19+
* </p>
20+
*/
21+
@ApplicationScoped
22+
public class MainEventBusProcessorInitializer {
23+
private static final Logger LOGGER = LoggerFactory.getLogger(MainEventBusProcessorInitializer.class);
24+
25+
@Inject
26+
MainEventBusProcessor processor;
27+
28+
/**
29+
* Observes ApplicationScoped initialization to force eager creation of MainEventBusProcessor.
30+
* The injection of MainEventBusProcessor in this bean triggers its creation, and calling
31+
* ensureStarted() forces the CDI proxy to be resolved, which ensures @PostConstruct has been
32+
* called and the background thread is running.
33+
*/
34+
void onStart(@Observes @Initialized(ApplicationScoped.class) Object event) {
35+
if (processor != null) {
36+
// Force proxy resolution to ensure @PostConstruct has been called
37+
processor.ensureStarted();
38+
LOGGER.info("MainEventBusProcessor initialized and started");
39+
} else {
40+
LOGGER.error("MainEventBusProcessor is null - initialization failed!");
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)