Class PlayerLinkChannel
- All Implemented Interfaces:
CloudPlayerLinks.Transport
CloudPlayerLinks: it frames
player.link.create, correlates the answer by envelope id, delivers completions and
expiries to the single owning module, and records each completion result in the shared ledger
before answering the gateway.
Pending creates are keyed by the envelope id the channel reports for the frame it just sent. A completion whose create is still pending without an answer waits for that answer so the module sees the link before the completion; a completion that arrives after a restart, with no create pending in this run, is delivered straight away.
Order of a completion result: the result is recorded and persisted in the ledger under the
completion's envelope id before the player.link.completed.result frame is handed to the
socket. A redelivery of that id finds the recorded result and re-sends it without calling the
handler again. A handler that does not answer in time sends nothing, so the gateway redelivers.
The result of a handler call is sent on the connection that is live when the handler finishes, not on the one the completion arrived on: the module may work for seconds, long enough for the socket to be replaced. If no connection is open at that moment, nothing is sent and the persisted receipt answers the next redelivery.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classA completion that arrived before its create was answered.private static final classThe owning module and its handler.private static final classOne create this run issued and has not answered yet.private static final classThe player fields shared by completions and expiries. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Supplier<CloudChannel> private final LongSupplierprivate final AtomicReference<PlayerLinkChannel.Owner> (package private) static final longHow long the handler may take before the framework stops waiting and sends no result.private final Executorprivate final DedupeLedgerprivate static final Patternprivate static final Loggerprivate static final longprivate final BooleanSupplierprivate final Map<String, PlayerLinkChannel.Pending> (package private) static final longHow long the gateway may take to answer one create, or one handler to answer a completion.private final ShutdownGate.Signalprivate final ScheduledExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionPlayerLinkChannel(Supplier<CloudChannel> channel, DedupeLedger ledger, BooleanSupplier onlineMode, LongSupplier gatewayClockOffsetMillis, ScheduledExecutorService timers, Executor handlerThread) Binds the channel to one connection's suppliers and to the shared session ledger.PlayerLinkChannel(Supplier<CloudChannel> channel, DedupeLedger ledger, BooleanSupplier onlineMode, LongSupplier gatewayClockOffsetMillis, ScheduledExecutorService timers, Executor handlerThread, ShutdownGate.Signal shutdown) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidanswer(CloudChannel connection, String id, com.google.gson.JsonObject result) private booleancallHandler(CloudPlayerLinks.LinkEventHandler target, CloudPlayerLinks.LinkCompletion completion, CloudChannel connection, String id, Runnable exit) private static voidcancel(PlayerLinkChannel.Pending pending) private CloudPlayerLinks.LinkCompletioncompletionOf(CloudRequest request) create(UltiToolsPlugin requester, UUID playerUuid, String playerName, CloudPlayerLinks.GameAuth gameAuth, Set<CloudPlayerLinks.LinkProof> offeredProofs) Sends oneplayer.link.createand tracks its answer.private com.google.gson.JsonObjectcreatePayload(UUID playerUuid, String playerName, CloudPlayerLinks.GameAuth gameAuth, Set<CloudPlayerLinks.LinkProof> offeredProofs) private Runnableprivate voiddeliver(CloudPlayerLinks.LinkCompletion completion, CloudChannel connection) Delivers one completion to the module's handler, or answers it when no handler is set.private static com.google.gson.JsonObjecterrorResult(String code, String message) private RunnableexitOnce()private voidexpireCreate(String id) private static CloudPlayerLinks.ExpiryReasonexpiryReason(String reason) private static CloudPlayerLinks.Failureprivate voidinvokeHandler(CloudPlayerLinks.LinkEventHandler target, CloudPlayerLinks.LinkCompletion completion, CloudChannel connection, String id, Runnable exit) private static com.google.gson.JsonObjectnoHandlerResult(CloudPlayerLinks.LinkCompletion completion) private static CompletableFuture<CloudPlayerLinks.LinkCreation> private static com.google.gson.JsonObject(package private) voidCompletes every pending create as not connected when the connection closes; held completions are dropped because the gateway redelivers them after the next welcome.private voidonCompleted(CloudRequest request, CloudChannel connection) private voidonCreated(CloudRequest request, CloudChannel connection) (package private) voidonErrorReply(CloudRequest request) Answers a correlatederrorreply for a create this run issued.private voidonExpired(CloudRequest request, CloudChannel connection) private static PlayerLinkChannel.Playerprivate static List<CloudPlayerLinks.LinkProof> proofs(com.google.gson.JsonArray array) (package private) voidregister(AgentMessageRouter router) Registers this channel's handlers for the three link messages and for correlated errors.voidremoveHandler(UltiToolsPlugin owner) Removes the handler ifownerset it.private static com.google.gson.JsonObjectprivate voidsendResult(CloudChannel connection, String id, com.google.gson.JsonObject result) voidsetHandler(UltiToolsPlugin owner, CloudPlayerLinks.LinkEventHandler handler) Installs the single-owner handler.private static StringwireOf(CloudPlayerLinks.LinkProof proof)
-
Field Details
-
LOGGER
-
REQUEST_DEADLINE_MS
static final long REQUEST_DEADLINE_MSHow long the gateway may take to answer one create, or one handler to answer a completion.- See Also:
-
HANDLER_DEADLINE_MS
static final long HANDLER_DEADLINE_MSHow long the handler may take before the framework stops waiting and sends no result.- See Also:
-
LINK_URL
-
MAX_CLOCK_VALUE
private static final long MAX_CLOCK_VALUE- See Also:
-
channel
-
ledger
-
onlineMode
-
gatewayClockOffsetMillis
-
timers
-
handlerThread
-
shutdown
-
pendingCreates
-
busyCompletions
-
handler
-
-
Constructor Details
-
PlayerLinkChannel
PlayerLinkChannel(Supplier<CloudChannel> channel, DedupeLedger ledger, BooleanSupplier onlineMode, LongSupplier gatewayClockOffsetMillis, ScheduledExecutorService timers, Executor handlerThread) Binds the channel to one connection's suppliers and to the shared session ledger.- Parameters:
channel- supplies the current connection, or null while none existsledger- the shared session ledger and synchronization monitoronlineMode- reports this server's online-mode settinggatewayClockOffsetMillis- the gateway clock minus the framework clock, in millisecondstimers- schedules the create and handler deadlineshandlerThread- runs the owning module's handler
-
PlayerLinkChannel
PlayerLinkChannel(Supplier<CloudChannel> channel, DedupeLedger ledger, BooleanSupplier onlineMode, LongSupplier gatewayClockOffsetMillis, ScheduledExecutorService timers, Executor handlerThread, ShutdownGate.Signal shutdown) - Parameters:
channel- supplies the current connection, or null while none existsledger- the shared session ledger and synchronization monitoronlineMode- reports this server's online-mode settinggatewayClockOffsetMillis- the gateway clock minus the framework clock, in millisecondstimers- schedules the create and handler deadlineshandlerThread- runs the owning module's handlershutdown- the shutdown signal (ShutdownGate): a completion is delivered only with a permit, which is returned when the handler's work and the receipt end (22-23 second verification); refused, the completion is left unanswered for redelivery after the next welcome
-
-
Method Details
-
register
Registers this channel's handlers for the three link messages and for correlated errors.- Parameters:
router- the session's message router
-
create
public CompletableFuture<CloudPlayerLinks.LinkCreation> create(UltiToolsPlugin requester, UUID playerUuid, String playerName, CloudPlayerLinks.GameAuth gameAuth, Set<CloudPlayerLinks.LinkProof> offeredProofs) Description copied from interface:CloudPlayerLinks.TransportSends oneplayer.link.createand tracks its answer.- Specified by:
createin interfaceCloudPlayerLinks.Transport- Parameters:
requester- the calling moduleplayerUuid- the player's UUIDplayerName- the player's namegameAuth- the game-authentication factsofferedProofs- the supported proofs- Returns:
- the answer future, never null
-
setHandler
Description copied from interface:CloudPlayerLinks.TransportInstalls the single-owner handler.- Specified by:
setHandlerin interfaceCloudPlayerLinks.Transport- Parameters:
owner- the owning modulehandler- the handler
-
removeHandler
Description copied from interface:CloudPlayerLinks.TransportRemoves the handler ifownerset it.- Specified by:
removeHandlerin interfaceCloudPlayerLinks.Transport- Parameters:
owner- the owning module
-
onChannelClosed
void onChannelClosed()Completes every pending create as not connected when the connection closes; held completions are dropped because the gateway redelivers them after the next welcome. -
deadlineOfCreate
-
expireCreate
-
onCreated
-
onCompleted
-
deliver
Delivers one completion to the module's handler, or answers it when no handler is set. Runs with its own shutdown permit (22-23 second verification), whichever thread delivers it -- the connection thread, the timer of a create's deadline, or the connection thread of a laterplayer.link.createdfor a held completion -- and returns it only when the handler's work and the receipt have ended; refused, the completion is left for the gateway to deliver again after the next welcome, exactly asShutdownGateleaves it. -
exitOnce
- Returns:
- a hook that returns this delivery's shutdown permit the first time it runs
-
invokeHandler
private void invokeHandler(CloudPlayerLinks.LinkEventHandler target, CloudPlayerLinks.LinkCompletion completion, CloudChannel connection, String id, Runnable exit) -
callHandler
private boolean callHandler(CloudPlayerLinks.LinkEventHandler target, CloudPlayerLinks.LinkCompletion completion, CloudChannel connection, String id, Runnable exit) - Returns:
- whether the permit now belongs to the handler's future (returned by
exitwhen it settles)
-
onExpired
-
onErrorReply
Answers a correlatederrorreply for a create this run issued.- Parameters:
request- the parsed error frame
-
answer
-
sendResult
-
notConnected
-
createPayload
private com.google.gson.JsonObject createPayload(UUID playerUuid, String playerName, CloudPlayerLinks.GameAuth gameAuth, Set<CloudPlayerLinks.LinkProof> offeredProofs) -
completionOf
-
playerOf
-
proofs
-
wireOf
-
failure
-
expiryReason
-
noHandlerResult
private static com.google.gson.JsonObject noHandlerResult(CloudPlayerLinks.LinkCompletion completion) -
resultOf
-
okResult
-
errorResult
-
cancel
-