1 | /** |
---|
2 | * This software is copyright (c) 2012-2014 by |
---|
3 | * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.client; |
---|
18 | |
---|
19 | import java.util.Collections; |
---|
20 | import java.util.List; |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | /** |
---|
25 | * Abstract base class for SRU responses. |
---|
26 | * |
---|
27 | * @see SRUExplainResponse |
---|
28 | * @see SRUScanResponse |
---|
29 | * @see SRUSearchRetrieveResponse |
---|
30 | */ |
---|
31 | class SRUAbstractResponse<T extends SRUAbstractRequest> { |
---|
32 | private final T request; |
---|
33 | private final List<SRUDiagnostic> diagnostics; |
---|
34 | private final List<SRUExtraResponseData> extraResponseData; |
---|
35 | private final int totalBytesTransferred; |
---|
36 | private final long timeTotal; |
---|
37 | private final long timeQueued; |
---|
38 | private final long timeNetwork; |
---|
39 | private final long timeProcessing; |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | * Constructor. |
---|
44 | * |
---|
45 | * @param diagnostics |
---|
46 | * a list of diagnostics associated to this result or |
---|
47 | * <code>null</code> if none. |
---|
48 | * @param extraResponseData |
---|
49 | * extra response data for this result or <code>null</code> if |
---|
50 | * none. |
---|
51 | * @param totalBytesTransferred |
---|
52 | * the total number of bytes transferred for this request |
---|
53 | * @param timeTotal |
---|
54 | * the total number of milliseconds elapsed while performing this |
---|
55 | * request |
---|
56 | * @param timeQueued |
---|
57 | * the total number of milliseconds elapsed while this request |
---|
58 | * was queued |
---|
59 | * @param timeNetwork |
---|
60 | * the total number of milliseconds elapsed while this request |
---|
61 | * waited for network operations to finish |
---|
62 | * @param timeProcessing |
---|
63 | * the total number of milliseconds elapsed while the client |
---|
64 | * processed the response from the endpoint |
---|
65 | */ |
---|
66 | protected SRUAbstractResponse(T request, |
---|
67 | List<SRUDiagnostic> diagnostics, |
---|
68 | List<SRUExtraResponseData> extraResponseData, |
---|
69 | int totalBytesTransferred, |
---|
70 | long timeTotal, |
---|
71 | long timeQueued, |
---|
72 | long timeNetwork, |
---|
73 | long timeProcessing) { |
---|
74 | this.request = request; |
---|
75 | this.diagnostics = ((diagnostics != null) && !diagnostics.isEmpty()) |
---|
76 | ? Collections.unmodifiableList(diagnostics) |
---|
77 | : null; |
---|
78 | this.extraResponseData = ((extraResponseData != null) && |
---|
79 | !extraResponseData.isEmpty()) |
---|
80 | ? Collections.unmodifiableList(extraResponseData) |
---|
81 | : null; |
---|
82 | this.totalBytesTransferred = totalBytesTransferred; |
---|
83 | this.timeTotal = timeTotal; |
---|
84 | this.timeQueued = timeQueued; |
---|
85 | this.timeNetwork = timeNetwork; |
---|
86 | this.timeProcessing = timeProcessing; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | /** |
---|
91 | * Get the request that produced this response. |
---|
92 | * |
---|
93 | * @return the request |
---|
94 | */ |
---|
95 | public T getRequest() { |
---|
96 | return request; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | /** |
---|
101 | * Get the diagnostics for this response. |
---|
102 | * |
---|
103 | * @return diagnostics for this response or <code>null</code> if none |
---|
104 | */ |
---|
105 | public List<SRUDiagnostic> getDiagnostics() { |
---|
106 | return diagnostics; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * Check, if the response contains any diagnostics. |
---|
112 | * |
---|
113 | * <p> |
---|
114 | * NB: Surrogate diagnostics are not covered by this. |
---|
115 | * </p> |
---|
116 | * |
---|
117 | * @return <code>true</code> if response contains any diagnostic, |
---|
118 | * <code>false</code> otherwise |
---|
119 | */ |
---|
120 | public boolean hasDiagnostics() { |
---|
121 | return diagnostics != null; |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | /** |
---|
126 | * Get the extra response data for this result. |
---|
127 | * |
---|
128 | * @return get a list of {@link SRUExtraResponseData} instances for the |
---|
129 | * extra response data from the SRU response or <code>null</code> if |
---|
130 | * none are available |
---|
131 | */ |
---|
132 | public List<SRUExtraResponseData> getExtraResponseData() { |
---|
133 | return extraResponseData; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | /** |
---|
138 | * Check, if this response has any extra response data attached to it. |
---|
139 | * |
---|
140 | * @return <code>true</code> if extra response is attached, |
---|
141 | * <code>false</code> otherwise |
---|
142 | */ |
---|
143 | public boolean hasExtraResponseData() { |
---|
144 | return extraResponseData != null; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | /** |
---|
149 | * Get the total number of bytes transferred for this request. |
---|
150 | * |
---|
151 | * @return the total number of bytes or <code>-1</code> if not available |
---|
152 | */ |
---|
153 | public long getTotalBytesTransferred() { |
---|
154 | return totalBytesTransferred; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | * Get the total number of milliseconds elapsed for this request. |
---|
160 | * |
---|
161 | * @return the total number of milliseconds or <code>-1</code> if not |
---|
162 | * available |
---|
163 | */ |
---|
164 | public long getTimeTotal() { |
---|
165 | return timeTotal; |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | /** |
---|
170 | * Get the number of milliseconds this request has been queued before it was |
---|
171 | * processed by the client. |
---|
172 | * |
---|
173 | * @return the number of milliseconds queued or <code>-1</code> if not |
---|
174 | * available |
---|
175 | */ |
---|
176 | public long getTimeWait() { |
---|
177 | return timeQueued; |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | /** |
---|
182 | * Get the number of milliseconds this request spend waiting for network |
---|
183 | * operations to finish. |
---|
184 | * |
---|
185 | * @return the number of milliseconds spend in waiting on network or |
---|
186 | * <code>-1</code> if not available |
---|
187 | */ |
---|
188 | public long getTimeNetwork() { |
---|
189 | return timeNetwork; |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /** |
---|
194 | * Get the number of milliseconds the client was busy processing the results |
---|
195 | * sent from the endpoint. |
---|
196 | * |
---|
197 | * @return the number of milliseconds spend in processing or <code>-1</code> |
---|
198 | * if not available |
---|
199 | */ |
---|
200 | public long getTimeProcessing() { |
---|
201 | return timeProcessing; |
---|
202 | } |
---|
203 | |
---|
204 | } // class SRUAbstractResponse |
---|