-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(evpn-bridge): intel e2000 vendor plugin
Co-authored-by: Vemula Venkatesh <venkatesh.vemula@intel.com> Co-authored-by: Saikumar Banoth <banoth.saikumar@intel.com> Co-authored-by: Jambekar Vishakha <vishakha.jambekar@intel.com> Co-authored-by: Dimitrios Markou <dimitrios.markou@ericsson.com> Signed-off-by: atulpatel261194 <Atul.Patel@intel.com>
- Loading branch information
1 parent
2d1d2ba
commit fab3989
Showing
7 changed files
with
6,462 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. | ||
|
||
// Package eventbus handles pub sub | ||
package eventbus | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// EventBus holds the event bus info | ||
type EventBus struct { | ||
subscribers map[string][]*Subscriber | ||
mutex sync.RWMutex | ||
} | ||
|
||
// Subscriber holds the info for each subscriber | ||
type Subscriber struct { | ||
Ch chan interface{} | ||
Quit chan struct{} | ||
} | ||
|
||
// NewEventBus initializes an EventBus object | ||
func NewEventBus() *EventBus { | ||
return &EventBus{ | ||
subscribers: make(map[string][]*Subscriber), | ||
} | ||
} | ||
|
||
// Subscribe api provides registration of a subscriber to the given eventType | ||
func (e *EventBus) Subscribe(eventType string) *Subscriber { | ||
e.mutex.Lock() | ||
defer e.mutex.Unlock() | ||
|
||
subscriber := &Subscriber{ | ||
Ch: make(chan interface{}), | ||
Quit: make(chan struct{}), | ||
} | ||
|
||
e.subscribers[eventType] = append(e.subscribers[eventType], subscriber) | ||
|
||
return subscriber | ||
} | ||
|
||
// Publish api notifies the subscribers with certain eventType | ||
func (e *EventBus) Publish(eventType string, data interface{}) { | ||
e.mutex.RLock() | ||
defer e.mutex.RUnlock() | ||
|
||
subscribers, ok := e.subscribers[eventType] | ||
if !ok { | ||
return | ||
} | ||
|
||
for _, sub := range subscribers { | ||
sub.Ch <- data | ||
} | ||
} | ||
|
||
// Unsubscribe the subscriber, which delete the subscriber(all resources will be washed out) | ||
func (s *Subscriber) Unsubscribe() { | ||
close(s.Ch) | ||
} |
Oops, something went wrong.