Class DaRelaySender
Uses the settings from DaRelayListener.connect(java.lang.String, int, java.lang.String, java.lang.String, boolean) automatically, or call
init(java.lang.String, int, java.lang.String, java.lang.String, boolean) yourself on a server that only sends.
send(java.lang.String, java.lang.String) blocks on the network (connecting and waiting for the reply each time out
after 5 s), so from a game's main thread prefer sendAsync(java.lang.String, java.lang.String).
This is plain pub/sub: a message reaches the servers that are connected right now and nobody else. Nothing is stored or re-sent.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose()Close the sending connection and forget the settings.static voidConfigure the sender explicitly.static longPublish a message.static CompletableFuture<Long> Same assend(java.lang.String, java.lang.String), but runs off the calling thread.
-
Method Details
-
init
Configure the sender explicitly. Only needed if you never call DaRelayListener.connect(). -
send
Publish a message. Returns how many subscribers received it.If a connection that was already open turns out to be closed, the message is sent once more on a fresh one. A timeout is never retried, because the message may have gone out.
- Throws:
UncheckedIOException- if Valkey can't be reached or refuses the messageIllegalStateException- if neither init() nor DaRelayListener.connect() was called
-
sendAsync
Same assend(java.lang.String, java.lang.String), but runs off the calling thread. Messages go out in the order they were queued. A failure is logged and also completes the returned future exceptionally, so you may ignore the future if a log line is enough for you. -
close
public static void close()Close the sending connection and forget the settings. Called by DaRelayListener.shutdown(). Waits up to 2 s for messages already handed tosendAsync(java.lang.String, java.lang.String)to go out first.
-