// Service returns the *connect.Service structure represented by this config.
501018
func (c *Config) Service(client *api.Client, logger *log.Logger) (*connect.Service, error) {
	return connect.NewServiceWithLogger(c.ProxiedServiceName, client, logger)
}
621950
func (s *Snapshot) Services(node string) (memdb.ResultIterator, error) {
	iter, err := s.tx.Get("services", "node", node)
	if err != nil {
		return nil, err
	}
	return iter, nil
}
221875
func (s *auditService) Serve() {
	defer close(s.stopped)
	sub := events.Default.Subscribe(events.AllEvents)
	defer events.Default.Unsubscribe(sub)
	enc := json.NewEncoder(s.w)

	// We're ready to start processing events.
	close(s.started)

	for {
		select {
		case ev := <-sub.C():
			enc.Encode(ev)
		case <-s.stop:
			return
		}
	}
}
216582
func (s *Service) connect(fail chan struct{}) (*Client, bool) {
	// prepare new client
	client := New()
	client.Session = s.Session
	client.Logger = s.Logger
	client.futureStore = s.futureStore

	// set callback
	client.Callback = func(msg *packet.Message, err error) error {
		if err != nil {
			s.err("Client", err)
			close(fail)
			return nil
		}

		// call the handler
		if s.MessageCallback != nil {
			return s.MessageCallback(msg)
		}

		return nil
	}

	// attempt to connect
	connectFuture, err := client.Connect(s.config)
	if err != nil {
		s.err("Connect", err)
		return nil, false
	}

	// wait for connack
	err = connectFuture.Wait(s.ConnectTimeout)

	// check if future has been canceled
	if err == future.ErrCanceled {
		s.err("Connect", err)
		return nil, false
	}

	// check if future has timed out
	if err == future.ErrTimeout {
		client.Close()

		s.err("Connect", err)
		return nil, false
	}

	return client, connectFuture.SessionPresent()
}
1294709
func providerService(c *Config) *sc.ProviderService {
	ret := &sc.ProviderService{
		Service:        c.Service,
		ServiceVersion: c.Version,
		Capabilities:   map[string]int{},
		Meta:           c.Meta,
		ResourceType:   c.ResourceType,
	}

	return ret
}
400508
func (a *api) AddService(config ServiceConfig) (*service.ServiceDetails, error) {
	client, err := a.connectDAO()
	if err != nil {
		return nil, err
	}

	endpoints := make([]servicedefinition.EndpointDefinition, len(*config.LocalPorts)+len(*config.RemotePorts))
	i := 0
	for _, e := range *config.LocalPorts {
		e.Purpose = "local"
		endpoints[i] = e
		i++
	}
	for _, e := range *config.RemotePorts {
		e.Purpose = "remote"
		endpoints[i] = e
		i++
	}

	sd := &servicedefinition.ServiceDefinition{
		Name:      config.Name,
		Command:   config.Command,
		Instances: domain.MinMax{Min: 1, Max: 1, Default: 1},
		ImageID:   config.ImageID,
		Launch:    commons.AUTO,
		Endpoints: endpoints,
	}

	var serviceID string
	if err := client.DeployService(dao.ServiceDeploymentRequest{ParentID: config.ParentServiceID, Service: *sd}, &serviceID); err != nil {
		return nil, err
	}

	return a.GetServiceDetails(serviceID)
}
425179
func (r *remoteImpl) service(ctx context.Context) (*configApi.Service, error) {
	client, err := r.clients(ctx)
	if err != nil {
		return nil, err
	}
	service, err := configApi.New(client)
	if err != nil {
		return nil, err
	}

	service.BasePath = r.serviceURL
	return service, nil
}
230466
func (s *Server) Serve(l net.Listener) error {
	fmt.Fprintf(s.Transcript, "Serving on %s\n", l.Addr().String())
	defer l.Close()
	for {
		conn, err := l.Accept()
		if err != nil {
			return fmt.Errorf("Error accepting connection: %s\n", err)
		}

		fmt.Fprintf(s.Transcript, "Connection accepted\n")
		c, err := s.newConn(conn)
		if err != nil {
			return err
		}

		go c.Start()
	}
}
928894
func (ctx *SimpleContext) service(unitName string, renderer shell.Renderer) (deployerService, error) {
	// Service name can be at most 64 characters long, we limit it to 56 just to be safe.
	tag, err := names.NewUnitTag(unitName).ShortenedString(56)
	if err != nil {
		return nil, errors.Trace(err)
	}

	svcName := "jujud-" + tag

	info := service.NewAgentInfo(
		service.AgentKindUnit,
		unitName,
		ctx.agentConfig.DataDir(),
		ctx.agentConfig.LogDir(),
	)

	// TODO(thumper): 2013-09-02 bug 1219630
	// As much as I'd like to remove JujuContainerType now, it is still
	// needed as MAAS still needs it at this stage, and we can't fix
	// everything at once.
	containerType := ctx.agentConfig.Value(agent.ContainerType)

	conf := service.ContainerAgentConf(info, renderer, containerType)
	return ctx.discoverService(svcName, conf)
}
392710
func (a *Accessory) AddService(s *service.Service) {
	a.Services = append(a.Services, s)
}
924247
func (h *Health) serviceNodesConnect(ws memdb.WatchSet, s *state.Store, args *structs.ServiceSpecificRequest) (uint64, structs.CheckServiceNodes, error) {
	return s.CheckConnectServiceNodes(ws, args.ServiceName)
}
425796
func (c *Subcommand) ConfigService(ctx context.Context, host string) (*config.Service, error) {
	authOpts, err := c.authFlags.Options()
	if err != nil {
		return nil, err
	}
	client, err := auth.NewAuthenticator(ctx, auth.SilentLogin, authOpts).Client()
	if err != nil {
		return nil, err
	}

	svc, err := config.New(client)
	if err != nil {
		return nil, err
	}
	svc.BasePath = fmt.Sprintf("https://%s/_ah/api/config/v1/", host)
	svc.UserAgent = lucicfg.UserAgent
	return svc, nil
}
556967
func (c *Catalog) Service(service, tag string, q *QueryOptions) ([]*CatalogService, *QueryMeta, error) {
	var tags []string
	if tag != "" {
		tags = []string{tag}
	}
	return c.service(service, tags, q, false)
}
1292596
func (s *Simulation) Services(name string) (services map[enode.ID]node.Service) {
	nodes := s.Net.GetNodes()
	services = make(map[enode.ID]node.Service)
	for _, node := range nodes {
		if !node.Up() {
			continue
		}
		simNode, ok := node.Node.(*adapters.SimNode)
		if !ok {
			continue
		}
		services[node.ID()] = simNode.Service(name)
	}
	return services
}
275326
func (app *App) ServeInfrastructure(i *infrastructure.Infrastructure) {
	app.GET("/infrastructure", func(ctx *Context) {
		i.Lock.RLock()
		i.CurrentTimestamp = time.Now().UnixNano()
		ctx.CORS()
		e := ctx.JSON(i)
		_ = e
		i.Lock.RUnlock()
	})
	app.POST("/infrastructure/register/service", func(ctx *Context) {
		s := infrastructure.Service{
			Addresses: make([]infrastructure.Address, 0),
		}
		_, err := ctx.UnJSONBytes(ctx.PostBody(), &s)
		if err != nil {
			if err := ctx.JSONError(err.Error()); err != nil {
				// things really messed up.
				// this panic is handled gracefully in the core
				panic(err)
			}
			return
		}
		i.MergeService(s.Name, s)
		e := ctx.JSON(s)
		_ = e
	})
}
1080640
func Service(g Generator, s *compile.ServiceSpec) (map[string]*bytes.Buffer, error) {
	files := make(map[string]*bytes.Buffer)

	for _, functionName := range sortStringKeys(s.Functions) {
		fileName := fmt.Sprintf("%s_%s.go", strings.ToLower(s.Name), strings.ToLower(functionName))

		function := s.Functions[functionName]
		if err := ServiceFunction(g, s, function); err != nil {
			return nil, fmt.Errorf(
				"could not generate types for %s.%s: %v",
				s.Name, functionName, err)
		}

		buff := new(bytes.Buffer)
		if err := g.Write(buff, token.NewFileSet()); err != nil {
			return nil, fmt.Errorf("could not write %s.%s: %v", s.Name, functionName, err)
		}

		// TODO check for conflicts
		files[fileName] = buff
	}

	return files, nil
}
990044
func (c *Catalog) Connect(service, tag string, q *QueryOptions) ([]*CatalogService, *QueryMeta, error) {
	var tags []string
	if tag != "" {
		tags = []string{tag}
	}
	return c.service(service, tags, q, true)
}