node.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package rocommon
  2. import (
  3. "time"
  4. )
  5. //代表多种类型
  6. type ServerNode interface {
  7. //开启服务器
  8. Start() ServerNode
  9. Stop()
  10. //tcpConnector / tcpAcceptor
  11. TypeOfName() string
  12. }
  13. type ServerNodeProperty interface {
  14. GetName() string //ServerName gate/game/db
  15. SetName(s string)
  16. GetAddr() string
  17. SetAddr(s string)
  18. SetQueue(v NetEventQueue)
  19. Queue() NetEventQueue
  20. SetServerType(t int)
  21. ServerType() int
  22. SetZone(t int)
  23. GetZone() int
  24. SetIndex(t int)
  25. GetIndex() int
  26. }
  27. //session管理接口
  28. type SessionMagExport interface {
  29. GetSession(uint64) Session
  30. SessionNum() int
  31. CloseAllSession()
  32. SetUuidCreateKey(genKey int)
  33. }
  34. //socketOption socketOption.go
  35. type TCPSocketOption interface {
  36. SetSocketBuff(read, write int, noDelay bool)
  37. SetMaxMsgLen(size int)
  38. SetSocketDeadline(read, write time.Duration)
  39. }
  40. type MySqlOption interface {
  41. SetConnCount(val int)
  42. }
  43. //NetProcessorRPC procrpc.go
  44. type ProcessorRPCBundle interface {
  45. SetTransmitter(v MessageProcessor)
  46. SetHooker(v EventHook)
  47. SetCallback(v EventCallBack)
  48. }
  49. //tcpConnector暴露的对外接口
  50. type TCPConnector interface {
  51. TCPSocketOption
  52. SetReconnectTime(delta time.Duration)
  53. Session() Session
  54. }
  55. //tcpAcceptor暴露的对外接口
  56. type TCPAcceptor interface {
  57. TCPSocketOption
  58. SessionMagExport
  59. }
  60. //NetContextSet nodeproperty.go
  61. type ContextSet interface {
  62. //绑定自定义属性
  63. SetContextData(key, value interface{}, from string)
  64. //获得key对应的属性
  65. GetContextData(key interface{}) (interface{}, bool)
  66. //根据给定类型获取数据
  67. RawContextData(key interface{}, valuePtr interface{}) bool //sid(etcd期间使用) ctx(连接成功后服务器之间使用)
  68. }
  69. type HTTPConnector interface {
  70. Request(method, path string, param *HTTPRequest) error
  71. }