| package instance |
|
|
| import ( |
| "github.com/pinchtab/pinchtab/internal/allocation" |
| "github.com/pinchtab/pinchtab/internal/bridge" |
| ) |
|
|
| |
| |
| |
| type Manager struct { |
| Repo *Repository |
| Locator *Locator |
| Allocator *Allocator |
| } |
|
|
| |
| func NewManager(launcher InstanceLauncher, fetcher TabFetcher, policy allocation.Policy) *Manager { |
| if policy == nil { |
| policy = &allocation.FCFS{} |
| } |
|
|
| repo := NewRepository(launcher) |
| locator := NewLocator(repo, fetcher) |
| allocator := NewAllocator(repo, policy) |
|
|
| return &Manager{ |
| Repo: repo, |
| Locator: locator, |
| Allocator: allocator, |
| } |
| } |
|
|
| |
|
|
| |
| func (m *Manager) Launch(name, port string, headless bool) (*bridge.Instance, error) { |
| return m.Repo.Launch(name, port, headless) |
| } |
|
|
| |
| func (m *Manager) Stop(id string) error { |
| m.Locator.InvalidateInstance(id) |
| return m.Repo.Stop(id) |
| } |
|
|
| |
| func (m *Manager) List() []bridge.Instance { |
| return m.Repo.List() |
| } |
|
|
| |
| func (m *Manager) Get(id string) (*bridge.Instance, bool) { |
| return m.Repo.Get(id) |
| } |
|
|
| |
| func (m *Manager) Running() []bridge.Instance { |
| return m.Repo.Running() |
| } |
|
|
| |
|
|
| |
| func (m *Manager) FindInstanceByTabID(tabID string) (*bridge.Instance, error) { |
| return m.Locator.FindInstanceByTabID(tabID) |
| } |
|
|
| |
| func (m *Manager) RegisterTab(tabID, instanceID string) { |
| m.Locator.Register(tabID, instanceID) |
| } |
|
|
| |
| func (m *Manager) InvalidateTab(tabID string) { |
| m.Locator.Invalidate(tabID) |
| } |
|
|
| |
|
|
| |
| func (m *Manager) Allocate() (*bridge.Instance, error) { |
| return m.Allocator.Allocate() |
| } |
|
|