Class PlatformApi<P,R>

java.lang.Object
io.github.theword.queqiao.core.api.Api<P,R>
io.github.theword.queqiao.core.api.PlatformApi<P,R>
Type Parameters:
P - 负载类型
R - 返回类型
Direct Known Subclasses:
BroadcastApi, SendActionBarApi, SendPrivateMessageApi, SendTitleApi

public abstract class PlatformApi<P,R> extends Api<P,R>
依赖平台的协议 API 基类

用于表达"这个协议能力需要平台配合才能实现"。相对 Api,它多强制持有一样东西: AbstractPlatformContext。

三层职责边界:

 Api                     = 协议能力
 PlatformApi             = 依赖平台的协议能力(= Api + 平台上下文)
 AbstractPlatformContext = 平台能力本身
 

本类只负责:继承 Api、持有 Logger、强制持有平台上下文。 不要在这里增加 broadcast() / sendMessage() / sendTitle() / findPlayer() 之类的转发方法——那些能力属于 AbstractPlatformContext, 转发只会多出一层需要同步维护的薄壳。

线程安全:与 Api 相同,实例在多个连接、多个线程之间共享, 因此实现必须无状态;平台上下文本身也是构造期注入的协作者,不随请求变化。

  • Field Details

    • platform

      protected final AbstractPlatformContext<?,?,?> platform
      平台上下文

      由创建方注入,构造时即校验非 null,因此子类可以直接使用而不必再判空。

  • Constructor Details

    • PlatformApi

      protected PlatformApi(Class<P> payloadType, org.slf4j.Logger logger, AbstractPlatformContext<?,?,?> platform)
      Parameters:
      payloadType - 负载类型,不得为 null
      logger - 日志实现,不得为 null
      platform - 平台上下文,不得为 null