...

Source file src/google.golang.org/grpc/xds/internal/balancer/priority/ignore_resolve_now.go

Documentation: google.golang.org/grpc/xds/internal/balancer/priority

     1  /*
     2   *
     3   * Copyright 2021 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 priority
    20  
    21  import (
    22  	"sync/atomic"
    23  
    24  	"google.golang.org/grpc/balancer"
    25  	"google.golang.org/grpc/resolver"
    26  )
    27  
    28  // ignoreResolveNowClientConn wraps a balancer.ClientConn and overrides the
    29  // ResolveNow() method to ignore those calls if the ignoreResolveNow bit is set.
    30  type ignoreResolveNowClientConn struct {
    31  	balancer.ClientConn
    32  	ignoreResolveNow *uint32
    33  }
    34  
    35  func newIgnoreResolveNowClientConn(cc balancer.ClientConn, ignore bool) *ignoreResolveNowClientConn {
    36  	ret := &ignoreResolveNowClientConn{
    37  		ClientConn:       cc,
    38  		ignoreResolveNow: new(uint32),
    39  	}
    40  	ret.updateIgnoreResolveNow(ignore)
    41  	return ret
    42  }
    43  
    44  func (i *ignoreResolveNowClientConn) updateIgnoreResolveNow(b bool) {
    45  	if b {
    46  		atomic.StoreUint32(i.ignoreResolveNow, 1)
    47  		return
    48  	}
    49  	atomic.StoreUint32(i.ignoreResolveNow, 0)
    50  
    51  }
    52  
    53  func (i ignoreResolveNowClientConn) ResolveNow(o resolver.ResolveNowOptions) {
    54  	if atomic.LoadUint32(i.ignoreResolveNow) != 0 {
    55  		return
    56  	}
    57  	i.ClientConn.ResolveNow(o)
    58  }
    59  

View as plain text