Enhance the event store interface to support channeling (#7343)

- Avoids code duplication across the other targets. By having a
  centralized function call.

- Reduce the room for race.
This commit is contained in:
Praveen raj Mani
2019-04-10 18:16:01 +05:30
committed by Nitish Tiwari
parent ddb0d646aa
commit 47ca411163
20 changed files with 377 additions and 144 deletions

View File

@@ -57,7 +57,7 @@ func (store *MemoryStore) Put(e event.Event) error {
store.Lock()
defer store.Unlock()
if store.eC == store.limit {
return ErrLimitExceeded
return errLimitExceeded
}
key, kErr := getNewUUID()
if kErr != nil {
@@ -77,27 +77,41 @@ func (store *MemoryStore) Get(key string) (event.Event, error) {
return event, nil
}
return event.Event{}, ErrNoSuchKey
return event.Event{}, errNoSuchKey
}
// Del - deletes the event from store.
func (store *MemoryStore) Del(key string) {
func (store *MemoryStore) Del(key string) error {
store.Lock()
defer store.Unlock()
delete(store.events, key)
store.eC--
return nil
}
// ListAll - lists all the keys in the store.
func (store *MemoryStore) ListAll() []string {
// ListN - lists atmost N keys in the store.
func (store *MemoryStore) ListN(n int) []string {
store.RLock()
defer store.RUnlock()
var i int
if n == -1 {
n = len(store.events)
}
keys := []string{}
for k := range store.events {
keys = append(keys, k)
if i < n {
keys = append(keys, k)
i++
continue
} else {
break
}
}
return keys