|
@@ -104,33 +104,50 @@ type LogWatcher struct {
|
|
|
// For sending log messages to a reader.
|
|
|
Msg chan *Message
|
|
|
// For sending error messages that occur while while reading logs.
|
|
|
- Err chan error
|
|
|
- closeOnce sync.Once
|
|
|
- closeNotifier chan struct{}
|
|
|
+ Err chan error
|
|
|
+ producerOnce sync.Once
|
|
|
+ producerGone chan struct{}
|
|
|
+ consumerOnce sync.Once
|
|
|
+ consumerGone chan struct{}
|
|
|
}
|
|
|
|
|
|
// NewLogWatcher returns a new LogWatcher.
|
|
|
func NewLogWatcher() *LogWatcher {
|
|
|
return &LogWatcher{
|
|
|
- Msg: make(chan *Message, logWatcherBufferSize),
|
|
|
- Err: make(chan error, 1),
|
|
|
- closeNotifier: make(chan struct{}),
|
|
|
+ Msg: make(chan *Message, logWatcherBufferSize),
|
|
|
+ Err: make(chan error, 1),
|
|
|
+ producerGone: make(chan struct{}),
|
|
|
+ consumerGone: make(chan struct{}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Close notifies the underlying log reader to stop.
|
|
|
-func (w *LogWatcher) Close() {
|
|
|
+// ProducerGone notifies the underlying log reader that
|
|
|
+// the logs producer (a container) is gone.
|
|
|
+func (w *LogWatcher) ProducerGone() {
|
|
|
// only close if not already closed
|
|
|
- w.closeOnce.Do(func() {
|
|
|
- close(w.closeNotifier)
|
|
|
+ w.producerOnce.Do(func() {
|
|
|
+ close(w.producerGone)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// WatchClose returns a channel receiver that receives notification
|
|
|
-// when the watcher has been closed. This should only be called from
|
|
|
-// one goroutine.
|
|
|
-func (w *LogWatcher) WatchClose() <-chan struct{} {
|
|
|
- return w.closeNotifier
|
|
|
+// WatchProducerGone returns a channel receiver that receives notification
|
|
|
+// once the logs producer (a container) is gone.
|
|
|
+func (w *LogWatcher) WatchProducerGone() <-chan struct{} {
|
|
|
+ return w.producerGone
|
|
|
+}
|
|
|
+
|
|
|
+// ConsumerGone notifies that the logs consumer is gone.
|
|
|
+func (w *LogWatcher) ConsumerGone() {
|
|
|
+ // only close if not already closed
|
|
|
+ w.consumerOnce.Do(func() {
|
|
|
+ close(w.consumerGone)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// WatchConsumerGone returns a channel receiver that receives notification
|
|
|
+// when the log watcher consumer is gone.
|
|
|
+func (w *LogWatcher) WatchConsumerGone() <-chan struct{} {
|
|
|
+ return w.consumerGone
|
|
|
}
|
|
|
|
|
|
// Capability defines the list of capabilities that a driver can implement
|