18d19e4eaa0a52d8eb9c0f9ddceb411335d08b6c
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / Bierman02RestConfWiring.java
1 /*
2  * Copyright (c) 2019 Red Hat, 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 javax.annotation.PostConstruct;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.servlet.ServletException;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
17 import org.opendaylight.mdsal.dom.api.DOMRpcService;
18 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
19 import org.opendaylight.netconf.sal.rest.impl.RestconfApplication;
20 import org.opendaylight.netconf.sal.restconf.api.RestConfConfig;
21 import org.opendaylight.netconf.sal.restconf.web.WebInitializer;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
25 import org.opendaylight.yangtools.yang.common.Uint16;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * Standalone wiring for RESTCONF.
31  *
32  * <p>ACK: Some lines here were originally inspired by the RestConfWiring class in
33  * opendaylight-simple which in turn was inspired by the CommunityRestConf class
34  * from lighty.io. The differences include (1) that this class is "pure Java"
35  * without depending on any binding framework utility classes; (2) we do not mix
36  * bierman02 and rfc8040 for proper modularity;  (3) we simply use {@literal @}Inject
37  * instead of manual object wiring, where possible.
38  *
39  * @author Michael Vorburger.ch (see ACK note for history)
40  */
41 @SuppressWarnings("deprecation")
42 // NOT @Singleton, to avoid  that the blueprint-maven-plugin generates <bean>, which we don't want for this
43 public class Bierman02RestConfWiring {
44
45     private static final Logger LOG = LoggerFactory.getLogger(Bierman02RestConfWiring.class);
46
47     private final RestconfProviderImpl webSocketServer;
48
49     @Inject
50     // The point of all the arguments here is simply to make your chosen Dependency Injection (DI) framework init. them
51     public Bierman02RestConfWiring(final RestConfConfig config,
52             final DOMSchemaService domSchemaService, final DOMMountPointService domMountPointService,
53             final DOMRpcService domRpcService, final DOMDataBroker domDataBroker,
54             final DOMNotificationService domNotificationService, final ControllerContext controllerContext,
55             final RestconfApplication application, final BrokerFacade broker, final RestconfImpl restconf,
56             final StatisticsRestconfServiceWrapper stats, final JSONRestconfServiceImpl jsonRestconfServiceImpl,
57             final WebInitializer webInitializer) {
58
59         // WebSocket
60         LOG.info("webSocketAddress = {}, webSocketPort = {}", config.webSocketAddress(), config.webSocketPort());
61         IpAddress wsIpAddress = IpAddressBuilder.getDefaultInstance(config.webSocketAddress().getHostAddress());
62         this.webSocketServer = new RestconfProviderImpl(stats, wsIpAddress,
63             new PortNumber(Uint16.valueOf(config.webSocketPort())));
64     }
65
66     @PostConstruct
67     public void start() throws ServletException {
68         this.webSocketServer.start();
69     }
70
71     @PreDestroy
72     public void stop() {
73         this.webSocketServer.close();
74     }
75 }