2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.sal.restconf.impl;
10 import static java.util.Objects.requireNonNull;
12 import java.math.BigInteger;
13 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
14 import org.opendaylight.netconf.sal.rest.api.RestConnector;
15 import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
16 import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
17 import org.opendaylight.netconf.sal.restconf.impl.jmx.Get;
18 import org.opendaylight.netconf.sal.restconf.impl.jmx.Operational;
19 import org.opendaylight.netconf.sal.restconf.impl.jmx.Post;
20 import org.opendaylight.netconf.sal.restconf.impl.jmx.Put;
21 import org.opendaylight.netconf.sal.restconf.impl.jmx.RestConnectorRuntimeMXBean;
22 import org.opendaylight.netconf.sal.restconf.impl.jmx.Rpcs;
23 import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
27 public class RestconfProviderImpl extends AbstractMXBean
28 implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
29 private final IpAddress websocketAddress;
30 private final PortNumber websocketPort;
31 private final StatisticsRestconfServiceWrapper stats;
32 private Thread webSocketServerThread;
34 public RestconfProviderImpl(final StatisticsRestconfServiceWrapper stats, final IpAddress websocketAddress,
35 final PortNumber websocketPort) {
36 super("Draft02ProviderStatistics", "restconf-connector", null);
37 this.stats = requireNonNull(stats);
38 this.websocketAddress = requireNonNull(websocketAddress);
39 this.websocketPort = requireNonNull(websocketPort);
43 this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
44 websocketAddress.stringValue(), websocketPort.getValue().toJava()));
45 this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
46 this.webSocketServerThread.start();
53 WebSocketServer.destroyInstance();
54 if (this.webSocketServerThread != null) {
55 this.webSocketServerThread.interrupt();
62 public Config getConfig() {
63 final Config config = new Config();
65 final Get get = new Get();
66 get.setReceivedRequests(this.stats.getConfigGet());
67 get.setSuccessfulResponses(this.stats.getSuccessGetConfig());
68 get.setFailedResponses(this.stats.getFailureGetConfig());
71 final Post post = new Post();
72 post.setReceivedRequests(this.stats.getConfigPost());
73 post.setSuccessfulResponses(this.stats.getSuccessPost());
74 post.setFailedResponses(this.stats.getFailurePost());
77 final Put put = new Put();
78 put.setReceivedRequests(this.stats.getConfigPut());
79 put.setSuccessfulResponses(this.stats.getSuccessPut());
80 put.setFailedResponses(this.stats.getFailurePut());
83 final Delete delete = new Delete();
84 delete.setReceivedRequests(this.stats.getConfigDelete());
85 delete.setSuccessfulResponses(this.stats.getSuccessDelete());
86 delete.setFailedResponses(this.stats.getFailureDelete());
87 config.setDelete(delete);
93 public Operational getOperational() {
94 final BigInteger opGet = this.stats.getOperationalGet();
95 final Operational operational = new Operational();
96 final Get get = new Get();
97 get.setReceivedRequests(opGet);
98 get.setSuccessfulResponses(this.stats.getSuccessGetOperational());
99 get.setFailedResponses(this.stats.getFailureGetOperational());
100 operational.setGet(get);
105 public Rpcs getRpcs() {
106 final BigInteger rpcInvoke = this.stats.getRpc();
107 final Rpcs rpcs = new Rpcs();
108 rpcs.setReceivedRequests(rpcInvoke);