// start is a method on ManifoldConfig because it's more readable than a closure.
557834
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	var clk clock.Clock
	if err := context.Get(config.ClockName, &clk); err != nil {
		return nil, errors.Trace(err)
	}

	var agent agent.Agent
	if err := context.Get(config.AgentName, &agent); err != nil {
		return nil, errors.Trace(err)
	}
	var transport raft.Transport
	if err := context.Get(config.TransportName, &transport); err != nil {
		return nil, errors.Trace(err)
	}

	// TODO(axw) make the directory path configurable, so we can
	// potentially have multiple Rafts. The dqlite raft should go
	// in <data-dir>/dqlite.
	agentConfig := agent.CurrentConfig()
	raftDir := filepath.Join(agentConfig.DataDir(), "raft")

	return config.NewWorker(Config{
		FSM:                  config.FSM,
		Logger:               config.Logger,
		StorageDir:           raftDir,
		LocalID:              raft.ServerID(agentConfig.Tag().Id()),
		Transport:            transport,
		Clock:                clk,
		PrometheusRegisterer: config.PrometheusRegisterer,
	})
}
842262
func manifoldStart(
	apiCaller base.APICaller,
	newExternalControllerWatcherClient NewExternalControllerWatcherClientFunc,
) (worker.Worker, error) {
	client := externalcontrollerupdater.New(apiCaller)
	worker, err := New(
		client,
		newExternalControllerWatcherClient,
		clock.WallClock,
	)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return worker, nil
}
611997
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	var stTracker workerstate.StateTracker
	if err := context.Get(config.StateName, &stTracker); err != nil {
		return nil, errors.Trace(err)
	}

	pool, err := stTracker.Use()
	if err != nil {
		return nil, errors.Trace(err)
	}

	w, err := config.NewWorker(Config{
		Logger:               config.Logger,
		WatcherFactory:       func() BackingWatcher { return pool.SystemState().WatchAllModels(pool) },
		PrometheusRegisterer: config.PrometheusRegisterer,
		Cleanup:              func() { _ = stTracker.Done() },
	})
	if err != nil {
		_ = stTracker.Done()
		return nil, errors.Trace(err)
	}
	return w, nil
}
206796
func Manifold(config ManifoldConfig) dependency.Manifold {
	return dependency.Manifold{
		Inputs: []string{
			config.APICallerName,
		},
		Start: func(context dependency.Context) (worker.Worker, error) {
			if err := config.Validate(); err != nil {
				return nil, errors.Trace(err)
			}
			var apiCaller base.APICaller
			if err := context.Get(config.APICallerName, &apiCaller); err != nil {
				return nil, err
			}
			return manifoldStart(apiCaller, config.NewExternalControllerWatcherClient)
		},
	}
}
1138616
func (config ManifoldConfig) start(apiCaller base.APICaller) (worker.Worker, error) {
	facade, err := config.NewFacade(apiCaller)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return config.NewWorker(Config{
		Facade: facade,
	})
}
306381
func (p *Project) Start(image string) (types.ContainerJSON, error) {
	return p.StartWithConfig(image, ContainerConfig{})
}
168035
func (h *discoverProviderHealer) Start() {
	// check if started channel is already filled
	// if not, we start a new loop
	select {
	case h.started <- struct{}{}:
	default:
		return
	}

	go func() {
		for {
			// loop or quit
			select {
			case <-h.node.clock.After(h.period):
			case <-h.quit:
				return
			}

			// attempt heal with the pro
			if h.rand.Float64() < h.Probability() {
				h.Heal()
			}
		}
	}()
}
945132
func (this *MirrorMaker) Start() {
	this.initializeMessageChannels()
	this.startConsumers()
	this.startProducers()
	<-this.stopped
}
1168913
func (s *serverManager) Start(username string, password string, host string, port int) (Server, error) {
	startedCh := make(chan error)
	server := &server{
		logger: s.logger,
		logTag: "registryServer",
	}
	go func() {
		err := server.start(username, password, host, port, startedCh)
		if err != nil {
			s.logger.Debug(s.logTag, "Registry error occurred: %s", err.Error())
		}
	}()

	// block until started
	err := <-startedCh
	if err != nil {
		if stopErr := server.Stop(); stopErr != nil {
			s.logger.Warn(s.logTag, "Failed to stop server: %s", stopErr.Error())
		}
	}
	return server, err
}
928941
func Manifold(config ManifoldConfig) dependency.Manifold {
	typedConfig := engine.AgentAPIManifoldConfig{
		AgentName:     config.AgentName,
		APICallerName: config.APICallerName,
	}
	return engine.AgentAPIManifold(typedConfig, config.start)
}
1271646
func (config FlagManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	var gate Waiter
	if err := context.Get(config.GateName, &gate); err != nil {
		return nil, errors.Trace(err)
	}
	worker, err := config.NewWorker(gate)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return worker, nil

}
14737
func (s *Server) Start(ctx context.Context) {
	go func() {
		defer s.Close()
		<-ctx.Done()
		logger := log.FromContext(ctx)
		logger.Info("I have to go...")
		logger.Info("Stopping server gracefully")
		s.Stop()
	}()

	s.startTCPServers()
	s.routinesPool.Go(func(stop chan bool) {
		s.listenProviders(stop)
	})
	s.routinesPool.Go(func(stop chan bool) {
		s.listenConfigurations(stop)
	})
	s.startProvider()
	s.routinesPool.Go(func(stop chan bool) {
		s.listenSignals(stop)
	})
}
781002
func Manifold(config ManifoldConfig) dependency.Manifold {
	return dependency.Manifold{
		Inputs: []string{
			config.AgentName,
			config.ClockName,
			config.ControllerPortName,
			config.StateName,
		},
		Start: config.start,
	}
}
852234
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	var clk clock.Clock
	if err := context.Get(config.ClockName, &clk); err != nil {
		return nil, errors.Trace(err)
	}

	var agent agent.Agent
	if err := context.Get(config.AgentName, &agent); err != nil {
		return nil, errors.Trace(err)
	}

	var authenticator httpcontext.Authenticator
	if err := context.Get(config.AuthenticatorName, &authenticator); err != nil {
		return nil, errors.Trace(err)
	}

	var hub *pubsub.StructuredHub
	if err := context.Get(config.HubName, &hub); err != nil {
		return nil, errors.Trace(err)
	}

	var mux *apiserverhttp.Mux
	if err := context.Get(config.MuxName, &mux); err != nil {
		return nil, errors.Trace(err)
	}

	apiInfo, ok := agent.CurrentConfig().APIInfo()
	if !ok {
		return nil, dependency.ErrMissing
	}
	certPool, err := api.CreateCertPool(apiInfo.CACert)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return config.NewWorker(Config{
		APIInfo:       apiInfo,
		Authenticator: authenticator,
		DialConn:      config.DialConn,
		Hub:           hub,
		Mux:           mux,
		Path:          config.Path,
		LocalID:       raft.ServerID(agent.CurrentConfig().Tag().Id()),
		TLSConfig:     api.NewTLSConfig(certPool),
		Clock:         clk,
		Timeout:       raftNetworkTimeout,
	})
}
113583
func Manifold(config ManifoldConfig) dependency.Manifold {
	inputs := []string{config.ClockName}
	if config.StateName != "" {
		inputs = append(inputs, config.StateName)
	} else {
		inputs = append(inputs, config.LeaseManagerName)
	}
	if config.RaftName != "" {
		inputs = append(inputs, config.RaftName)
	}
	return dependency.Manifold{
		Inputs: inputs,
		Start:  config.start,
	}
}
279502
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	var clock clock.Clock
	if err := context.Get(config.ClockName, &clock); err != nil {
		return nil, errors.Trace(err)
	}

	if config.RaftName != "" {
		// We don't need anything from raft directly, but if it's set
		// ensure it's running before continuing.
		if err := context.Get(config.RaftName, nil); err != nil {
			return nil, errors.Trace(err)
		}
	}

	cleanup := func() error { return nil }
	var updaterFunc func() (globalclock.Updater, error)
	if config.StateName != "" {
		var stTracker workerstate.StateTracker
		if err := context.Get(config.StateName, &stTracker); err != nil {
			return nil, errors.Trace(err)
		}
		statePool, err := stTracker.Use()
		if err != nil {
			return nil, errors.Trace(err)
		}
		cleanup = stTracker.Done
		updaterFunc = statePool.SystemState().GlobalClockUpdater
	} else {

		var updater globalclock.Updater
		if err := context.Get(config.LeaseManagerName, &updater); err != nil {
			return nil, errors.Trace(err)
		}
		updaterFunc = func() (globalclock.Updater, error) {
			return updater, nil
		}
	}

	worker, err := config.NewWorker(Config{
		NewUpdater:     updaterFunc,
		LocalClock:     clock,
		UpdateInterval: config.UpdateInterval,
		BackoffDelay:   config.BackoffDelay,
		Logger:         config.Logger,
	})
	if err != nil {
		cleanup()
		return nil, errors.Trace(err)
	}

	go func() {
		worker.Wait()
		cleanup()
	}()
	return worker, nil
}
328483
func (c *Client) Start() error {
	if err := c.Listen(); err != nil {
		return err
	}
	return c.Serve()
}