diff options
author | Wolfy-J <[email protected]> | 2018-06-10 17:53:13 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-10 17:53:13 +0300 |
commit | 4fd4c7a1e8194287249fa59252afc2cd260d5643 (patch) | |
tree | 7f2f3872ff13ff063acca14d4294b4d299c3dea2 /server.go | |
parent | 094a4c211022b9446ef988c74c546ad6efb09722 (diff) |
rr is working now
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 92 |
1 files changed, 46 insertions, 46 deletions
@@ -54,52 +54,6 @@ func (srv *Server) Listen(l func(event int, ctx interface{})) { srv.listener = l } -// Reconfigure re-configures underlying pool and destroys it's previous version if any. Reconfigure will ignore factory -// and relay settings. -func (srv *Server) Reconfigure(cfg *ServerConfig) error { - srv.mu.Lock() - if !srv.started { - srv.cfg = cfg - srv.mu.Unlock() - return nil - } - srv.mu.Unlock() - - if srv.cfg.Differs(cfg) { - return errors.New("unable to reconfigure server (cmd and pool changes are allowed)") - } - - srv.mu.Lock() - previous := srv.pool - srv.mu.Unlock() - - pool, err := NewPool(cfg.makeCommand(), srv.factory, cfg.Pool) - if err != nil { - return err - } - - srv.mu.Lock() - srv.cfg.Pool, srv.pool = cfg.Pool, pool - srv.pool.Listen(srv.poolListener) - srv.mu.Unlock() - - srv.throw(EventPoolConstruct, pool) - - if previous != nil { - go func(previous Pool) { - srv.throw(EventPoolDestruct, previous) - previous.Destroy() - }(previous) - } - - return nil -} - -// Reset resets the state of underlying pool and rebuilds all of it's workers. -func (srv *Server) Reset() error { - return srv.Reconfigure(srv.cfg) -} - // Start underlying worker pool, configure factory and command provider. func (srv *Server) Start() (err error) { srv.mu.Lock() @@ -151,6 +105,52 @@ func (srv *Server) Exec(rqs *Payload) (rsp *Payload, err error) { return pool.Exec(rqs) } +// Reconfigure re-configures underlying pool and destroys it's previous version if any. Reconfigure will ignore factory +// and relay settings. +func (srv *Server) Reconfigure(cfg *ServerConfig) error { + srv.mu.Lock() + if !srv.started { + srv.cfg = cfg + srv.mu.Unlock() + return nil + } + srv.mu.Unlock() + + if srv.cfg.Differs(cfg) { + return errors.New("unable to reconfigure server (cmd and pool changes are allowed)") + } + + srv.mu.Lock() + previous := srv.pool + srv.mu.Unlock() + + pool, err := NewPool(cfg.makeCommand(), srv.factory, cfg.Pool) + if err != nil { + return err + } + + srv.mu.Lock() + srv.cfg.Pool, srv.pool = cfg.Pool, pool + srv.pool.Listen(srv.poolListener) + srv.mu.Unlock() + + srv.throw(EventPoolConstruct, pool) + + if previous != nil { + go func(previous Pool) { + srv.throw(EventPoolDestruct, previous) + previous.Destroy() + }(previous) + } + + return nil +} + +// Reset resets the state of underlying pool and rebuilds all of it's workers. +func (srv *Server) Reset() error { + return srv.Reconfigure(srv.cfg) +} + // Workers returns worker list associated with the server pool. func (srv *Server) Workers() (workers []*Worker) { p := srv.Pool() |