refactor actionType to be public field

pull/375/head
Minh Doan 6 years ago committed by Minh Doan
parent 44b13478cc
commit f8ffecdcbe
  1. 21
      api/service/manager.go
  2. 4
      api/service/manager_test.go
  3. 4
      cmd/harmony.go

@ -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):

@ -25,9 +25,9 @@ func TestTakeAction(t *testing.T) {
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
select { select {
case <-time.After(WaitForStatusUpdate): 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})
} }

@ -207,7 +207,6 @@ func main() {
// Assign closure functions to the consensus object // Assign closure functions to the consensus object
consensus.BlockVerifier = currentNode.VerifyNewBlock consensus.BlockVerifier = currentNode.VerifyNewBlock
consensus.OnConsensusDone = currentNode.PostConsensusProcessing consensus.OnConsensusDone = currentNode.PostConsensusProcessing
currentNode.State = node.NodeWaitToJoin currentNode.State = node.NodeWaitToJoin
if consensus.IsLeader { if consensus.IsLeader {
@ -224,6 +223,7 @@ func main() {
if consensus.IsLeader { if consensus.IsLeader {
go currentNode.SupportClient() go currentNode.SupportClient()
} }
currentNode.AddAndRunServices() currentNode.ServiceManagerSetup()
currentNode.RunServices()
currentNode.StartServer() currentNode.StartServer()
} }

Loading…
Cancel
Save