Skip to content
Newer
Older
100644 169 lines (152 sloc) 4.56 KB
efc953a @davidlehn Add connection monitor support.
davidlehn authored
1 /*
2 * Copyright (c) 2011 Digital Bazaar, Inc. All rights reserved.
3 */
4 #ifndef monarch_http_HttpConnectionMonitor_h
5 #define monarch_http_HttpConnectionMonitor_h
6
7 #include "monarch/http/HttpConnection.h"
8 #include "monarch/http/HttpRequest.h"
9 #include "monarch/http/HttpResponse.h"
10
11 namespace monarch
12 {
13 namespace http
14 {
15
16 /**
17 * An HttpConnectionMonitor monitors HttpConnectionServicers.
18 *
19 * It contains a number of hooks that will be called for various servicer
20 * events.
21 *
22 * @author David I. Lehn
23 */
24 class HttpConnectionMonitor
25 {
26 public:
27 // stats
28 uint64_t mTotalTime;
29 uint64_t mTotalConnections;
30 uint64_t mActiveConnections;
31 uint64_t mTotalRequests;
32 uint64_t mActiveRequests;
33 uint64_t mTotalErrors;
34 uint64_t mTotalBytesRead;
35 uint64_t mTotalContentBytesRead;
36 uint64_t mTotalBytesWritten;
37 uint64_t mTotalContentBytesWritten;
38 // status code results
39 uint64_t mTotalStatus1xx;
40 uint64_t mTotalStatus2xx;
41 uint64_t mTotalStatus3xx;
42 uint64_t mTotalStatus4xx;
43 uint64_t mTotalStatus5xx;
44 uint64_t mTotalStatusOther;
45
46 public:
47 /**
48 * Creates a new HttpConnectionMonitor.
49 */
50 HttpConnectionMonitor();
51
52 /**
53 * Destructs this HttpConnectionMonitor.
54 */
55 virtual ~HttpConnectionMonitor();
56
57 /**
58 * Get a DynamicObject with connection monitor statistics that include all
59 * connections and requests serviced or in progress.
60 *
61 * Available statistics:
62 * totalTime
63 * totalConnections
64 * activeConnections
65 * totalRequests
66 * activeRequests
67 * totalErrors
68 * totalBytesRead
69 * totalContentBytesRead
70 * totalBytesWritten
71 * totalContentBytesWritten
72 * totalStatus1xx
73 * totalStatus2xx
74 * totalStatus3xx
75 * totalStatus4xx
76 * totalStatus5xx
77 * totalStatusOther
78 */
79 virtual monarch::rt::DynamicObject getStats();
80
81 /**
82 * Called before a connection begins servicing requests.
83 *
84 * @param connection the HttpConnection that is being monitored.
85 */
86 virtual void beforeServicingConnection(HttpConnection* connection);
87
88 /**
89 * Called before a connection finishes servicing requests.
90 *
91 * @param connection the HttpConnection that is being monitored.
92 */
93 virtual void afterServicingConnection(HttpConnection* connection);
94
95 /**
96 * Called before a request is received.
97 *
98 * @param connection the HttpConnection that is being monitored.
99 * @param request the HttpRequest that was serviced.
100 * @param response the HttpResponse for the request.
101 */
102 virtual void beforeRequest(HttpConnection* connection);
103
104 /**
105 * Called after a successful request or request error.
106 *
107 * @param connection the HttpConnection that is being monitored.
108 */
109 virtual void afterRequest(HttpConnection* connection);
110
111 /**
112 * Called before a request is serviced.
113 *
114 * @param connection the HttpConnection that is being monitored.
115 * @param request the HttpRequest that was serviced.
116 * @param response the HttpResponse for the request.
117 */
118 virtual void beforeServicingRequest(
119 HttpConnection* connection,
120 HttpRequest* request,
121 HttpResponse* response);
122
123 /**
124 * Called after a request was serviced.
125 *
126 * @param connection the HttpConnection that is being monitored.
127 * @param request the HttpRequest that was serviced.
128 * @param response the HttpResponse for the request.
129 */
130 virtual void afterServicingRequest(
131 HttpConnection* connection,
132 HttpRequest* request,
133 HttpResponse* response);
134
135 /**
136 * Called before a request error is serviced.
137 *
138 * @param connection the HttpConnection that is being monitored.
139 * @param request the HttpRequest that was serviced.
140 * @param response the HttpResponse for the request.
141 */
142 virtual void beforeRequestError(
143 HttpConnection* connection,
144 HttpRequest* request,
145 HttpResponse* response);
146
147 /**
148 * Called after a request has been serviced.
149 *
150 * @param connection the HttpConnection that is being monitored.
151 * @param request the HttpRequest that was serviced.
152 * @param response the HttpResponse for the request.
153 * @param exception the Exception associated with this error.
154 */
155 virtual void afterRequestError(
156 HttpConnection* connection,
157 HttpRequest* request,
158 HttpResponse* response,
159 monarch::rt::ExceptionRef& exception);
160 };
161
162 // type definition for a reference counted HttpConnectionMonitor
163 typedef monarch::rt::Collectable<HttpConnectionMonitor>
164 HttpConnectionMonitorRef;
165
166 } // end namespace http
167 } // end namespace monarch
168 #endif
Something went wrong with that request. Please try again.