22
33import com .marketdata .consumer .shared .Console ;
44import com .marketdata .sdk .MarketDataClient ;
5- import com .marketdata .sdk .Response ;
5+ import com .marketdata .sdk .MarketDataResponse ;
6+ import com .marketdata .sdk .UtilitiesHeadersResponse ;
7+ import com .marketdata .sdk .UtilitiesStatusResponse ;
8+ import com .marketdata .sdk .UtilitiesUserResponse ;
9+ import java .util .Map ;
610import com .marketdata .sdk .utilities .ApiStatus ;
711import com .marketdata .sdk .utilities .RequestHeaders ;
812import com .marketdata .sdk .utilities .ServiceStatus ;
@@ -38,18 +42,18 @@ public static void main(String[] args) {
3842 Console .header ("/status/ (sync) — unversioned, no token required" );
3943 Console .run (
4044 () -> client .utilities ().status (),
41- r -> "data() has " + r .data (). services ().size () + " services; " + describe (r ));
45+ r -> "data() has " + r .values ().size () + " services; " + describe (r ));
4246
4347 Console .header ("/status/ (async) — same call via the async surface" );
4448 Console .run (
4549 () -> joinResponse (client .utilities ().statusAsync ()),
46- r -> "data() has " + r .data (). services ().size () + " services; " + describe (r ));
50+ r -> "data() has " + r .values ().size () + " services; " + describe (r ));
4751
4852 Console .header ("/user/ (sync) — needs a token" );
4953 Console .run (
5054 () -> client .utilities ().user (),
5155 r -> {
52- User u = r .data ();
56+ User u = r .values ();
5357 return "requestsRemaining="
5458 + u .requestsRemaining ()
5559 + ", requestsLimit="
@@ -64,10 +68,10 @@ public static void main(String[] args) {
6468 Console .run (
6569 () -> client .utilities ().headers (),
6670 r -> {
67- RequestHeaders rh = r .data ();
68- String auth = rh .headers (). getOrDefault ("authorization" , "(absent)" );
71+ Map < String , String > rh = r .values ();
72+ String auth = rh .getOrDefault ("authorization" , "(absent)" );
6973 return "headers="
70- + rh .headers (). size ()
74+ + rh .size ()
7175 + " entries (authorization echoed back: "
7276 + auth
7377 + "); "
@@ -76,9 +80,9 @@ public static void main(String[] args) {
7680
7781 Console .header ("Parallel async — fan out 3 calls, await all" );
7882 long t0 = System .nanoTime ();
79- CompletableFuture <Response < ApiStatus > > a = client .utilities ().statusAsync ();
80- CompletableFuture <Response < User > > b = client .utilities ().userAsync ();
81- CompletableFuture <Response < RequestHeaders > > c = client .utilities ().headersAsync ();
83+ CompletableFuture <UtilitiesStatusResponse > a = client .utilities ().statusAsync ();
84+ CompletableFuture <UtilitiesUserResponse > b = client .utilities ().userAsync ();
85+ CompletableFuture <UtilitiesHeadersResponse > c = client .utilities ().headersAsync ();
8286 // exceptionally() turns a failure into a null sentinel so allOf doesn't short-circuit on
8387 // the first failing call — we still want to see whether the others succeeded.
8488 CompletableFuture <Object > aSafe = a .thenApply (r -> (Object ) r ).exceptionally (t -> t );
@@ -91,11 +95,11 @@ public static void main(String[] args) {
9195 + elapsedMs
9296 + " ms (≈ slowest single call, not sum — proves true parallelism)" );
9397 describeResult ("status" , aSafe .join (), r -> {
94- List <ServiceStatus > services = ((Response < ApiStatus > ) r ).data (). services ();
98+ List <ServiceStatus > services = ((UtilitiesStatusResponse ) r ).values ();
9599 return services .size () + " services; first: " + services .get (0 ).service ();
96100 });
97- describeResult ("user" , bSafe .join (), r -> "remaining=" + ((Response < User > ) r ).data ().requestsRemaining ());
98- describeResult ("headers" , cSafe .join (), r -> ((Response < RequestHeaders > ) r ).data (). headers ().size () + " entries" );
101+ describeResult ("user" , bSafe .join (), r -> "remaining=" + ((UtilitiesUserResponse ) r ).values ().requestsRemaining ());
102+ describeResult ("headers" , cSafe .join (), r -> ((UtilitiesHeadersResponse ) r ).values ().size () + " entries" );
99103
100104 Console .header ("Final rate-limit snapshot" );
101105 Console .info ("rateLimits after the calls: " + client .getRateLimits ());
@@ -112,11 +116,11 @@ private static void describeResult(String label, Object resultOrThrowable, java.
112116 }
113117 }
114118
115- private static String describe (Response <?> r ) {
119+ private static String describe (MarketDataResponse <?> r ) {
116120 return "status=" + r .statusCode () + ", requestId=" + r .requestId () + ", url=" + r .requestUrl ();
117121 }
118122
119- private static <T > Response < T > joinResponse (CompletableFuture <Response < T > > f ) {
123+ private static <R > R joinResponse (CompletableFuture <R > f ) {
120124 // CompletableFuture.join wraps the cause in CompletionException, but the SDK's joinSync
121125 // contract is to surface MarketDataException directly. We mimic that here so the demo's
122126 // exception output matches what a sync caller would see.
0 commit comments