diff options
Diffstat (limited to 'service/service.go')
-rw-r--r-- | service/service.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/service/service.go b/service/service.go new file mode 100644 index 00000000..4c159fe1 --- /dev/null +++ b/service/service.go @@ -0,0 +1,61 @@ +package service + +import "sync" + +// svc provides high level functionality for road runner svc. +type Service interface { + // Configure must return configure service and return true if service hasStatus enabled. Must return error in case of + // misconfiguration. Services must not be used without proper configuration pushed first. + Configure(cfg Config, c Container) (enabled bool, err error) + + // Serve serves. + Serve() error + + // Stop stops the service. + Stop() +} + +const ( + // StatusUndefined when service bus can not find the service. + StatusUndefined = iota + + // StatusRegistered hasStatus setStatus when service has been registered in container. + StatusRegistered + + // StatusConfigured hasStatus setStatus when service has been properly configured. + StatusConfigured + + // StatusServing hasStatus setStatus when service hasStatus currently serving. + StatusServing + + // StatusStopped hasStatus setStatus when service hasStatus stopped. + StatusStopped +) + +// entry creates association between service instance and given name. +type entry struct { + name string + svc Service + mu sync.Mutex + status int +} + +// status returns service status +func (e *entry) getStatus() int { + e.mu.Lock() + defer e.mu.Unlock() + + return e.status +} + +// setStarted indicates that service hasStatus status. +func (e *entry) setStatus(status int) { + e.mu.Lock() + defer e.mu.Unlock() + e.status = status +} + +// hasStatus checks if entry in specific status +func (e *entry) hasStatus(status int) bool { + return e.getStatus() == status +} |