Class ChannelManager

java.lang.Object
io.agentscope.harness.agent.gateway.ChannelManager

public final class ChannelManager extends Object
Registry and lifecycle manager for Channel adapters. Provides outbound dispatch so the gateway can deliver proactive messages (e.g. subagent announces) through the correct channel.

Lifecycle

  1. register(Channel) — add a channel to the registry
  2. initAll(Gateway) — inject the gateway into all registered channels
  3. startAll() — start all channels (connect to external transports)
  4. stopAll() — stop all channels and release resources

Outbound delivery

deliver(OutboundAddress, List) looks up the target channel by OutboundAddress.channelId() and delegates to Channel.deliver(OutboundAddress, List).
  • Constructor Details

    • ChannelManager

      public ChannelManager()
  • Method Details

    • register

      public void register(Channel channel)
      Registers a channel adapter. If a channel with the same Channel.channelId() is already registered, it is replaced.
    • unregister

      public boolean unregister(String channelId)
      Stops and removes the channel registered under channelId, if any. Returns true when a channel was removed, false when no channel was registered under that id.
    • getChannel

      public Optional<Channel> getChannel(String channelId)
      Returns the channel registered under the given id, if any.
    • channelIds

      public List<String> channelIds()
      Returns an unmodifiable snapshot of all registered channel ids.
    • getAllChannels

      public Collection<Channel> getAllChannels()
      Returns an unmodifiable snapshot of all registered channels.
    • initAll

      public void initAll(Gateway gateway)
      Injects the gateway into all registered channels via Channel.init(Gateway). Called once during bootstrap before startAll().
    • startAll

      public void startAll()
      Starts all registered channels. Channels that fail to start are logged but do not abort.
    • stopAll

      public void stopAll()
      Stops all registered channels and clears the registry.
    • isStarted

      public boolean isStarted()
      Whether startAll() has been called.
    • deliver

      public void deliver(OutboundAddress address, List<io.agentscope.core.message.Msg> messages)
      Delivers proactive outbound messages through the channel identified by OutboundAddress.channelId(). If the target channel is not registered, the messages are dropped with a warning log.
      Parameters:
      address - the delivery target
      messages - the messages to deliver