summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 17:53:13 +0300
committerWolfy-J <[email protected]>2018-06-10 17:53:13 +0300
commit4fd4c7a1e8194287249fa59252afc2cd260d5643 (patch)
tree7f2f3872ff13ff063acca14d4294b4d299c3dea2 /server.go
parent094a4c211022b9446ef988c74c546ad6efb09722 (diff)
rr is working now
Diffstat (limited to 'server.go')
-rw-r--r--server.go92
1 files changed, 46 insertions, 46 deletions
diff --git a/server.go b/server.go
index 84dedb52..6ee2a170 100644
--- a/server.go
+++ b/server.go
@@ -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()