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;
31 private Thread webSocketServerThread;
33 public RestconfProviderImpl(StatisticsRestconfServiceWrapper stats, IpAddress websocketAddress,
34 PortNumber websocketPort) {
35 super("Draft02ProviderStatistics", "restconf-connector", null);
36 this.stats = Preconditions.checkNotNull(stats);
37 this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
38 this.websocketPort = Preconditions.checkNotNull(websocketPort);
42 this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
43 websocketAddress.stringValue(), websocketPort.getValue().toJava()));
44 this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
45 this.webSocketServerThread.start();
52 WebSocketServer.destroyInstance();
53 if (this.webSocketServerThread != null) {
54 this.webSocketServerThread.interrupt();
61 public Config getConfig() {
62 final Config config = new Config();
64 final Get get = new Get();
65 get.setReceivedRequests(this.stats.getConfigGet());
66 get.setSuccessfulResponses(this.stats.getSuccessGetConfig());
67 get.setFailedResponses(this.stats.getFailureGetConfig());
70 final Post post = new Post();
71 post.setReceivedRequests(this.stats.getConfigPost());
72 post.setSuccessfulResponses(this.stats.getSuccessPost());
73 post.setFailedResponses(this.stats.getFailurePost());
76 final Put put = new Put();
77 put.setReceivedRequests(this.stats.getConfigPut());
78 put.setSuccessfulResponses(this.stats.getSuccessPut());
79 put.setFailedResponses(this.stats.getFailurePut());
82 final Delete delete = new Delete();
83 delete.setReceivedRequests(this.stats.getConfigDelete());
84 delete.setSuccessfulResponses(this.stats.getSuccessDelete());
85 delete.setFailedResponses(this.stats.getFailureDelete());
86 config.setDelete(delete);
92 public Operational getOperational() {
93 final BigInteger opGet = this.stats.getOperationalGet();
94 final Operational operational = new Operational();
95 final Get get = new Get();
96 get.setReceivedRequests(opGet);
97 get.setSuccessfulResponses(this.stats.getSuccessGetOperational());
98 get.setFailedResponses(this.stats.getFailureGetOperational());
99 operational.setGet(get);
104 public Rpcs getRpcs() {
105 final BigInteger rpcInvoke = this.stats.getRpc();
106 final Rpcs rpcs = new Rpcs();
107 rpcs.setReceivedRequests(rpcInvoke);