application.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package mhayaFacade
  2. import (
  3. "time"
  4. jsoniter "github.com/json-iterator/go"
  5. )
  6. type (
  7. // INode 节点信息
  8. INode interface {
  9. NodeId() string // 节点id(全局唯一)
  10. NodeType() string // 节点类型
  11. Address() string // 对外网络监听地址(前端节点用)
  12. RpcAddress() string // rpc监听地址(未用)
  13. Settings() ProfileJSON // 节点配置参数
  14. Enabled() bool // 是否启用
  15. }
  16. IApplication interface {
  17. INode
  18. Running() bool // 是否运行中
  19. DieChan() chan bool // die chan
  20. IsFrontend() bool // 是否为前端节点
  21. Register(components ...IComponent) // 注册组件
  22. Find(name string) IComponent // 根据name获取组件对象
  23. Remove(name string) IComponent // 根据name移除组件对象
  24. All() []IComponent // 获取所有组件列表
  25. OnShutdown(fn ...func()) // 关闭前执行的函数
  26. Startup() // 启动应用实例
  27. Shutdown() // 关闭应用实例
  28. Serializer() ISerializer // 序列化
  29. Discovery() IDiscovery // 发现服务
  30. Cluster() ICluster // 集群服务
  31. ActorSystem() IActorSystem // actor系统
  32. }
  33. // ProfileJSON profile配置文件读取接口
  34. ProfileJSON interface {
  35. jsoniter.Any
  36. GetConfig(path ...interface{}) ProfileJSON
  37. GetString(path interface{}, defaultVal ...string) string
  38. GetBool(path interface{}, defaultVal ...bool) bool
  39. GetInt(path interface{}, defaultVal ...int) int
  40. GetInt32(path interface{}, defaultVal ...int32) int32
  41. GetInt64(path interface{}, defaultVal ...int64) int64
  42. GetDuration(path interface{}, defaultVal ...time.Duration) time.Duration
  43. Unmarshal(ptrVal interface{}) error
  44. }
  45. )