|
|
@ -56,8 +56,8 @@ const ( |
|
|
|
|
|
|
|
|
|
|
|
// Action is type of service action.
|
|
|
|
// Action is type of service action.
|
|
|
|
type Action struct { |
|
|
|
type Action struct { |
|
|
|
action ActionType |
|
|
|
Action ActionType |
|
|
|
serviceType Type |
|
|
|
ServiceType Type |
|
|
|
params map[string]interface{} |
|
|
|
params map[string]interface{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +73,12 @@ type Manager struct { |
|
|
|
actionChannel chan *Action |
|
|
|
actionChannel chan *Action |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Register new service to service store.
|
|
|
|
// GetServices returns all registered services.
|
|
|
|
|
|
|
|
func (m *Manager) GetServices() map[Type]Interface { |
|
|
|
|
|
|
|
return m.services |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register registers new service to service store.
|
|
|
|
func (m *Manager) Register(t Type, service Interface) { |
|
|
|
func (m *Manager) Register(t Type, service Interface) { |
|
|
|
if m.services == nil { |
|
|
|
if m.services == nil { |
|
|
|
m.services = make(map[Type]Interface) |
|
|
|
m.services = make(map[Type]Interface) |
|
|
@ -108,13 +113,13 @@ func (m *Manager) TakeAction(action *Action) { |
|
|
|
utils.GetLogInstance().Error("Service store is not initialized.") |
|
|
|
utils.GetLogInstance().Error("Service store is not initialized.") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if service, ok := m.services[action.serviceType]; ok { |
|
|
|
if service, ok := m.services[action.ServiceType]; ok { |
|
|
|
switch action.action { |
|
|
|
switch action.Action { |
|
|
|
case Start: |
|
|
|
case Start: |
|
|
|
fmt.Printf("Start %s\n", action.serviceType) |
|
|
|
fmt.Printf("Start %s\n", action.ServiceType) |
|
|
|
service.StartService() |
|
|
|
service.StartService() |
|
|
|
case Stop: |
|
|
|
case Stop: |
|
|
|
fmt.Printf("Stop %s\n", action.serviceType) |
|
|
|
fmt.Printf("Stop %s\n", action.ServiceType) |
|
|
|
service.StopService() |
|
|
|
service.StopService() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -128,7 +133,7 @@ func (m *Manager) StartServiceManager() chan *Action { |
|
|
|
select { |
|
|
|
select { |
|
|
|
case action := <-ch: |
|
|
|
case action := <-ch: |
|
|
|
m.TakeAction(action) |
|
|
|
m.TakeAction(action) |
|
|
|
if action.serviceType == Done { |
|
|
|
if action.ServiceType == Done { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
case <-time.After(WaitForStatusUpdate): |
|
|
|
case <-time.After(WaitForStatusUpdate): |
|
|
|