// OnStateChange is called whenever the state of CircuitBreaker changes.
769028
func OnStateChange(fn OnStateChangeFunc) Option {
	return func(r *Rabbus) error {
		r.config.breaker.onStateChange = fn
		return nil
	}
}
167903
func (circuit *CircuitBreaker) ReportEvent(eventTypes []string, start time.Time, runDuration time.Duration) error {
	if len(eventTypes) == 0 {
		return fmt.Errorf("no event types sent for metrics")
	}

	circuit.mutex.RLock()
	o := circuit.open
	circuit.mutex.RUnlock()
	if eventTypes[0] == "success" && o {
		circuit.setClose()
	}

	var concurrencyInUse float64
	if circuit.executorPool.Max > 0 {
		concurrencyInUse = float64(circuit.executorPool.ActiveCount()) / float64(circuit.executorPool.Max)
	}

	select {
	case circuit.metrics.Updates <- &commandExecution{
		Types:            eventTypes,
		Start:            start,
		RunDuration:      runDuration,
		ConcurrencyInUse: concurrencyInUse,
	}:
	default:
		return CircuitError{Message: fmt.Sprintf("metrics channel (%v) is at capacity", circuit.Name)}
	}

	return nil
}
446109
func (s *AssessmentRunFilter) SetStateChangeTimeRange(v *TimestampRange) *AssessmentRunFilter {
	s.StateChangeTimeRange = v
	return s
}
812216
func (m *Manager) NotifyStateChance() {
	m.Lock()
	defer m.Unlock()

	for _, watcher := range m.watchers {
		watcher.NotifyStateChance()
	}
}
342602
func (c *CircuitBreaker) setTripped(e endpoint.Endpoint) bool {
	c.m.Lock()
	defer c.m.Unlock()

	if c.state == stateTripped {
		log.Infof("%v skip set tripped", c)
		return false
	}

	c.setState(stateTripped, c.tm.UtcNow().Add(c.o.FallbackDuration))
	c.resetStats(e)
	return true
}
303920
func Logger(l *log.Logger) CircuitBreakerOption {
	return func(c *CircuitBreaker) error {
		c.log = l
		return nil
	}
}
1328596
func (b *Button) OnKeyEvent(ev KeyEvent) {
	if !b.IsFocused() {
		return
	}
	if ev.Key == KeyEnter && b.onActivated != nil {
		b.onActivated(b)
	}
}
992366
func (r *renoState) updateCongestionAvoidance(packetsAcked int) {
	// Consume the packets in congestion avoidance mode.
	r.s.sndCAAckCount += packetsAcked
	if r.s.sndCAAckCount >= r.s.sndCwnd {
		r.s.sndCwnd += r.s.sndCAAckCount / r.s.sndCwnd
		r.s.sndCAAckCount = r.s.sndCAAckCount % r.s.sndCwnd
	}
}
1162731
func (kcs *kbfsCurrentStatus) PushConnectionStatusChange(service string, err error) {
	kcs.lock.Lock()
	defer kcs.lock.Unlock()

	if err != nil {
		// Exit early if the service is already failed, to avoid an
		// invalidation.
		_, errExisted := kcs.failingServices[service]
		kcs.failingServices[service] = err
		if errExisted {
			return
		}
	} else {
		// Potentially exit early if nothing changes.
		_, exist := kcs.failingServices[service]
		if !exist {
			return
		}
		delete(kcs.failingServices, service)
	}

	close(kcs.invalidateChan)
	kcs.invalidateChan = make(chan StatusUpdate)
}
823234
func (c *Controller) OnShutdown(fn func() error) {
	c.instance.onShutdown = append(c.instance.onShutdown, fn)
}
1074980
func (s *Server) OnConnect(f func(*Client)) {
	s.eventHub.Subscribe(clientConnected, func(e hub.Event) {
		go f(e.(connectionEvent).Client)
	})
}
972760
func (m *CircuitBreakers_Thresholds) Validate() error {
	if m == nil {
		return nil
	}

	// no validation rules for Priority

	{
		tmp := m.GetMaxConnections()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return CircuitBreakers_ThresholdsValidationError{
					field:  "MaxConnections",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	{
		tmp := m.GetMaxPendingRequests()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return CircuitBreakers_ThresholdsValidationError{
					field:  "MaxPendingRequests",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	{
		tmp := m.GetMaxRequests()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return CircuitBreakers_ThresholdsValidationError{
					field:  "MaxRequests",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	{
		tmp := m.GetMaxRetries()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return CircuitBreakers_ThresholdsValidationError{
					field:  "MaxRetries",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	// no validation rules for TrackRemaining

	{
		tmp := m.GetMaxConnectionPools()

		if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

			if err := v.Validate(); err != nil {
				return CircuitBreakers_ThresholdsValidationError{
					field:  "MaxConnectionPools",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}

	return nil
}
555540
func Fallback(h http.Handler) CircuitBreakerOption {
	return func(c *CircuitBreaker) error {
		c.fallback = h
		return nil
	}
}
174052
func (bg *balancerGroup) handleSubConnStateChange(sc balancer.SubConn, state connectivity.State) {
	grpclog.Infof("balancer group: handle subconn state change: %p, %v", sc, state)
	bg.mu.Lock()
	var b balancer.Balancer
	if id, ok := bg.scToID[sc]; ok {
		if state == connectivity.Shutdown {
			// Only delete sc from the map when state changed to Shutdown.
			delete(bg.scToID, sc)
		}
		b = bg.idToBalancer[id]
	}
	bg.mu.Unlock()
	if b == nil {
		grpclog.Infof("balancer group: balancer not found for sc state change")
		return
	}
	if ub, ok := b.(balancer.V2Balancer); ok {
		ub.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: state})
	} else {
		b.HandleSubConnStateChange(sc, state)
	}
}
675787
func (t *TxStateChange) CheckAndSet() {
	t.c.txStateMu.Lock()
	defer t.c.txStateMu.Unlock()
	defer func() { t.done = true }()

	if t.done {
		panic("CheckAndSet should only be called once")
	}

	if !t.tx && t.c.TransactionActive() && t.c.TxStartedAt.IsZero() {
		t.c.TxStartedAt = time.Now()
	} else if t.tx && !t.c.TransactionActive() && !t.c.TxStartedAt.IsZero() {
		t.c.TxStartedAt = time.Time{}
	}
}
63462
func (l *RelayDriver) Toggle() (err error) {
	if l.State() {
		err = l.Off()
	} else {
		err = l.On()
	}
	return
}
760829
func (p *Plugin) OnConnect(callback func() error) {
	p.Lock()
	defer p.Unlock()

	if p.connected {
		if err := callback(); err != nil {
			p.Log.Errorf("callback for OnConnect failed: %v", err)
		}
	} else {
		p.onConnection = append(p.onConnection, callback)
	}
}