Remove static RestconfImpl
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / StatisticsRestconfServiceWrapper.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.sal.restconf.impl;
9
10 import java.math.BigInteger;
11 import java.util.concurrent.atomic.AtomicLong;
12 import javax.ws.rs.core.Response;
13 import javax.ws.rs.core.Response.Status;
14 import javax.ws.rs.core.UriInfo;
15 import org.opendaylight.netconf.sal.rest.api.RestconfService;
16 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
17 import org.opendaylight.restconf.common.patch.PatchContext;
18 import org.opendaylight.restconf.common.patch.PatchStatusContext;
19
20 public final class StatisticsRestconfServiceWrapper implements RestconfService {
21
22     AtomicLong operationalGet = new AtomicLong();
23     AtomicLong configGet = new AtomicLong();
24     AtomicLong rpc = new AtomicLong();
25     AtomicLong configPost = new AtomicLong();
26     AtomicLong configPut = new AtomicLong();
27     AtomicLong configDelete = new AtomicLong();
28     AtomicLong successGetConfig = new AtomicLong();
29     AtomicLong successGetOperational = new AtomicLong();
30     AtomicLong successPost = new AtomicLong();
31     AtomicLong successPut = new AtomicLong();
32     AtomicLong successDelete = new AtomicLong();
33     AtomicLong failureGetConfig = new AtomicLong();
34     AtomicLong failureGetOperational = new AtomicLong();
35     AtomicLong failurePost = new AtomicLong();
36     AtomicLong failurePut = new AtomicLong();
37     AtomicLong failureDelete = new AtomicLong();
38
39     private static final StatisticsRestconfServiceWrapper INSTANCE = new StatisticsRestconfServiceWrapper();
40
41     private RestconfService delegate;
42
43     @Deprecated
44     private StatisticsRestconfServiceWrapper() {
45     }
46
47     private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
48         this.delegate = delegate;
49     }
50
51     @Deprecated
52     public static StatisticsRestconfServiceWrapper getInstance() {
53         return INSTANCE;
54     }
55
56     public static StatisticsRestconfServiceWrapper newInstance(RestconfService delegate) {
57         INSTANCE.delegate = delegate;
58         return INSTANCE;
59         //return new StatisticsRestconfServiceWrapper(delegate);
60     }
61
62     @Override
63     public Object getRoot() {
64         return this.delegate.getRoot();
65     }
66
67     @Override
68     public NormalizedNodeContext getModules(final UriInfo uriInfo) {
69         return this.delegate.getModules(uriInfo);
70     }
71
72     @Override
73     public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
74         return this.delegate.getModules(identifier, uriInfo);
75     }
76
77     @Override
78     public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
79         return this.delegate.getModule(identifier, uriInfo);
80     }
81
82     @Override
83     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
84         return this.delegate.getOperations(uriInfo);
85     }
86
87     @Override
88     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
89         return this.delegate.getOperations(identifier, uriInfo);
90     }
91
92     @Override
93     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
94             final UriInfo uriInfo) {
95         this.rpc.incrementAndGet();
96         return this.delegate.invokeRpc(identifier, payload, uriInfo);
97     }
98
99     @Override
100     public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
101         this.rpc.incrementAndGet();
102         return this.delegate.invokeRpc(identifier, noPayload, uriInfo);
103     }
104
105     @SuppressWarnings("checkstyle:IllegalCatch")
106     @Override
107     public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
108         this.configGet.incrementAndGet();
109         NormalizedNodeContext normalizedNodeContext = null;
110         try {
111             normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
112             if (normalizedNodeContext.getData() != null) {
113                 this.successGetConfig.incrementAndGet();
114             } else {
115                 this.failureGetConfig.incrementAndGet();
116             }
117         } catch (final Exception e) {
118             this.failureGetConfig.incrementAndGet();
119             throw e;
120         }
121         return normalizedNodeContext;
122     }
123
124     @SuppressWarnings("checkstyle:IllegalCatch")
125     @Override
126     public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
127         this.operationalGet.incrementAndGet();
128         NormalizedNodeContext normalizedNodeContext = null;
129         try {
130             normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
131             if (normalizedNodeContext.getData() != null) {
132                 this.successGetOperational.incrementAndGet();
133             } else {
134                 this.failureGetOperational.incrementAndGet();
135             }
136         } catch (final Exception e) {
137             this.failureGetOperational.incrementAndGet();
138             throw e;
139         }
140         return normalizedNodeContext;
141     }
142
143     @SuppressWarnings("checkstyle:IllegalCatch")
144     @Override
145     public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
146             final UriInfo uriInfo) {
147         this.configPut.incrementAndGet();
148         Response response = null;
149         try {
150             response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
151             if (response.getStatus() == Status.OK.getStatusCode()) {
152                 this.successPut.incrementAndGet();
153             } else {
154                 this.failurePut.incrementAndGet();
155             }
156         } catch (final Exception e) {
157             this.failurePut.incrementAndGet();
158             throw e;
159         }
160         return response;
161     }
162
163     @SuppressWarnings("checkstyle:IllegalCatch")
164     @Override
165     public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
166             final UriInfo uriInfo) {
167         this.configPost.incrementAndGet();
168         Response response = null;
169         try {
170             response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
171             if (response.getStatus() == Status.OK.getStatusCode()) {
172                 this.successPost.incrementAndGet();
173             } else {
174                 this.failurePost.incrementAndGet();
175             }
176         } catch (final Exception e) {
177             this.failurePost.incrementAndGet();
178             throw e;
179         }
180         return response;
181     }
182
183     @SuppressWarnings("checkstyle:IllegalCatch")
184     @Override
185     public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
186         this.configPost.incrementAndGet();
187         Response response = null;
188         try {
189             response = this.delegate.createConfigurationData(payload, uriInfo);
190             if (response.getStatus() == Status.OK.getStatusCode()) {
191                 this.successPost.incrementAndGet();
192             } else {
193                 this.failurePost.incrementAndGet();
194             }
195         } catch (final Exception e) {
196             this.failurePost.incrementAndGet();
197             throw e;
198         }
199         return response;
200     }
201
202     @SuppressWarnings("checkstyle:IllegalCatch")
203     @Override
204     public Response deleteConfigurationData(final String identifier) {
205         this.configDelete.incrementAndGet();
206         Response response = null;
207         try {
208             response = this.delegate.deleteConfigurationData(identifier);
209             if (response.getStatus() == Status.OK.getStatusCode()) {
210                 this.successDelete.incrementAndGet();
211             } else {
212                 this.failureDelete.incrementAndGet();
213             }
214         } catch (final Exception e) {
215             this.failureDelete.incrementAndGet();
216             throw e;
217         }
218         return response;
219     }
220
221     @Override
222     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
223         return this.delegate.subscribeToStream(identifier, uriInfo);
224     }
225
226     @Override
227     public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
228         return this.delegate.getAvailableStreams(uriInfo);
229     }
230
231     @Override
232     public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
233                                                      final UriInfo uriInfo) {
234         return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
235     }
236
237     @Override
238     public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
239         return this.delegate.patchConfigurationData(payload, uriInfo);
240     }
241
242     public BigInteger getConfigDelete() {
243         return BigInteger.valueOf(this.configDelete.get());
244     }
245
246     public BigInteger getConfigGet() {
247         return BigInteger.valueOf(this.configGet.get());
248     }
249
250     public BigInteger getConfigPost() {
251         return BigInteger.valueOf(this.configPost.get());
252     }
253
254     public BigInteger getConfigPut() {
255         return BigInteger.valueOf(this.configPut.get());
256     }
257
258     public BigInteger getOperationalGet() {
259         return BigInteger.valueOf(this.operationalGet.get());
260     }
261
262     public BigInteger getRpc() {
263         return BigInteger.valueOf(this.rpc.get());
264     }
265
266     public BigInteger getSuccessGetConfig() {
267         return BigInteger.valueOf(this.successGetConfig.get());
268     }
269
270     public BigInteger getSuccessGetOperational() {
271         return BigInteger.valueOf(this.successGetOperational.get());
272     }
273
274     public BigInteger getSuccessPost() {
275         return BigInteger.valueOf(this.successPost.get());
276     }
277
278     public BigInteger getSuccessPut() {
279         return BigInteger.valueOf(this.successPut.get());
280     }
281
282     public BigInteger getSuccessDelete() {
283         return BigInteger.valueOf(this.successDelete.get());
284     }
285
286     public BigInteger getFailureGetConfig() {
287         return BigInteger.valueOf(this.failureGetConfig.get());
288     }
289
290     public BigInteger getFailureGetOperational() {
291         return BigInteger.valueOf(this.failureGetOperational.get());
292     }
293
294     public BigInteger getFailurePost() {
295         return BigInteger.valueOf(this.failurePost.get());
296     }
297
298     public BigInteger getFailurePut() {
299         return BigInteger.valueOf(this.failurePut.get());
300     }
301
302     public BigInteger getFailureDelete() {
303         return BigInteger.valueOf(this.failureDelete.get());
304     }
305 }