watchable

package
v2.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentMap

type AgentMap struct {
	// contains filtered or unexported fields
}

AgentMap is a wrapper around map[string]*manager.AgentInfo that is very similar to sync.Map, and that provides the additional features that:

  1. it is thread-safe (compared to a bare map)
  2. it provides type safety (compared to a sync.Map)
  3. it provides a compare-and-swap operation
  4. you can Subscribe to either the whole map or just a subset of the map to watch for updates. This gives you complete snapshots, deltas, and coalescing of rapid updates.

func (*AgentMap) Close

func (tm *AgentMap) Close()

Close marks the map as "finished", all subscriber channels are closed and further mutations are forbidden.

After .Close() is called, any calls to .Store() will block forever, and any calls to .Subscribe() will return an already-closed channel.

.Load() and .LoadAll() calls will continue to work normally after .Close() has been called.

func (*AgentMap) CompareAndSwap

func (tm *AgentMap) CompareAndSwap(key string, old, new *manager.AgentInfo) bool

CompareAndSwap is the atomic equivalent of:

if loadedVal, loadedOK := m.Load(key); loadedOK && proto.Equal(loadedVal, old) {
    m.Store(key, new)
    return true
}
return false

func (*AgentMap) Delete

func (tm *AgentMap) Delete(key string)

Delete deletes the value for a key. This blocks forever if .Close() has already been called.

func (*AgentMap) Load

func (tm *AgentMap) Load(key string) (value *manager.AgentInfo, ok bool)

Load returns a deepcopy of the value for a specific key.

func (*AgentMap) LoadAll

func (tm *AgentMap) LoadAll() map[string]*manager.AgentInfo

LoadAll returns a deepcopy of all key/value pairs in the map.

func (*AgentMap) LoadAllMatching added in v2.4.5

func (tm *AgentMap) LoadAllMatching(filter func(string, *manager.AgentInfo) bool) map[string]*manager.AgentInfo

LoadAllMatching returns a deepcopy of all key/value pairs in the map for which the given function returns true. The map is locked during the evaluation of the filter.

func (*AgentMap) LoadAndDelete

func (tm *AgentMap) LoadAndDelete(key string) (value *manager.AgentInfo, loaded bool)

LoadAndDelete deletes the value for a key, returning a deepcopy of the previous value if any. The 'loaded' result reports whether the key was present.

If the value does need to be deleted, all the same blocking semantics as .Delete() apply.

func (*AgentMap) LoadOrStore

func (tm *AgentMap) LoadOrStore(key string, val *manager.AgentInfo) (value *manager.AgentInfo, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The 'loaded' result is true if the value was loaded, false if stored.

If the value does need to be stored, all the same blocking semantics as .Store() apply

func (*AgentMap) Store

func (tm *AgentMap) Store(key string, val *manager.AgentInfo)

Store sets a key sets the value for a key. This blocks forever if .Close() has already been called.

func (*AgentMap) Subscribe

func (tm *AgentMap) Subscribe(ctx context.Context) <-chan AgentMapSnapshot

Subscribe returns a channel that will emit a complete snapshot of the map immediately after the call to Subscribe(), and then whenever the map changes. Updates are coalesced; if you do not need to worry about reading from the channel faster than you are able. The snapshot will contain the full list of coalesced updates; the initial snapshot will contain 0 updates. A read from the channel will block as long as there are no changes since the last read.

The values in the snapshot are deepcopies of the actual values in the map, but values may be reused between snapshots; if you mutate a value in a snapshot, that mutation may erroneously persist in future snapshots.

The returned channel will be closed when the Context is Done, or .Close() is called. If .Close() has already been called, then an already-closed channel is returned.

func (*AgentMap) SubscribeSubset

func (tm *AgentMap) SubscribeSubset(ctx context.Context, include func(string, *manager.AgentInfo) bool) <-chan AgentMapSnapshot

SubscribeSubset is like Subscribe, but the snapshot returned only includes entries that satisfy the 'include' predicate. Mutations to entries that don't satisfy the predicate do not cause a new snapshot to be emitted. If the value for a key changes from satisfying the predicate to not satisfying it, then this is treated as a delete operation, and a new snapshot is generated.

type AgentMapSnapshot

type AgentMapSnapshot struct {
	// State is the current state of the snapshot.
	State map[string]*manager.AgentInfo
	// Updates is the list of mutations that have happened since the previous snapshot.
	// Mutations that delete a value have .Delete=true, and .Value set to the value that was
	// deleted.  No-op updates are not included (i.e., setting something to its current value,
	// or deleting something that does not exist).
	Updates []AgentMapUpdate
}

AgentMapSnapshot contains a snapshot of the current state of a AgentMap, as well as a list of changes that have happened since the last snapshot.

type AgentMapUpdate

type AgentMapUpdate struct {
	Key    string
	Delete bool // Whether this is deleting the entry for .Key, or setting it to .Value.
	Value  *manager.AgentInfo
}

AgentMapUpdate describes a mutation made to a AgentMap.

type ClientMap

type ClientMap struct {
	// contains filtered or unexported fields
}

ClientMap is a wrapper around map[string]*manager.ClientInfo that is very similar to sync.Map, and that provides the additional features that:

  1. it is thread-safe (compared to a bare map)
  2. it provides type safety (compared to a sync.Map)
  3. it provides a compare-and-swap operation
  4. you can Subscribe to either the whole map or just a subset of the map to watch for updates. This gives you complete snapshots, deltas, and coalescing of rapid updates.

func (*ClientMap) Close

func (tm *ClientMap) Close()

Close marks the map as "finished", all subscriber channels are closed and further mutations are forbidden.

After .Close() is called, any calls to .Store() will block forever, and any calls to .Subscribe() will return an already-closed channel.

.Load() and .LoadAll() calls will continue to work normally after .Close() has been called.

func (*ClientMap) CompareAndSwap

func (tm *ClientMap) CompareAndSwap(key string, old, new *manager.ClientInfo) bool

CompareAndSwap is the atomic equivalent of:

if loadedVal, loadedOK := m.Load(key); loadedOK && proto.Equal(loadedVal, old) {
    m.Store(key, new)
    return true
}
return false

func (*ClientMap) Delete

func (tm *ClientMap) Delete(key string)

Delete deletes the value for a key. This blocks forever if .Close() has already been called.

func (*ClientMap) Load

func (tm *ClientMap) Load(key string) (value *manager.ClientInfo, ok bool)

Load returns a deepcopy of the value for a specific key.

func (*ClientMap) LoadAll

func (tm *ClientMap) LoadAll() map[string]*manager.ClientInfo

LoadAll returns a deepcopy of all key/value pairs in the map.

func (*ClientMap) LoadAllMatching added in v2.4.5

func (tm *ClientMap) LoadAllMatching(filter func(string, *manager.ClientInfo) bool) map[string]*manager.ClientInfo

LoadAllMatching returns a deepcopy of all key/value pairs in the map for which the given function returns true. The map is locked during the evaluation of the filter.

func (*ClientMap) LoadAndDelete

func (tm *ClientMap) LoadAndDelete(key string) (value *manager.ClientInfo, loaded bool)

LoadAndDelete deletes the value for a key, returning a deepcopy of the previous value if any. The 'loaded' result reports whether the key was present.

If the value does need to be deleted, all the same blocking semantics as .Delete() apply.

func (*ClientMap) LoadOrStore

func (tm *ClientMap) LoadOrStore(key string, val *manager.ClientInfo) (value *manager.ClientInfo, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The 'loaded' result is true if the value was loaded, false if stored.

If the value does need to be stored, all the same blocking semantics as .Store() apply

func (*ClientMap) Store

func (tm *ClientMap) Store(key string, val *manager.ClientInfo)

Store sets a key sets the value for a key. This blocks forever if .Close() has already been called.

func (*ClientMap) Subscribe

func (tm *ClientMap) Subscribe(ctx context.Context) <-chan ClientMapSnapshot

Subscribe returns a channel that will emit a complete snapshot of the map immediately after the call to Subscribe(), and then whenever the map changes. Updates are coalesced; if you do not need to worry about reading from the channel faster than you are able. The snapshot will contain the full list of coalesced updates; the initial snapshot will contain 0 updates. A read from the channel will block as long as there are no changes since the last read.

The values in the snapshot are deepcopies of the actual values in the map, but values may be reused between snapshots; if you mutate a value in a snapshot, that mutation may erroneously persist in future snapshots.

The returned channel will be closed when the Context is Done, or .Close() is called. If .Close() has already been called, then an already-closed channel is returned.

func (*ClientMap) SubscribeSubset

func (tm *ClientMap) SubscribeSubset(ctx context.Context, include func(string, *manager.ClientInfo) bool) <-chan ClientMapSnapshot

SubscribeSubset is like Subscribe, but the snapshot returned only includes entries that satisfy the 'include' predicate. Mutations to entries that don't satisfy the predicate do not cause a new snapshot to be emitted. If the value for a key changes from satisfying the predicate to not satisfying it, then this is treated as a delete operation, and a new snapshot is generated.

type ClientMapSnapshot

type ClientMapSnapshot struct {
	// State is the current state of the snapshot.
	State map[string]*manager.ClientInfo
	// Updates is the list of mutations that have happened since the previous snapshot.
	// Mutations that delete a value have .Delete=true, and .Value set to the value that was
	// deleted.  No-op updates are not included (i.e., setting something to its current value,
	// or deleting something that does not exist).
	Updates []ClientMapUpdate
}

ClientMapSnapshot contains a snapshot of the current state of a ClientMap, as well as a list of changes that have happened since the last snapshot.

type ClientMapUpdate

type ClientMapUpdate struct {
	Key    string
	Delete bool // Whether this is deleting the entry for .Key, or setting it to .Value.
	Value  *manager.ClientInfo
}

ClientMapUpdate describes a mutation made to a ClientMap.

type InterceptMap

type InterceptMap struct {
	// contains filtered or unexported fields
}

InterceptMap is a wrapper around map[string]*manager.InterceptInfo that is very similar to sync.Map, and that provides the additional features that:

  1. it is thread-safe (compared to a bare map)
  2. it provides type safety (compared to a sync.Map)
  3. it provides a compare-and-swap operation
  4. you can Subscribe to either the whole map or just a subset of the map to watch for updates. This gives you complete snapshots, deltas, and coalescing of rapid updates.

func (*InterceptMap) Close

func (tm *InterceptMap) Close()

Close marks the map as "finished", all subscriber channels are closed and further mutations are forbidden.

After .Close() is called, any calls to .Store() will block forever, and any calls to .Subscribe() will return an already-closed channel.

.Load() and .LoadAll() calls will continue to work normally after .Close() has been called.

func (*InterceptMap) CompareAndSwap

func (tm *InterceptMap) CompareAndSwap(key string, old, new *manager.InterceptInfo) bool

CompareAndSwap is the atomic equivalent of:

if loadedVal, loadedOK := m.Load(key); loadedOK && proto.Equal(loadedVal, old) {
    m.Store(key, new)
    return true
}
return false

func (*InterceptMap) Delete

func (tm *InterceptMap) Delete(key string)

Delete deletes the value for a key. This blocks forever if .Close() has already been called.

func (*InterceptMap) Load

func (tm *InterceptMap) Load(key string) (value *manager.InterceptInfo, ok bool)

Load returns a deepcopy of the value for a specific key.

func (*InterceptMap) LoadAll

func (tm *InterceptMap) LoadAll() map[string]*manager.InterceptInfo

LoadAll returns a deepcopy of all key/value pairs in the map.

func (*InterceptMap) LoadAllMatching added in v2.4.5

func (tm *InterceptMap) LoadAllMatching(filter func(string, *manager.InterceptInfo) bool) map[string]*manager.InterceptInfo

LoadAllMatching returns a deepcopy of all key/value pairs in the map for which the given function returns true. The map is locked during the evaluation of the filter.

func (*InterceptMap) LoadAndDelete

func (tm *InterceptMap) LoadAndDelete(key string) (value *manager.InterceptInfo, loaded bool)

LoadAndDelete deletes the value for a key, returning a deepcopy of the previous value if any. The 'loaded' result reports whether the key was present.

If the value does need to be deleted, all the same blocking semantics as .Delete() apply.

func (*InterceptMap) LoadOrStore

func (tm *InterceptMap) LoadOrStore(key string, val *manager.InterceptInfo) (value *manager.InterceptInfo, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The 'loaded' result is true if the value was loaded, false if stored.

If the value does need to be stored, all the same blocking semantics as .Store() apply

func (*InterceptMap) Store

func (tm *InterceptMap) Store(key string, val *manager.InterceptInfo)

Store sets a key sets the value for a key. This blocks forever if .Close() has already been called.

func (*InterceptMap) Subscribe

func (tm *InterceptMap) Subscribe(ctx context.Context) <-chan InterceptMapSnapshot

Subscribe returns a channel that will emit a complete snapshot of the map immediately after the call to Subscribe(), and then whenever the map changes. Updates are coalesced; if you do not need to worry about reading from the channel faster than you are able. The snapshot will contain the full list of coalesced updates; the initial snapshot will contain 0 updates. A read from the channel will block as long as there are no changes since the last read.

The values in the snapshot are deepcopies of the actual values in the map, but values may be reused between snapshots; if you mutate a value in a snapshot, that mutation may erroneously persist in future snapshots.

The returned channel will be closed when the Context is Done, or .Close() is called. If .Close() has already been called, then an already-closed channel is returned.

func (*InterceptMap) SubscribeSubset

func (tm *InterceptMap) SubscribeSubset(ctx context.Context, include func(string, *manager.InterceptInfo) bool) <-chan InterceptMapSnapshot

SubscribeSubset is like Subscribe, but the snapshot returned only includes entries that satisfy the 'include' predicate. Mutations to entries that don't satisfy the predicate do not cause a new snapshot to be emitted. If the value for a key changes from satisfying the predicate to not satisfying it, then this is treated as a delete operation, and a new snapshot is generated.

type InterceptMapSnapshot

type InterceptMapSnapshot struct {
	// State is the current state of the snapshot.
	State map[string]*manager.InterceptInfo
	// Updates is the list of mutations that have happened since the previous snapshot.
	// Mutations that delete a value have .Delete=true, and .Value set to the value that was
	// deleted.  No-op updates are not included (i.e., setting something to its current value,
	// or deleting something that does not exist).
	Updates []InterceptMapUpdate
}

InterceptMapSnapshot contains a snapshot of the current state of a InterceptMap, as well as a list of changes that have happened since the last snapshot.

type InterceptMapUpdate

type InterceptMapUpdate struct {
	Key    string
	Delete bool // Whether this is deleting the entry for .Key, or setting it to .Value.
	Value  *manager.InterceptInfo
}

InterceptMapUpdate describes a mutation made to a InterceptMap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL