• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cluster.Cluster类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中euphoria/io/heim/cluster.Cluster的典型用法代码示例。如果您正苦于以下问题:Golang Cluster类的具体用法?Golang Cluster怎么用?Golang Cluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Cluster类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: LoadFromEtcd

func (cfg *ServerConfig) LoadFromEtcd(c cluster.Cluster) error {
	cfgString, err := c.GetValue("config")
	if err != nil {
		return fmt.Errorf("load from etcd: %s", err)
	}

	if err := yaml.Unmarshal([]byte(cfgString), cfg); err != nil {
		return fmt.Errorf("load from etcd: %s", err)
	}

	return nil
}
开发者ID:CylonicRaider,项目名称:heim,代码行数:12,代码来源:config.go


示例2: NewBackend

func NewBackend(
	ctx scope.Context, dsn string, c cluster.Cluster, serverDesc *cluster.PeerDesc) (*Backend, error) {

	var version string

	if serverDesc == nil {
		version = "dev"
	} else {
		version = serverDesc.Version
	}

	parsedDSN, err := url.Parse(dsn)
	if err == nil {
		if parsedDSN.User != nil {
			parsedDSN.User = url.UserPassword(parsedDSN.User.Username(), "xxxxxx")
		}
		log.Printf("psql backend %s on %s", version, parsedDSN.String())
	} else {
		return nil, fmt.Errorf("url.Parse: %s", err)
	}

	db, err := sql.Open("postgres", dsn)
	if err != nil {
		return nil, fmt.Errorf("sql.Open: %s", err)
	}

	b := &Backend{
		DB:        db,
		dsn:       dsn,
		desc:      serverDesc,
		version:   version,
		cluster:   c,
		peers:     map[string]string{},
		listeners: map[string]ListenerMap{},
		ctx:       ctx,
	}
	b.logger = log.New(os.Stdout, fmt.Sprintf("[backend %p] ", b), log.LstdFlags)

	if serverDesc != nil {
		b.peers[serverDesc.ID] = serverDesc.Era
		for _, desc := range c.Peers() {
			b.peers[desc.ID] = desc.Era
		}
	}

	if err := b.start(); err != nil {
		return nil, err
	}

	return b, nil
}
开发者ID:ArkaneMoose,项目名称:heim,代码行数:51,代码来源:backend.go


示例3: NewServer

func NewServer(
	ctx scope.Context, backend proto.Backend, cluster cluster.Cluster, kms security.KMS,
	id, era, staticPath string) (*Server, error) {

	mime.AddExtensionType(".map", "application/json")

	cookieSecret, err := cluster.GetSecret(kms, "cookie", cookieKeySize)
	if err != nil {
		return nil, fmt.Errorf("error coordinating shared cookie secret: %s", err)
	}

	s := &Server{
		ID:         id,
		Era:        era,
		b:          backend,
		kms:        kms,
		staticPath: staticPath,
		sc:         securecookie.New(cookieSecret, nil),
		rootCtx:    ctx,
	}
	s.route()
	return s, nil
}
开发者ID:algustionesa,项目名称:heim,代码行数:23,代码来源:server.go


示例4: scan

func scan(ctx scope.Context, c cluster.Cluster, pb *psql.Backend) error {
	type PresenceWithUserAgent struct {
		psql.Presence
		UserAgent string `db:"user_agent"`
	}

	rows, err := pb.DbMap.Select(
		PresenceWithUserAgent{},
		"SELECT p.room, p.session_id, p.server_id, p.server_era, p.updated, p.fact, s.user_agent"+
			" FROM presence p, session_log s WHERE p.session_id = s.session_id")
	if err != nil {
		return err
	}

	peers := map[string]string{}
	for _, desc := range c.Peers() {
		peers[desc.ID] = desc.Era
	}

	activeRows := 0
	activeRowsPerRoom := map[string]int{}
	activeSessionsPerAgent := map[string]int{}
	lurkingSessionsPerAgent := map[string]int{}
	webSessionsPerAgent := map[string]int{}

	lurkingRows := 0
	lurkingRowsPerRoom := map[string]int{}

	for _, row := range rows {
		presence, ok := row.(*PresenceWithUserAgent)
		if !ok {
			fmt.Printf("error: expected row of type *PresenceWithUserAgent, got %T\n", row)
			continue
		}

		if peers[presence.ServerID] == presence.ServerEra {
			activeRows++
			activeRowsPerRoom[presence.Room]++

			parts := strings.Split(presence.SessionID, "-")
			activeSessionsPerAgent[parts[0]]++

			// Check web-client status.
			// TODO: use positive fingerprint from web client instead of user-agent
			if presence.UserAgent != "" && !strings.HasPrefix(presence.UserAgent, "Python") {
				webSessionsPerAgent[parts[0]]++
			}

			// Check lurker status. Currently this is indicated by a blank name on the session.
			session, err := presence.SessionView(proto.General)
			if err != nil {
				fmt.Printf("error: failed to extract session from presence row: %s\n", err)
				continue
			}
			if session.Name == "" {
				lurkingRows++
				lurkingRowsPerRoom[presence.Room]++
				lurkingSessionsPerAgent[parts[0]]++
			}
		}
	}

	rowCount.Set(float64(len(rows)))
	activeRowCount.Set(float64(activeRows))
	lurkingRowCount.Set(float64(lurkingRows))
	uniqueAgentCount.Set(float64(len(activeSessionsPerAgent)))
	uniqueLurkingAgentCount.Set(float64(len(lurkingSessionsPerAgent)))
	uniqueWebAgentCount.Set(float64(len(webSessionsPerAgent)))

	for room, count := range activeRowsPerRoom {
		activeRowCountPerRoom.With(prometheus.Labels{"room": room}).Set(float64(count))
	}

	for room, count := range lurkingRowsPerRoom {
		lurkingRowCountPerRoom.With(prometheus.Labels{"room": room}).Set(float64(count))
	}

	for _, count := range activeSessionsPerAgent {
		sessionsPerAgent.Observe(float64(count))
	}

	return nil
}
开发者ID:logan,项目名称:heim,代码行数:83,代码来源:scanner.go



注:本文中的euphoria/io/heim/cluster.Cluster类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang proto.MakeEvent函数代码示例发布时间:2022-05-24
下一篇:
Golang backend.Logger函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap