예제 #1
0
// 获取 msgType 对应的 MessageHandler, 如果没有找到返回 nil.
func (mux *SuiteMessageServeMux) getMessageHandler(msgType string) (handler MessageHandler) {
	if msgType == "" {
		return nil
	}

	mux.rwmutex.RLock()
	handler = mux.messageHandlerMap[util.ToLower(msgType)]
	if handler == nil {
		handler = mux.defaultMessageHandler
	}
	mux.rwmutex.RUnlock()
	return
}
예제 #2
0
// 获取 eventType 对应的 MessageHandler, 如果没有找到返回 nil.
func (mux *MessageServeMux) getEventHandler(eventType string) (handler MessageHandler) {
	if eventType == "" {
		return nil
	}

	mux.rwmutex.RLock()
	handler = mux.eventHandlerMap[util.ToLower(eventType)]
	if handler == nil {
		handler = mux.defaultEventHandler
	}
	mux.rwmutex.RUnlock()
	return
}
예제 #3
0
// 注册特定类型事件的 MessageHandler.
func (mux *MessageServeMux) EventHandle(eventType string, handler MessageHandler) {
	if eventType == "" {
		panic("empty eventType")
	}
	if handler == nil {
		panic("nil MessageHandler")
	}

	mux.rwmutex.Lock()
	if mux.eventHandlerMap == nil {
		mux.eventHandlerMap = make(map[string]MessageHandler)
	}
	mux.eventHandlerMap[util.ToLower(eventType)] = handler
	mux.rwmutex.Unlock()
}
예제 #4
0
// 注册特定类型消息的 MessageHandler.
func (mux *SuiteMessageServeMux) MessageHandle(msgType string, handler MessageHandler) {
	if msgType == "" {
		panic("empty msgType")
	}
	if handler == nil {
		panic("nil MessageHandler")
	}

	mux.rwmutex.Lock()
	if mux.messageHandlerMap == nil {
		mux.messageHandlerMap = make(map[string]MessageHandler)
	}
	mux.messageHandlerMap[util.ToLower(msgType)] = handler
	mux.rwmutex.Unlock()
}