AS AgentScopeAPI 手册 / API Reference

PortManager

public class PortManager
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:33–207

Port 管理器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.sandbox.manager.utils 包。核心成员包括 allocatePort、allocatePorts、registerContainerPorts、releasePort、releaseContainerPorts、releasePorts。

Thread-safe port allocation manager Manages port allocation and release to avoid port conflicts

构造器摘要Constructor Summary

构造器Constructor说明Description
public PortManager(PortRange portRange)
初始化 `PortManager` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public synchronized int allocatePort()
synchronized
返回 `allocatePort` 结果。
Allocate a free port Thread-safe operation that guarantees no port conflicts
public synchronized int[] allocatePorts(int count)
synchronized
设置该参数。
Allocate multiple ports
public void registerContainerPorts(String containerName, int... ports)
注册 `registerContainerPorts`。
Register ports for a container This allows tracking which ports belong to which container
public synchronized void releasePort(int port)
synchronized
设置该参数。
Release a specific port
public synchronized void releaseContainerPorts(String containerName)
synchronized
设置该参数。
Release all ports for a container
public synchronized void releasePorts(int... ports)
synchronized
设置该参数。
Release multiple ports
public int getAllocatedPortCount()
获取 `getAllocatedPortCount`。
Get the number of allocated ports
public int getAvailablePortCount()
获取 `getAvailablePortCount`。
Get the number of available ports
public synchronized void clear()
synchronized
清空或重置内部状态。
Clear all allocated ports (for cleanup)

构造器详情Constructor Detail

PortManager

public PortManager(PortRange portRange)

初始化 PortManager 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
portRangePortRangeport Range(类型 `PortRange`)。The port range.
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:42–45

方法详情Method Detail

allocatePort

public synchronized int allocatePort()
synchronized

返回 allocatePort 结果。

Allocate a free port Thread-safe operation that guarantees no port conflicts

返回Returns int
返回数值结果。An available port number, or -1 if no port is available
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:53–71

allocatePorts

public synchronized int[] allocatePorts(int count)
synchronized

设置该参数。

Allocate multiple ports

参数Parameters
名称Name类型Type说明Description
countint数量(类型 `int`)。Number of ports to allocate
返回Returns int[]
返回int[]。Array of allocated ports, or null if not enough ports available
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:79–102

registerContainerPorts

public void registerContainerPorts(String containerName, int... ports)

注册 registerContainerPorts。

Register ports for a container This allows tracking which ports belong to which container

参数Parameters
名称Name类型Type说明Description
containerNameString容器名称。The container name
ports varargsint...ports(类型 `int...`)。The ports to register
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:111–120

releasePort

public synchronized void releasePort(int port)
synchronized

设置该参数。

Release a specific port

参数Parameters
名称Name类型Type说明Description
portintport(类型 `int`)。The port to release
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:127–131

releaseContainerPorts

public synchronized void releaseContainerPorts(String containerName)
synchronized

设置该参数。

Release all ports for a container

参数Parameters
名称Name类型Type说明Description
containerNameString容器名称。The container name
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:138–146

releasePorts

public synchronized void releasePorts(int... ports)
synchronized

设置该参数。

Release multiple ports

参数Parameters
名称Name类型Type说明Description
ports varargsint...ports(类型 `int...`)。The ports to release
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:153–157

getAllocatedPortCount

public int getAllocatedPortCount()

获取 getAllocatedPortCount。

Get the number of allocated ports

返回Returns int
返回数值结果。The count of allocated ports
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:185–187

getAvailablePortCount

public int getAvailablePortCount()

获取 getAvailablePortCount。

Get the number of available ports

返回Returns int
返回数值结果。The count of available ports
源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:194–197

clear

public synchronized void clear()
synchronized

清空或重置内部状态。

Clear all allocated ports (for cleanup)

源码Source io/agentscope/runtime/sandbox/manager/utils/PortManager.java:202–206
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.