podman
94 строки · 2.6 Кб
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
19// Package connectivity defines connectivity semantics.
20// For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md.
21package connectivity
22
23import (
24"google.golang.org/grpc/grpclog"
25)
26
27var logger = grpclog.Component("core")
28
29// State indicates the state of connectivity.
30// It can be the state of a ClientConn or SubConn.
31type State int
32
33func (s State) String() string {
34switch s {
35case Idle:
36return "IDLE"
37case Connecting:
38return "CONNECTING"
39case Ready:
40return "READY"
41case TransientFailure:
42return "TRANSIENT_FAILURE"
43case Shutdown:
44return "SHUTDOWN"
45default:
46logger.Errorf("unknown connectivity state: %d", s)
47return "INVALID_STATE"
48}
49}
50
51const (
52// Idle indicates the ClientConn is idle.
53Idle State = iota
54// Connecting indicates the ClientConn is connecting.
55Connecting
56// Ready indicates the ClientConn is ready for work.
57Ready
58// TransientFailure indicates the ClientConn has seen a failure but expects to recover.
59TransientFailure
60// Shutdown indicates the ClientConn has started shutting down.
61Shutdown
62)
63
64// ServingMode indicates the current mode of operation of the server.
65//
66// Only xDS enabled gRPC servers currently report their serving mode.
67type ServingMode int
68
69const (
70// ServingModeStarting indicates that the server is starting up.
71ServingModeStarting ServingMode = iota
72// ServingModeServing indicates that the server contains all required
73// configuration and is serving RPCs.
74ServingModeServing
75// ServingModeNotServing indicates that the server is not accepting new
76// connections. Existing connections will be closed gracefully, allowing
77// in-progress RPCs to complete. A server enters this mode when it does not
78// contain the required configuration to serve RPCs.
79ServingModeNotServing
80)
81
82func (s ServingMode) String() string {
83switch s {
84case ServingModeStarting:
85return "STARTING"
86case ServingModeServing:
87return "SERVING"
88case ServingModeNotServing:
89return "NOT_SERVING"
90default:
91logger.Errorf("unknown serving mode: %d", s)
92return "INVALID_MODE"
93}
94}
95