local_partition_publishers.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package topic
  2. import "sync"
  3. type LocalPartitionPublishers struct {
  4. publishers map[string]*LocalPublisher
  5. publishersLock sync.RWMutex
  6. }
  7. type LocalPublisher struct {
  8. }
  9. func NewLocalPublisher() *LocalPublisher {
  10. return &LocalPublisher{}
  11. }
  12. func (p *LocalPublisher) SignalShutdown() {
  13. }
  14. func NewLocalPartitionPublishers() *LocalPartitionPublishers {
  15. return &LocalPartitionPublishers{
  16. publishers: make(map[string]*LocalPublisher),
  17. }
  18. }
  19. func (p *LocalPartitionPublishers) AddPublisher(clientName string, publisher *LocalPublisher) {
  20. p.publishersLock.Lock()
  21. defer p.publishersLock.Unlock()
  22. p.publishers[clientName] = publisher
  23. }
  24. func (p *LocalPartitionPublishers) RemovePublisher(clientName string) {
  25. p.publishersLock.Lock()
  26. defer p.publishersLock.Unlock()
  27. delete(p.publishers, clientName)
  28. }
  29. func (p *LocalPartitionPublishers) SignalShutdown() {
  30. p.publishersLock.RLock()
  31. defer p.publishersLock.RUnlock()
  32. for _, publisher := range p.publishers {
  33. publisher.SignalShutdown()
  34. }
  35. }
  36. func (p *LocalPartitionPublishers) Size() int {
  37. p.publishersLock.RLock()
  38. defer p.publishersLock.RUnlock()
  39. return len(p.publishers)
  40. }