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 com.google.common.base.Preconditions;
11 import java.math.BigInteger;
12 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
13 import org.opendaylight.netconf.sal.rest.api.RestConnector;
14 import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
15 import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
16 import org.opendaylight.netconf.sal.restconf.impl.jmx.Get;
17 import org.opendaylight.netconf.sal.restconf.impl.jmx.Operational;
18 import org.opendaylight.netconf.sal.restconf.impl.jmx.Post;
19 import org.opendaylight.netconf.sal.restconf.impl.jmx.Put;
20 import org.opendaylight.netconf.sal.restconf.impl.jmx.RestConnectorRuntimeMXBean;
21 import org.opendaylight.netconf.sal.restconf.impl.jmx.Rpcs;
22 import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
26 public class RestconfProviderImpl extends AbstractMXBean
27 implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
28 private final IpAddress websocketAddress;
29 private final PortNumber websocketPort;
30 private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
31 private Thread webSocketServerThread;
33 public RestconfProviderImpl(IpAddress websocketAddress, PortNumber websocketPort) {
34 super("Draft02ProviderStatistics", "restconf-connector", null);
35 this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
36 this.websocketPort = Preconditions.checkNotNull(websocketPort);
40 this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
41 new String(websocketAddress.getValue()), websocketPort.getValue()));
42 this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
43 this.webSocketServerThread.start();
50 WebSocketServer.destroyInstance();
51 if (this.webSocketServerThread != null) {
52 this.webSocketServerThread.interrupt();
59 public Config getConfig() {
60 final Config config = new Config();
62 final Get get = new Get();
63 get.setReceivedRequests(this.stats.getConfigGet());
64 get.setSuccessfulResponses(this.stats.getSuccessGetConfig());
65 get.setFailedResponses(this.stats.getFailureGetConfig());
68 final Post post = new Post();
69 post.setReceivedRequests(this.stats.getConfigPost());
70 post.setSuccessfulResponses(this.stats.getSuccessPost());
71 post.setFailedResponses(this.stats.getFailurePost());
74 final Put put = new Put();
75 put.setReceivedRequests(this.stats.getConfigPut());
76 put.setSuccessfulResponses(this.stats.getSuccessPut());
77 put.setFailedResponses(this.stats.getFailurePut());
80 final Delete delete = new Delete();
81 delete.setReceivedRequests(this.stats.getConfigDelete());
82 delete.setSuccessfulResponses(this.stats.getSuccessDelete());
83 delete.setFailedResponses(this.stats.getFailureDelete());
84 config.setDelete(delete);
90 public Operational getOperational() {
91 final BigInteger opGet = this.stats.getOperationalGet();
92 final Operational operational = new Operational();
93 final Get get = new Get();
94 get.setReceivedRequests(opGet);
95 get.setSuccessfulResponses(this.stats.getSuccessGetOperational());
96 get.setFailedResponses(this.stats.getFailureGetOperational());
97 operational.setGet(get);
102 public Rpcs getRpcs() {
103 final BigInteger rpcInvoke = this.stats.getRpc();
104 final Rpcs rpcs = new Rpcs();
105 rpcs.setReceivedRequests(rpcInvoke);