Package com.btcvelocity.api.storage
Interface StorageService
public interface StorageService
Asynchronous storage service for persisting player data and proxy state
to a durable backend (PostgreSQL).
All methods are non-blocking and return CompletableFutures.
Callers should never block on the returned futures from a Netty event
loop thread. Operations are dispatched to a dedicated thread pool so
that database I/O never stalls the proxy's network threads.
Implementations must use parameterized queries to protect against SQL injection. Any exception encountered during a database operation completes the returned future exceptionally.
-
Method Summary
Modifier and TypeMethodDescriptionRetrieves the persisted data for the player with the given UUID.getPlayerByName(String username) Retrieves the persisted data for the player with the given username.updatePlayerLastSeen(UUID uuid, String serverName, long lastSeen) Updates thelast_seentimestamp and current server for the player with the given UUID.updateProxyHeartbeat(String proxyId, int playerCount, long uptimeSeconds) Updates the heartbeat row for the specified proxy, recording the current player count and uptime.upsertPlayer(PlayerData data) Inserts or updates the persisted record for the given player.
-
Method Details
-
upsertPlayer
Inserts or updates the persisted record for the given player.If a row with the same UUID already exists, all columns are updated to the values in
data. Otherwise a new row is inserted.- Parameters:
data- the player data to persist; must not benull- Returns:
- a future that completes when the upsert is done, or completes exceptionally on database error
-
getPlayer
Retrieves the persisted data for the player with the given UUID.- Parameters:
uuid- the player's unique identifier; must not benull- Returns:
- a future that completes with an
Optionalcontaining the player data, or an empty optional if no row was found; completes exceptionally on database error
-
getPlayerByName
Retrieves the persisted data for the player with the given username.The lookup is case-insensitive.
- Parameters:
username- the player's username; must not benull- Returns:
- a future that completes with an
Optionalcontaining the player data, or an empty optional if no row was found; completes exceptionally on database error
-
updateProxyHeartbeat
Updates the heartbeat row for the specified proxy, recording the current player count and uptime.If no row exists for the given
proxyId, one is inserted.- Parameters:
proxyId- the proxy identifier; must not benullplayerCount- the current number of players on the proxyuptimeSeconds- the proxy uptime in seconds- Returns:
- a future that completes when the heartbeat is written, or completes exceptionally on database error
-
updatePlayerLastSeen
Updates thelast_seentimestamp and current server for the player with the given UUID.- Parameters:
uuid- the player's unique identifier; must not benullserverName- the name of the server the player is now on, ornullto clear itlastSeen- the epoch millisecond timestamp to record- Returns:
- a future that completes when the update is done, or completes exceptionally on database error
-