@@ -39,10 +39,10 @@ type RunCanceler interface {
3939// and add a function to call manager.InformCleanup if it's not going to be used
4040const numberOfServersToCreate = 4
4141
42- // Manager represents the graceful server manager interface
43- var manager * Manager
44-
45- var initOnce = sync. Once {}
42+ var (
43+ manager * Manager
44+ initOnce sync. Once
45+ )
4646
4747// GetManager returns the Manager
4848func GetManager () * Manager {
@@ -147,12 +147,12 @@ func (g *Manager) doShutdown() {
147147 go g .doHammerTime (setting .GracefulHammerTime )
148148 }
149149 go func () {
150- g .WaitForServers ()
150+ g .runningServerWaitGroup . Wait ()
151151 // Mop up any remaining unclosed events.
152152 g .doHammerTime (0 )
153153 <- time .After (1 * time .Second )
154154 g .doTerminate ()
155- g .WaitForTerminate ()
155+ g .terminateWaitGroup . Wait ()
156156 g .lock .Lock ()
157157 g .managerCtxCancel ()
158158 g .lock .Unlock ()
@@ -199,55 +199,26 @@ func (g *Manager) IsChild() bool {
199199}
200200
201201// IsShutdown returns a channel which will be closed at shutdown.
202- // The order of closure is IsShutdown, IsHammer (potentially), IsTerminate
202+ // The order of closure is shutdown, hammer (potentially), terminate
203203func (g * Manager ) IsShutdown () <- chan struct {} {
204204 return g .shutdownCtx .Done ()
205205}
206206
207- // IsHammer returns a channel which will be closed at hammer
208- // The order of closure is IsShutdown, IsHammer (potentially), IsTerminate
207+ // IsHammer returns a channel which will be closed at hammer.
209208// Servers running within the running server wait group should respond to IsHammer
210209// if not shutdown already
211210func (g * Manager ) IsHammer () <- chan struct {} {
212211 return g .hammerCtx .Done ()
213212}
214213
215- // IsTerminate returns a channel which will be closed at terminate
216- // The order of closure is IsShutdown, IsHammer (potentially), IsTerminate
217- // IsTerminate will only close once all running servers have stopped
218- func (g * Manager ) IsTerminate () <- chan struct {} {
219- return g .terminateCtx .Done ()
220- }
221-
222214// ServerDone declares a running server done and subtracts one from the
223215// running server wait group. Users probably do not want to call this
224216// and should use one of the RunWithShutdown* functions
225217func (g * Manager ) ServerDone () {
226218 g .runningServerWaitGroup .Done ()
227219}
228220
229- // WaitForServers waits for all running servers to finish. Users should probably
230- // instead use AtTerminate or IsTerminate
231- func (g * Manager ) WaitForServers () {
232- g .runningServerWaitGroup .Wait ()
233- }
234-
235- // WaitForTerminate waits for all terminating actions to finish.
236- // Only the main go-routine should use this
237- func (g * Manager ) WaitForTerminate () {
238- g .terminateWaitGroup .Wait ()
239- }
240-
241- func (g * Manager ) getState () state {
242- g .lock .RLock ()
243- defer g .lock .RUnlock ()
244- return g .state
245- }
246-
247221func (g * Manager ) setStateTransition (old , new state ) bool {
248- if old != g .getState () {
249- return false
250- }
251222 g .lock .Lock ()
252223 if g .state != old {
253224 g .lock .Unlock ()
@@ -258,13 +229,6 @@ func (g *Manager) setStateTransition(old, new state) bool {
258229 return true
259230}
260231
261- func (g * Manager ) setState (st state ) {
262- g .lock .Lock ()
263- defer g .lock .Unlock ()
264-
265- g .state = st
266- }
267-
268232// InformCleanup tells the cleanup wait group that we have either taken a listener or will not be taking a listener.
269233// At the moment the total number of servers (numberOfServersToCreate) are pre-defined as a const before global init,
270234// so this function MUST be called if a server is not used.
0 commit comments