/
subscribe.go
36 lines (29 loc) · 1.17 KB
/
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
33
34
35
36
// 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.
// This function is being called inside a RLock, so it must not attempt
// to acquire a lock on the EndpointManager.
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.
// This function is being called inside a RLock, so it must not attempt
// to acquire a lock on the EndpointManager.
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)
}