//
// General methods
//
// AddEventHandler registers a function that acts as an event handler for a specific msg type
432870
func (p Protos) AddEventHandler(msgType string, handler func(...interface{})) error {
	switch msgType {
	case EventNewMessage:
		eventHandlers[EventNewMessage] = handler
	case EventTimer:
		eventHandlers[EventTimer] = handler
	case EventTerminate:
		eventHandlers[EventTerminate] = handler
	default:
		return fmt.Errorf("Failed to add event handler. Message type %s is not supported", msgType)
	}
	return nil
}
328674
func (e *EventServer) processEvent(ctx context.Context, eventInfo *common.EventInfo) (err error) {

	if e.registerer == nil {
		return fmt.Errorf("No registered handlers")
	}

	f, err := e.registerer.GetHandler(eventInfo.PUType, eventInfo.EventType)
	if err != nil {
		return fmt.Errorf("Handler not found: %s", err)
	}

	return f(ctx, eventInfo)
}
636767
@Override
	public void addEventHandler(EventHandler eventHandler) {
		Preconditions.checkNotNull(eventHandler.getName(), "Missing Name");
		if(getEventHandler(eventHandler.getName()) != null) {
			throw new ApplicationException(Code.CONFLICT, "EventHandler with name " + eventHandler.getName() + " already exists!");
		}
		index(eventHandler);
		dynoClient.hset(nsKey(EVENT_HANDLERS), eventHandler.getName(), toJson(eventHandler));
		recordRedisDaoRequests("addEventHandler");
	}
1120519
func (c *Collector) handleEvent(event events.Event) {
	switch event.(type) {
	case api.EventNode:
		c.handleNodeEvent(event)
	case api.EventTask:
		c.handleTaskEvent(event)
	case api.EventService:
		c.handleServiceEvent(event)
	case api.EventNetwork:
		c.handleNetworkEvent(event)
	case api.EventSecret:
		c.handleSecretsEvent(event)
	case api.EventConfig:
		c.handleConfigsEvent(event)
	}
}
1313359
func (c *Container) addHandler(service *WebService, serveMux *http.ServeMux) bool {
	pattern := fixedPrefixPath(service.RootPath())
	// check if root path registration is needed
	if "/" == pattern || "" == pattern {
		serveMux.HandleFunc("/", c.dispatch)
		return true
	}
	// detect if registration already exists
	alreadyMapped := false
	for _, each := range c.webServices {
		if each.RootPath() == service.RootPath() {
			alreadyMapped = true
			break
		}
	}
	if !alreadyMapped {
		serveMux.HandleFunc(pattern, c.dispatch)
		if !strings.HasSuffix(pattern, "/") {
			serveMux.HandleFunc(pattern+"/", c.dispatch)
		}
	}
	return false
}
1102355
func AddHandler(h Handler, levels ...Level) {
	rw.Lock()
	for _, level := range levels {
		handler := append(logHandlers[level], h)
		logHandlers[level] = handler
	}
	rw.Unlock()
}
422717
func (rtm *Client) AddEventListener(event Event, handler EventListener) {
	rtm.EventListeners[event] = append(rtm.EventListeners[event], handler)
}
196939
func (h *Handler) HandleEvent(e *events.Event) {
	buf := bufferPool.Get().(*buffer)
	buf.b = buf.b[:0]
	buf.b = append(buf.b, h.Prefix...)

	if fmt := h.TimeFormat; len(fmt) != 0 {
		loc := h.TimeLocation
		if loc == nil {
			loc = time.Local
		}
		buf.b = e.Time.In(loc).AppendFormat(buf.b, fmt)
		buf.b = append(buf.b, " - "...)
	}

	if len(e.Source) != 0 {
		buf.b = append(buf.b, e.Source...)
		buf.b = append(buf.b, " - "...)
	}

	buf.b = append(buf.b, e.Message...)
	buf.b = append(buf.b, '\n')

	if h.EnableArgs {
		hasError := false

		for _, a := range e.Args {
			if _, ok := a.Value.(error); ok {
				hasError = true
			} else {
				buf.b = append(buf.b, '\t')
				buf.b = append(buf.b, a.Name...)
				buf.b = append(buf.b, ':', ' ')
				fmt.Fprintf(buf, "%v\n", a.Value)
			}
		}

		if hasError {
			fmt.Fprint(buf, "\terrors:\n")

			for _, a := range e.Args {
				if err, ok := a.Value.(error); ok {
					fmt.Fprintf(buf, "\t\t- %+v\n", err)
				}
			}
		}
	}

	h.mutex.Lock()
	h.Output.Write(buf.b)
	h.mutex.Unlock()
	bufferPool.Put(buf)
}
1042208
func (m *Mux) AddHandler(meth, pat string, h http.Handler) error {
	m.mu.Lock()
	defer m.mu.Unlock()
	for _, ph := range m.added[meth] {
		if ph.pat == pat {
			return errors.AlreadyExistsf("handler for %s %q", meth, pat)
		}
	}
	m.added[meth] = append(m.added[meth], patternHandler{pat, h})
	m.recreate()
	return nil
}
1083966
func (client *BaseClient) AddInvokeHandler(handler ...InvokeHandler) Client {
	client.handlerManager.AddInvokeHandler(handler...)
	return client
}
1258514
func (s *Service) RegisterHandler(name string, handler Handler) {
	s.handlers[name] = handler
}
196136
func (hs Handlers) HandleEvent(ctx context.Context, e *executor.Event) (err error) {
	if h := hs[e.GetType()]; h != nil {
		return h.HandleEvent(ctx, e)
	}
	return nil
}
831803
func (c *ClusterManager) AddEventListener(listener cluster.ClusterListener) error {
	logrus.Printf("Adding cluster event listener: %s", listener.String())
	c.listeners.PushBack(listener)
	return nil
}
1181785
func (s *Application) AddEvent(eventName string, handler interface{}) *Application {
	if h, ok := handler.(func(func(bool), ...interface{})); ok {
		events.AddEvent(eventName, h)
		return s
	}
	if h, ok := handler.(func(...interface{}) bool); ok {
		events.AddEvent(eventName, func(next func(bool), sessions ...interface{}) {
			next(h(sessions...))
		})
		return s
	}
	s.Core.Logger().Warnf(`Invalid event function: %T`, handler)
	return s
}
748396
func NewHandler(fun func(eventtypes.Message) string) *Handler {
	return &Handler{
		keyFunc:  fun,
		handlers: make(map[string]func(eventtypes.Message)),
	}
}
796138
func (d *dispatcher) addListener(targetID, eventName string, l Listener) {
	d.m.Lock()
	defer d.m.Unlock()
	if _, ok := d.l[targetID]; !ok {
		d.l[targetID] = make(map[string]map[int]Listener)
	}
	if _, ok := d.l[targetID][eventName]; !ok {
		d.l[targetID][eventName] = make(map[int]Listener)
	}
	d.id++
	d.l[targetID][eventName][d.id] = l
}
966583
func (c *Client) AddEventListener(listener chan<- *APIEvents) error {
	var err error
	if !c.eventMonitor.isEnabled() {
		err = c.eventMonitor.enableEventMonitoring(c)
		if err != nil {
			return err
		}
	}
	return c.eventMonitor.addListener(listener)
}