// ConsumeRemoteRelationChange consumes a change to settings originating
// from the remote/offering side of a relation.
547591
func (c *Client) ConsumeRemoteRelationChange(change params.RemoteRelationChangeEvent) error {
	args := params.RemoteRelationsChanges{
		Changes: []params.RemoteRelationChangeEvent{change},
	}
	var results params.ErrorResults
	err := c.facade.FacadeCall("ConsumeRemoteRelationChanges", args, &results)
	if err != nil {
		return errors.Trace(err)
	}
	return results.OneError()
}
417314
func (s *RouterService) NewChangeServiceForRouterParams(id string, serviceofferingid string) *ChangeServiceForRouterParams {
	p := &ChangeServiceForRouterParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	p.p["serviceofferingid"] = serviceofferingid
	return p
}
877869
func (c *Client) RelationUnitSettings(relationUnits []params.RemoteRelationUnit) ([]params.SettingsResult, error) {
	var (
		args         params.RemoteRelationUnits
		retryIndices []int
	)

	args = params.RemoteRelationUnits{RelationUnits: relationUnits}
	// Use any previously cached discharge macaroons.
	for i, arg := range args.RelationUnits {
		if ms, ok := c.getCachedMacaroon("relation unit settings", arg.RelationToken); ok {
			newArg := arg
			newArg.Macaroons = ms
			args.RelationUnits[i] = newArg
		}
	}

	var results params.SettingsResults
	apiCall := func() error {
		// Reset the results struct before each api call.
		results = params.SettingsResults{}
		err := c.facade.FacadeCall("RelationUnitSettings", args, &results)
		if err != nil {
			return errors.Trace(err)
		}
		if len(results.Results) != len(args.RelationUnits) {
			return errors.Errorf("expected %d result(s), got %d", len(args.RelationUnits), len(results.Results))
		}
		return nil
	}

	// Make the api call the first time.
	if err := apiCall(); err != nil {
		return nil, errors.Trace(err)
	}
	// On error, possibly discharge the macaroon and retry.
	result := results.Results
	args = params.RemoteRelationUnits{}
	// Separate the successful calls from those needing a retry.
	for i, res := range results.Results {
		if res.Error == nil {
			continue
		}
		mac, err := c.handleError(res.Error)
		if err != nil {
			resCopy := res
			resCopy.Error.Message = err.Error()
			result[i] = resCopy
			continue
		}
		retryArg := relationUnits[i]
		retryArg.Macaroons = mac
		args.RelationUnits = append(args.RelationUnits, retryArg)
		retryIndices = append(retryIndices, i)
		c.cache.Upsert(retryArg.RelationToken, mac)
	}
	// Nothing to retry so return the original result.
	if len(args.RelationUnits) == 0 {
		return result, nil
	}

	if err := apiCall(); err != nil {
		return nil, errors.Trace(err)
	}
	// After a retry, insert the results into the original result slice.
	for j, res := range results.Results {
		resCopy := res
		result[retryIndices[j]] = resCopy
	}
	return result, nil
}
1215142
func NewSharingChangeMemberPolicyType(Description string) *SharingChangeMemberPolicyType {
	s := new(SharingChangeMemberPolicyType)
	s.Description = Description
	return s
}
786760
func ApplyPropertyChange(obj Reference, changes []types.PropertyChange) {
	t := typeInfoForType(obj.Reference().Type)
	v := reflect.ValueOf(obj)

	for _, p := range changes {
		rv, ok := t.props[p.Name]
		if !ok {
			continue
		}

		assignValue(v, rv, reflect.ValueOf(p.Val))
	}
}
1175111
func (b *Broker) BatchConsumer(conf ConsumerConf) (BatchConsumer, error) {
	return b.consumer(conf)
}
485510
func (api *CrossModelRelationsAPI) PublishIngressNetworkChanges(
	changes params.IngressNetworksChanges,
) (params.ErrorResults, error) {
	results := params.ErrorResults{
		Results: make([]params.ErrorResult, len(changes.Changes)),
	}
	for i, change := range changes.Changes {
		relationTag, err := api.st.GetRemoteEntity(change.RelationToken)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		logger.Debugf("relation tag for token %+v is %v", change.RelationToken, relationTag)

		if err := api.checkMacaroonsForRelation(relationTag, change.Macaroons); err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		if err := commoncrossmodel.PublishIngressNetworkChange(api.st, relationTag, change); err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
	}
	return results, nil
}
468314
func (n *ng) parseChange(response *etcd.Response) (interface{}, error) {
	// Order parsers from the most to the least frequently used.
	matchers := []MatcherFn{
		n.parseBackendServerChange,
		n.parseBackendChange,
		n.parseFrontendMiddlewareChange,
		n.parseFrontendChange,
		n.parseHostChange,
		n.parseListenerChange,
	}
	for _, matcher := range matchers {
		a, err := matcher(response)
		if a != nil || err != nil {
			return a, err
		}
	}
	return nil, nil
}
1085523
func DeviceChange(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "devicechange", Listener: listener}
}
860540
func (n *NotifyRouter) HandleKeyfamilyChanged(uid keybase1.UID) {
	if n == nil {
		return
	}

	n.G().Log.Debug("+ Sending keyfamily changed notification")
	// For all connections we currently have open...
	n.cm.ApplyAll(func(id ConnectionID, xp rpc.Transporter) bool {
		// If the connection wants the `Favorites` notification type
		if n.getNotificationChannels(id).Keyfamily {
			// In the background do...
			go func() {
				(keybase1.NotifyKeyfamilyClient{
					Cli: rpc.NewClient(xp, NewContextifiedErrorUnwrapper(n.G()), nil),
				}).KeyfamilyChanged(context.Background(), uid)
			}()
		}
		return true
	})

	n.runListeners(func(listener NotifyListener) {
		listener.KeyfamilyChanged(uid)
	})
	n.G().Log.Debug("- Sent keyfamily changed notification")
}
837109
func (s *ArtifactRevision) SetRevisionChangeIdentifier(v string) *ArtifactRevision {
	s.RevisionChangeIdentifier = &v
	return s
}
1346292
func (s *StepStatus) SetStateChangeReason(v *StepStateChangeReason) *StepStatus {
	s.StateChangeReason = v
	return s
}
189380
func (ic *IngressIPController) enqueueChange(new interface{}, old interface{}) {
	ic.lock.Lock()
	defer ic.lock.Unlock()

	change := &serviceChange{}

	if new != nil {
		// Queue the key needed to retrieve the lastest state from the
		// cache when the change is processed.
		key, err := controller.KeyFunc(new)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %+v: %v", new, err))
			return
		}
		change.key = key
	}

	if old != nil {
		service, ok := old.(*v1.Service)
		if !ok {
			tombstone, ok := old.(cache.DeletedFinalStateUnknown)
			if !ok {
				utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", old))
				return
			}
			service, ok = tombstone.Obj.(*v1.Service)
			if !ok {
				utilruntime.HandleError(fmt.Errorf("tombstone contained unexpected object %#v", old))
				return
			}
		}
		change.oldService = service
	}

	ic.queue.Add(change)
}
1059035
func (s *InstanceStatus) SetStateChangeReason(v *InstanceStateChangeReason) *InstanceStatus {
	s.StateChangeReason = v
	return s
}
60008
func (api *CrossModelRelationsAPI) RelationUnitSettings(relationUnits params.RemoteRelationUnits) (params.SettingsResults, error) {
	results := params.SettingsResults{
		Results: make([]params.SettingsResult, len(relationUnits.RelationUnits)),
	}
	for i, arg := range relationUnits.RelationUnits {
		relationTag, err := api.st.GetRemoteEntity(arg.RelationToken)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		if err := api.checkMacaroonsForRelation(relationTag, arg.Macaroons); err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}

		ru := params.RelationUnit{
			Relation: relationTag.String(),
			Unit:     arg.Unit,
		}
		settings, err := commoncrossmodel.RelationUnitSettings(api.st, ru)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		results.Results[i].Settings = settings
	}
	return results, nil
}
399710
func (_m *LifeCycleChangeListener) LifeCycleChangeListener(channel string, chaincodes chaincode.MetadataSet) {
	_m.Called(channel, chaincodes)
}
1124549
func (p *ExamplePlugin) consumer() {
	defer p.wg.Done()

	p.Log.Print("Consumer started")
	for {
		select {
		// WATCH: demonstrate how to receive data change events.
		case dataEv, ok := <-p.changeChannel:
			if !ok {
				return
			}
			p.Log.Printf("Received event: %v", dataEv)
			// If event arrives, the key is extracted and used together with
			// the expected prefix to identify item.

			for _, dataChng := range dataEv.GetChanges() {
				key := dataChng.GetKey()
				if strings.HasPrefix(key, etcdKeyPrefix(p.ServiceLabel.GetAgentLabel())) {
					var value, previousValue etcdexample.EtcdExample
					// The first return value is diff - boolean flag whether previous value exists or not
					err := dataChng.GetValue(&value)
					if err != nil {
						p.Log.Error(err)
					}
					diff, err := dataChng.GetPrevValue(&previousValue)
					if err != nil {
						p.Log.Error(err)
					}
					p.Log.Infof("Event arrived to etcd eventHandler, key %v, update: %v, change type: %v,",
						dataChng.GetKey(), diff, dataChng.GetChangeType())
					// Increase event counter (expecting two events).
					p.eventCounter++

					if p.eventCounter == 2 {
						// After creating/updating data, unregister key
						p.Log.Infof("Unregister key %v", etcdKeyPrefix(p.ServiceLabel.GetAgentLabel()))
						p.watchDataReg.Unregister(etcdKeyPrefix(p.ServiceLabel.GetAgentLabel()))
					}
				}
			}

			// Here you would test for other event types with one if statement
			// for each key prefix:
			//
			// if strings.HasPrefix(key, etcd prefix) { ... }

			// Here you would also watch for resync events
			// (not published in this example):
			//
			// case resyncEvent := <-plugin.ResyncEvent:
			//   ...
		case rs := <-p.resyncChannel:
			// Resync event notification
			p.Log.Infof("Resync event %v called", rs)
			rs.Done(nil)
		case <-p.context.Done():
			p.Log.Debugf("Stop watching events")
			return
		}
	}
}