able to read chan and write chan

This commit is contained in:
Chris Lu
2020-05-08 02:47:22 -07:00
parent a8bc8eb351
commit dfccc3c263
23 changed files with 734 additions and 260 deletions

View File

@@ -16,6 +16,13 @@ type TopicPartition struct {
Topic string
Partition int32
}
const (
TopicPartitionFmt = "%s/%s_%2d"
)
func (tp *TopicPartition) String() string {
return fmt.Sprintf(TopicPartitionFmt, tp.Namespace, tp.Topic, tp.Partition)
}
type TopicLock struct {
sync.Mutex
cond *sync.Cond
@@ -101,3 +108,13 @@ func (tl *TopicLocks) ReleaseLock(partition TopicPartition, isPublisher bool) {
delete(tl.locks, partition)
}
}
func (tl *TopicLocks) ListTopicPartitions() (tps []TopicPartition) {
tl.Lock()
defer tl.Unlock()
for k := range tl.locks {
tps = append(tps, k)
}
return
}