CONFIG - 对应的插件配置类类型SEND - sender送信器对应类型SET - setter送信器对应类型GET - getter送信器对应类型public abstract class BaseApplication<CONFIG extends BaseConfiguration,SEND extends SenderSendList,SET extends SenderSetList,GET extends SenderGetList,APPLICATION extends BaseApplication,CONTEXT extends SimpleRobotContext<SEND,SET,GET,CONFIG,APPLICATION>> extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
protected static class |
BaseApplication.DefaultSenders<SEND extends SenderSendList,SET extends SenderSetList,GET extends SenderGetList>
三个送信器的临时承载类
|
| Modifier and Type | Field and Description |
|---|---|
protected static QQLogLang |
RUN_LOG
启动器使用的日志,前缀为“run”
|
| Constructor and Description |
|---|
BaseApplication()
无参构造
|
BaseApplication(QQLogBack qqLogBack)
日志拦截构造
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
__$f$__() |
protected void |
_hello$()
打个招呼
|
protected void |
afterDepend(CONFIG config,
Application<CONFIG> app,
Register register,
DependCenter dependCenter)
依赖扫描之后
同时也是监听函数扫描之前
|
protected Consumer<Class<?>[]>[] |
afterListener(CONFIG config,
Application<CONFIG> app)
监听函数扫描之后
|
protected void |
afterStart(CONFIG config)
服务启动后, 构建无参数送信器之前
|
protected void |
beforeDepend(CONFIG config,
Application<CONFIG> app,
Register register)
依赖扫描之前
|
protected void |
beforeRegisterListener(CONFIG config,
Application<CONFIG> app,
ListenerMethodScanner scanner,
DependCenter dependCenter)
监听函数注册之前,可以执行重写并进行额外的监听注入
|
protected void |
beforeStart(CONFIG config)
服务启动前
|
void |
close()
默认情况下会执行
DependCenter的close方法。 |
abstract void |
doClose()
do for close
|
protected String[] |
getArgs()
直接返回参数列表对象。
|
BotManager |
getBotManager()
获取账号管理器,在dependCenter初始化完成被初始化
|
protected abstract CONTEXT |
getComponentContext(BaseApplication.DefaultSenders<SEND,SET,GET> defaultSenders,
BotManager manager,
MsgParser msgParser,
MsgProcessor processor,
DependCenter dependCenter,
CONFIG config)
获取一个组件专属的SimpleRobotContext对象
|
protected CONFIG |
getConf()
获取Config对象。如果尚未初始化则会优先初始化
|
protected abstract CONFIG |
getConfiguration()
开发者实现的获取Config对象实例的方法
此方法将会最先被执行,并会将值保存,使用时可使用
getConf() 方法获取 |
protected Object |
getContext(String key) |
protected abstract GET |
getDefaultGetter(BotManager botManager)
提供一个BotManager,将其转化为默认的GetList。一般情况下,Default送信器只会实例化一次。
|
protected MsgSender |
getDefaultMsgSender(DependCenter dependCenter,
ListenerManager manager,
BotRuntime runtime,
SenderSendList sender,
SenderSetList setter,
SenderGetList getter)
获取一个不使用在监听函数中的默认送信器
1.12.x: 此方法不再作为抽象方法,并默认使用BotManager中的DefaultBot进行送信
|
protected abstract SEND |
getDefaultSender(BotManager botManager)
提供一个BotManager,将其转化为默认的SendList。一般情况下,Default送信器只会实例化一次。
|
protected BaseApplication.DefaultSenders<SEND,SET,GET> |
getDefaultSenders(BotManager botManager)
根据
getDefaultSender(BotManager), getDefaultSetter(BotManager), getDefaultGetter(BotManager) 三个函数构建一个RootSenderList
参数分别为一个BotManager和一个MsgGet对象
如果组件不是分为三个部分而构建,则可以考虑重写此函数 |
protected abstract SET |
getDefaultSetter(BotManager botManager)
提供一个BotManager,将其转化为默认的SetList。一般情况下,Default送信器只会实例化一次。
|
DependCenter |
getDependCenter()
获取依赖获取器
|
protected abstract GET |
getGetter(MsgGet msgGet,
BotManager botManager)
提供一个msgGet,将其转化为GetList
|
protected QQLogLang |
getLog()
获取日志对象
|
protected MsgParser |
getMsgParser()
获取MsgParser函数, 默认根据
msgParse(String)生成 |
MsgSender |
getMsgSender()
获取空函数送信器
※ 此送信器无法进行阻断 |
protected Function<MsgGet,RootSenderList> |
getRootSenderFunction(BotManager botManager)
根据
getSender(MsgGet, BotManager), getSetter(MsgGet, BotManager), getGetter(MsgGet, BotManager) 三个函数构建一个RootSenderList
参数分别为一个BotManager和一个MsgGet对象
如果组件不是分为三个部分而构建,则可以考虑重写此函数
此函数最终会被送入组件实现的runServer(DependCenter, ListenerManager, MsgProcessor, MsgParser)中 |
protected abstract SEND |
getSender(MsgGet msgGet,
BotManager botManager)
提供一个msgGet,将其转化为SendList
|
protected abstract SET |
getSetter(MsgGet msgGet,
BotManager botManager)
提供一个msgGet,将其转化为SetList
|
Object |
getSpecialApi()
Deprecated.
|
boolean |
isClosed()
判断是否已经关闭了
|
protected abstract MsgGet |
msgParse(String str)
字符串转化为MsgGet的方法,最终会被转化为
MsgParser函数,
会作为参数传入runServer(DependCenter, ListenerManager, MsgProcessor, MsgParser), 也会封装进SimpleRobotContext中 |
protected abstract void |
resourceInit()
开发者实现的资源初始化
此方法将会在所有的无配置初始化方法最后执行
将会在用户配置之前执行
|
protected abstract void |
resourceInit(CONFIG config)
开发者实现的资源初始化
此方法将会在所有的初始化方法最后执行
增加一个参数
此资源配置将会在配置之后执行
|
CONTEXT |
run(Application<CONFIG> app,
String... args)
执行的主程序
|
CONTEXT |
run(Class<?> appClass,
String... args)
使用一个Class来指定启动器。
如果这个类存在
SimpleRobotApplication注解,则以注解信息为主。
如果不存在,则判断是否为Application接口的子类。如果是,尝试实例化,否则抛出异常。 |
static SimpleRobotContext |
runAuto(Class appClass,
ClassLoader classLoader,
String... args)
根据启动器类和自动装载的组件启动器来自动启动
|
static SimpleRobotContext |
runAuto(Class appClass,
String... args)
根据启动器类和自动装载的组件启动器来自动启动
|
protected abstract String |
runServer(DependCenter dependCenter,
ListenerManager manager,
MsgProcessor msgProcessor,
MsgParser msgParser)
启动一个服务,这有可能是http或者是ws的监听服务
|
CONTEXT |
runWithApplication(Application<CONFIG> app,
String... args)
使一个实例也可以进行注解解析。
此时,
SimpleRobotApplication.application() 参数将会失效 |
protected void |
setArgs(String[] args)
设置执行参数
|
protected void |
setContext(String key,
Object value) |
protected ExecutorService |
threadPoolInit(CONFIG config)
线程工厂初始化
|
protected VerifyFunction |
verifyBot()
获取账号验证的函数
|
protected BotInfo[] |
verifyBot(Map<String,List<BotInfo>> confBotInfos)
启动时候的初始验证函数
|
protected abstract BotInfo |
verifyBot(String code,
BotInfo info)
start之前,会先对账号进行验证。将会使用此方法对注册的bot账号信息进行验证。
|
protected static final QQLogLang RUN_LOG
public BaseApplication()
public BaseApplication(QQLogBack qqLogBack)
protected QQLogLang getLog()
protected ExecutorService threadPoolInit(CONFIG config)
protected abstract void resourceInit(CONFIG config)
protected abstract void resourceInit()
protected abstract SEND getSender(MsgGet msgGet, BotManager botManager)
msgGet - msgGetSenderSendListprotected abstract SET getSetter(MsgGet msgGet, BotManager botManager)
msgGet - msgGetSenderSetListprotected abstract GET getGetter(MsgGet msgGet, BotManager botManager)
msgGet - msgGetSenderGetListprotected abstract SEND getDefaultSender(BotManager botManager)
SenderSendListprotected abstract SET getDefaultSetter(BotManager botManager)
SenderSetListprotected abstract GET getDefaultGetter(BotManager botManager)
SenderGetListprotected Function<MsgGet,RootSenderList> getRootSenderFunction(BotManager botManager)
getSender(MsgGet, BotManager), getSetter(MsgGet, BotManager), getGetter(MsgGet, BotManager) 三个函数构建一个RootSenderList
参数分别为一个BotManager和一个MsgGet对象
如果组件不是分为三个部分而构建,则可以考虑重写此函数
此函数最终会被送入组件实现的runServer(DependCenter, ListenerManager, MsgProcessor, MsgParser)中protected BaseApplication.DefaultSenders<SEND,SET,GET> getDefaultSenders(BotManager botManager)
getDefaultSender(BotManager), getDefaultSetter(BotManager), getDefaultGetter(BotManager) 三个函数构建一个RootSenderList
参数分别为一个BotManager和一个MsgGet对象
如果组件不是分为三个部分而构建,则可以考虑重写此函数protected abstract CONTEXT getComponentContext(BaseApplication.DefaultSenders<SEND,SET,GET> defaultSenders, BotManager manager, MsgParser msgParser, MsgProcessor processor, DependCenter dependCenter, CONFIG config)
defaultSenders - 函数getDefaultSenders(BotManager)的最终返回值manager - botManager对象msgParser - 消息字符串转化函数processor - 消息处理器dependCenter - 依赖中心protected MsgParser getMsgParser()
msgParse(String)生成protected BotInfo[] verifyBot(Map<String,List<BotInfo>> confBotInfos)
confBotInfos - protected abstract BotInfo verifyBot(String code, BotInfo info)
start之前,会先对账号进行验证。将会使用此方法对注册的bot账号信息进行验证。鉴于机制的变更,最好在bot初始化的时候便将每个bot所对应的sender初始化结束。此验证函数后续会被注入至BotManager对象中用于动态验证。推荐在验证失败的时候抛出异常。
code - 用户账号,可能为nullinfo - 用于验证的bot,一般来讲应当至少存在一个pathprotected VerifyFunction verifyBot()
@Deprecated public Object getSpecialApi()
protected MsgSender getDefaultMsgSender(DependCenter dependCenter, ListenerManager manager, BotRuntime runtime, SenderSendList sender, SenderSetList setter, SenderGetList getter)
dependCenter - 依赖中心manager - 监听器管理中心protected abstract String runServer(DependCenter dependCenter, ListenerManager manager, MsgProcessor msgProcessor, MsgParser msgParser)
dependCenter - 依赖中心manager - 监听管理器msgProcessor - 送信解析器protected abstract MsgGet msgParse(String str)
MsgParser函数,
会作为参数传入runServer(DependCenter, ListenerManager, MsgProcessor, MsgParser), 也会封装进SimpleRobotContext中str - protected abstract CONFIG getConfiguration()
getConf() 方法获取protected CONFIG getConf()
protected void beforeDepend(CONFIG config, Application<CONFIG> app, Register register)
config - 配置文件app - 启动器接口实现类register - 注册器protected void afterDepend(CONFIG config, Application<CONFIG> app, Register register, DependCenter dependCenter)
protected Consumer<Class<?>[]>[] afterListener(CONFIG config, Application<CONFIG> app)
protected void beforeStart(CONFIG config)
protected void afterStart(CONFIG config)
protected void beforeRegisterListener(CONFIG config, Application<CONFIG> app, ListenerMethodScanner scanner, DependCenter dependCenter)
public CONTEXT run(Class<?> appClass, String... args)
SimpleRobotApplication注解,则以注解信息为主。
如果不存在,则判断是否为Application接口的子类。如果是,尝试实例化,否则抛出异常。appClass - 启动类args - 参数public CONTEXT runWithApplication(Application<CONFIG> app, String... args)
SimpleRobotApplication.application() 参数将会失效app - 启动器实例args - java执行参数public static SimpleRobotContext runAuto(Class appClass, ClassLoader classLoader, String... args) throws IOException
appClass - 携带SimpleRobotApplication注解的启动器类classLoader - 使用的类加载器args - 参数SimpleRobotContextIOExceptionpublic static SimpleRobotContext runAuto(Class appClass, String... args) throws IOException
appClass - 携带SimpleRobotApplication注解的启动器类args - 参数SimpleRobotContextIOExceptionpublic CONTEXT run(Application<CONFIG> app, String... args)
app - 启动器接口的实现类args - 可能会有用的额外指令参数,一般是main方法的参数protected void setArgs(String[] args)
args - 执行参数数组protected String[] getArgs()
public BotManager getBotManager()
public DependCenter getDependCenter()
public MsgSender getMsgSender()
public final void close()
DependCenter的close方法。close in interface Closeableclose in interface AutoCloseablepublic boolean isClosed()
public abstract void doClose()
protected void _hello$()
使得这个方法可以被覆盖。别吐槽里面的变量名了。
protected String __$f$__()
Copyright © 2020. All rights reserved.