| 55 | } |
| 56 | |
| 57 | func (w *FailureWatcher) WatchManager(manager *Manager) { |
| 58 | // Ensure that if the caller request to watch services, then the FailureWatcher |
| 59 | // has been initialized. |
| 60 | if w == nil { |
| 61 | panic(errFailureWatcherNotInitialized) |
| 62 | } |
| 63 | |
| 64 | w.mu.Lock() |
| 65 | defer w.mu.Unlock() |
| 66 | |
| 67 | if w.closed { |
| 68 | panic(errFailureWatcherClosed) |
| 69 | } |
| 70 | |
| 71 | stop := manager.AddListener(NewManagerListener(nil, nil, func(service Service) { |
| 72 | w.ch <- errors.Wrapf(service.FailureCase(), "service %s failed", DescribeService(service)) |
| 73 | })) |
| 74 | w.unregisterListeners = append(w.unregisterListeners, stop) |
| 75 | } |
| 76 | |
| 77 | // Close stops this failure watcher and closes channel returned by Chan() method. After closing failure watcher, |
| 78 | // it cannot be used to watch additional services or managers. |