Skip to content

Commit

Permalink
⚡ Cache results of RustTeams query
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGraversen committed Oct 2, 2023
1 parent fe4fdc8 commit 39654f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public List<FullRustPlayer> players() {

@Override
public List<RustTeam> teams() {
return null;
return rustTeams.get();
}

@Override
Expand Down Expand Up @@ -154,6 +154,7 @@ protected void configure() {
registerInternalTask(rustTeamsEmitTask, Duration.ofMinutes(5), Duration.ofSeconds(10));
registerRustDiagnosticsListener();
registerRustPlayerEventListener();
registerRustTeamsEventListener();
}

protected ScheduledExecutorService createScheduledExecutorService() {
Expand Down Expand Up @@ -248,6 +249,11 @@ private void registerRustPlayerEventListener() {
registerEvents(new RustPlayerEventListener(rustPlayers::set));
}

private void registerRustTeamsEventListener() {
log.info("Registering {}", RustTeamsEventListener.class.getSimpleName());
registerEvents(new RustTeamsEventListener(rustTeams::set));
}

private void runConfigure() {
log.info("Running internal configuration hook");
configure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RustPlayerEventListener {
private final @NonNull Consumer<List<FullRustPlayer>> rustPlayersConsumer;

@Subscribe
public void onServerInfo(RustPlayersEvent rustPlayersEvent) {
public void onRustPlayers(RustPlayersEvent rustPlayersEvent) {
final var rustPlayers = mapRustPlayers().apply(rustPlayersEvent);
rustPlayersConsumer.accept(rustPlayers);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/graversen/rust/rcon/RustTeamsEventListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.graversen.rust.rcon;

import com.google.common.eventbus.Subscribe;
import io.graversen.rust.rcon.event.server.RustTeamsEvent;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.function.Consumer;

@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class RustTeamsEventListener {
private final @NonNull Consumer<List<RustTeam>> rustTeamsConsumer;

@Subscribe
public void onRustTeams(RustTeamsEvent rustTeamsEvent) {
rustTeamsConsumer.accept(rustTeamsEvent.getRustTeams());
}
}

0 comments on commit 39654f9

Please sign in to comment.