-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
subscribe.go
32 lines (25 loc) · 955 Bytes
/
subscribe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package endpointmanager
import "github.com/cilium/cilium/pkg/endpoint"
// Subscribers may register via Subscribe() to be notified when events occur.
type Subscriber interface {
// EndpointCreated is called at the end of endpoint creation.
// Implementations must not attempt write operations on the
// EndpointManager from this callback.
EndpointCreated(ep *endpoint.Endpoint)
// EndpointDeleted is called at the end of endpoint deletion.
// Implementations must not attempt write operations on the
// EndpointManager from this callback.
EndpointDeleted(ep *endpoint.Endpoint, conf endpoint.DeleteConfig)
}
func (mgr *EndpointManager) Subscribe(s Subscriber) {
mgr.mutex.Lock()
defer mgr.mutex.Unlock()
mgr.subscribers[s] = struct{}{}
}
func (mgr *EndpointManager) Unsubscribe(s Subscriber) {
mgr.mutex.Lock()
defer mgr.mutex.Unlock()
delete(mgr.subscribers, s)
}