// NewOSOSubscriptionService returns a new OSOSubscriptionService implementation
975610
func NewOSOSubscriptionService(context servicecontext.ServiceContext, config OSOSubscriptionServiceConfiguration) service.OSOSubscriptionService {
	return &osoSubscriptionServiceImpl{
		BaseService: base.NewBaseService(context),
		config:      config,
		httpClient:  http.DefaultClient,
	}
}
248057
func (m *SubscriptionManager) cancelSubscription(sub *newSubscription) {
	select {
	case m.cancelSubscriptions <- &cancelSubscription{sub.id}:
	case <-m.quit:
	}
}
169195
func newServiceAccounts(c *Client, ns string) ServiceAccountsInterface {
	return &serviceAccounts{
		client:    c,
		namespace: ns,
	}
}
1103032
func newInterfaceWithStub(project string, service interfaces.Service) *Interface {
	return &Interface{project, service}
}
1226712
func NewFileChangeCommentSubscriptionType(Description string) *FileChangeCommentSubscriptionType {
	s := new(FileChangeCommentSubscriptionType)
	s.Description = Description
	return s
}
1066002
func NewSendClientSubuser(key, subuser string) *Client {
	request := GetRequestSubuser(key, "/v3/mail/send", "", subuser)
	request.Method = "POST"
	return &Client{request}
}
1011190
func (s *AuthService) DeleteSubscription(c context.Context, subscription string) error {
	var reply struct {
		Error struct {
			Code int `json:"code"`
		} `json:"error"`
	}
	req := internal.Request{
		Method: "DELETE",
		URL:    s.pubSubURL(subscription),
		Scopes: oauthScopes,
		Out:    &reply,
	}
	if err := req.Do(c); err != nil && reply.Error.Code != 404 {
		return err
	}
	return nil
}
172441
func NewService(cookieSecret string, smsService communication.SMSService, emailService communication.EmailService,
	identityservice *identityservice.Service, version string, testEnv bool) (service *Service) {
	service = &Service{smsService: smsService}

	p := &validation.IYOPhonenumberValidationService{SMSService: smsService}
	service.phonenumberValidationService = p
	e := &validation.IYOEmailAddressValidationService{EmailService: emailService}
	service.emailaddressValidationService = e

	service.identityService = identityservice

	service.version = version

	service.testEnv = testEnv

	service.initializeSessions(cookieSecret)
	return
}
1333275
func NewONSError(e error, description string) *ONSError {
	err := &ONSError{RootError: e}
	err.AddParameter("ErrorDescription", description)
	return err
}
722947
func (c *Connection) establishSubscription(h Headers) (*subscription, error, Headers) {
	c.log(SUBSCRIBE, "start establishSubscription")
	defer c.log(SUBSCRIBE, "end establishSubscription")
	//
	id, hid := h.Contains(HK_ID)
	uuid1 := Uuid()
	sha11 := Sha1(h.Value(HK_DESTINATION))
	//
	c.subsLock.RLock() // Acquire Read lock
	// No duplicates
	if hid {
		if _, q := c.subs[id]; q {
			c.subsLock.RUnlock()   // Release Read lock
			return nil, EDUPSID, h // Duplicate subscriptions not allowed
		}
		if _, q := c.subs[sha11]; q {
			c.subsLock.RUnlock()   // Release Read lock
			return nil, EDUPSID, h // Duplicate subscriptions not allowed
		}
	} else {
		if _, q := c.subs[uuid1]; q {
			c.subsLock.RUnlock()   // Release Read lock
			return nil, EDUPSID, h // Duplicate subscriptions not allowed
		}
	}
	c.subsLock.RUnlock() // Release Read lock
	//
	sd := new(subscription) // New subscription data
	if hid {
		sd.id = id // Note user supplied id
	}
	sd.cs = false                         // No shutdown yet
	sd.drav = false                       // Drain after value validity
	sd.dra = 0                            // Never drain MESSAGE frames
	sd.drmc = 0                           // Current drain count
	sd.md = make(chan MessageData, c.scc) // Make subscription MD channel
	sd.am = h.Value(HK_ACK)               // Set subscription ack mode
	//
	if !hid {
		// No caller supplied ID.  This STOMP client package supplies one.  It is the
		// caller's responsibility for discover the value from subsequent message
		// traffic.
		switch c.Protocol() {
		case SPL_10:
			nsid := sha11 // This will be unique for a given destination
			sd.id = nsid
			h = h.Add(HK_ID, nsid)
		case SPL_11:
			fallthrough
		case SPL_12:
			sd.id = uuid1
			h = h.Add(HK_ID, uuid1)
		default:
			log.Fatalf("Internal protocol level error:<%s>\n", c.Protocol())
		}
	}

	// STOMP Protocol Enhancement
	if dc, okda := h.Contains(StompPlusDrainAfter); okda {
		n, e := strconv.ParseInt(dc, 10, 0)
		if e != nil {
			log.Printf("sng_drafter conversion error: %v\n", e)
		} else {
			sd.drav = true   // Drain after value is OK
			sd.dra = uint(n) // Drain after count
		}
	}

	// This is a write lock
	c.subsLock.Lock()
	c.subs[sd.id] = sd // Add subscription to the connection subscription map
	c.subsLock.Unlock()
	//
	return sd, nil, h // Return the subscription pointer
}
634169
func UpgradeDescription(description string) UpdateOption {
	return func(opts *options) {
		opts.updateReq.Description = description
	}
}
107631
func NewDiscoveryService(self NetworkMember, comm CommService, crypt CryptoService, disPol DisclosurePolicy,
	config DiscoveryConfig) Discovery {
	d := &gossipDiscoveryImpl{
		self:             self,
		incTime:          uint64(time.Now().UnixNano()),
		seqNum:           uint64(0),
		deadLastTS:       make(map[string]*timestamp),
		aliveLastTS:      make(map[string]*timestamp),
		id2Member:        make(map[string]*NetworkMember),
		aliveMembership:  util.NewMembershipStore(),
		deadMembership:   util.NewMembershipStore(),
		crypt:            crypt,
		comm:             comm,
		lock:             &sync.RWMutex{},
		toDieChan:        make(chan struct{}, 1),
		toDieFlag:        int32(0),
		logger:           util.GetLogger(util.DiscoveryLogger, self.InternalEndpoint),
		disclosurePolicy: disPol,
		pubsub:           util.NewPubSub(),

		aliveTimeInterval:            config.AliveTimeInterval,
		aliveExpirationTimeout:       config.AliveExpirationTimeout,
		aliveExpirationCheckInterval: config.AliveExpirationCheckInterval,
		reconnectInterval:            config.ReconnectInterval,
	}

	d.validateSelfConfig()
	d.msgStore = newAliveMsgStore(d)

	go d.periodicalSendAlive()
	go d.periodicalCheckAlive()
	go d.handleMessages()
	go d.periodicalReconnectToDead()
	go d.handlePresumedDeadPeers()

	return d
}
691167
func (w *WSEvents) redoSubscriptionsAfter(d time.Duration) {
	time.Sleep(d)

	for q := range w.subscriptions {
		err := w.ws.Subscribe(context.Background(), q)
		if err != nil {
			w.Logger.Error("Failed to resubscribe", "err", err)
		}
	}
}
21943
func NewSubscription(producer func(<-chan struct{}) error) Subscription {
	s := &funcSub{unsub: make(chan struct{}), err: make(chan error, 1)}
	go func() {
		defer close(s.err)
		err := producer(s.unsub)
		s.mu.Lock()
		defer s.mu.Unlock()
		if !s.unsubscribed {
			if err != nil {
				s.err <- err
			}
			s.unsubscribed = true
		}
	}()
	return s
}
1049968
func (nc *Conn) resendSubscriptions() {
	// Since we are going to send protocols to the server, we don't want to
	// be holding the subsMu lock (which is used in processMsg). So copy
	// the subscriptions in a temporary array.
	nc.subsMu.RLock()
	subs := make([]*Subscription, 0, len(nc.subs))
	for _, s := range nc.subs {
		subs = append(subs, s)
	}
	nc.subsMu.RUnlock()
	for _, s := range subs {
		adjustedMax := uint64(0)
		s.mu.Lock()
		if s.max > 0 {
			if s.delivered < s.max {
				adjustedMax = s.max - s.delivered
			}
			// adjustedMax could be 0 here if the number of delivered msgs
			// reached the max, if so unsubscribe.
			if adjustedMax == 0 {
				s.mu.Unlock()
				fmt.Fprintf(nc.bw, unsubProto, s.sid, _EMPTY_)
				continue
			}
		}
		s.mu.Unlock()

		fmt.Fprintf(nc.bw, subProto, s.Subject, s.Queue, s.sid)
		if adjustedMax > 0 {
			maxStr := strconv.Itoa(int(adjustedMax))
			fmt.Fprintf(nc.bw, unsubProto, s.sid, maxStr)
		}
	}
}
146529
func parseSubscriptionName(rawArgs json.RawMessage) (string, error) {
	dec := json.NewDecoder(bytes.NewReader(rawArgs))
	if tok, _ := dec.Token(); tok != json.Delim('[') {
		return "", errors.New("non-array args")
	}
	v, _ := dec.Token()
	method, ok := v.(string)
	if !ok {
		return "", errors.New("expected subscription name as first argument")
	}
	return method, nil
}
238292
func NewUserService(ctx servicecontext.ServiceContext, config UserServiceConfiguration) service.UserService {
	return &userServiceImpl{
		BaseService: base.NewBaseService(ctx),
		config:      config,
	}
}