Class MessageHandlerRegistry

java.lang.Object
com.ultikits.ultitools.websocket.MessageHandlerRegistry

public class MessageHandlerRegistry extends Object
Registry for WebSocket message handlers. Manages registration and dispatch of message handlers.

WebSocket 消息处理器的注册表。 管理消息处理器的注册和分发。

Since:
6.2.0
Version:
1.0.0
Author:
wisdomme
  • Field Details

  • Constructor Details

    • MessageHandlerRegistry

      public MessageHandlerRegistry()
  • Method Details

    • register

      public void register(WebSocketMessageHandler handler)
      Registers a handler for its declared message type. 为其声明的消息类型注册处理器。
      Parameters:
      handler - the handler to register
    • registerGlobal

      public void registerGlobal(WebSocketMessageHandler handler)
      Registers a global handler that receives all messages. 注册接收所有消息的全局处理器。
      Parameters:
      handler - the global handler to register
    • unregister

      public void unregister(WebSocketMessageHandler handler)
      Unregisters a handler. 注销处理器。
      Parameters:
      handler - the handler to unregister
    • unregisterAll

      public void unregisterAll(String messageType)
      Unregisters all handlers for a message type. 注销某消息类型的所有处理器。
      Parameters:
      messageType - the message type to clear
    • clear

      public void clear()
      Clears all registered handlers. 清除所有已注册的处理器。
    • dispatch

      public boolean dispatch(com.google.gson.JsonObject message)
      Dispatches a message to the appropriate handlers. 将消息分发给适当的处理器。
      Parameters:
      message - the JSON message to dispatch
      Returns:
      true if at least one handler processed the message
    • dispatch

      public boolean dispatch(String jsonString)
      Dispatches a message from raw JSON string. 从原始 JSON 字符串分发消息。
      Parameters:
      jsonString - the JSON string to parse and dispatch
      Returns:
      true if at least one handler processed the message
    • hasHandler

      public boolean hasHandler(String messageType)
      Checks if a handler is registered for a message type. 检查是否为某消息类型注册了处理器。
      Parameters:
      messageType - the message type to check
      Returns:
      true if at least one handler is registered
    • getHandlerCount

      public int getHandlerCount(String messageType)
      Gets the number of handlers registered for a type. 获取某类型注册的处理器数量。
      Parameters:
      messageType - the message type
      Returns:
      the number of handlers
    • getRegisteredTypes

      public Set<String> getRegisteredTypes()
      Gets all registered message types. 获取所有已注册的消息类型。
      Returns:
      unmodifiable set of message types