Skip to content

Commit a039675

Browse files
author
Luqman Saeed
committed
Nitpick from jee-10 branch
1 parent 412da44 commit a039675

6 files changed

Lines changed: 1160 additions & 326 deletions

File tree

src/main/java/fish/payara/trader/aeron/AeronSubscriberBean.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.agrona.CloseHelper;
1919
import org.agrona.concurrent.BackoffIdleStrategy;
2020
import org.agrona.concurrent.IdleStrategy;
21+
import org.eclipse.microprofile.config.inject.ConfigProperty;
2122

2223
/**
2324
* Aeron Ingress Singleton Bean Launches an embedded MediaDriver and subscribes to market data
@@ -43,11 +44,20 @@ public class AeronSubscriberBean {
4344

4445
@Inject @VirtualThreadExecutor private ManagedExecutorService managedExecutorService;
4546

47+
@Inject
48+
@ConfigProperty(name = "TRADER_INGESTION_MODE", defaultValue = "AERON")
49+
private String ingestionMode;
50+
4651
void contextInitialized(@Observes @Initialized(ApplicationScoped.class) Object event) {
47-
managedExecutorService.submit(() -> init());
52+
managedExecutorService.submit(this::init);
4853
}
4954

5055
public void init() {
56+
if ("DIRECT".equalsIgnoreCase(ingestionMode)) {
57+
LOGGER.info("Running in DIRECT mode - Skipping Aeron/MediaDriver initialization.");
58+
return;
59+
}
60+
5161
LOGGER.info("Initializing Aeron Subscriber Bean...");
5262

5363
try {

src/main/java/fish/payara/trader/aeron/MarketDataPublisher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public class MarketDataPublisher {
5454
private final MarketDepthEncoder marketDepthEncoder = new MarketDepthEncoder();
5555
private final HeartbeatEncoder heartbeatEncoder = new HeartbeatEncoder();
5656

57-
// Buffer for encoding messages
58-
private final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_SIZE));
57+
private UnsafeBuffer buffer;
5958

6059
private final AtomicLong sequenceNumber = new AtomicLong(0);
6160
private final AtomicLong tradeIdGenerator = new AtomicLong(1000);
@@ -139,6 +138,9 @@ public void init() {
139138
return;
140139
}
141140

141+
// Initialize buffer only if in AERON mode
142+
this.buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(BUFFER_SIZE));
143+
142144
try {
143145
// Wait for AeronSubscriberBean to be ready (both observers fire at roughly same time)
144146
LOGGER.info("Waiting for AeronSubscriberBean to be ready...");

src/main/java/fish/payara/trader/rest/GCStatsResource.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public Response getComparison() {
7676
// Identify which JVM is running
7777
String jvmVendor = System.getProperty("java.vm.vendor");
7878
String jvmName = System.getProperty("java.vm.name");
79+
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
7980
String gcName =
80-
ManagementFactory.getGarbageCollectorMXBeans().stream()
81-
.map(GarbageCollectorMXBean::getName)
82-
.collect(Collectors.joining(", "));
81+
gcBeans.stream().map(GarbageCollectorMXBean::getName).collect(Collectors.joining(", "));
8382

84-
boolean isAzulC4 = jvmVendor != null && jvmVendor.contains("Azul");
83+
// More accurate check: C4 collector's MXBean is named "GPGC"
84+
boolean isAzulC4 = gcBeans.stream().anyMatch(bean -> "GPGC".equals(bean.getName()));
8585

8686
comparison.put("jvmVendor", jvmVendor);
8787
comparison.put("jvmName", jvmName);
@@ -91,6 +91,9 @@ public Response getComparison() {
9191

9292
// Current stress level
9393
comparison.put("allocationMode", memoryPressureService.getCurrentMode());
94+
comparison.put(
95+
"allocationRateMBps",
96+
memoryPressureService.getCurrentMode().getBytesPerSecond() / (1024 * 1024));
9497
comparison.put("messageRate", publisher.getMessagesPublished());
9598

9699
// GC Performance Metrics (keep old stats for backward compatibility)

src/main/java/fish/payara/trader/websocket/MarketDataBroadcaster.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.hazelcast.core.HazelcastInstance;
44
import com.hazelcast.topic.ITopic;
5-
import com.hazelcast.topic.Message;
6-
import com.hazelcast.topic.MessageListener;
75
import jakarta.annotation.PostConstruct;
86
import jakarta.enterprise.context.ApplicationScoped;
97
import jakarta.inject.Inject;
@@ -51,12 +49,9 @@ public void init() {
5149
if (hazelcastInstance != null) {
5250
clusterTopic = hazelcastInstance.getTopic(TOPIC_NAME);
5351
clusterTopic.addMessageListener(
54-
new MessageListener<String>() {
55-
@Override
56-
public void onMessage(Message<String> message) {
57-
// Broadcast to local WebSocket sessions only
58-
broadcastLocal(message.getMessageObject());
59-
}
52+
message -> {
53+
// Broadcast to local WebSocket sessions only
54+
broadcastLocal(message.getMessageObject());
6055
});
6156
LOGGER.info("Subscribed to Hazelcast topic: " + TOPIC_NAME + " (clustered mode)");
6257
} else {

0 commit comments

Comments
 (0)