本文整理汇总了Golang中github.com/couchbase/sync_gateway/base.Bucket.StartTapFeed方法的典型用法代码示例。如果您正苦于以下问题:Golang Bucket.StartTapFeed方法的具体用法?Golang Bucket.StartTapFeed怎么用?Golang Bucket.StartTapFeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/sync_gateway/base.Bucket
的用法示例。
在下文中一共展示了Bucket.StartTapFeed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewShadower
// Creates a new Shadower.
func NewShadower(context *DatabaseContext, bucket base.Bucket, docIDPattern *regexp.Regexp) (*Shadower, error) {
tapFeed, err := bucket.StartTapFeed(sgbucket.TapArguments{Backfill: 0})
if err != nil {
return nil, err
}
s := &Shadower{context: context, bucket: bucket, tapFeed: tapFeed, docIDPattern: docIDPattern}
go s.readTapFeed()
return s, nil
}
示例2: NewShadower
// Creates a new Shadower.
func NewShadower(context *DatabaseContext, bucket base.Bucket, docIDPattern *regexp.Regexp) (*Shadower, error) {
tapFeed, err := bucket.StartTapFeed(sgbucket.TapArguments{Backfill: 0, Notify: func(bucket string, err error) {
context.TakeDbOffline("Lost shadower TAP Feed")
}})
if err != nil {
return nil, err
}
s := &Shadower{context: context, bucket: bucket, tapFeed: tapFeed, docIDPattern: docIDPattern}
go s.readTapFeed()
return s, nil
}
示例3: Start
// Starts a changeListener on a given Bucket.
func (listener *changeListener) Start(bucket base.Bucket, trackDocs bool, notify sgbucket.BucketNotifyFn) error {
listener.bucket = bucket
listener.TapArgs = sgbucket.TapArguments{
Backfill: sgbucket.TapNoBackfill,
Notify: notify,
}
tapFeed, err := bucket.StartTapFeed(listener.TapArgs)
if err != nil {
return err
}
listener.tapFeed = tapFeed
listener.counter = 1
listener.terminateCheckCounter = 0
listener.keyCounts = map[string]uint64{}
listener.tapNotifier = sync.NewCond(&sync.Mutex{})
if trackDocs {
listener.DocChannel = make(chan sgbucket.TapEvent, 100)
}
// Start a goroutine to broadcast to the tapNotifier whenever a channel or user/role changes:
go func() {
defer func() {
listener.notifyStopping()
if listener.DocChannel != nil {
close(listener.DocChannel)
}
}()
for event := range tapFeed.Events() {
if event.Opcode == sgbucket.TapMutation || event.Opcode == sgbucket.TapDeletion {
key := string(event.Key)
if strings.HasPrefix(key, auth.UserKeyPrefix) ||
strings.HasPrefix(key, auth.RoleKeyPrefix) {
if listener.OnDocChanged != nil {
listener.OnDocChanged(key, event.Value, event.Sequence, event.VbNo)
}
listener.Notify(base.SetOf(key))
} else if trackDocs && !strings.HasPrefix(key, KSyncKeyPrefix) && !strings.HasPrefix(key, kIndexPrefix) {
if listener.OnDocChanged != nil {
listener.OnDocChanged(key, event.Value, event.Sequence, event.VbNo)
}
listener.DocChannel <- event
}
}
}
}()
return nil
}