summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java')
-rw-r--r--netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java b/netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
new file mode 100644
index 0000000..5b6608e
--- /dev/null
+++ b/netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import java.math.BigInteger;
+import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
+import org.opendaylight.netconf.sal.rest.api.RestConnector;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Get;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Operational;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Post;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Put;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.RestConnectorRuntimeMXBean;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Rpcs;
+import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+
+public class RestconfProviderImpl extends AbstractMXBean
+ implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
+ private final IpAddress websocketAddress;
+ private final PortNumber websocketPort;
+ private final StatisticsRestconfServiceWrapper stats;
+ private Thread webSocketServerThread;
+
+ public RestconfProviderImpl(final StatisticsRestconfServiceWrapper stats, final IpAddress websocketAddress,
+ final PortNumber websocketPort) {
+ super("Draft02ProviderStatistics", "restconf-connector", null);
+ this.stats = requireNonNull(stats);
+ this.websocketAddress = requireNonNull(websocketAddress);
+ this.websocketPort = requireNonNull(websocketPort);
+ }
+
+ public void start() {
+ this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
+ websocketAddress.stringValue(), websocketPort.getValue().toJava()));
+ this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
+ this.webSocketServerThread.start();
+
+ registerMBean();
+ }
+
+ @Override
+ public void close() {
+ WebSocketServer.destroyInstance();
+ if (this.webSocketServerThread != null) {
+ this.webSocketServerThread.interrupt();
+ }
+
+ unregisterMBean();
+ }
+
+ @Override
+ public Config getConfig() {
+ final Config config = new Config();
+
+ final Get get = new Get();
+ get.setReceivedRequests(this.stats.getConfigGet());
+ get.setSuccessfulResponses(this.stats.getSuccessGetConfig());
+ get.setFailedResponses(this.stats.getFailureGetConfig());
+ config.setGet(get);
+
+ final Post post = new Post();
+ post.setReceivedRequests(this.stats.getConfigPost());
+ post.setSuccessfulResponses(this.stats.getSuccessPost());
+ post.setFailedResponses(this.stats.getFailurePost());
+ config.setPost(post);
+
+ final Put put = new Put();
+ put.setReceivedRequests(this.stats.getConfigPut());
+ put.setSuccessfulResponses(this.stats.getSuccessPut());
+ put.setFailedResponses(this.stats.getFailurePut());
+ config.setPut(put);
+
+ final Delete delete = new Delete();
+ delete.setReceivedRequests(this.stats.getConfigDelete());
+ delete.setSuccessfulResponses(this.stats.getSuccessDelete());
+ delete.setFailedResponses(this.stats.getFailureDelete());
+ config.setDelete(delete);
+
+ return config;
+ }
+
+ @Override
+ public Operational getOperational() {
+ final BigInteger opGet = this.stats.getOperationalGet();
+ final Operational operational = new Operational();
+ final Get get = new Get();
+ get.setReceivedRequests(opGet);
+ get.setSuccessfulResponses(this.stats.getSuccessGetOperational());
+ get.setFailedResponses(this.stats.getFailureGetOperational());
+ operational.setGet(get);
+ return operational;
+ }
+
+ @Override
+ public Rpcs getRpcs() {
+ final BigInteger rpcInvoke = this.stats.getRpc();
+ final Rpcs rpcs = new Rpcs();
+ rpcs.setReceivedRequests(rpcInvoke);
+ return rpcs;
+ }
+}