PortManager
public class PortManager
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:33–207Port 管理器,承载智能体的部署、调度与服务化运行。位于 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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
portRange | PortRange | port Range(类型 `PortRange`)。The port range. |
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:42–45方法详情Method Detail
allocatePort
public synchronized int allocatePort()
返回 allocatePort 结果。
Allocate a free port Thread-safe operation that guarantees no port conflicts
intio/agentscope/runtime/sandbox/manager/utils/PortManager.java:53–71allocatePorts
public synchronized int[] allocatePorts(int count)
设置该参数。
Allocate multiple ports
| 名称Name | 类型Type | 说明Description |
|---|---|---|
count | int | 数量(类型 `int`)。Number of ports to allocate |
int[]io/agentscope/runtime/sandbox/manager/utils/PortManager.java:79–102registerContainerPorts
public void registerContainerPorts(String containerName, int... ports)
注册 registerContainerPorts。
Register ports for a container This allows tracking which ports belong to which container
| 名称Name | 类型Type | 说明Description |
|---|---|---|
containerName | String | 容器名称。The container name |
ports varargs | int... | ports(类型 `int...`)。The ports to register |
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:111–120releasePort
public synchronized void releasePort(int port)
设置该参数。
Release a specific port
| 名称Name | 类型Type | 说明Description |
|---|---|---|
port | int | port(类型 `int`)。The port to release |
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:127–131releaseContainerPorts
public synchronized void releaseContainerPorts(String containerName)
设置该参数。
Release all ports for a container
| 名称Name | 类型Type | 说明Description |
|---|---|---|
containerName | String | 容器名称。The container name |
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:138–146releasePorts
public synchronized void releasePorts(int... ports)
设置该参数。
Release multiple ports
| 名称Name | 类型Type | 说明Description |
|---|---|---|
ports varargs | int... | ports(类型 `int...`)。The ports to release |
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:153–157getAllocatedPortCount
public int getAllocatedPortCount()
获取 getAllocatedPortCount。
Get the number of allocated ports
intio/agentscope/runtime/sandbox/manager/utils/PortManager.java:185–187getAvailablePortCount
public int getAvailablePortCount()
获取 getAvailablePortCount。
Get the number of available ports
intio/agentscope/runtime/sandbox/manager/utils/PortManager.java:194–197clear
public synchronized void clear()
清空或重置内部状态。
Clear all allocated ports (for cleanup)
io/agentscope/runtime/sandbox/manager/utils/PortManager.java:202–206