// NewState creates a new client-side Uniter facade.
547445
func NewState(
	caller base.APICaller,
	authTag names.UnitTag,
) *State {
	facadeCaller := base.NewFacadeCaller(
		caller,
		uniterFacade,
	)
	state := &State{
		ModelWatcher:     common.NewModelWatcher(facadeCaller),
		APIAddresser:     common.NewAPIAddresser(facadeCaller),
		UpgradeSeriesAPI: common.NewUpgradeSeriesAPI(facadeCaller, authTag),
		StorageAccessor:  NewStorageAccessor(facadeCaller),
		facade:           facadeCaller,
		unitTag:          authTag,
	}

	newWatcher := func(result params.NotifyWatchResult) watcher.NotifyWatcher {
		return apiwatcher.NewNotifyWatcher(caller, result)
	}
	state.LeadershipSettings = NewLeadershipSettingsAccessor(
		facadeCaller.FacadeCall,
		newWatcher,
		ErrIfNotVersionFn(2, state.BestAPIVersion()),
	)
	return state
}
916778
func NewStatement(effect Effect, principal Principal, actionSet ActionSet, resourceSet ResourceSet, conditions condition.Functions) Statement {
	return Statement{
		Effect:     effect,
		Principal:  principal,
		Actions:    actionSet,
		Resources:  resourceSet,
		Conditions: conditions,
	}
}
1026365
func NewStateFacade(ctx facade.Context) (*Facade, error) {
	authorizer := ctx.Auth()
	if !authorizer.AuthMachineAgent() {
		return nil, common.ErrPerm
	}

	resources := ctx.Resources()
	model, err := ctx.State().Model()
	if err != nil {
		return nil, errors.Trace(err)
	}
	cloudSpecAPI := cloudspec.NewCloudSpec(
		resources,
		cloudspec.MakeCloudSpecGetterForModel(ctx.State()),
		cloudspec.MakeCloudSpecWatcherForModel(ctx.State()),
		common.AuthFuncForTag(model.ModelTag()),
	)
	return &Facade{
		CloudSpecAPI:        cloudSpecAPI,
		ModelWatcher:        common.NewModelWatcher(model, resources, authorizer),
		ControllerConfigAPI: common.NewStateControllerConfig(ctx.State()),
		auth:                authorizer,
		resources:           resources,
	}, nil
}
741820
func NewStateAuthenticator(
	statePool *state.StatePool,
	mux *apiserverhttp.Mux,
	clock clock.Clock,
	abort <-chan struct{},
) (httpcontext.LocalMacaroonAuthenticator, error) {
	stateAuthenticator, err := stateauthenticator.NewAuthenticator(statePool, clock)
	if err != nil {
		return nil, errors.Trace(err)
	}
	stateAuthenticator.AddHandlers(mux)
	go stateAuthenticator.Maintain(abort)
	return stateAuthenticator, nil
}
536316
func (s *GetSubscriptionStateOutput) SetSubscriptionState(v string) *GetSubscriptionStateOutput {
	s.SubscriptionState = &v
	return s
}
928531
func NewState(db dbm.DB) *State {
	forest, err := storage.NewMutableForest(storage.NewPrefixDB(db, forestPrefix), defaultCacheCapacity)
	if err != nil {
		// This should only happen if we have negative cache capacity, which for us is a positive compile-time constant
		panic(fmt.Errorf("could not create new state because error creating MutableForest"))
	}
	ring := validator.NewRing(nil, DefaultValidatorsWindowSize)
	rs := ReadState{Forest: forest, History: ring}
	ws := writeState{forest: forest, ring: ring}
	return &State{
		db:         db,
		ReadState:  rs,
		writeState: ws,
		logger:     logging.NewNoopLogger(),
	}
}
889761
func newStatefulSets(c *AppsV1beta1Client, namespace string) *statefulSets {
	return &statefulSets{
		client: c.RESTClient(),
		ns:     namespace,
	}
}
1136260
func NewState() *State {
	return &State{
		store:                        store.NewNilStore(),
		monitor:                      monitor.NewNilMonitor(),
		invokeGlobalCallbacksOnFlush: true,
	}
}
652497
func (s *WorkGroupSummary) SetState(v string) *WorkGroupSummary {
	s.State = &v
	return s
}
961405
func BuildState(cb func(*SyncState)) *State {
	s := NewState()
	cb(s.SyncWrapper())
	return s
}
320841
func newSyncState(startBlock, syncedTo *BlockStamp) *syncState {

	return &syncState{
		startBlock: *startBlock,
		syncedTo:   *syncedTo,
	}
}
1307743
func newState(name string, out io.Writer, ctx map[string]Value, env *Env) *state {
	return &state{
		out:  out,
		node: nil,

		name: name,
		meta: &metadata{make(map[string]string)},

		blocks: make([]map[string]*parse.BlockNode, 0),
		macros: make(map[string]*parse.MacroNode),

		env:   env,
		scope: &scopeStack{[]map[string]Value{ctx}},
	}
}
907553
func NewStateLoader(doer httpcli.Doer, initialEndpoint urls.Builder, unmarshal Unmarshaler) StateLoader {
	return func(masters []string) (state.State, error) {
		return LoadMasterStateTryAll(masters, func(ip, port string) (state.State, error) {
			return LoadMasterStateFailover(ip, func(tryIP string) (state.State, error) {
				return LoadMasterState(doer, initialEndpoint, tryIP, port, unmarshal)
			})
		})
	}

}
855222
func (h *QuasiNewtonHelper) UpdateState(nextPos *core.Vector, nextGrad *core.Vector) (isOptimal bool) {
	if int64(len(h.sList)) >= h.numHist {
		h.sList = h.sList[1:]
		h.yList = h.yList[1:]
		h.roList = h.roList[1:]
	}
	newS := nextPos.ElemWiseMultiplyAdd(h.curPos, -1)
	newY := nextGrad.ElemWiseMultiplyAdd(h.curGrad, -1)
	ro := newS.Dot(newY)
	h.sList = append(h.sList, newS)
	h.yList = append(h.yList, newY)
	h.roList = append(h.roList, ro)
	h.curPos = nextPos
	h.curGrad = nextGrad
	return ro == 0
}
826832
func NewStateSync(root common.Hash, database ethdb.Reader) *trie.Sync {
	var syncer *trie.Sync
	callback := func(leaf []byte, parent common.Hash) error {
		var obj Account
		if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil {
			return err
		}
		syncer.AddSubTrie(obj.Root, 64, parent, nil)
		syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent)
		return nil
	}
	syncer = trie.NewSync(root, database, callback)
	return syncer
}
663901
func NewSNSTaskState(stateName string,
	parameters SNSTaskParameters) *SNSTaskState {

	sns := &SNSTaskState{
		BaseTask: BaseTask{
			baseInnerState: baseInnerState{
				name: stateName,
				id:   rand.Int63(),
			},
		},
		parameters: parameters,
	}
	return sns
}
249892
func (s *stateTracker) setState(newState folderState) {
	if newState == FolderError {
		panic("must use setError")
	}

	s.mut.Lock()
	if newState != s.current {
		/* This should hold later...
		if s.current != FolderIdle && (newState == FolderScanning || newState == FolderSyncing) {
			panic("illegal state transition " + s.current.String() + " -> " + newState.String())
		}
		*/

		eventData := map[string]interface{}{
			"folder": s.folderID,
			"to":     newState.String(),
			"from":   s.current.String(),
		}

		if !s.changed.IsZero() {
			eventData["duration"] = time.Since(s.changed).Seconds()
		}

		s.current = newState
		s.changed = time.Now()

		events.Default.Log(events.StateChanged, eventData)
	}
	s.mut.Unlock()
}