Skip to content

Commit

Permalink
fix(ws): implement periodic ping frame (#460)
Browse files Browse the repository at this point in the history
* fix(ws): implement periodic ping frame

* remove unused workers/schedulers
  • Loading branch information
andrewazores authored May 14, 2024
1 parent d67c297 commit 94134bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
23 changes: 0 additions & 23 deletions src/main/java/io/cryostat/Producers.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
package io.cryostat;

import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledExecutorService;

import io.cryostat.core.reports.InterruptibleReportGenerator;
import io.cryostat.core.sys.Clock;
Expand All @@ -32,7 +30,6 @@
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.projectnessie.cel.tools.ScriptHost;
Expand Down Expand Up @@ -60,12 +57,6 @@ public static FileSystem produceFileSystem() {
return new FileSystem();
}

@Produces
@ApplicationScoped
public static Base32 produceBase32() {
return new Base32();
}

@Produces
@ApplicationScoped
@DefaultBean
Expand All @@ -74,20 +65,6 @@ public static Base64 produceBase64Url() {
return new Base64(0, null, true);
}

@Produces
@ApplicationScoped
@DefaultBean
public static ExecutorService produceExecutorService() {
return ForkJoinPool.commonPool();
}

@Produces
@ApplicationScoped
@DefaultBean
public static ScheduledExecutorService produceScheduledExecutorService() {
return Executors.newSingleThreadScheduledExecutor();
}

@Produces
// RequestScoped so that each individual report generation request has its own interruptible
// generator with an independent task queueing thread which dispatches to the shared common pool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.function.Predicate;

import org.openjdk.jmc.flightrecorder.rules.IRule;
Expand Down Expand Up @@ -66,7 +65,6 @@ class StorageCachingReportsService implements ReportsService {
Duration expiry;

@Inject S3Client storage;
@Inject ExecutorService worker;
@Inject RecordingHelper recordingHelper;
@Inject ObjectMapper mapper;

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/cryostat/ws/MessagingServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package io.cryostat.ws;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.scheduler.Scheduled;
import io.quarkus.vertx.ConsumeEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand All @@ -38,6 +41,8 @@
public class MessagingServer {

private static final String CLIENT_ACTIVITY_CATEGORY = "WsClientActivity";
private static final ByteBuffer PING_MSG =
ByteBuffer.wrap("ping".getBytes(StandardCharsets.UTF_8));

@Inject ObjectMapper mapper;
@Inject Logger logger;
Expand Down Expand Up @@ -106,4 +111,16 @@ void broadcast(Notification notification) {
}
}));
}

@Scheduled(every = "${cryostat.websocket.ping-period:20s}")
void pingClients() {
sessions.forEach(
session -> {
try {
session.getBasicRemote().sendPing(PING_MSG);
} catch (IOException e) {
logger.debug(e);
}
});
}
}

0 comments on commit 94134bd

Please sign in to comment.