ms/packages/spring/src/server.ts
MiaoWoo 85f2bd5a10 feat: optimize framework & support depends check
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-10-13 09:24:58 +08:00

44 lines
1.5 KiB
TypeScript

import { constants, server } from '@ccms/api'
import { provideSingleton, postConstruct, Autowired, Container, ContainerInstance } from '@ccms/container'
import { CommandMap } from './internal/command'
@provideSingleton(server.Server)
export class SpringServer extends server.Server {
@Autowired(ContainerInstance)
private container: Container
@Autowired()
private commandMap: CommandMap
private nettyPipeline = base.getInstance().getAutowireCapableBeanFactory()
private rootLogger = Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
@postConstruct()
initialize() {
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.nettyPipeline)
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
}
getVersion(): string {
return "SpringFramework"
}
getConsoleSender() {
return {
name: 'CONSOLE',
sendMessage: (message: string) => console.console(message)
}
}
dispatchCommand(sender: any, command: string): boolean {
let cmd_args = command.split(" ")
return this.commandMap.dispatch(sender, cmd_args.shift(), cmd_args || [])
}
dispatchConsoleCommand(command: string): boolean {
return this.dispatchCommand(this.getConsoleSender(), command)
}
getNettyPipeline() {
return this.nettyPipeline
}
getRootLogger() {
return this.rootLogger
}
}