1
- package cache
1
+ package factory
2
2
3
3
import (
4
4
"fmt"
@@ -35,7 +35,7 @@ import (
35
35
// events. This is necessary because the Store API does not receive the deleted state on a
36
36
// watch.Deleted event (though this state is delivered by the watch API itself, it is not passed on
37
37
// to the reflector Store).
38
- type EventQueue struct {
38
+ type eventQueue struct {
39
39
lock sync.RWMutex
40
40
cond sync.Cond
41
41
store kcache.Store
@@ -56,7 +56,7 @@ type EventQueue struct {
56
56
}
57
57
58
58
// EventQueue implements kcache.Store
59
- var _ kcache.Store = & EventQueue {}
59
+ var _ kcache.Store = & eventQueue {}
60
60
61
61
// Describes the effect of processing a watch event on the event queue's state.
62
62
type watchEventEffect string
@@ -108,7 +108,7 @@ func (es EventQueueStopped) Error() string {
108
108
109
109
// handleEvent is called by Add, Update, and Delete to determine the effect
110
110
// of an event of the queue, realize that effect, and update the underlying store.
111
- func (eq * EventQueue ) handleEvent (obj interface {}, newEventType watch.EventType ) error {
111
+ func (eq * eventQueue ) handleEvent (obj interface {}, newEventType watch.EventType ) error {
112
112
key , err := eq .keyFn (obj )
113
113
if err != nil {
114
114
return err
@@ -162,13 +162,13 @@ func (eq *EventQueue) handleEvent(obj interface{}, newEventType watch.EventType)
162
162
}
163
163
164
164
// Cancel function to force Pop function to unblock
165
- func (eq * EventQueue ) Cancel () {
165
+ func (eq * eventQueue ) Cancel () {
166
166
eq .cond .Broadcast ()
167
167
}
168
168
169
169
// updateStore updates the stored value for the given key. Note that deletions are not handled
170
170
// here; they are performed in Pop in order to provide the deleted value on watch.Deleted events.
171
- func (eq * EventQueue ) updateStore (key string , obj interface {}, eventType watch.EventType ) error {
171
+ func (eq * eventQueue ) updateStore (key string , obj interface {}, eventType watch.EventType ) error {
172
172
if eventType == watch .Deleted {
173
173
return nil
174
174
}
@@ -183,7 +183,7 @@ func (eq *EventQueue) updateStore(key string, obj interface{}, eventType watch.E
183
183
}
184
184
185
185
// queueWithout returns the internal queue minus the given key.
186
- func (eq * EventQueue ) queueWithout (key string ) []string {
186
+ func (eq * eventQueue ) queueWithout (key string ) []string {
187
187
rq := make ([]string , 0 )
188
188
for _ , qkey := range eq .queue {
189
189
if qkey == key {
@@ -197,22 +197,22 @@ func (eq *EventQueue) queueWithout(key string) []string {
197
197
}
198
198
199
199
// Add enqueues a watch.Added event for the given state.
200
- func (eq * EventQueue ) Add (obj interface {}) error {
200
+ func (eq * eventQueue ) Add (obj interface {}) error {
201
201
return eq .handleEvent (obj , watch .Added )
202
202
}
203
203
204
204
// Update enqueues a watch.Modified event for the given state.
205
- func (eq * EventQueue ) Update (obj interface {}) error {
205
+ func (eq * eventQueue ) Update (obj interface {}) error {
206
206
return eq .handleEvent (obj , watch .Modified )
207
207
}
208
208
209
209
// Delete enqueues a watch.Delete event for the given object.
210
- func (eq * EventQueue ) Delete (obj interface {}) error {
210
+ func (eq * eventQueue ) Delete (obj interface {}) error {
211
211
return eq .handleEvent (obj , watch .Deleted )
212
212
}
213
213
214
214
// List returns a list of all enqueued items.
215
- func (eq * EventQueue ) List () []interface {} {
215
+ func (eq * eventQueue ) List () []interface {} {
216
216
eq .lock .RLock ()
217
217
defer eq .lock .RUnlock ()
218
218
@@ -232,7 +232,7 @@ func (eq *EventQueue) List() []interface{} {
232
232
}
233
233
234
234
// ListKeys returns all enqueued keys.
235
- func (eq * EventQueue ) ListKeys () []string {
235
+ func (eq * eventQueue ) ListKeys () []string {
236
236
eq .lock .RLock ()
237
237
defer eq .lock .RUnlock ()
238
238
@@ -244,7 +244,7 @@ func (eq *EventQueue) ListKeys() []string {
244
244
// ContainedIDs returns a sets.String containing all IDs of the enqueued items.
245
245
// This is a snapshot of a moment in time, and one should keep in mind that
246
246
// other go routines can add or remove items after you call this.
247
- func (eq * EventQueue ) ContainedIDs () sets.String {
247
+ func (eq * eventQueue ) ContainedIDs () sets.String {
248
248
eq .lock .RLock ()
249
249
defer eq .lock .RUnlock ()
250
250
@@ -257,7 +257,7 @@ func (eq *EventQueue) ContainedIDs() sets.String {
257
257
}
258
258
259
259
// Get returns the requested item, or sets exists=false.
260
- func (eq * EventQueue ) Get (obj interface {}) (item interface {}, exists bool , err error ) {
260
+ func (eq * eventQueue ) Get (obj interface {}) (item interface {}, exists bool , err error ) {
261
261
key , err := eq .keyFn (obj )
262
262
if err != nil {
263
263
return nil , false , err
@@ -266,7 +266,7 @@ func (eq *EventQueue) Get(obj interface{}) (item interface{}, exists bool, err e
266
266
}
267
267
268
268
// GetByKey returns the requested item, or sets exists=false.
269
- func (eq * EventQueue ) GetByKey (key string ) (item interface {}, exists bool , err error ) {
269
+ func (eq * eventQueue ) GetByKey (key string ) (item interface {}, exists bool , err error ) {
270
270
eq .lock .RLock ()
271
271
defer eq .lock .RUnlock ()
272
272
@@ -280,7 +280,7 @@ func (eq *EventQueue) GetByKey(key string) (item interface{}, exists bool, err e
280
280
281
281
// Pop gets the event and object at the head of the queue. If the event
282
282
// is a delete event, Pop deletes the key from the underlying cache.
283
- func (eq * EventQueue ) Pop () (watch.EventType , interface {}, error ) {
283
+ func (eq * eventQueue ) Pop () (watch.EventType , interface {}, error ) {
284
284
eq .lock .Lock ()
285
285
defer eq .lock .Unlock ()
286
286
@@ -327,7 +327,7 @@ func (eq *EventQueue) Pop() (watch.EventType, interface{}, error) {
327
327
// populates the queue with a watch.Modified event for each of the replaced
328
328
// objects. The backing store takes ownership of keyToObjs; you should not
329
329
// reference the map again after calling this function.
330
- func (eq * EventQueue ) Replace (objects []interface {}, resourceVersion string ) error {
330
+ func (eq * eventQueue ) Replace (objects []interface {}, resourceVersion string ) error {
331
331
eq .lock .Lock ()
332
332
defer eq .lock .Unlock ()
333
333
@@ -360,15 +360,15 @@ func (eq *EventQueue) Replace(objects []interface{}, resourceVersion string) err
360
360
361
361
// ListSuccessfulAtLeastOnce indicates whether a List operation was
362
362
// successfully completed regardless of whether any items were queued.
363
- func (eq * EventQueue ) ListSuccessfulAtLeastOnce () bool {
363
+ func (eq * eventQueue ) ListSuccessfulAtLeastOnce () bool {
364
364
eq .lock .Lock ()
365
365
defer eq .lock .Unlock ()
366
366
367
367
return eq .replaceCalled
368
368
}
369
369
370
370
// ListCount returns how many objects were queued by the most recent List operation.
371
- func (eq * EventQueue ) ListCount () int {
371
+ func (eq * eventQueue ) ListCount () int {
372
372
eq .lock .Lock ()
373
373
defer eq .lock .Unlock ()
374
374
@@ -377,15 +377,15 @@ func (eq *EventQueue) ListCount() int {
377
377
378
378
// ListConsumed indicates whether the items queued by a List/Relist
379
379
// operation have been consumed.
380
- func (eq * EventQueue ) ListConsumed () bool {
380
+ func (eq * eventQueue ) ListConsumed () bool {
381
381
eq .lock .Lock ()
382
382
defer eq .lock .Unlock ()
383
383
384
384
return eq .lastReplaceKey == ""
385
385
}
386
386
387
387
// Resync will touch all objects to put them into the processing queue
388
- func (eq * EventQueue ) Resync () error {
388
+ func (eq * eventQueue ) Resync () error {
389
389
eq .lock .Lock ()
390
390
defer eq .lock .Unlock ()
391
391
@@ -409,9 +409,9 @@ func (eq *EventQueue) Resync() error {
409
409
return nil
410
410
}
411
411
412
- // NewEventQueue returns a new EventQueue.
413
- func NewEventQueue (keyFn kcache.KeyFunc ) * EventQueue {
414
- q := & EventQueue {
412
+ // newEventQueue returns a new EventQueue.
413
+ func newEventQueue (keyFn kcache.KeyFunc ) * eventQueue {
414
+ q := & eventQueue {
415
415
store : kcache .NewStore (keyFn ),
416
416
events : map [string ]watch.EventType {},
417
417
queue : []string {},
@@ -421,9 +421,9 @@ func NewEventQueue(keyFn kcache.KeyFunc) *EventQueue {
421
421
return q
422
422
}
423
423
424
- // NewEventQueueForStore returns a new EventQueue that uses the provided store.
425
- func NewEventQueueForStore (keyFn kcache.KeyFunc , store kcache.Store ) * EventQueue {
426
- q := & EventQueue {
424
+ // newEventQueueForStore returns a new EventQueue that uses the provided store.
425
+ func newEventQueueForStore (keyFn kcache.KeyFunc , store kcache.Store ) * eventQueue {
426
+ q := & eventQueue {
427
427
store : store ,
428
428
events : map [string ]watch.EventType {},
429
429
queue : []string {},
0 commit comments