mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
package topic
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
type LocalPartitionPublishers struct {
|
||
|
publishers map[string]*LocalPublisher
|
||
|
publishersLock sync.RWMutex
|
||
|
}
|
||
|
type LocalPublisher struct {
|
||
|
}
|
||
|
|
||
|
func NewLocalPublisher() *LocalPublisher {
|
||
|
return &LocalPublisher{}
|
||
|
}
|
||
|
func (p *LocalPublisher) SignalShutdown() {
|
||
|
}
|
||
|
|
||
|
func NewLocalPartitionPublishers() *LocalPartitionPublishers {
|
||
|
return &LocalPartitionPublishers{
|
||
|
publishers: make(map[string]*LocalPublisher),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *LocalPartitionPublishers) AddPublisher(clientName string, publisher *LocalPublisher) {
|
||
|
p.publishersLock.Lock()
|
||
|
defer p.publishersLock.Unlock()
|
||
|
|
||
|
p.publishers[clientName] = publisher
|
||
|
}
|
||
|
|
||
|
func (p *LocalPartitionPublishers) RemovePublisher(clientName string) {
|
||
|
p.publishersLock.Lock()
|
||
|
defer p.publishersLock.Unlock()
|
||
|
|
||
|
delete(p.publishers, clientName)
|
||
|
}
|
||
|
|
||
|
func (p *LocalPartitionPublishers) SignalShutdown() {
|
||
|
p.publishersLock.RLock()
|
||
|
defer p.publishersLock.RUnlock()
|
||
|
|
||
|
for _, publisher := range p.publishers {
|
||
|
publisher.SignalShutdown()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *LocalPartitionPublishers) IsEmpty() bool {
|
||
|
p.publishersLock.RLock()
|
||
|
defer p.publishersLock.RUnlock()
|
||
|
|
||
|
return len(p.publishers) == 0
|
||
|
}
|