add create/delete/start/stop to runtime

This commit is contained in:
Asim Aslam 2019-09-13 21:58:03 -07:00
parent 0fc4c180ee
commit 0cdfc7b9ea
2 changed files with 26 additions and 8 deletions

View File

@ -141,7 +141,7 @@ func (s *service) Wait() {
s.running = false
}
func (r *runtime) Register(s *Service) error {
func (r *runtime) Create(s *Service) error {
r.Lock()
defer r.Unlock()
@ -155,7 +155,19 @@ func (r *runtime) Register(s *Service) error {
return nil
}
func (r *runtime) Run() error {
func (r *runtime) Delete(s *Service) error {
r.Lock()
defer r.Unlock()
if s, ok := r.services[s.Name]; ok {
delete(r.services, s.Name)
return s.Stop()
}
return nil
}
func (r *runtime) Start() error {
r.Lock()
// already running

View File

@ -4,9 +4,11 @@ package runtime
// Runtime is a service runtime manager
type Runtime interface {
// Registers a service
Register(*Service) error
Create(*Service) error
// Remove a service
Delete(*Service) error
// starts the runtime
Run() error
Start() error
// Shutdown the runtime
Stop() error
}
@ -26,12 +28,16 @@ var (
DefaultRuntime = newRuntime()
)
func Register(s *Service) error {
return DefaultRuntime.Register(s)
func Create(s *Service) error {
return DefaultRuntime.Create(s)
}
func Run() error {
return DefaultRuntime.Run()
func Delete(s *Service) error {
return DefaultRuntime.Delete(s)
}
func Start() error {
return DefaultRuntime.Start()
}
func Stop() error {