---

# Business Logic — Example.getURIs() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.http.Example` |
| Layer | Utility / Example (Common Component) |
| Module | `http` (Package: `io.github.biezhi.java11.http`) |

## 1. Role

### Example.getURIs()

This method performs **parallel HTTP requests** (並列請求 — *heiretsu seikyuu*, parallel requests) against a collection of URIs using the Java 11 `HttpClient` API. It serves as an **entry-point utility** demonstrating how to dispatch multiple asynchronous HTTP requests concurrently and wait for all of them to complete. The method implements a **fan-out / gather design pattern**: it transforms a list of `URI` objects into fully-built `HttpRequest` instances, dispatches each one asynchronously via `HttpClient.sendAsync()`, and uses `CompletableFuture.allOf()` to block until every in-flight request resolves. It does not route by service type, branch on domain logic, or transform business data — its sole responsibility is to parallelize I/O-bound HTTP calls for a given set of endpoints, making it a shared concurrency utility suitable for any domain that needs to hit multiple HTTP targets simultaneously.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getURIs(List&lt;URI&gt; uris)"])

    START --> S1["Create HttpClient client via HttpClient.newHttpClient()"]
    S1 --> S2["Stream uris -> map HttpRequest::newBuilder"]
    S2 --> S3["Map HttpRequest.Builder::build -> collect to List&lt;HttpRequest&gt;"]
    S3 --> S4["Stream requests -> map sendAsync(client, BodyHandlers.ofString)"]
    S4 --> S5["Convert Stream to CompletableFuture&lt;?&gt;[] array"]
    S5 --> S6["CompletableFuture.allOf(array) -> join()"]
    S6 --> END_NODE(["Return / Next"])

    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 --> S6
    S6 --> END_NODE
```

**Processing flow description:**

1. **Create HttpClient** — A new `HttpClient` instance is created via the static factory `HttpClient.newHttpClient()`. This provides a default-configured client (no proxy, no custom timeout, HTTP/1.1 or HTTP/2 auto-negotiation).
2. **Build requests** — The input `uris` list is streamed. Each `URI` is converted into an `HttpRequest.Builder` via `HttpRequest::newBuilder`, then each builder is finalized into an `HttpRequest` via `HttpRequest.Builder::build`. The result is collected into a `List<HttpRequest>`.
3. **Dispatch async requests** — Each `HttpRequest` is sent asynchronously using `client.sendAsync(request, HttpResponse.BodyHandlers.ofString())`, which returns a `CompletableFuture<HttpResponse<String>>`. The comments are discarded; the futures are collected into an array.
4. **Wait for all to complete** — `CompletableFuture.allOf()` aggregates all futures into a single `CompletableFuture<Void>`, and `.join()` blocks the calling thread until every async request has either completed normally or completed exceptionally. If any request fails, a `CompletionException` is thrown.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `uris` | `List<URI>` | A list of Uniform Resource Identifiers representing the target HTTP endpoints to be hit in parallel. Each URI specifies a protocol (HTTP/HTTPS), host, port, and optional path/query. The method treats all URIs equally — no filtering, prioritization, or type-based routing is applied. |

**External state read:**

| No | Field | Type | Business Description |
|----|-------|------|---------------------|
| 1 | `client` (local variable) | `HttpClient` | A newly instantiated, default-configured HTTP client used to dispatch all requests. Not shared with other threads; created fresh per call. |

## 4. CRUD Operations / Called Services

This method performs I/O operations (HTTP client calls) rather than traditional database CRUD. No SC Codes, CBS codes, or database tables are involved.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| I/O (Read) | `client.sendAsync()` | N/A | N/A (HTTP endpoints) | Sends each `HttpRequest` asynchronously and reads the response body as a `String`. No data is retained — responses are discarded. |

**How to classify:**
- The method does not interact with any database, SC, or CBS layer.
- Each call to `sendAsync()` is an **HTTP GET-equivalent read** (the builder defaults to the `GET` method unless overridden at the URI/HttpRequest level).
- This is **I/O-bound read** against external HTTP services, not a traditional database read.

## 5. Dependency Trace

No external callers were found for this method. It is a self-contained example/utility method within the `Example` class.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | *(none found)* | — | — |

This method appears to be a **demonstration/example** method in a Java 11 HTTP client showcase repository (biezhi/java11-http) and is not called by any production screen, batch, or service component. It is not referenced in the `main()` method or any other method within the `Example` class.

## 6. Per-Branch Detail Blocks

This method has **no conditional branches** (no if/else, no switch, no loops outside of stream operations). The control flow is linear with two stream pipelines.

**Block 1** — [PROCEDURE] `(HttpClient creation)` (L176)

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newHttpClient();` // Create a default HTTP client instance |

**Block 2** — [PROCEDURE] `(Build requests from URIs)` (L177–180)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `uris.stream()` // Start streaming the input URI list |
| 2 | EXEC | `.map(HttpRequest::newBuilder)` // Convert each URI to an HttpRequest.Builder |
| 3 | EXEC | `.map(HttpRequest.Builder::build)` // Finalize each builder into an HttpRequest |
| 4 | SET | `List<HttpRequest> requests = ... .collect(toList());` // Collect built requests into a list |

**Block 3** — [PROCEDURE] `(Dispatch async requests and wait)` (L182–185)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `requests.stream()` // Stream the built request list |
| 2 | EXEC | `.map(request -> client.sendAsync(request, HttpResponse.BodyHandlers.ofString()))` // Send each request asynchronously; discard HttpResponse futures |
| 3 | EXEC | `.toArray(CompletableFuture<?>[]::new)` // Convert stream to CompletableFuture array |
| 4 | EXEC | `CompletableFuture.allOf(...).join()` // Wait for all async requests to complete; throws CompletionException if any fails |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `HttpClient` | Class | Java 11 HTTP Client — the built-in HTTP/1.1 and HTTP/2 client library in `java.net.http` package |
| `HttpRequest` | Class | Represents an HTTP request with method, headers, and body. Built from a `URI` via `HttpRequest.newBuilder(uri)` |
| `HttpResponse.BodyHandlers.ofString()` | Class/Method | A response body handler that reads the full HTTP response body into a `String` |
| `sendAsync()` | Method | Asynchronous HTTP client method — sends a request and returns a `CompletableFuture<HttpResponse<T>>` immediately without blocking |
| `CompletableFuture.allOf()` | Method | Aggregates multiple `CompletableFuture` instances into a single future that completes when all input futures complete |
| `join()` | Method | Blocks the calling thread until the `CompletableFuture` completes; throws `CompletionException` if any contained future completed exceptionally |
| `URI` | Class | Uniform Resource Identifier — represents a resource location (e.g., `https://example.com/api/users`) |
| 並列請求 (Heiretsu Seikyuu) | Comment | "Parallel requests" — the Japanese comment describing this method's purpose: dispatching multiple HTTP calls concurrently |
| `toList()` | Method | `Collectors.toList()` — a Java Stream collector that gathers stream elements into a `List` |
