You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
70 lines
1.5 KiB
package rconversion
|
|
|
|
import (
|
|
msg_pb "github.com/harmony-one/harmony/api/proto/message"
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
)
|
|
|
|
// Service is the role conversion service.
|
|
type Service struct {
|
|
stopChan chan struct{}
|
|
stoppedChan chan struct{}
|
|
messageChan chan *msg_pb.Message
|
|
}
|
|
|
|
// New returns role conversion service.
|
|
func New() *Service {
|
|
return &Service{}
|
|
}
|
|
|
|
// StartService starts role conversion service.
|
|
func (s *Service) StartService() {
|
|
s.stopChan = make(chan struct{})
|
|
s.stoppedChan = make(chan struct{})
|
|
|
|
s.Init()
|
|
s.Run(s.stopChan, s.stoppedChan)
|
|
}
|
|
|
|
// Init initializes role conversion service.
|
|
func (s *Service) Init() {
|
|
}
|
|
|
|
// Run runs role conversion.
|
|
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) {
|
|
go func() {
|
|
defer close(stoppedChan)
|
|
for {
|
|
select {
|
|
default:
|
|
utils.GetLogInstance().Info("Running role conversion")
|
|
// TODO: Write some logic here.
|
|
s.DoService()
|
|
case <-stopChan:
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
// DoService does role conversion.
|
|
func (s *Service) DoService() {
|
|
}
|
|
|
|
// StopService stops role conversion service.
|
|
func (s *Service) StopService() {
|
|
utils.GetLogInstance().Info("Stopping role conversion service.")
|
|
s.stopChan <- struct{}{}
|
|
<-s.stoppedChan
|
|
utils.GetLogInstance().Info("Role conversion stopped.")
|
|
}
|
|
|
|
// NotifyService notify service
|
|
func (s *Service) NotifyService(params map[string]interface{}) {
|
|
return
|
|
}
|
|
|
|
// SetMessageChan sets up message channel to service.
|
|
func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) {
|
|
s.messageChan = messageChan
|
|
}
|
|
|