diff --git a/api/service/manager.go b/api/service/manager.go index 7e88f0853..1854cd23d 100644 --- a/api/service/manager.go +++ b/api/service/manager.go @@ -56,8 +56,8 @@ const ( // Action is type of service action. type Action struct { - action ActionType - serviceType Type + Action ActionType + ServiceType Type params map[string]interface{} } @@ -73,7 +73,12 @@ type Manager struct { 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) { if m.services == nil { m.services = make(map[Type]Interface) @@ -108,13 +113,13 @@ func (m *Manager) TakeAction(action *Action) { utils.GetLogInstance().Error("Service store is not initialized.") return } - if service, ok := m.services[action.serviceType]; ok { - switch action.action { + if service, ok := m.services[action.ServiceType]; ok { + switch action.Action { case Start: - fmt.Printf("Start %s\n", action.serviceType) + fmt.Printf("Start %s\n", action.ServiceType) service.StartService() case Stop: - fmt.Printf("Stop %s\n", action.serviceType) + fmt.Printf("Stop %s\n", action.ServiceType) service.StopService() } } @@ -128,7 +133,7 @@ func (m *Manager) StartServiceManager() chan *Action { select { case action := <-ch: m.TakeAction(action) - if action.serviceType == Done { + if action.ServiceType == Done { return } case <-time.After(WaitForStatusUpdate): diff --git a/api/service/manager_test.go b/api/service/manager_test.go index 5e83accbf..c1780a627 100644 --- a/api/service/manager_test.go +++ b/api/service/manager_test.go @@ -25,9 +25,9 @@ func TestTakeAction(t *testing.T) { for i := 0; i < 2; i++ { select { case <-time.After(WaitForStatusUpdate): - m.SendAction(&Action{action: Start, serviceType: SupportSyncing}) + m.SendAction(&Action{Action: Start, ServiceType: SupportSyncing}) } } - m.SendAction(&Action{serviceType: Done}) + m.SendAction(&Action{ServiceType: Done}) } diff --git a/cmd/harmony.go b/cmd/harmony.go index 7371a789a..dcc9ae0a0 100644 --- a/cmd/harmony.go +++ b/cmd/harmony.go @@ -207,7 +207,6 @@ func main() { // Assign closure functions to the consensus object consensus.BlockVerifier = currentNode.VerifyNewBlock consensus.OnConsensusDone = currentNode.PostConsensusProcessing - currentNode.State = node.NodeWaitToJoin if consensus.IsLeader { @@ -224,6 +223,7 @@ func main() { if consensus.IsLeader { go currentNode.SupportClient() } - currentNode.AddAndRunServices() + currentNode.ServiceManagerSetup() + currentNode.RunServices() currentNode.StartServer() }