@@ -124,13 +124,13 @@ public void transform(TypeTransformer transformer) {
124124 this .getClass ().getName () + "$RequestWithHostAndContextAndHandlerAdvice" );
125125 }
126126
127- public static class AdviceLocals {
127+ public static class AdviceScope {
128128 public final ClassicHttpRequest request ;
129129 public final Context parentContext ;
130130 public final Context context ;
131131 public final Scope scope ;
132132
133- private AdviceLocals (
133+ private AdviceScope (
134134 ClassicHttpRequest request , Context parentContext , Context context , Scope scope ) {
135135 this .request = request ;
136136 this .context = context ;
@@ -139,39 +139,44 @@ private AdviceLocals(
139139 }
140140
141141 @ Nullable
142- public static AdviceLocals start (ClassicHttpRequest request ) {
142+ public static AdviceScope start (ClassicHttpRequest request ) {
143143 Context parentContext = currentContext ();
144144
145145 if (!instrumenter ().shouldStart (parentContext , request )) {
146146 return null ;
147147 }
148148 Context context = instrumenter ().start (parentContext , request );
149- return new AdviceLocals (request , parentContext , context , context .makeCurrent ());
149+ return new AdviceScope (request , parentContext , context , context .makeCurrent ());
150150 }
151151
152152 public void end (Object result , Throwable throwable ) {
153153 scope .close ();
154154 ApacheHttpClientHelper .doMethodExit (context , request , result , throwable );
155155 }
156+
157+ public WrappingStatusSettingResponseHandler <?> wrapResponseHandler (
158+ HttpClientResponseHandler <?> handler ) {
159+ return new WrappingStatusSettingResponseHandler <>(context , parentContext , request , handler );
160+ }
156161 }
157162
158163 @ SuppressWarnings ("unused" )
159164 public static class RequestAdvice {
160165
161166 @ Nullable
162167 @ Advice .OnMethodEnter (suppress = Throwable .class )
163- public static AdviceLocals methodEnter (@ Advice .Argument (0 ) ClassicHttpRequest request ) {
164- return AdviceLocals .start (request );
168+ public static AdviceScope methodEnter (@ Advice .Argument (0 ) ClassicHttpRequest request ) {
169+ return AdviceScope .start (request );
165170 }
166171
167172 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
168173 public static void methodExit (
169174 @ Advice .Return Object result ,
170175 @ Advice .Thrown Throwable throwable ,
171- @ Advice .Enter @ Nullable AdviceLocals locals ) {
176+ @ Advice .Enter @ Nullable AdviceScope scope ) {
172177
173- if (locals != null ) {
174- locals .end (result , throwable );
178+ if (scope != null ) {
179+ scope .end (result , throwable );
175180 }
176181 }
177182 }
@@ -186,18 +191,16 @@ public static Object[] methodEnter(
186191 @ Advice .Argument (1 ) HttpClientResponseHandler <?> originalHandler ) {
187192
188193 HttpClientResponseHandler <?> handler = originalHandler ;
189- AdviceLocals locals = AdviceLocals .start (request );
190- if (locals == null ) {
194+ AdviceScope scope = AdviceScope .start (request );
195+ if (scope == null ) {
191196 return new Object [] {null , handler };
192197 }
193198
194199 // Wrap the handler so we capture the status code
195200 if (handler != null ) {
196- handler =
197- new WrappingStatusSettingResponseHandler <>(
198- locals .context , locals .parentContext , request , handler );
201+ handler = scope .wrapResponseHandler (handler );
199202 }
200- return new Object [] {locals , handler };
203+ return new Object [] {scope , handler };
201204 }
202205
203206 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
@@ -207,9 +210,9 @@ public static void methodExit(
207210 @ Advice .Thrown Throwable throwable ,
208211 @ Advice .Enter Object [] enterResult ) {
209212
210- AdviceLocals locals = (AdviceLocals ) enterResult [0 ];
211- if (locals != null ) {
212- locals .end (result , throwable );
213+ AdviceScope scope = (AdviceScope ) enterResult [0 ];
214+ if (scope != null ) {
215+ scope .end (result , throwable );
213216 }
214217 }
215218 }
@@ -224,18 +227,16 @@ public static Object[] methodEnter(
224227 @ Advice .Argument (2 ) HttpClientResponseHandler <?> originalHandler ) {
225228
226229 HttpClientResponseHandler <?> handler = originalHandler ;
227- AdviceLocals locals = AdviceLocals .start (request );
228- if (locals == null ) {
230+ AdviceScope scope = AdviceScope .start (request );
231+ if (scope == null ) {
229232 return new Object [] {null , handler };
230233 }
231234
232235 // Wrap the handler so we capture the status code
233236 if (handler != null ) {
234- handler =
235- new WrappingStatusSettingResponseHandler <>(
236- locals .context , locals .parentContext , request , handler );
237+ handler = scope .wrapResponseHandler (handler );
237238 }
238- return new Object [] {locals , handler };
239+ return new Object [] {scope , handler };
239240 }
240241
241242 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
@@ -245,9 +246,9 @@ public static void methodExit(
245246 @ Advice .Thrown Throwable throwable ,
246247 @ Advice .Enter Object [] enterResult ) {
247248
248- AdviceLocals locals = (AdviceLocals ) enterResult [0 ];
249- if (locals != null ) {
250- locals .end (result , throwable );
249+ AdviceScope scope = (AdviceScope ) enterResult [0 ];
250+ if (scope != null ) {
251+ scope .end (result , throwable );
251252 }
252253 }
253254 }
@@ -257,20 +258,20 @@ public static class RequestWithHostAdvice {
257258
258259 @ Nullable
259260 @ Advice .OnMethodEnter (suppress = Throwable .class )
260- public static AdviceLocals methodEnter (
261+ public static AdviceScope methodEnter (
261262 @ Advice .Argument (0 ) HttpHost host , @ Advice .Argument (1 ) ClassicHttpRequest request ) {
262263
263- return AdviceLocals .start (new RequestWithHost (host , request ));
264+ return AdviceScope .start (new RequestWithHost (host , request ));
264265 }
265266
266267 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
267268 public static void methodExit (
268269 @ Advice .Return Object result ,
269270 @ Advice .Thrown Throwable throwable ,
270- @ Advice .Enter @ Nullable AdviceLocals locals ) {
271+ @ Advice .Enter @ Nullable AdviceScope scope ) {
271272
272- if (locals != null ) {
273- locals .end (result , throwable );
273+ if (scope != null ) {
274+ scope .end (result , throwable );
274275 }
275276 }
276277 }
@@ -286,19 +287,17 @@ public static Object[] methodEnter(
286287 @ Advice .Argument (2 ) HttpClientResponseHandler <?> originalHandler ) {
287288
288289 HttpClientResponseHandler <?> handler = originalHandler ;
289- AdviceLocals locals = AdviceLocals .start (new RequestWithHost (host , request ));
290+ AdviceScope scope = AdviceScope .start (new RequestWithHost (host , request ));
290291
291- if (locals == null ) {
292+ if (scope == null ) {
292293 return new Object [] {null , handler };
293294 }
294295
295296 // Wrap the handler so we capture the status code
296297 if (handler != null ) {
297- handler =
298- new WrappingStatusSettingResponseHandler <>(
299- locals .context , locals .parentContext , locals .request , handler );
298+ scope .wrapResponseHandler (handler );
300299 }
301- return new Object [] {locals , handler };
300+ return new Object [] {scope , handler };
302301 }
303302
304303 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
@@ -307,9 +306,9 @@ public static void methodExit(
307306 @ Advice .Thrown Throwable throwable ,
308307 @ Advice .Enter Object [] enterResult ) {
309308
310- AdviceLocals locals = (AdviceLocals ) enterResult [0 ];
311- if (locals != null ) {
312- locals .end (result , throwable );
309+ AdviceScope scope = (AdviceScope ) enterResult [0 ];
310+ if (scope != null ) {
311+ scope .end (result , throwable );
313312 }
314313 }
315314 }
@@ -325,19 +324,17 @@ public static Object[] methodEnter(
325324 @ Advice .Argument (3 ) HttpClientResponseHandler <?> originalHandler ) {
326325
327326 HttpClientResponseHandler <?> handler = originalHandler ;
328- AdviceLocals locals = AdviceLocals .start (new RequestWithHost (host , request ));
327+ AdviceScope scope = AdviceScope .start (new RequestWithHost (host , request ));
329328
330- if (locals == null ) {
329+ if (scope == null ) {
331330 return new Object [] {null , handler };
332331 }
333332
334333 // Wrap the handler so we capture the status code
335334 if (handler != null ) {
336- handler =
337- new WrappingStatusSettingResponseHandler <>(
338- locals .context , locals .parentContext , locals .request , handler );
335+ handler = scope .wrapResponseHandler (handler );
339336 }
340- return new Object [] {locals , handler };
337+ return new Object [] {scope , handler };
341338 }
342339
343340 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
@@ -346,9 +343,9 @@ public static void methodExit(
346343 @ Advice .Thrown Throwable throwable ,
347344 @ Advice .Enter Object [] enterResult ) {
348345
349- AdviceLocals locals = (AdviceLocals ) enterResult [0 ];
350- if (locals != null ) {
351- locals .end (result , throwable );
346+ AdviceScope scope = (AdviceScope ) enterResult [0 ];
347+ if (scope != null ) {
348+ scope .end (result , throwable );
352349 }
353350 }
354351 }
0 commit comments