Files
weave-scope/examples/plugins/traffic-control/store.go
Krzesimir Nowak c5cc9814fe Add an example traffic control plugin
As it is an initial implementation, it only controls latency of the
outgoing (egress) traffic. There is also a TODO to turn this plugin
into something more serious. Also, at some point we may consider
moving this plugin outside of "example" directory.
2016-09-06 11:53:35 +02:00

58 lines
983 B
Go

package main
import (
"sync"
)
type State int
const (
Created State = iota
Running
Stopped
Destroyed
)
type Container struct {
State State
PID int
}
type Store struct {
lock sync.Mutex
containers map[string]Container
}
func NewStore() *Store {
return &Store{
containers: map[string]Container{},
}
}
func (s *Store) Container(containerID string) (Container, bool) {
s.lock.Lock()
defer s.lock.Unlock()
container, found := s.containers[containerID]
return container, found
}
func (s *Store) SetContainer(containerID string, container Container) {
s.lock.Lock()
defer s.lock.Unlock()
s.containers[containerID] = container
}
func (s *Store) DeleteContainer(containerID string) {
s.lock.Lock()
defer s.lock.Unlock()
delete(s.containers, containerID)
}
func (s *Store) ForEach(callback func(ID string, c Container)) {
s.lock.Lock()
defer s.lock.Unlock()
for containerID, container := range s.containers {
callback(containerID, container)
}
}