// NewPushNotification creates and returns a PushNotification structure.
// It also initializes the pseudo-random identifier.
172232
func NewPushNotification() (pn *PushNotification) {
	pn = new(PushNotification)
	pn.payload = make(map[string]interface{})
	pn.Identifier = rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(IdentifierUbound)
	pn.Priority = 10
	return
}
1021309
func NewPusher(g prometheus.Gatherer) *Pusher {
	return &Pusher{
		URL: "https://telemetry.influxdata.com/metrics/job/influxdb",
		Gather: &pr.Filter{
			Gatherer: g,
			Matcher:  telemetryMatcher,
		},
		Client: &http.Client{
			Transport: http.DefaultTransport,
			Timeout:   10 * time.Second,
		},
		PushFormat: expfmt.FmtText,
	}
}
1265228
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
	if len(args) != 3 {
		return nil, fmt.Errorf("incorrect number of arguments to "+
			".New(...), expected 3, instead passed %v", len(args))
	}

	config, ok := args[0].(*neutrino.ChainService)
	if !ok {
		return nil, errors.New("first argument to neutrinonotify.New " +
			"is incorrect, expected a *neutrino.ChainService")
	}

	spendHintCache, ok := args[1].(chainntnfs.SpendHintCache)
	if !ok {
		return nil, errors.New("second argument to neutrinonotify.New " +
			"is  incorrect, expected a chainntfs.SpendHintCache")
	}

	confirmHintCache, ok := args[2].(chainntnfs.ConfirmHintCache)
	if !ok {
		return nil, errors.New("third argument to neutrinonotify.New " +
			"is  incorrect, expected a chainntfs.ConfirmHintCache")
	}

	return New(config, spendHintCache, confirmHintCache), nil
}
584242
func (h *BasicHost) PushIdentify() {
	push := false

	h.mx.Lock()
	addrs := h.Addrs()
	if !sameAddrs(addrs, h.lastAddrs) {
		push = true
		h.lastAddrs = addrs
	}
	h.mx.Unlock()

	if push {
		h.ids.Push()
	}
}
1247717
func newPush(url *string, timeout time.Duration) (p push, err error) {
	err = p.connect(url)
	p.SetTimeout(timeout)
	return
}
954850
func NewPushSocket() (*PushSocket, error) {
	s, err := NewSocket(AF_SP, PUSH)
	return &PushSocket{s}, err
}
472984
func (n *CgroupNotifierFactory) NewCgroupNotifier(path, attribute string, threshold int64) (CgroupNotifier, error) {
	return NewCgroupNotifier(path, attribute, threshold)
}
1074141
func newRedeemingTxNotification(txHex string, index int, block *btcutil.Block) ([]byte, error) {
	// Create and marshal the notification.
	ntfn := btcjson.NewRedeemingTxNtfn(txHex, blockDetails(block, index))
	return btcjson.MarshalCmd(nil, ntfn)
}
270625
func (s *UpdateNotificationSettingsInput) SetNotification(v *NotificationSpecification) *UpdateNotificationSettingsInput {
	s.Notification = v
	return s
}
1016153
func (s *NotificationConfig) SetNotificationType(v string) *NotificationConfig {
	s.NotificationType = &v
	return s
}
157748
func (m *Machine) RegisterNotifier(services ...NotificationService) {
	for _, service := range services {
		m.notifiers = append(m.notifiers, service)
	}
}
1256845
func (pn *PushNotification) AddPayload(p *Payload) {
	// This deserves some explanation.
	//
	// Setting an exported field of type int to 0
	// triggers the omitempty behavior if you've set it.
	// Since the badge is optional, we should omit it if
	// it's not set. However, we want to include it if the
	// value is 0, so there's a hack in push_notification.go
	// that exploits the fact that Apple treats -1 for a
	// badge value as though it were 0 (i.e. it clears the
	// badge but doesn't stop the notification from going
	// through successfully.)
	//
	// Still a hack though :)
	if p.Badge == 0 {
		p.Badge = -1
	}
	pn.Set("aps", p)
}
207475
func PushToIOS(req PushNotification) bool {
	LogAccess.Debug("Start push notification for iOS")
	if PushConf.Core.Sync {
		defer req.WaitDone()
	}

	var (
		retryCount = 0
		maxRetry   = PushConf.Ios.MaxRetry
	)

	if req.Retry > 0 && req.Retry < maxRetry {
		maxRetry = req.Retry
	}

Retry:
	var (
		isError   = false
		newTokens []string
	)

	notification := GetIOSNotification(req)
	client := getApnsClient(req)

	for _, token := range req.Tokens {
		notification.DeviceToken = token

		// send ios notification
		res, err := client.Push(notification)

		if err != nil {
			// apns server error
			LogPush(FailedPush, token, req, err)
			if PushConf.Core.Sync {
				req.AddLog(getLogPushEntry(FailedPush, token, req, err))
			}
			StatStorage.AddIosError(1)
			newTokens = append(newTokens, token)
			isError = true
			continue
		}

		if res.StatusCode != 200 {
			// error message:
			// ref: https://github.com/sideshow/apns2/blob/master/response.go#L14-L65
			LogPush(FailedPush, token, req, errors.New(res.Reason))
			if PushConf.Core.Sync {
				req.AddLog(getLogPushEntry(FailedPush, token, req, errors.New(res.Reason)))
			}
			StatStorage.AddIosError(1)
			newTokens = append(newTokens, token)
			isError = true
			continue
		}

		if res.Sent() {
			LogPush(SucceededPush, token, req, nil)
			StatStorage.AddIosSuccess(1)
		}
	}

	if isError && retryCount < maxRetry {
		retryCount++

		// resend fail token
		req.Tokens = newTokens
		goto Retry
	}

	return isError
}
904615
func (s *CreateReplicationGroupInput) SetNotificationTopicArn(v string) *CreateReplicationGroupInput {
	s.NotificationTopicArn = &v
	return s
}
1166021
func NewPushNodesByBackendIDsToFrontendArgs(backendNodeIDs []BackendNodeID) *PushNodesByBackendIDsToFrontendArgs {
	args := new(PushNodesByBackendIDsToFrontendArgs)
	args.BackendNodeIDs = backendNodeIDs
	return args
}
766482
func (r User_Customer_MobileDevice) GetPushNotificationSubscriptions() (resp []datatypes.Notification_User_Subscriber, err error) {
	err = r.Session.DoRequest("SoftLayer_User_Customer_MobileDevice", "getPushNotificationSubscriptions", nil, &r.Options, &resp)
	return
}
62781
func (a *API) UpdateNotification(user int, notification *Notification) (*Notification, error) {
	dst := new(Notification)
	url := a.BuildURL("/v2/user/%d/notification/%d", user, notification.Id)
	err := a.Put(url, Params{}, notification, dst)
	return dst, err
}