Polish the comments

This commit is contained in:
iamqizhao
2016-05-24 17:37:44 -07:00
parent 0b1df3bca2
commit 53fe56a73e

View File

@ -43,6 +43,7 @@ import (
) )
// Address represents a server the client connects to. // Address represents a server the client connects to.
// This is the EXPERIMENTAL API and may be changed or extended in the future.
type Address struct { type Address struct {
// Addr is the server address on which a connection will be established. // Addr is the server address on which a connection will be established.
Addr string Addr string
@ -52,10 +53,11 @@ type Address struct {
Metadata interface{} Metadata interface{}
} }
// BalancerGetOption can configure a Get call. // BalancerGetOption configures a Get call.
// This is the EXPERIMENTAL API and may be changed or extended in the future.
type BalancerGetOptions struct { type BalancerGetOptions struct {
// BlockingWait specifies whether Get should block when there is no // BlockingWait specifies whether Get should block when there is no
// address ready for transmission. // connected address.
BlockingWait bool BlockingWait bool
} }
@ -63,30 +65,29 @@ type BalancerGetOptions struct {
// This is the EXPERIMENTAL API and may be changed or extended in the future. // This is the EXPERIMENTAL API and may be changed or extended in the future.
type Balancer interface { type Balancer interface {
// Start does the initialization work to bootstrap a Balancer. For example, // Start does the initialization work to bootstrap a Balancer. For example,
// this function may start the service discovery and watch the name resolution // this function may start the name resolution and watch the updates.
// updates.
Start(target string) error Start(target string) error
// Up informs the balancer that gRPC has a connection to the server at // Up informs the Balancer that gRPC has a connection to the server at
// addr. It returns down which is called once the connection to addr gets // addr. It returns down which is called once the connection to addr gets
// lost or closed. Once down is called, addr may no longer be returned // lost or closed.
// by Get.
Up(addr Address) (down func(error)) Up(addr Address) (down func(error))
// Get gets the address of a server for the rpc corresponding to ctx. // Get gets the address of a server for the rpc corresponding to ctx.
// If opts.BlockingWait is true, it blocks if there is no connection available, // If opts.BlockingWait is true, it blocks if there is no connection available,
// i.e., invocations of Up(...) is equal to that of Down(...). It respects the // i.e., invocations of Up(...) is equal to those of Down(...). It respects the
// timeout or cancellation of ctx when blocking. If opts.BlockingWait is // timeout or cancellation of ctx when blocking. If opts.BlockingWait is
// false, it may return any address it has notified via Notify(...). It returns // false, it may return any address it has notified via Notify(...) instead of
// blocking. The returned address may or may not be connected. The function returns
// put which is called once the rpc has completed or failed. put can collect and // put which is called once the rpc has completed or failed. put can collect and
// report rpc stats to remote load balancer. // report rpc stats to a remote load balancer.
Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error)
// Notify gRPC internals the list of Address which should be connected. The list // Notify notifies gRPC internals the list of Address to be connected. The list
// may be from a name resolver or remote load balancer. gRPC internals will // may be from a name resolver or remote load balancer. gRPC internals will
// compare it with the exisiting connected addresses. If the address Balancer // compare it with the exisiting connected addresses. If the address Balancer
// notified is not in the list of the connected addresses, gRPC starts to connect // notified is not in the exisitng connected addresses, gRPC starts to connect
// the address. If an address in the connected addresses is not in the notification // the address. If an address in the exisiting connected addresses is not in
// list, the corresponding connect will be shutdown gracefully. Otherwise, there // the notification list, the corresponding connection is shutdown gracefully.
// are no operations. Note that this function must return the full list of the // Otherwise, there are no operations to take. Note that this function must
// Addrresses which should be connected. It is NOT delta. // return the full list of the Addrresses which should be connected. It is NOT delta.
Notify() <-chan []Address Notify() <-chan []Address
// Close shuts down the balancer. // Close shuts down the balancer.
Close() error Close() error
@ -100,7 +101,7 @@ func RoundRobin(r naming.Resolver) Balancer {
type roundRobin struct { type roundRobin struct {
r naming.Resolver r naming.Resolver
open []Address // all the known addresses the client can potentially connect open []Address // all the addresses the client should potentially connect
mu sync.Mutex mu sync.Mutex
addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to. addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to.
connected []Address // all the connected addresses connected []Address // all the connected addresses