SandboxConnector
public class SandboxConnector
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:44–330沙箱 Connector,在隔离环境中安全执行代码和工具。位于 io.agentscope.extensions.sandbox.kubernetes.client.internal 包。核心成员包括 connect、close、isConnected、getStrategy、sendRequest、sendRequestForBytes。
Manages HTTP connectivity to the sandbox (via router or in-cluster), including URL discovery, retry logic, and header injection.
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void connect() throws Exception | 建立连接并完成初始化。 Discovers the base URL via the connection strategy. |
public void close() | 关闭连接并释放相关资源。 Tears down the transport. |
public boolean isConnected() | 判断是否已连接。 Returns whether the connected. |
public ConnectionStrategy getStrategy() | 获取 `getStrategy`。 Returns the strategy. |
public HttpResponse<String> sendRequest(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType, int maxRetries) throws IOException, InterruptedException | 发送请求。 Sends an HTTP request with retry logic and optional sandbox headers. |
public HttpResponse<byte[]> sendRequestForBytes(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType) throws IOException, InterruptedException | 发送请求用于字节。 Sends a request and returns the raw byte response (for file downloads). |
构造器详情Constructor Detail
SandboxConnector
public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier)
初始化 SandboxConnector 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sandboxId | String | 沙箱标识(类型 `String`)。The sandbox id. |
namespace | String | 命名空间(类型 `String`)。The namespace. |
connectionConfig | SandboxConnectionConfig | 连接配置(类型 `SandboxConnectionConfig`)。The connection config. |
k8sHelper | K8sHelper | k 8 s Helper(类型 `K8sHelper`)。The k 8 s helper. |
podIpSupplier | Supplier<String> | pod Ip Supplier(类型 `Supplier`)。The pod ip supplier. |
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:64–71SandboxConnector
public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier, Duration requestTimeout, Duration perAttemptTimeout)
初始化 SandboxConnector 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sandboxId | String | 沙箱标识(类型 `String`)。The sandbox id. |
namespace | String | 命名空间(类型 `String`)。The namespace. |
connectionConfig | SandboxConnectionConfig | 连接配置(类型 `SandboxConnectionConfig`)。The connection config. |
k8sHelper | K8sHelper | k 8 s Helper(类型 `K8sHelper`)。The k 8 s helper. |
podIpSupplier | Supplier<String> | pod Ip Supplier(类型 `Supplier`)。The pod ip supplier. |
requestTimeout | Duration | 请求超时(类型 `Duration`)。The request timeout. |
perAttemptTimeout | Duration | 每个尝试超时(类型 `Duration`)。The per attempt timeout. |
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:73–97方法详情Method Detail
connect
public void connect() throws Exception
建立连接并完成初始化。
Discovers the base URL via the connection strategy.
Exception可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:150–155close
public void close()
关闭连接并释放相关资源。
Tears down the transport.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:158–165isConnected
public boolean isConnected()
判断是否已连接。
Returns whether the connected.
boolean返回布尔值,表示判断结果。Returns a boolean result.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:167–169getStrategy
public ConnectionStrategy getStrategy()
获取 getStrategy。
Returns the strategy.
ConnectionStrategy返回ConnectionStrategy。Returns connection strategy.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:171–173sendRequest
public HttpResponse<String> sendRequest(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType, int maxRetries) throws IOException, InterruptedException
发送请求。
Sends an HTTP request with retry logic and optional sandbox headers.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
method | String | 方法(类型 `String`)。HTTP method |
endpoint | String | 端点地址(类型 `String`)。path relative to base URL |
body | HttpRequest.BodyPublisher | 正文(类型 `HttpRequest.BodyPublisher`)。request body, or null for GET |
contentType | String | 内容类型(类型 `String`)。content type header |
maxRetries | int | 最大重试(类型 `int`)。max attempts (0 = default) |
HttpResponse<String>返回HttpResponse。HTTP response
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.InterruptedException可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:185–239sendRequestForBytes
public HttpResponse<byte[]> sendRequestForBytes(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType) throws IOException, InterruptedException
发送请求用于字节。
Sends a request and returns the raw byte response (for file downloads).
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
method | String | 方法(类型 `String`)。HTTP method |
endpoint | String | 端点地址(类型 `String`)。path |
body | HttpRequest.BodyPublisher | 正文(类型 `HttpRequest.BodyPublisher`)。body or null |
contentType | String | 内容类型(类型 `String`)。content type |
HttpResponse<byte[]>返回HttpResponse。byte response
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.InterruptedException可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source
io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:250–261