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 s.running = false
} }
func (r *runtime) Register(s *Service) error { func (r *runtime) Create(s *Service) error {
r.Lock() r.Lock()
defer r.Unlock() defer r.Unlock()
@ -155,7 +155,19 @@ func (r *runtime) Register(s *Service) error {
return nil 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() r.Lock()
// already running // already running

View File

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