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

Golang pubsub.NewPublisher函数代码示例

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

本文整理汇总了Golang中github.com/docker/docker/pkg/pubsub.NewPublisher函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPublisher函数的具体用法?Golang NewPublisher怎么用?Golang NewPublisher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: newRaft

func newRaft(home, addr string, peerStore *peerStoreWrapper, fsm raft.FSM, trans *raft.NetworkTransport, cfg *raft.Config) (*Raft, error) {
	if err := os.MkdirAll(home, 0700); err != nil {
		return nil, err
	}
	db, err := raftboltdb.NewBoltStore(filepath.Join(home, "raft.db"))
	if err != nil {
		return nil, fmt.Errorf("error initializing raft db: %v", err)
	}

	snapStore, err := raft.NewFileSnapshotStore(filepath.Join(home, "snapshots"), 5, nil)
	if err != nil {
		return nil, fmt.Errorf("error intializing raft snap store: %v", err)
	}

	r, err := raft.NewRaft(cfg, fsm, db, db, snapStore, peerStore, trans)
	if err != nil {
		return nil, err
	}

	raft := &Raft{
		r:          r,
		peers:      peerStore,
		trans:      trans,
		db:         db,
		shutdownCh: make(chan struct{}),
		pub:        pubsub.NewPublisher(defaultTimeout, 1),
	}
	go raft.waitLeader()
	return raft, nil
}
开发者ID:cpuguy83,项目名称:drax,代码行数:30,代码来源:raft.go


示例2: New

// New creates new JSONFileLogger which writes to filename
func New(ctx logger.Context) (logger.Logger, error) {
	log, err := os.OpenFile(ctx.LogPath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600)
	if err != nil {
		return nil, err
	}
	var capval int64 = -1
	if capacity, ok := ctx.Config["max-size"]; ok {
		var err error
		capval, err = units.FromHumanSize(capacity)
		if err != nil {
			return nil, err
		}
	}
	var maxFiles int = 1
	if maxFileString, ok := ctx.Config["max-file"]; ok {
		maxFiles, err = strconv.Atoi(maxFileString)
		if err != nil {
			return nil, err
		}
		if maxFiles < 1 {
			return nil, fmt.Errorf("max-files cannot be less than 1.")
		}
	}
	return &JSONFileLogger{
		f:            log,
		buf:          bytes.NewBuffer(nil),
		ctx:          ctx,
		capacity:     capval,
		n:            maxFiles,
		readers:      make(map[*logger.LogWatcher]struct{}),
		notifyRotate: pubsub.NewPublisher(0, 1),
	}, nil
}
开发者ID:ChanderG,项目名称:docker,代码行数:34,代码来源:jsonfilelog.go


示例3: collect

// collect registers the container with the collector and adds it to
// the event loop for collection on the specified interval returning
// a channel for the subscriber to receive on.
func (s *statsCollector) collect(c *container.Container) chan interface{} {
	s.m.Lock()
	defer s.m.Unlock()
	publisher, exists := s.publishers[c]
	if !exists {
		publisher = pubsub.NewPublisher(100*time.Millisecond, 1024)
		s.publishers[c] = publisher
	}
	return publisher.Subscribe()
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:13,代码来源:stats_collector.go


示例4: collect

// collect registers the container with the collector and adds it to
// the event loop for collection on the specified interval returning
// a channel for the subscriber to receive on.
func (s *statsCollector) collect(c runtime.Container) chan interface{} {
	s.m.Lock()
	defer s.m.Unlock()
	publisher, exists := s.publishers[c.ID()]
	if !exists {
		pub := pubsub.NewPublisher(100*time.Millisecond, 1024)
		publisher = &statsPair{ct: c, pub: pub}
		s.publishers[c.ID()] = publisher
	}
	return publisher.pub.Subscribe()
}
开发者ID:mynameismevin,项目名称:containerd,代码行数:14,代码来源:stats_collector.go


示例5: NewRotateFileWriter

//NewRotateFileWriter creates new RotateFileWriter
func NewRotateFileWriter(logPath string, capacity int64, maxFiles int) (*RotateFileWriter, error) {
	log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
	if err != nil {
		return &RotateFileWriter{}, err
	}

	return &RotateFileWriter{
		f:            log,
		capacity:     capacity,
		maxFiles:     maxFiles,
		notifyRotate: pubsub.NewPublisher(0, 1),
	}, nil
}
开发者ID:m1911,项目名称:hyper,代码行数:14,代码来源:rotatefilewriter.go


示例6: New

// New creates new JSONFileLogger which writes to filename passed in
// on given context.
func New(ctx logger.Context) (logger.Logger, error) {
	var capval int64 = -1
	if capacity, ok := ctx.Config["max-size"]; ok {
		var err error
		capval, err = units.FromHumanSize(capacity)
		if err != nil {
			return nil, err
		}
	}
	var maxFiles = 1
	if maxFileString, ok := ctx.Config["max-file"]; ok {
		var err error
		maxFiles, err = strconv.Atoi(maxFileString)
		if err != nil {
			return nil, err
		}
		if maxFiles < 1 {
			return nil, fmt.Errorf("max-file cannot be less than 1")
		}
	}

	writer, err := loggerutils.NewRotateFileWriter(ctx.LogPath, capval, maxFiles)
	if err != nil {
		return nil, err
	}

	var extra []byte
	if attrs := ctx.ExtraAttributes(nil); len(attrs) > 0 {
		var err error
		extra, err = json.Marshal(attrs)
		if err != nil {
			return nil, err
		}
	}

	return &JSONFileLogger{
		buf:           bytes.NewBuffer(nil),
		writer:        writer,
		readers:       make(map[*logger.LogWatcher]struct{}),
		extra:         extra,
		writeNotifier: pubsub.NewPublisher(0, 10),
	}, nil
}
开发者ID:fsoppelsa,项目名称:docker,代码行数:45,代码来源:jsonfilelog.go


示例7: main

func main() {
	var id string
	flag.StringVar(&id, "id", "", "ID to subscribe from")
	flag.Parse()
	props := property.Init()

	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["current.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	sState = ScalarState{}
	sState.state = make(map[int]map[int]*bson.M)
	sState.mx = &sync.Mutex{}
	isCurrent = false
	stateUpdate := pubsub.NewPublisher(time.Millisecond*100, 1024)
	err = evStore.Listenner2().Subscribe2("scalar", scalarHandler)
	if err != nil {
		log.Fatalln("Error subscribing for changes", err)
	}
	ctx1, cancel := context.WithCancel(context.Background())
	ctx := context.WithValue(ctx1, "stateUpdate", stateUpdate)
	defer cancel()
	sState.lastID = evStore.Listenner2().GetLastID()
	log.Println("Before Listen call")
	go evStore.Listenner2().Listen(ctx, id)

	go processClientConnection(ctx, wsServer)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["current.url"], nil)
	evStore.Close()
}
开发者ID:vsysoev,项目名称:goeventstore,代码行数:37,代码来源:currentsrv.go


示例8: New

// New returns new *Events instance
func New() *Events {
	return &Events{
		events: make([]eventtypes.Message, 0, eventsLimit),
		pub:    pubsub.NewPublisher(100*time.Millisecond, bufferSize),
	}
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:7,代码来源:events.go


示例9: New

// New returns new *Events instance
func New() *Events {
	return &Events{
		events: make([]*jsonmessage.JSONMessage, 0, eventsLimit),
		pub:    pubsub.NewPublisher(100*time.Millisecond, 1024),
	}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:7,代码来源:events.go


示例10: TestScalarHandler

func TestScalarHandler(t *testing.T) {
	Convey("When pass empty message slice to scalarHandler", t, func() {
		var msgs []interface{}
		Convey("It should not panic", func() {
			So(func() { scalarHandler(context.Background(), msgs) }, ShouldNotPanic)
		})
	})
	Convey("When pass message with int boxID, varID", t, func() {
		var msgs []interface{}
		sState = ScalarState{}
		sState.state = make(map[int]map[int]*bson.M)
		sState.mx = &sync.Mutex{}
		stateUpdateChannel := pubsub.NewPublisher(time.Millisecond*100, 1024)
		ctx := context.WithValue(context.Background(), "stateUpdate", stateUpdateChannel)
		id := bson.NewObjectId()
		msg := bson.M{"_id": id, "tag": "scalar", "event": bson.M{"box_id": 1, "var_id": 1, "value": 1.5}}
		msgs = append(msgs, msg)
		Convey("It should not panic with type assertion", func() {
			So(func() { scalarHandler(ctx, msgs) }, ShouldNotPanic)
		})
	})
	Convey("When pass message with float64 boxID, varID", t, func() {
		var msgs []interface{}
		sState = ScalarState{}
		sState.state = make(map[int]map[int]*bson.M)
		sState.mx = &sync.Mutex{}
		stateUpdateChannel := pubsub.NewPublisher(time.Millisecond*100, 1024)
		ctx := context.WithValue(context.Background(), "stateUpdate", stateUpdateChannel)
		id := bson.NewObjectId()
		msg := bson.M{"_id": id, "tag": "scalar", "event": bson.M{"box_id": 1.0, "var_id": 1.0, "value": 1.5}}
		msgs = append(msgs, msg)
		Convey("It should not panic with type assertion", func() {
			So(func() { scalarHandler(ctx, msgs) }, ShouldNotPanic)
		})
	})
	Convey("When pass message with string boxID, varID", t, func() {
		var msgs []interface{}
		sState = ScalarState{}
		sState.state = make(map[int]map[int]*bson.M)
		sState.mx = &sync.Mutex{}
		stateUpdateChannel := make(chan *bson.M, 256)
		ctx := context.WithValue(context.Background(), "stateUpdateChannel", stateUpdateChannel)
		id := bson.NewObjectId()
		msg := bson.M{"_id": id, "tag": "scalar", "event": bson.M{"box_id": "1.0", "var_id": "1.0", "value": 1.5}}
		msgs = append(msgs, msg)
		Convey("It should not panic with type assertion", func() {
			So(func() { scalarHandler(ctx, msgs) }, ShouldNotPanic)
		})
	})
	Convey("When pass message with int boxID and string varID", t, func() {
		var msgs []interface{}
		sState = ScalarState{}
		sState.state = make(map[int]map[int]*bson.M)
		sState.mx = &sync.Mutex{}
		stateUpdateChannel := make(chan *bson.M, 256)
		ctx := context.WithValue(context.Background(), "stateUpdateChannel", stateUpdateChannel)
		id := bson.NewObjectId()
		msg := bson.M{"_id": id, "tag": "scalar", "event": bson.M{"box_id": 1, "var_id": "1.0", "value": 1.5}}
		msgs = append(msgs, msg)
		Convey("It should not panic with type assertion", func() {
			So(func() { scalarHandler(ctx, msgs) }, ShouldNotPanic)
		})
	})
}
开发者ID:vsysoev,项目名称:goeventstore,代码行数:64,代码来源:currentsrv_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang reexec.Command函数代码示例发布时间:2022-05-23
下一篇:
Golang promise.Go函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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