// Accepts: foo,bar,qux@timer
//          *
//          *@error
//          *@error,database@timer
770212
func parsePackageSettings(input string, defaultOutputSettings *OutputSettings) map[string]*OutputSettings {
	all := map[string]*OutputSettings{}
	items := strings.Split(input, ",")

	for _, item := range items {
		name, verbosity := parsePackageName(item)
		if verbosity == nil {
			verbosity = defaultOutputSettings
		}

		all[name] = verbosity
	}

	return all
}
198931
func (s *ReindexService) Timeout(timeout string) *ReindexService {
	s.timeout = timeout
	return s
}
308834
func clockDelta(c *mgo.Collection) (time.Duration, error) {
	var server struct {
		time.Time `bson:"retval"`
	}
	var isMaster struct {
		LocalTime time.Time `bson:"localTime"`
	}
	var after time.Time
	var before time.Time
	var serverDelay time.Duration
	supportsMasterLocalTime := true
	session := c.Database.Session.Copy()
	defer session.Close()
	db := c.Database.With(session)
	for i := 0; i < 10; i++ {
		if supportsMasterLocalTime {
			// Try isMaster.localTime, which is present since MongoDB 2.2
			// and does not require admin privileges.
			// TODO(perrito666) 2016-05-02 lp:1558657
			before = time.Now()
			err := db.Run("isMaster", &isMaster)
			// TODO(perrito666) 2016-05-02 lp:1558657
			after = time.Now()
			if err != nil {
				return 0, errors.Trace(err)
			}
			if isMaster.LocalTime.IsZero() {
				supportsMasterLocalTime = false
				continue
			} else {
				serverDelay = isMaster.LocalTime.Sub(before)
			}
		} else {
			// If MongoDB doesn't have localTime as part of
			// isMaster result, it means that the server is likely
			// a MongoDB older than 2.2.
			//
			// Fallback to 'eval' works fine on versions older than
			// 2.4 where it does not require admin privileges.
			//
			// NOTE: 'eval' takes a global write lock unless you
			// specify 'nolock' (which we are not doing below, for
			// no apparent reason), so it is quite likely that the
			// eval could take a relatively long time to acquire
			// the lock and thus cause a retry on the callDelay
			// check below on a busy server.
			// TODO(perrito666) 2016-05-02 lp:1558657
			before = time.Now()
			err := db.Run(bson.D{{"$eval", "function() { return new Date(); }"}}, &server)
			// TODO(perrito666) 2016-05-02 lp:1558657
			after = time.Now()
			if err != nil {
				return 0, errors.Trace(err)
			}
			serverDelay = server.Sub(before)
		}
		// If the call to the server takes longer than a few seconds we
		// retry it a couple more times before giving up. It is unclear
		// why the retry would help at all here.
		//
		// If the server takes longer than the specified amount of time
		// on every single try, then we simply give up.
		callDelay := after.Sub(before)
		if callDelay > 5*time.Second {
			continue
		}
		return serverDelay, nil
	}
	return 0, errors.Errorf("cannot synchronize clock with database server")
}
1362809
func Init(dbcfgs *dbconfigs.DBConfigs) error {
	qs, err := initProxy(dbcfgs)
	if err != nil {
		return err
	}

	servenv.OnRun(func() {
		qs.Register()
		addStatusParts(qs)
	})

	healthCheckTimer := timer.NewTimer(*healthCheckInterval)
	healthCheckTimer.Start(func() {
		if !qs.IsServing() {
			_ /* stateChanged */, healthErr := qs.SetServingType(topodatapb.TabletType_MASTER, true, nil)
			if healthErr != nil {
				log.Errorf("state %v: vtqueryserver SetServingType failed: %v", qs.GetState(), healthErr)
			}
		}
	})
	healthCheckTimer.Trigger()

	servenv.OnClose(func() {
		healthCheckTimer.Stop()
		// We now leave the queryservice running during lameduck,
		// so stop it in OnClose(), after lameduck is over.
		qs.StopService()
	})

	return nil
}
347800
func writeSystemTZ(s Session) {
	sql := fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES ("%s", "%s", "TiDB Global System Timezone.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%s"`,
		mysql.SystemDB, mysql.TiDBTable, tidbSystemTZ, timeutil.InferSystemTZ(), timeutil.InferSystemTZ())
	mustExecute(s, sql)
}
224282
func (db *DB) HExpire(key []byte, duration int64) (int64, error) {
	if duration <= 0 {
		return 0, errExpireValue
	}

	return db.hExpireAt(key, time.Now().Unix()+duration)
}
1177661
func (v *KeyType) Accept(value interface{}) error {
	var tmp KeyType
	switch x := value.(type) {
	case string:
		tmp = KeyType(x)
	case KeyType:
		tmp = x
	default:
		return errors.Errorf(`invalid type for jwa.KeyType: %T`, value)
	}
	switch tmp {
	case EC, OctetSeq, RSA:
	default:
		return errors.Errorf(`invalid jwa.KeyType value`)
	}

	*v = tmp
	return nil
}
361477
func (s *CloseIndexService) Timeout(timeout string) *CloseIndexService {
	s.timeout = timeout
	return s
}
455990
func (s *Server) AcceptN(n int, maxWait time.Duration) []*ReceivedRequest {
	var ret []*ReceivedRequest
	tmr := time.After(maxWait)
	for i := 0; i < n; i++ {
		select {
		case recvReq := <-s.ch:
			ret = append(ret, recvReq)
		case <-s.closeSig:
			return ret
		case <-tmr:
			return ret
		}
	}
	return ret
}
80063
func (c *Command) ExecTimeout(timeout time.Duration, f interface{}, args ...interface{}) Return {
	var retvals chan []reflect.Value = make(chan []reflect.Value)
	val := reflect.ValueOf(f)
	if val.Kind() != reflect.Func {
		panic("f is not a function")
	}
	t := val.Type()
	if t.NumIn() != len(args) {
		panic("invalid number of arguments")
	}
	a := make([]reflect.Value, len(args))
	for i, arg := range args {
		a[i] = reflect.ValueOf(arg)
		if !a[i].Type().AssignableTo(t.In(i)) {
			panic(fmt.Sprintf("invalid argument type, argument %v must be assignable to %v", a[i].Type(), t.In(i)))
		}
	}
	go func() {
		var err error
		if timeout != 0 {
			err = c.Conn.SetDeadline(time.Now().Add(timeout))
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		} else {
			err = c.Conn.SetDeadline(time.Time{})
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		}
		values := val.Call(a)
		if timeout != 0 {
			err = c.Conn.SetDeadline(time.Time{})
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		}
		setError(values, err)
		retvals <- values
	}()

	return func(args ...interface{}) {
		retvals := <-retvals
		if len(retvals) != len(args) {
			panic(fmt.Sprintf("the number of arguments (%v) in Returns must be equal to the number of return values in the function (%v)", len(args), len(retvals)))
		}
		for i, retval := range retvals {
			val := reflect.ValueOf(args[i])
			if val.Kind() != reflect.Ptr {
				panic("Returns arguments must be pointers")
			}
			if retval.Type() != val.Elem().Type() {
				panic("diferent kind")
			}
			val.Elem().Set(retval)
		}
	}
}
608169
func (a MultiStatsClient) Timing(name string, value time.Duration, rate float64) {
	for _, c := range a {
		c.Timing(name, value, rate)
	}
}
224444
func (b *Buffer) Accept(batch []telegraf.Metric) {
	b.Lock()
	defer b.Unlock()

	for _, m := range batch {
		b.metricWritten(m)
	}

	b.resetBatch()
	b.BufferSize.Set(int64(b.length()))
}
1232432
func (db *DB) WithTimeout(d time.Duration) *DB {
	return newDB(db.ctx, db.baseDB.WithTimeout(d))
}
721435
func (l *lexer) acceptBareString() {
	l.acceptFunc(
		func(r rune) bool {
			return !any(r, bareStringDisallowed) && r != eof
		},
	)
}
894379
func (p *fooBarQueryProperty) LessThan(value interface{}) *fooBarQueryBuilder {
	p.bldr.q = p.bldr.q.Filter(p.name+" <", value)
	if p.bldr.plugin != nil {
		p.bldr.plugin.Filter(p.name, "<", value)
	}
	return p.bldr
}
893235
func (l *NSQLookupd) Main() error {
	ctx := &Context{l}

	exitCh := make(chan error)
	var once sync.Once
	exitFunc := func(err error) {
		once.Do(func() {
			if err != nil {
				l.logf(LOG_FATAL, "%s", err)
			}
			exitCh <- err
		})
	}

	tcpServer := &tcpServer{ctx: ctx}
	l.waitGroup.Wrap(func() {
		exitFunc(protocol.TCPServer(l.tcpListener, tcpServer, l.logf))
	})
	httpServer := newHTTPServer(ctx)
	l.waitGroup.Wrap(func() {
		exitFunc(http_api.Serve(l.httpListener, httpServer, "HTTP", l.logf))
	})

	err := <-exitCh
	return err
}
1015594
func (t *Time) check(sc *stmtctx.StatementContext) error {
	allowZeroInDate := false
	allowInvalidDate := false
	// We should avoid passing sc as nil here as far as possible.
	if sc != nil {
		allowZeroInDate = sc.IgnoreZeroInDate
		allowInvalidDate = sc.AllowInvalidDate
	}
	var err error
	switch t.Type {
	case mysql.TypeTimestamp:
		err = checkTimestampType(sc, t.Time)
	case mysql.TypeDatetime:
		err = checkDatetimeType(t.Time, allowZeroInDate, allowInvalidDate)
	case mysql.TypeDate:
		err = checkDateType(t.Time, allowZeroInDate, allowInvalidDate)
	}
	return errors.Trace(err)
}