connectivity.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. *
  3. * Copyright 2017 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package connectivity defines connectivity semantics.
  19. // For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md.
  20. package connectivity
  21. import (
  22. "google.golang.org/grpc/grpclog"
  23. )
  24. var logger = grpclog.Component("core")
  25. // State indicates the state of connectivity.
  26. // It can be the state of a ClientConn or SubConn.
  27. type State int
  28. func (s State) String() string {
  29. switch s {
  30. case Idle:
  31. return "IDLE"
  32. case Connecting:
  33. return "CONNECTING"
  34. case Ready:
  35. return "READY"
  36. case TransientFailure:
  37. return "TRANSIENT_FAILURE"
  38. case Shutdown:
  39. return "SHUTDOWN"
  40. default:
  41. logger.Errorf("unknown connectivity state: %d", s)
  42. return "INVALID_STATE"
  43. }
  44. }
  45. const (
  46. // Idle indicates the ClientConn is idle.
  47. Idle State = iota
  48. // Connecting indicates the ClientConn is connecting.
  49. Connecting
  50. // Ready indicates the ClientConn is ready for work.
  51. Ready
  52. // TransientFailure indicates the ClientConn has seen a failure but expects to recover.
  53. TransientFailure
  54. // Shutdown indicates the ClientConn has started shutting down.
  55. Shutdown
  56. )
  57. // ServingMode indicates the current mode of operation of the server.
  58. //
  59. // Only xDS enabled gRPC servers currently report their serving mode.
  60. type ServingMode int
  61. const (
  62. // ServingModeStarting indicates that the server is starting up.
  63. ServingModeStarting ServingMode = iota
  64. // ServingModeServing indicates that the server contains all required
  65. // configuration and is serving RPCs.
  66. ServingModeServing
  67. // ServingModeNotServing indicates that the server is not accepting new
  68. // connections. Existing connections will be closed gracefully, allowing
  69. // in-progress RPCs to complete. A server enters this mode when it does not
  70. // contain the required configuration to serve RPCs.
  71. ServingModeNotServing
  72. )
  73. func (s ServingMode) String() string {
  74. switch s {
  75. case ServingModeStarting:
  76. return "STARTING"
  77. case ServingModeServing:
  78. return "SERVING"
  79. case ServingModeNotServing:
  80. return "NOT_SERVING"
  81. default:
  82. logger.Errorf("unknown serving mode: %d", s)
  83. return "INVALID_MODE"
  84. }
  85. }