// Register a URL to receive notification callbacks when the value of the given key changes
543519
func (c *agency) RegisterChangeCallback(ctx context.Context, key []string, cbURL string) error {
	conn := c.conn
	req, err := conn.NewRequest("POST", "_api/agency/write")
	if err != nil {
		return driver.WithStack(err)
	}

	fullKey := createFullKey(key)
	writeTxs := writeTransactions{
		writeTransaction{
			// Update
			map[string]interface{}{
				fullKey: writeUpdate{
					Operation: "observe",
					URL:       cbURL,
				},
			},
		},
	}

	req, err = req.SetBody(writeTxs)
	if err != nil {
		return driver.WithStack(err)
	}
	resp, err := conn.Do(ctx, req)
	if err != nil {
		return driver.WithStack(err)
	}

	var result writeResult
	if err := resp.CheckStatus(200, 201, 202); err != nil {
		return driver.WithStack(err)
	}
	if err := resp.ParseBody("", &result); err != nil {
		return driver.WithStack(err)
	}

	// "results" should be 1 long
	if len(result.Results) != 1 {
		return driver.WithStack(fmt.Errorf("Expected results of 1 long, got %d", len(result.Results)))
	}

	// Success
	return nil
}
641883
func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
	c.UnregisterCloseCallback()
	goCallbackId := registerCallbackId(callback)
	var err C.virError
	res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
	if res != 0 {
		freeCallbackId(goCallbackId)
		return makeError(&err)
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
1229313
func RegisterParsingCallback(serverType, afterDir string, callback ParsingCallback) {
	if _, ok := parsingCallbacks[serverType]; !ok {
		parsingCallbacks[serverType] = make(map[string][]ParsingCallback)
	}
	parsingCallbacks[serverType][afterDir] = append(parsingCallbacks[serverType][afterDir], callback)
}
518932
func (r *Registrar) Register() {
	if err := r.client.Register(r.service); err != nil {
		r.logger.Log("err", err)
	} else {
		r.logger.Log("action", "register")
	}
	if r.service.TTL != nil {
		go r.loop()
	}
}
366618
func (r DockerImageReference) RegistryURL() *url.URL {
	return &url.URL{
		Scheme: "https",
		Host:   r.AsV2().Registry,
	}
}
1112906
func (c *kregistry) Register(s *registry.Service, opts ...registry.RegisterOption) error {
	if len(s.Nodes) == 0 {
		return errors.New("you must register at least one node")
	}

	// TODO: grab podname from somewhere better than this.
	podName := os.Getenv("HOSTNAME")
	svcName := s.Name

	// encode micro service
	b, err := json.Marshal(s)
	if err != nil {
		return err
	}
	svc := string(b)

	pod := &client.Pod{
		Metadata: &client.Meta{
			Labels: map[string]*string{
				labelTypeKey:                             &labelTypeValueService,
				svcSelectorPrefix + serviceName(svcName): &svcSelectorValue,
			},
			Annotations: map[string]*string{
				annotationServiceKeyPrefix + serviceName(svcName): &svc,
			},
		},
	}

	if _, err := c.client.UpdatePod(podName, pod); err != nil {
		return err
	}

	return nil

}
944437
func (w *MachineLXDProfileWatcher) applicationCharmURLChange(topic string, value interface{}) {
	// We don't want to respond to any events until we have been fully initialized.
	select {
	case <-w.initialized:
	case <-w.tomb.Dying():
		return
	}
	var notify bool
	defer func(notify *bool) {
		if *notify {
			w.notify()
			w.metrics.LXDProfileChangeHit.Inc()
		} else {
			w.metrics.LXDProfileChangeMiss.Inc()
		}
	}(&notify)

	values, ok := value.(appCharmUrlChange)
	if !ok {
		w.logError("programming error, value not of type appCharmUrlChange")
		return
	}
	appName, chURL := values.appName, values.chURL
	info, ok := w.applications[appName]
	if ok {
		ch, err := w.modeler.Charm(chURL)
		if err != nil {
			w.logError(fmt.Sprintf("error getting charm %s to evaluate for lxd profile notification: %s", chURL, err))
			return
		}

		// notify if:
		// 1. the prior charm had a profile and the new one does not.
		// 2. the new profile is not empty.
		lxdProfile := ch.LXDProfile()
		if (!info.charmProfile.Empty() && lxdProfile.Empty()) || !lxdProfile.Empty() {
			logger.Tracef("notifying due to change of charm lxd profile for %s, machine-%s", appName, w.machineId)
			notify = true
		} else {
			logger.Tracef("no notification of charm lxd profile needed for %s, machine-%s", appName, w.machineId)
		}

		info.charmProfile = lxdProfile
		info.charmURL = chURL
		w.applications[appName] = info
	} else {
		logger.Tracef("not watching %s on machine-%s", appName, w.machineId)
	}
	logger.Tracef("end of application charm url change %#v", w.applications)
}
509993
func (c *Client) RegisterChannel(id uint) error {
	_, err := c.ExecCmd(NewCmd("servernotifyregister").WithArgs(
		NewArg("event", ChannelEvents),
		NewArg("id", id),
	))
	return err
}
37315
func (d *Daemon) NotifyChange(ctx context.Context, change v9.Change) error {
	switch change.Kind {
	case v9.GitChange:
		gitUpdate := change.Source.(v9.GitUpdate)
		if gitUpdate.URL != d.Repo.Origin().URL && gitUpdate.Branch != d.GitConfig.Branch {
			// It isn't strictly an _error_ to be notified about a repo/branch pair
			// that isn't ours, but it's worth logging anyway for debugging.
			d.Logger.Log("msg", "notified about unrelated change",
				"url", gitUpdate.URL,
				"branch", gitUpdate.Branch)
			break
		}
		d.Repo.Notify()
	case v9.ImageChange:
		imageUpdate := change.Source.(v9.ImageUpdate)
		d.ImageRefresh <- imageUpdate.Name
	}
	return nil
}
1257637
func Register(callback func(action interface{})) ID {
	idCounter++
	id := idCounter
	callbacks[id] = callback
	return id
}
1337558
func (app *App) register(routeName string, dispatch dispatchFunc) {
	handler := app.dispatcher(dispatch)

	// Chain the handler with prometheus instrumented handler
	if app.Config.HTTP.Debug.Prometheus.Enabled {
		namespace := metrics.NewNamespace(prometheus.NamespacePrefix, "http", nil)
		httpMetrics := namespace.NewDefaultHttpMetrics(strings.Replace(routeName, "-", "_", -1))
		metrics.Register(namespace)
		handler = metrics.InstrumentHandler(httpMetrics, handler)
	}

	// TODO(stevvooe): This odd dispatcher/route registration is by-product of
	// some limitations in the gorilla/mux router. We are using it to keep
	// routing consistent between the client and server, but we may want to
	// replace it with manual routing and structure-based dispatch for better
	// control over the request execution.

	app.router.GetRoute(routeName).Handler(handler)
}
1142563
func (h *Handler) notifyRegistry(err error) {
	if err == nil {
		err = h.sendReady()
	}

	if err != nil {
		h.Registry.Failed(h.chaincodeID.Name, err)
		chaincodeLogger.Errorf("failed to start %s", h.chaincodeID)
		return
	}

	h.Registry.Ready(h.chaincodeID.Name)
}
782232
func RegisterListener(listenerObj core.EventListener, key ...string) error {
	return factory.RegisterListener(listenerObj, key...)
}
854328
func Register() {
	httpcli.Register(httpcli.AuthBasic, httpcli.DoerFactory(func(cm httpcli.ConfigMap, c *http.Client) (doer httpcli.Doer) {
		obj := cm.FindOrPanic(httpcli.AuthBasic)
		config, ok := obj.(Credentials)
		if !ok {
			panic(fmt.Errorf("expected Credentials instead of %#+v", obj))
		}
		validate(config)
		if c != nil {
			doer = Doer(c, config)
		}
		return
	}))
}
1148761
func (u *URLQueryParameters) Add(Key string, value string) {
	u.params = append(u.params, URLQueryParameter{Key: Key, Value: value})
}
804968
func (reg *WatchDataReg) Register(resyncName, keyPrefix string) error {
	reg.adapter.access.Lock()
	defer reg.adapter.access.Unlock()

	for resName, sub := range reg.adapter.subscriptions {
		if resName == resyncName {
			// Verify that prefix does not exist yet
			for _, regPrefix := range sub.KeyPrefixes {
				if regPrefix == keyPrefix {
					return fmt.Errorf("prefix %q already exists", keyPrefix)
				}
			}
			sub.KeyPrefixes = append(sub.KeyPrefixes, keyPrefix)
			return nil
		}
	}
	return fmt.Errorf("cannot register prefix %s, resync name %s not found", keyPrefix, resyncName)
}
423157
func (n *Notification) GetURL() string {
	if n == nil || n.URL == nil {
		return ""
	}
	return *n.URL
}