diff options
author | Wolfy-J <[email protected]> | 2018-06-06 16:01:06 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-06 16:01:06 +0300 |
commit | c0abdf657a0a5de02b63683a60bf13b88895ef79 (patch) | |
tree | b497e98a7c2cf73f7a8377de7566a3f7b4b72a5e | |
parent | e863c6cdcf7c318fb251e096bf92812ed98ea03c (diff) |
better server re-configuration
-rw-r--r-- | cmd/_____/http/request.go (renamed from http/request.go) | 0 | ||||
-rw-r--r-- | cmd/_____/http/uploads.go (renamed from http/uploads.go) | 0 | ||||
-rw-r--r-- | cmd/_____/server.go | 64 | ||||
-rw-r--r-- | server.go | 12 |
4 files changed, 5 insertions, 71 deletions
diff --git a/http/request.go b/cmd/_____/http/request.go index fd483744..fd483744 100644 --- a/http/request.go +++ b/cmd/_____/http/request.go diff --git a/http/uploads.go b/cmd/_____/http/uploads.go index c3b18169..c3b18169 100644 --- a/http/uploads.go +++ b/cmd/_____/http/uploads.go diff --git a/cmd/_____/server.go b/cmd/_____/server.go deleted file mode 100644 index 5542e7c9..00000000 --- a/cmd/_____/server.go +++ /dev/null @@ -1,64 +0,0 @@ -package roadrunner - -import ( - "os/exec" - "sync" -) - -const ( - // EventNewPool triggered when server creates new pool. - EventNewPool = 60 - - // EventDestroyPool triggered when server destroys existed pool. - EventDestroyPool = 61 -) - -// Service manages pool creation and swapping. -type Server struct { - // configures server, pool, cmd creation and factory. - scfg *ServerConfig - - // worker command creator - cmd func() *exec.Cmd - - // observes pool events (can be attached to multiple pools at the same time) - observer func(event int, ctx interface{}) - - // creates and connects to workers - factory Factory - - // protects pool while the switch - mu sync.Mutex -} - -// todo: do assignment - -// Reconfigure configures underlying pool and destroys it's previous version if any. -func (r *Server) Configure(cfg Config) error { - r.mu.Lock() - previous := r.pool - r.mu.Unlock() - - pool, err := NewPool(r.cmd, r.factory, cfg) - if err != nil { - return err - } - - r.throw(EventNewPool, pool) - - r.mu.Lock() - - r.cfg, r.pool = cfg, pool - r.pool.Observe(r.poolObserver) - - r.mu.Unlock() - - if previous != nil { - go func(p Pool) { - r.throw(EventDestroyPool, p) - p.Destroy() - }(previous) - } - - return nil -} @@ -46,8 +46,11 @@ type Server struct { } // NewServer creates new router. Make sure to call configure before the usage. -func NewServer(cfg *ServerConfig) *Server { - return &Server{cfg: cfg} +func NewServer(cfg *ServerConfig, o func(event int, ctx interface{})) *Server { + return &Server{ + cfg: cfg, + observer: o, + } } // Reconfigure re-configures underlying pool and destroys it's previous version if any. @@ -94,11 +97,6 @@ func (srv *Server) Reset() error { return srv.Reconfigure(srv.cfg) } -// Observe attaches event watcher to the router. -func (srv *Server) Observe(o func(event int, ctx interface{})) { - srv.observer = o -} - // Start underlying worker pool, configure factory and command provider. func (srv *Server) Start() (err error) { srv.mu.Lock() |