|
|
@ -10,16 +10,42 @@ import ( |
|
|
|
// ActionType ...
|
|
|
|
// ActionType ...
|
|
|
|
type ActionType byte |
|
|
|
type ActionType byte |
|
|
|
|
|
|
|
|
|
|
|
// Constants ...
|
|
|
|
// Constants for Action Type.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
SyncingAction ActionType = iota |
|
|
|
Start ActionType = iota |
|
|
|
KillSyncingAction |
|
|
|
Stop |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Type is service type.
|
|
|
|
|
|
|
|
type Type byte |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Constants for Type.
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
SyncingSupport Type = iota |
|
|
|
SupportClient |
|
|
|
SupportClient |
|
|
|
SupportExplorer |
|
|
|
SupportExplorer |
|
|
|
SyncingActionTest |
|
|
|
Test |
|
|
|
Done |
|
|
|
Done |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (t Type) String() string { |
|
|
|
|
|
|
|
switch t { |
|
|
|
|
|
|
|
case SupportClient: |
|
|
|
|
|
|
|
return "SupportClient" |
|
|
|
|
|
|
|
case SyncingSupport: |
|
|
|
|
|
|
|
return "SyncingSupport" |
|
|
|
|
|
|
|
case SupportExplorer: |
|
|
|
|
|
|
|
return "SupportExplorer" |
|
|
|
|
|
|
|
case Test: |
|
|
|
|
|
|
|
return "Test" |
|
|
|
|
|
|
|
case Done: |
|
|
|
|
|
|
|
return "Done" |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return "Unknown" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Constants for timing.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// WaitForStatusUpdate is the delay time to update new status. Currently set 1 second for development. Should be 30 minutes for production.
|
|
|
|
// WaitForStatusUpdate is the delay time to update new status. Currently set 1 second for development. Should be 30 minutes for production.
|
|
|
|
WaitForStatusUpdate = time.Second * 1 |
|
|
|
WaitForStatusUpdate = time.Second * 1 |
|
|
@ -27,10 +53,22 @@ const ( |
|
|
|
|
|
|
|
|
|
|
|
// Action is type of service action.
|
|
|
|
// Action is type of service action.
|
|
|
|
type Action struct { |
|
|
|
type Action struct { |
|
|
|
t ActionType |
|
|
|
action ActionType |
|
|
|
|
|
|
|
serviceType Type |
|
|
|
params map[string]interface{} |
|
|
|
params map[string]interface{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ServiceInterface ...
|
|
|
|
|
|
|
|
type ServiceInterface interface { |
|
|
|
|
|
|
|
Start() |
|
|
|
|
|
|
|
Stop() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ServiceStore stores all services for service manager.
|
|
|
|
|
|
|
|
type ServiceStore struct { |
|
|
|
|
|
|
|
services map[Type]ServiceInterface |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start node.
|
|
|
|
// Start node.
|
|
|
|
func (node *Node) Start() { |
|
|
|
func (node *Node) Start() { |
|
|
|
node.actionChannel = node.StartServiceManager() |
|
|
|
node.actionChannel = node.StartServiceManager() |
|
|
@ -43,18 +81,19 @@ func (node *Node) SendAction(action *Action) { |
|
|
|
|
|
|
|
|
|
|
|
// TakeAction ...
|
|
|
|
// TakeAction ...
|
|
|
|
func (node *Node) TakeAction(action *Action) { |
|
|
|
func (node *Node) TakeAction(action *Action) { |
|
|
|
switch action.t { |
|
|
|
if node.serviceStore == nil { |
|
|
|
case SyncingActionTest: |
|
|
|
utils.GetLogInstance().Error("Service store is not initialized.") |
|
|
|
fmt.Println("Running syncing support") |
|
|
|
return |
|
|
|
case SyncingAction: |
|
|
|
} |
|
|
|
utils.GetLogInstance().Info("Running syncing support") |
|
|
|
if service, ok := node.serviceStore.services[action.serviceType]; ok { |
|
|
|
go node.SupportSyncing() |
|
|
|
switch action.action { |
|
|
|
case KillSyncingAction: |
|
|
|
case Start: |
|
|
|
utils.GetLogInstance().Info("Killing syncing") |
|
|
|
fmt.Printf("Start %s\n", action.serviceType) |
|
|
|
case SupportClient: |
|
|
|
service.Start() |
|
|
|
go node.SupportClient() |
|
|
|
case Stop: |
|
|
|
case SupportExplorer: |
|
|
|
fmt.Printf("Stop %s\n", action.serviceType) |
|
|
|
go node.SupportExplorer() |
|
|
|
service.Stop() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -66,7 +105,7 @@ func (node *Node) StartServiceManager() chan *Action { |
|
|
|
select { |
|
|
|
select { |
|
|
|
case action := <-ch: |
|
|
|
case action := <-ch: |
|
|
|
node.TakeAction(action) |
|
|
|
node.TakeAction(action) |
|
|
|
if action.t == Done { |
|
|
|
if action.serviceType == Done { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
case <-time.After(WaitForStatusUpdate): |
|
|
|
case <-time.After(WaitForStatusUpdate): |
|
|
|