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

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

@ -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()
}

Loading…
Cancel
Save