// FetchState fetches state
491434
func (cs *ChannelState) FetchState() (endorsement.State, error) {
	qe, err := cs.NewQueryExecutor()
	if err != nil {
		return nil, err
	}

	return &StateContext{
		QueryExecutor: qe,
		Store:         cs.Store,
	}, nil
}
837127
func (r *RepoStatus) GetState() string {
	if r == nil || r.State == nil {
		return ""
	}
	return *r.State
}
415473
func (r *TasksService) GetStates() *TasksGetStatesCall {
	c := &TasksGetStatesCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	return c
}
1338585
func (db *StakeDatabase) DBState() (uint32, *chainhash.Hash, error) {
	db.nodeMtx.RLock()
	defer db.nodeMtx.RUnlock()

	return db.dbState()
}
879106
func (bc *BlockChain) HasState(hash common.Hash) bool {
	_, err := bc.stateCache.OpenTrie(hash)
	return err == nil
}
113295
func withState(ctx context.Context, s *State) context.Context {
	return context.WithValue(ctx, &stateCtxKey, s)
}
1224110
func (agent *ActionAgent) RefreshState(ctx context.Context) error {
	if err := agent.lock(ctx); err != nil {
		return err
	}
	defer agent.unlock()

	return agent.refreshTablet(ctx, "RefreshState")
}
1363977
func (observer *Observer) fetchStat(keyName string, seconds int64) int64 {
	now := time.Now().UTC().Unix() - 2 // we can only look for already written stats
	keys := make([]string, 0)

	for i := int64(0); i < seconds; i++ {
		key := fmt.Sprintf("%s::%d", keyName, now)
		keys = append(keys, key)
		now--
	}
	vals, err := observer.redisClient.MGet(keys...).Result()
	if err != nil {
		return 0
	}
	nilVal := 0
	sum := int64(0)
	for _, val := range vals {
		if val == nil {
			nilVal++
			continue
		}
		num, _ := strconv.ParseInt(val.(string), 10, 64)
		sum += num
	}
	return sum / seconds
}
408648
func (c *upgradeContext) APIState() api.Connection {
	if c.api == nil {
		panic("API not available from this context")
	}
	return c.api
}
1089455
func (s *StatusEvent) GetState() string {
	if s == nil || s.State == nil {
		return ""
	}
	return *s.State
}
1203679
func (_m *Store) GetState() (state.State, error) {
	ret := _m.Called()

	var r0 state.State
	if rf, ok := ret.Get(0).(func() state.State); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(state.State)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
74797
func genState() uint64 {
	prime, err := rand.Prime(rand.Reader, 64)
	if err != nil {
		panic(err)
	}
	return prime.Uint64()
}
178122
func (d *decoder) pushState(s json.Delim) {
	d.parseState = append(d.parseState, s)
}
799774
func FetchState(conn net.Conn) (*State, error) {
	err := write(conn, []byte{0x81, 0x8a, 0x8b})
	if err != nil {
		return nil, err
	}

	resp := make([]byte, 100)
	conn.SetReadDeadline(time.Now().Add(time.Second * 5))
	n, err := conn.Read(resp)
	if err != nil {
		return nil, err
	}

	// Seems like flux sends back multiple responses if they are backed up, sometimes not all
	// complete, so just grab the last 14 bytes
	if n > 14 {
		resp = resp[n-14 : n]
		if len(resp) != 14 {
			return nil, fmt.Errorf("unknown response from get state")
		}
	}

	state := &State{}
	power := resp[2]
	switch power {
	case 0x23:
		state.Power = 1
	case 0x24:
		state.Power = 0
	default:
		state.Power = 2
	}

	pattern := resp[3]
	wwLevel := resp[9]
	mode := "unknown"
	switch pattern {
	case 0x61, 0x62:
		if wwLevel != 0 {
			mode = "ww"
		} else {
			mode = "color"
		}
	case 0x60:
		mode = "custom"
	}
	state.Mode = mode

	switch mode {
	case "color":
		state.R = resp[6]
		state.G = resp[7]
		state.B = resp[8]
	}
	return state, nil
}
320489
func (s *State) refreshState() error {
	payload, err := s.Client.Get()
	if err != nil {
		return err
	}

	// no remote state is OK
	if payload == nil {
		s.readState = nil
		s.lineage = ""
		s.serial = 0
		return nil
	}

	stateFile, err := statefile.Read(bytes.NewReader(payload.Data))
	if err != nil {
		return err
	}

	s.lineage = stateFile.Lineage
	s.serial = stateFile.Serial
	s.state = stateFile.State
	s.readState = s.state.DeepCopy() // our states must be separate instances so we can track changes
	return nil
}
656626
func (c *Client) GetAllocState(allocID string) (*arstate.State, error) {
	ar, err := c.getAllocRunner(allocID)
	if err != nil {
		return nil, err
	}

	return ar.AllocState(), nil
}
1075694
func (ar *allocRunner) AllocState() *state.State {
	ar.stateLock.RLock()
	state := ar.state.Copy()
	ar.stateLock.RUnlock()

	// If TaskStateUpdated has not been called yet, ar.state.TaskStates
	// won't be set as it is not the canonical source of TaskStates.
	if len(state.TaskStates) == 0 {
		ar.state.TaskStates = make(map[string]*structs.TaskState, len(ar.tasks))
		for k, tr := range ar.tasks {
			state.TaskStates[k] = tr.TaskState()
		}
	}

	// Generate alloc to get other state fields
	alloc := ar.clientAlloc(state.TaskStates)
	state.ClientStatus = alloc.ClientStatus
	state.ClientDescription = alloc.ClientDescription
	state.DeploymentStatus = alloc.DeploymentStatus

	return state
}