1
1
package com .yammer .metrics .httpclient ;
2
2
3
- import com .yammer .metrics .Metrics ;
3
+ import com .yammer .metrics .core . MetricsRegistry ;
4
4
import com .yammer .metrics .core .Timer ;
5
5
import com .yammer .metrics .core .TimerContext ;
6
6
import org .apache .commons .logging .Log ;
@@ -22,21 +22,20 @@ class InstrumentedRequestDirector extends DefaultRequestDirector {
22
22
OPTIONS = "OPTIONS" , DELETE = "DELETE" , TRACE = "TRACE" ,
23
23
CONNECT = "CONNECT" , MOVE = "MOVE" , PATCH = "PATCH" ;
24
24
25
- private static final Timer GET_TIMER = Metrics .newTimer (HttpClient .class , "get-requests" );
26
- private static final Timer POST_TIMER = Metrics .newTimer (HttpClient .class , "post-requests" );
27
- private static final Timer HEAD_TIMER = Metrics .newTimer (HttpClient .class , "head-requests" );
28
- private static final Timer PUT_TIMER = Metrics .newTimer (HttpClient .class , "put-requests" );
29
- private static final Timer DELETE_TIMER = Metrics .newTimer (HttpClient .class , "delete-requests" );
30
- private static final Timer OPTIONS_TIMER = Metrics .newTimer (HttpClient .class ,
31
- "options-requests" );
32
- private static final Timer TRACE_TIMER = Metrics .newTimer (HttpClient .class , "trace-requests" );
33
- private static final Timer CONNECT_TIMER = Metrics .newTimer (HttpClient .class ,
34
- "connect-requests" );
35
- private static final Timer MOVE_TIMER = Metrics .newTimer (HttpClient .class , "move-requests" );
36
- private static final Timer PATCH_TIMER = Metrics .newTimer (HttpClient .class , "patch-requests" );
37
- private static final Timer OTHER_TIMER = Metrics .newTimer (HttpClient .class , "other-requests" );
25
+ private final Timer getTimer ;
26
+ private final Timer postTimer ;
27
+ private final Timer headTimer ;
28
+ private final Timer putTimer ;
29
+ private final Timer deleteTimer ;
30
+ private final Timer optionsTimer ;
31
+ private final Timer traceTimer ;
32
+ private final Timer connectTimer ;
33
+ private final Timer moveTimer ;
34
+ private final Timer patchTimer ;
35
+ private final Timer otherTimer ;
38
36
39
- InstrumentedRequestDirector (Log log ,
37
+ InstrumentedRequestDirector (MetricsRegistry registry ,
38
+ Log log ,
40
39
HttpRequestExecutor requestExec ,
41
40
ClientConnectionManager conman ,
42
41
ConnectionReuseStrategy reustrat ,
@@ -45,8 +44,8 @@ class InstrumentedRequestDirector extends DefaultRequestDirector {
45
44
HttpProcessor httpProcessor ,
46
45
HttpRequestRetryHandler retryHandler ,
47
46
RedirectStrategy redirectStrategy ,
48
- AuthenticationHandler targetAuthHandler ,
49
- AuthenticationHandler proxyAuthHandler ,
47
+ AuthenticationStrategy targetAuthStrategy ,
48
+ AuthenticationStrategy proxyAuthStrategy ,
50
49
UserTokenHandler userTokenHandler ,
51
50
HttpParams params ) {
52
51
super (log ,
@@ -58,10 +57,21 @@ class InstrumentedRequestDirector extends DefaultRequestDirector {
58
57
httpProcessor ,
59
58
retryHandler ,
60
59
redirectStrategy ,
61
- targetAuthHandler ,
62
- proxyAuthHandler ,
60
+ targetAuthStrategy ,
61
+ proxyAuthStrategy ,
63
62
userTokenHandler ,
64
63
params );
64
+ getTimer = registry .newTimer (HttpClient .class , "get-requests" );
65
+ postTimer = registry .newTimer (HttpClient .class , "post-requests" );
66
+ headTimer = registry .newTimer (HttpClient .class , "head-requests" );
67
+ putTimer = registry .newTimer (HttpClient .class , "put-requests" );
68
+ deleteTimer = registry .newTimer (HttpClient .class , "delete-requests" );
69
+ optionsTimer = registry .newTimer (HttpClient .class , "options-requests" );
70
+ traceTimer = registry .newTimer (HttpClient .class , "trace-requests" );
71
+ connectTimer = registry .newTimer (HttpClient .class , "connect-requests" );
72
+ moveTimer = registry .newTimer (HttpClient .class , "move-requests" );
73
+ patchTimer = registry .newTimer (HttpClient .class , "patch-requests" );
74
+ otherTimer = registry .newTimer (HttpClient .class , "other-requests" );
65
75
}
66
76
67
77
@ Override
@@ -77,26 +87,26 @@ public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext co
77
87
private Timer timer (HttpRequest request ) {
78
88
final String method = request .getRequestLine ().getMethod ();
79
89
if (GET .equalsIgnoreCase (method )) {
80
- return GET_TIMER ;
90
+ return getTimer ;
81
91
} else if (POST .equalsIgnoreCase (method )) {
82
- return POST_TIMER ;
92
+ return postTimer ;
83
93
} else if (PUT .equalsIgnoreCase (method )) {
84
- return PUT_TIMER ;
94
+ return putTimer ;
85
95
} else if (HEAD .equalsIgnoreCase (method )) {
86
- return HEAD_TIMER ;
96
+ return headTimer ;
87
97
} else if (DELETE .equalsIgnoreCase (method )) {
88
- return DELETE_TIMER ;
98
+ return deleteTimer ;
89
99
} else if (OPTIONS .equalsIgnoreCase (method )) {
90
- return OPTIONS_TIMER ;
100
+ return optionsTimer ;
91
101
} else if (TRACE .equalsIgnoreCase (method )) {
92
- return TRACE_TIMER ;
102
+ return traceTimer ;
93
103
} else if (CONNECT .equalsIgnoreCase (method )) {
94
- return CONNECT_TIMER ;
104
+ return connectTimer ;
95
105
} else if (PATCH .equalsIgnoreCase (method )) {
96
- return PATCH_TIMER ;
106
+ return patchTimer ;
97
107
} else if (MOVE .equalsIgnoreCase (method )) {
98
- return MOVE_TIMER ;
108
+ return moveTimer ;
99
109
}
100
- return OTHER_TIMER ;
110
+ return otherTimer ;
101
111
}
102
112
}
0 commit comments