예제 #1
0
// Shutdown all consumers and producers in a clean way.
// The internal log is flushed after the consumers have been shut down so that
// consumer related messages are still in the log.
// Producers are flushed after flushing the log, so producer related shutdown
// messages will be posted to stdout
func (plex *multiplexer) shutdown() {
	// Make sure the log is printed to stdout if we are stuck here
	logFallback := time.AfterFunc(time.Duration(3)*time.Second, func() {
		Log.SetWriter(os.Stdout)
	})
	defer logFallback.Stop()

	// Handle panics if any
	if r := recover(); r != nil {
		log.Println(r)
	}

	// Make Ctrl+C possible during shutdown sequence
	if plex.signal != nil {
		signal.Stop(plex.signal)
	}

	Log.Note.Print("Filthy little hobbites. They stole it from us. (shutdown)")
	stateAtShutdown := plex.state

	// Shutdown consumers
	plex.state = multiplexerStateStopConsumers
	if stateAtShutdown >= multiplexerStateStartConsumers {
		for _, cons := range plex.consumers {
			Log.Debug.Printf("Closing consumer %s", reflect.TypeOf(cons).String())
			cons.Control() <- core.PluginControlStopConsumer
		}
		core.StreamRegistry.ActivateAllFuses()
		Log.Debug.Print("Waiting for consumers to close")
		plex.consumerWorker.Wait()
	}

	// Make sure remaining warning / errors are written to stderr
	Log.Note.Print("It's the only way. Go in, or go back. (flushing)")
	logFallback.Stop()
	Log.SetWriter(os.Stdout)

	// Shutdown producers
	plex.state = multiplexerStateStopProducers
	if stateAtShutdown >= multiplexerStateStartProducers {
		for _, prod := range plex.producers {
			Log.Debug.Printf("Closing producer %s", reflect.TypeOf(prod).String())
			prod.Control() <- core.PluginControlStopProducer
		}
		Log.Debug.Print("Waiting for producers to close")
		plex.producerWorker.Wait()
	}

	plex.state = multiplexerStateStopped
}
예제 #2
0
// Shutdown all consumers and producers in a clean way.
// The internal log is flushed after the consumers have been shut down so that
// consumer related messages are still in the log.
// Producers are flushed after flushing the log, so producer related shutdown
// messages will be posted to stdout
func (plex *multiplexer) shutdown() {
	// Handle panics if any
	if r := recover(); r != nil {
		log.Println(r)
	}

	// Make Ctrl+C possible during shutdown sequence
	if plex.signal != nil {
		signal.Stop(plex.signal)
	}

	Log.Note.Print("Filthy little hobbites. They stole it from us. (shutdown)")
	stateAtShutdown := plex.state

	// Shutdown consumers
	plex.state = multiplexerStateStopConsumers
	if stateAtShutdown >= multiplexerStateStartConsumers {
		for _, consumer := range plex.consumers {
			consumer.Control() <- core.PluginControlStop
		}

		plex.consumerWorker.Wait()
	}

	// Make sure remaining warning / errors are written to stderr
	Log.SetWriter(os.Stdout)
	Log.Note.Print("It's the only way. Go in, or go back. (flushing)")

	// Shutdown producers
	plex.state = multiplexerStateStopProducers
	if stateAtShutdown >= multiplexerStateStartProducers {
		for _, producer := range plex.producers {
			producer.Control() <- core.PluginControlStop
		}
		plex.producerWorker.Wait()
	}

	plex.state = multiplexerStateStopped
}