func (sinkManager *SinkManager) RegisterSink(sink sinks.Sink) bool {
	ok := sinkManager.sinks.Register(sink)
	if !ok {
		return false
	}

	sinkManager.Metrics.Inc(sink)

	sinkManager.logger.Infof("SinkManager: Sink with channel %v requested. Opened it.", sink.Channel())
	return true
}
func (sinkManager *SinkManager) UnregisterSink(sink sinks.Sink) {
	sinkManager.sinks.Delete(sink)
	close(sink.Channel())

	sinkManager.Metrics.Dec(sink)

	if syslogSink, ok := sink.(*sinks.SyslogSink); ok {
		syslogSink.Disconnect()
	}

	sinkManager.logger.Infof("SinkManager: Sink with channel %v and identifier %s requested closing. Closed it.", sink.Channel(), sink.Identifier())
}
Beispiel #3
0
func (sinkManager *SinkManager) UnregisterSink(sink sinks.Sink) {

	ok := sinkManager.sinks.CloseAndDelete(sink)
	if !ok {
		return
	}
	sinkManager.Metrics.Dec(sink)

	if syslogSink, ok := sink.(*syslog.SyslogSink); ok {
		syslogSink.Disconnect()
	} else if _, ok := sink.(*dump.DumpSink); ok {
		sinkManager.appStoreUpdateChan <- domain.AppServices{AppId: sink.AppId()}
	}

	sinkManager.logger.Debugf("SinkManager: Sink with identifier %s requested closing. Closed it.", sink.Identifier())
}
func (messageRouter *messageRouter) unregisterSink(s sinks.Sink, activeSinks *groupedsinks.GroupedSinks) {
	messageRouter.Lock()
	defer messageRouter.Unlock()

	activeSinks.Delete(s)
	close(s.Channel())
	switch s.(type) {
	case *sinks.DumpSink:
		messageRouter.activeDumpSinksCounter--
	case *sinks.SyslogSink:
		messageRouter.activeSyslogSinksCounter--
	case *sinks.WebsocketSink:
		messageRouter.activeWebsocketSinksCounter--
	}
	messageRouter.logger.Infof("MessageRouter: Sink with channel %v requested closing. Closed it.", s.Channel())
}
Beispiel #5
0
func (sinkManager *SinkManager) RegisterSink(sink sinks.Sink) bool {
	inputChan := make(chan *logmessage.Message)
	ok := sinkManager.sinks.Register(inputChan, sink)
	if !ok {
		return false
	}

	sinkManager.Metrics.Inc(sink)

	sinkManager.logger.Debugf("SinkManager: Sink with identifier %v requested. Opened it.", sink.Identifier())

	go func() {
		sink.Run(inputChan)
		sinkManager.UnregisterSink(sink)
	}()

	return true
}
Beispiel #6
0
func (gc *GroupedSinks) Delete(sink sinks.Sink) bool {
	gc.Lock()
	defer gc.Unlock()
	wrapper, ok := gc.apps[sink.AppId()][sink.Identifier()]
	if ok {
		close(wrapper.inputChan)
		delete(gc.apps[sink.AppId()], sink.Identifier())
		return true
	}
	return false
}
Beispiel #7
0
func (sinkManager *SinkManager) RegisterSink(sink sinks.Sink, block ...bool) bool {
	inputChan := make(chan *logmessage.Message)
	ok := sinkManager.sinks.Register(inputChan, sink)
	if !ok {
		return false
	}

	sinkManager.Metrics.Inc(sink)

	sinkManager.logger.Infof("SinkManager: Sink with identifier %v requested. Opened it.", sink.Identifier())
	if len(block) > 0 {
		sink.Run(inputChan)
		sinkManager.unregisterSink(sink)
	} else {
		go func() {
			sink.Run(inputChan)
			sinkManager.unregisterSink(sink)
		}()
	}
	return true
}
Beispiel #8
0
func (gc *GroupedSinks) Register(s sinks.Sink) bool {
	gc.Lock()
	defer gc.Unlock()

	appId := s.AppId()
	if appId == "" || s.Identifier() == "" {
		return false
	}
	if gc.apps[appId] == nil {
		gc.apps[appId] = make(map[string]sinks.Sink)
	}

	if gc.apps[appId][s.Identifier()] != nil {
		return false
	}
	gc.apps[appId][s.Identifier()] = s
	return true
}
func (messageRouter *messageRouter) dumpToSink(sink sinks.Sink, activeSinks *groupedsinks.GroupedSinks) {
	dumpChan := make(chan *logmessage.Message, 20)
	if sink := activeSinks.DumpFor(sink.AppId()); sink != nil {
		sink.Dump(dumpChan)
	} else {
		close(dumpChan)
	}
	for message := range dumpChan {
		sink.Channel() <- message
	}
}
Beispiel #10
0
func (gc *GroupedSinks) Register(in chan<- *logmessage.Message, s sinks.Sink) bool {
	gc.Lock()
	defer gc.Unlock()

	appId := s.AppId()
	if appId == "" || s.Identifier() == "" {
		return false
	}
	sinksForApp := gc.apps[appId]
	if sinksForApp == nil {
		gc.apps[appId] = make(map[string]*sinkWrapper)
		sinksForApp = gc.apps[appId]
	}

	if _, ok := sinksForApp[s.Identifier()]; ok {
		return false
	}
	sinksForApp[s.Identifier()] = &sinkWrapper{inputChan: in, s: s}
	return true
}
Beispiel #11
0
func (gc *GroupedSinks) Delete(sink sinks.Sink) {
	gc.Lock()
	defer gc.Unlock()

	delete(gc.apps[sink.AppId()], sink.Identifier())
}
	w.disconnected = !newValue
}

func (r *SyslogWriterRecorder) Close() error {
	return nil
}

func (r *SyslogWriterRecorder) ReceivedMessages() []string {
	r.Lock()
	defer r.Unlock()

	return r.receivedMessages
}

var _ = Describe("SyslogSink", func() {
	var syslogSink sinks.Sink
	var sysLogger *SyslogWriterRecorder
	var sysLoggerDoneChan chan bool
	var errorChannel chan *logmessage.Message
	var mutex sync.Mutex

	closeSysLoggerDoneChan := func() {
		mutex.Lock()
		defer mutex.Unlock()
		close(sysLoggerDoneChan)
	}

	newSysLoggerDoneChan := func() {
		mutex.Lock()
		defer mutex.Unlock()
		sysLoggerDoneChan = make(chan bool)
Beispiel #13
0
func (messageRouter *messageRouter) registerSink(s sinks.Sink, activeSinks *groupedsinks.GroupedSinks) bool {
	messageRouter.Lock()
	defer messageRouter.Unlock()

	ok := activeSinks.Register(s)
	switch s.(type) {
	case *sinks.DumpSink:
		messageRouter.activeDumpSinksCounter++
	case *sinks.SyslogSink:
		messageRouter.activeSyslogSinksCounter++
	case *sinks.WebsocketSink:
		messageRouter.activeWebsocketSinksCounter++
		go messageRouter.dumpToSink(s, activeSinks)
	}
	messageRouter.logger.Infof("MessageRouter: Sink with channel %v requested. Opened it.", s.Channel())
	return ok
}