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

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

## 1. Role

### Example.getURIs()

This method acts as a lightweight HTTP fan-out executor for a collection of URI targets. Its business role is to take a list of endpoint addresses, convert each one into an immutable `HttpRequest`, and dispatch all requests concurrently using the Java 11 `HttpClient` asynchronous API. The method does not interpret the response payloads or perform domain-specific validation; instead, it serves as a transport-oriented orchestration step that demonstrates bulk outbound call execution.

From a system-design perspective, it implements a simple pipeline pattern: input normalization, request construction, concurrent dispatch, and synchronization. It is useful as a shared utility for scenarios where a caller needs to trigger many HTTP requests and wait until every call has completed before continuing. Because it uses `CompletableFuture.allOf(...).join()`, the method behaves like a barrier synchronization point for all outbound network operations.

The method has only one logical processing path and no business branching. Every URI in the input list is treated uniformly, which makes the method deterministic and suitable for general-purpose HTTP integration examples, batch connectivity checks, or demonstration code for the Java 11 HTTP client.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getURIs(uris)"])
    CREATE_CLIENT["Create HttpClient with newHttpClient()"]
    STREAM_URIS["Stream input URIs"]
    MAP_BUILDER["Map each URI to HttpRequest.newBuilder()"]
    BUILD_REQUEST["Build HttpRequest objects"]
    COLLECT_LIST["Collect requests into a list"]
    STREAM_REQUESTS["Stream request list"]
    SEND_ASYNC["Send each request asynchronously with sendAsync()"]
    TO_ARRAY["Convert futures to CompletableFuture[]"]
    ALL_OF["Wait for all futures with CompletableFuture.allOf()"]
    JOIN["Block until all asynchronous requests complete"]
    END_NODE(["Return void"])

    START --> CREATE_CLIENT
    CREATE_CLIENT --> STREAM_URIS
    STREAM_URIS --> MAP_BUILDER
    MAP_BUILDER --> BUILD_REQUEST
    BUILD_REQUEST --> COLLECT_LIST
    COLLECT_LIST --> STREAM_REQUESTS
    STREAM_REQUESTS --> SEND_ASYNC
    SEND_ASYNC --> TO_ARRAY
    TO_ARRAY --> ALL_OF
    ALL_OF --> JOIN
    JOIN --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `uris` | `List<URI>` | Collection of outbound HTTP target addresses to be invoked in parallel. Each URI represents one remote endpoint that will be converted into an `HttpRequest` and executed asynchronously. The list may contain one or many targets; every entry is processed uniformly and contributes one future to the completion barrier. |

External state read by the method:
- The Java runtime HTTP client factory `HttpClient.newHttpClient()`.
- The standard stream and future APIs used to create and synchronize asynchronous requests.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `HttpClient.newHttpClient` | N/A | N/A | Creates a reusable HTTP client instance for outbound communication. |
| C | `HttpRequest.newBuilder` | N/A | N/A | Builds a new outbound request definition for each URI in the input list. |
| R | `HttpRequest.Builder.build` | N/A | N/A | Finalizes the request object from the builder state. |
| R | `HttpClient.sendAsync` | N/A | N/A | Issues each HTTP request asynchronously and returns a future representing the remote call. |
| R | `CompletableFuture.allOf` | N/A | N/A | Aggregates multiple asynchronous call results into a single completion barrier. |
| R | `CompletableFuture.join` | N/A | N/A | Waits for all outbound calls to complete before the method exits. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `Example` (self-contained example entry point) | `Example.getURIs` | `HttpClient.sendAsync [R] N/A` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] (L175-L185)

> Create the HTTP client and prepare outbound request execution for the supplied URI list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newHttpClient();` |
| 2 | EXEC | `uris.stream();` |
| 3 | EXEC | `.map(HttpRequest::newBuilder)` |
| 4 | CALL | `.map(HttpRequest.Builder::build)` |
| 5 | EXEC | `.collect(toList());` |
| 6 | EXEC | `requests.stream();` |
| 7 | CALL | `.map(request -> client.sendAsync(request, HttpResponse.BodyHandlers.ofString()))` |
| 8 | EXEC | `.toArray(CompletableFuture<?>[]::new);` |
| 9 | CALL | `CompletableFuture.allOf(...)` |
| 10 | CALL | `.join();` |
| 11 | RETURN | `return;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `uris` | Field | Input collection of remote HTTP target locations to be contacted. |
| `URI` | Technical type | Uniform Resource Identifier — the standard address format for a remote endpoint. |
| `HttpClient` | Technical type | Java 11 HTTP client used to send outbound network requests. |
| `HttpRequest` | Technical type | Immutable HTTP request definition sent to a remote endpoint. |
| `HttpRequest.Builder` | Technical type | Builder used to assemble a request before dispatch. |
| `sendAsync` | Technical operation | Asynchronous outbound call that returns a future immediately. |
| `CompletableFuture` | Technical type | Asynchronous computation handle used to coordinate completion of multiple calls. |
| `allOf` | Technical operation | Aggregation method that completes when all supplied futures complete. |
| `join` | Technical operation | Blocking wait that prevents method exit until all futures are done. |
| `BodyHandlers.ofString()` | Technical operation | Response body conversion strategy that reads the response as text. |
| fan-out | Business term | Sending one input workload to many remote endpoints in parallel. |
| barrier synchronization | Technical term | Coordination point that waits for every asynchronous task to finish before continuing. |
