本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/base.Bucket.StartTapFeed方法的典型用法代码示例。如果您正苦于以下问题:Golang Bucket.StartTapFeed方法的具体用法?Golang Bucket.StartTapFeed怎么用?Golang Bucket.StartTapFeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/sync_gateway/base.Bucket
的用法示例。
在下文中一共展示了Bucket.StartTapFeed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Start
// Starts a changeListener on a given Bucket.
func (listener *changeListener) Start(bucket base.Bucket) error {
listener.bucket = bucket
tapFeed, err := bucket.StartTapFeed(walrus.TapArguments{Backfill: walrus.TapNoBackfill})
if err != nil {
return err
}
listener.tapFeed = tapFeed
listener.counter = 1
listener.tapNotifier = sync.NewCond(&sync.Mutex{})
// Start a goroutine to broadcast to the tapNotifier whenever a channel or user/role changes:
go func() {
defer listener.notify("")
for event := range tapFeed.Events() {
if event.Opcode == walrus.TapMutation || event.Opcode == walrus.TapDeletion {
key := string(event.Key)
if strings.HasPrefix(key, kChannelLogKeyPrefix) ||
strings.HasPrefix(key, auth.UserKeyPrefix) ||
strings.HasPrefix(key, auth.RoleKeyPrefix) {
listener.notify(key)
}
}
}
}()
return nil
}
示例2: NewDatabaseContext
func NewDatabaseContext(dbName string, bucket base.Bucket) (*DatabaseContext, error) {
context := &DatabaseContext{
Name: dbName,
Bucket: bucket,
tapNotifier: sync.NewCond(&sync.Mutex{}),
}
var err error
context.sequences, err = newSequenceAllocator(bucket)
if err != nil {
return nil, err
}
tapFeed, err := bucket.StartTapFeed(walrus.TapArguments{Backfill: walrus.TapNoBackfill})
if err != nil {
return nil, err
}
// Start a goroutine to broadcast to the tapNotifier whenever a document changes:
go func() {
for event := range tapFeed.Events() {
if event.Opcode == walrus.TapMutation || event.Opcode == walrus.TapDeletion {
key := string(event.Key)
if strings.HasPrefix(key, "_sync:") && !strings.HasPrefix(key, "_sync:user") &&
!strings.HasPrefix(key, "_sync:role") {
continue // ignore metadata docs (sequence counter, attachments, local docs...)
}
base.LogTo("Changes", "Notifying that %q changed (key=%q)", dbName, event.Key)
context.tapNotifier.Broadcast()
}
}
}()
return context, nil
}
示例3: NewShadower
// Creates a new Shadower.
func NewShadower(context *DatabaseContext, bucket base.Bucket, docIDPattern *regexp.Regexp) (*Shadower, error) {
tapFeed, err := bucket.StartTapFeed(walrus.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
}
示例4: Start
// Starts a changeListener on a given Bucket.
func (listener *changeListener) Start(bucket base.Bucket, trackDocs bool) error {
listener.bucket = bucket
tapFeed, err := bucket.StartTapFeed(walrus.TapArguments{Backfill: walrus.TapNoBackfill})
if err != nil {
return err
}
listener.tapFeed = tapFeed
listener.counter = 1
listener.keyCounts = map[string]uint64{}
listener.tapNotifier = sync.NewCond(&sync.Mutex{})
if trackDocs {
listener.DocChannel = make(chan walrus.TapEvent, 100)
}
// Start a goroutine to broadcast to the tapNotifier whenever a channel or user/role changes:
go func() {
defer func() {
listener.notify("")
if listener.DocChannel != nil {
close(listener.DocChannel)
}
}()
for event := range tapFeed.Events() {
if event.Opcode == walrus.TapMutation || event.Opcode == walrus.TapDeletion {
key := string(event.Key)
if strings.HasPrefix(key, kChannelLogKeyPrefix) {
if listener.OnChannelChanged != nil {
channelName := string(event.Key)[len(kChannelLogKeyPrefix):]
// Notify the client synchronously via a fn call, instead of by writing
// to a channel, to ensure that the client can cache the updated channel
// log before any subsequent document change is processed.
listener.OnChannelChanged(channelName, event.Value)
}
listener.notify(key)
} else if strings.HasPrefix(key, auth.UserKeyPrefix) ||
strings.HasPrefix(key, auth.RoleKeyPrefix) {
listener.notify(key)
} else if trackDocs && !strings.HasPrefix(key, kSyncKeyPrefix) {
listener.DocChannel <- event
}
}
}
}()
return nil
}
示例5: Start
// Starts a changeListener on a given Bucket.
func (listener *changeListener) Start(bucket base.Bucket, trackDocs bool) error {
listener.bucket = bucket
tapFeed, err := bucket.StartTapFeed(walrus.TapArguments{Backfill: walrus.TapNoBackfill})
if err != nil {
return err
}
listener.tapFeed = tapFeed
listener.counter = 1
listener.keyCounts = map[string]uint64{}
listener.tapNotifier = sync.NewCond(&sync.Mutex{})
if trackDocs {
listener.DocChannel = make(chan walrus.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 == walrus.TapMutation || event.Opcode == walrus.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)
}
listener.Notify(base.SetOf(key))
} else if trackDocs && !strings.HasPrefix(key, kSyncKeyPrefix) {
if listener.OnDocChanged != nil {
listener.OnDocChanged(key, event.Value)
}
listener.DocChannel <- event
}
}
}
}()
return nil
}