// NewConnectedStatusHandler creates a new meter status handler for handling meter status
// changes as provided by the API.
505164
func NewConnectedStatusHandler(cfg ConnectedConfig) (watcher.NotifyHandler, error) {
	if err := cfg.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	w := &connectedStatusHandler{
		config: cfg,
	}
	return w, nil
}
922415
func (s *Server) handleRemoteStatus(pb Message) {
	// Ignore NodeStatus messages until the cluster is in a Normal state.
	if s.cluster.State() != ClusterStateNormal {
		return
	}

	go func() {
		// Make sure the holder has opened.
		s.holder.opened.Recv()

		err := s.mergeRemoteStatus(pb.(*NodeStatus))
		if err != nil {
			s.logger.Printf("merge remote status: %s", err)
		}
	}()
}
120654
func (w *connectedStatusHandler) Handle(abort <-chan struct{}) error {
	logger.Debugf("got meter status change signal from watcher")
	currentCode, currentInfo, err := w.config.Status.MeterStatus()
	if err != nil {
		return errors.Trace(err)
	}
	if currentCode == w.code && currentInfo == w.info {
		logger.Tracef("meter status (%q, %q) matches stored information (%q, %q), skipping", currentCode, currentInfo, w.code, w.info)
		return nil
	}
	w.applyStatus(currentCode, currentInfo, abort)
	w.code, w.info = currentCode, currentInfo
	err = w.config.StateFile.Write(w.code, w.info, nil)
	if err != nil {
		return errors.Annotate(err, "failed to record meter status worker state")
	}
	return nil
}
1371200
func (f *FirewallerAPIV4) SetRelationsStatus(args params.SetStatus) (params.ErrorResults, error) {
	var result params.ErrorResults
	result.Results = make([]params.ErrorResult, len(args.Entities))
	for i, entity := range args.Entities {
		relationTag, err := names.ParseRelationTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}
		rel, err := f.st.KeyRelation(relationTag.Id())
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}
		err = rel.SetStatus(status.StatusInfo{
			Status:  status.Status(entity.Status),
			Message: entity.Info,
		})
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
213935
func NewHandler(
	connections chan<- net.Conn,
	abort <-chan struct{},
) *Handler {
	return &Handler{
		connections: connections,
		abort:       abort,
	}
}
524337
func NewRequestsStatsHandler(sub Subsystem, vec *prometheus.GaugeVec) *RequestsStatsHandler {
	return &RequestsStatsHandler{
		baseStatsHandler: baseStatsHandler{
			subsystem: sub,
			collector: vec,
		},
		vec: vec,
	}
}
215164
func (api *MetricsDebugAPI) SetMeterStatus(args params.MeterStatusParams) (params.ErrorResults, error) {
	results := params.ErrorResults{
		Results: make([]params.ErrorResult, len(args.Statuses)),
	}
	for i, arg := range args.Statuses {
		tag, err := names.ParseTag(arg.Tag)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		err = api.setEntityMeterStatus(tag, state.MeterStatus{
			Code: state.MeterStatusFromString(arg.Code),
			Info: arg.Info,
		})
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
	}
	return results, nil
}
672407
func (u *Unit) RelationsStatus() ([]RelationStatus, error) {
	args := params.Entities{
		Entities: []params.Entity{{Tag: u.tag.String()}},
	}
	var results params.RelationUnitStatusResults
	err := u.st.facade.FacadeCall("RelationsStatus", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != 1 {
		return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	var statusResult []RelationStatus
	for _, result := range result.RelationResults {
		tag, err := names.ParseRelationTag(result.RelationTag)
		if err != nil {
			return nil, err
		}
		statusResult = append(statusResult, RelationStatus{
			Tag:       tag,
			InScope:   result.InScope,
			Suspended: result.Suspended,
		})
	}
	return statusResult, nil
}
219289
func NewRemovedStatus(IsRecoverable bool, IsDisconnected bool) *RemovedStatus {
	s := new(RemovedStatus)
	s.IsRecoverable = IsRecoverable
	s.IsDisconnected = IsDisconnected
	return s
}
322175
func (h *StatsHandler) HandleConn(ctx context.Context, sts stats.ConnStats) {
	for _, c := range h.handlers {
		c.HandleConn(ctx, sts)
	}
}
1317657
func (c *Client) SetMeterStatus(tag, code, info string) error {
	args := params.MeterStatusParams{
		Statuses: []params.MeterStatusParam{{
			Tag:  tag,
			Code: code,
			Info: info,
		},
		},
	}
	results := new(params.ErrorResults)
	if err := c.facade.FacadeCall("SetMeterStatus", args, results); err != nil {
		return errors.Trace(err)
	}
	if err := results.OneError(); err != nil {
		return errors.Trace(err)
	}
	return nil
}
1309519
func NewHandler(h http.Handler) http.Handler {
	return NewHandlerWith(stats.DefaultEngine, h)
}
503786
func (c *Client) SetAfterConnectHandler(h handler) {
	c.Lock()
	defer c.Unlock()
	c.afterConnect = h
}
5447
func (m *Model) SetMeterStatus(status, info string) error {
	if _, err := isValidMeterStatusCode(status); err != nil {
		return errors.Trace(err)
	}
	ops := []txn.Op{{
		C:  modelsC,
		Id: m.doc.UUID,
		Update: bson.D{{"$set", bson.D{{"meter-status", modelMeterStatusdoc{
			Code: status,
			Info: info,
		}}}}},
	}}
	err := m.st.db().RunTransaction(ops)
	if err != nil {
		return errors.Trace(err)
	}
	return m.Refresh()
}
200759
func NewConnectionStore(dialer SecureDialer, tlsConnectionCount metrics.Gauge) *ConnectionStore {
	connMapping := &ConnectionStore{
		Connections: &connMapperReporter{
			ConnectionMapper:          make(ConnByCertMap),
			tlsConnectionCountMetrics: tlsConnectionCount,
		},
		dialer: dialer,
	}
	return connMapping
}
1068841
func (client *Client) PaginateRunstatusIncidents(ctx context.Context, page RunstatusPage, callback func(*RunstatusIncident, error) bool) {
	if page.IncidentsURL == "" {
		callback(nil, fmt.Errorf("empty Incidents URL for %#v", page))
		return
	}

	incidentsURL := page.IncidentsURL
	for incidentsURL != "" {
		resp, err := client.runstatusRequest(ctx, incidentsURL, nil, "GET")
		if err != nil {
			callback(nil, err)
			return
		}

		var is *RunstatusIncidentList
		if err := json.Unmarshal(resp, &is); err != nil {
			callback(nil, err)
			return
		}

		for i := range is.Incidents {
			if cont := callback(&is.Incidents[i], nil); !cont {
				return
			}
		}

		incidentsURL = is.Next
	}
}
526224
func NewMockMeterStatusState(ctrl *gomock.Controller) *MockMeterStatusState {
	mock := &MockMeterStatusState{ctrl: ctrl}
	mock.recorder = &MockMeterStatusStateMockRecorder{mock}
	return mock
}