func (group *GroupedSinks) CloseAndDelete(sink sinks.Sink) bool {
	group.Lock()
	defer group.Unlock()

	appId := sink.AppID()
	wrapper, ok := group.apps[appId][sink.Identifier()]
	if ok {
		close(wrapper.InputChan)
		delete(group.apps[appId], sink.Identifier())
		return true
	}
	return false
}
func (group *GroupedSinks) IsFirehoseRegistered(sink sinks.Sink) bool {
	group.RLock()
	defer group.RUnlock()
	subscriptionId := sink.AppID()
	if subscriptionId == "" {
		return false
	}

	fgroup := group.firehoses[subscriptionId]
	if fgroup == nil {
		return false
	}

	return fgroup.Exists(sink)
}
func (group *GroupedSinks) RegisterFirehoseSink(in chan<- *events.Envelope, sink sinks.Sink) bool {
	group.Lock()
	defer group.Unlock()

	subscriptionId := sink.AppID()
	if subscriptionId == "" {
		return false
	}

	fgroup := group.firehoses[subscriptionId]
	if fgroup == nil {
		group.firehoses[subscriptionId] = firehose_group.NewFirehoseGroup()
		fgroup = group.firehoses[subscriptionId]
	}

	return fgroup.AddSink(sink, in)
}
func (group *GroupedSinks) RegisterAppSink(in chan<- *events.Envelope, sink sinks.Sink) bool {
	group.Lock()
	defer group.Unlock()

	appId := sink.AppID()
	if appId == "" || sink.Identifier() == "" {
		return false
	}
	sinksForApp := group.apps[appId]
	if sinksForApp == nil {
		group.apps[appId] = make(map[string]*sink_wrapper.SinkWrapper)
		sinksForApp = group.apps[appId]
	}

	if _, ok := sinksForApp[sink.Identifier()]; ok {
		return false
	}
	sinksForApp[sink.Identifier()] = &sink_wrapper.SinkWrapper{InputChan: in, Sink: sink}
	return true
}
func (group *GroupedSinks) CloseAndDeleteFirehose(sink sinks.Sink) bool {
	group.Lock()
	defer group.Unlock()
	firehoseSubscriptionId := sink.AppID()
	fgroup, ok := group.firehoses[firehoseSubscriptionId]
	if !ok {
		return false
	}

	removed := fgroup.RemoveSink(sink)

	if removed == false {
		return false
	}

	if fgroup.IsEmpty() == true {
		delete(group.firehoses, firehoseSubscriptionId)
	}

	return true
}