Similar to the previous patch that was done for ControllerContext.
keeps the static BrokerFacade instance temporarily
for the RestconfApplication but converts the rest of the code to
reference it non-statically.
Change-Id: Iafdb26200f8d645a8ed61c7006edd0b106d7d976
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
+import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class BrokerFacade {
+@SuppressWarnings("checkstyle:FinalClass")
+public class BrokerFacade implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(BrokerFacade.class);
private static final BrokerFacade INSTANCE = new BrokerFacade();
private DOMNotificationService domNotification;
private ControllerContext controllerContext;
- BrokerFacade() {
-
+ // Temporary until the static instance is removed.
+ @Deprecated
+ private BrokerFacade() {
}
- public void setRpcService(final DOMRpcService router) {
- this.rpcService = router;
+ private BrokerFacade(DOMRpcService rpcService, DOMDataBroker domDataBroker, DOMNotificationService domNotification,
+ ControllerContext controllerContext) {
+ this.rpcService = rpcService;
+ this.domDataBroker = domDataBroker;
+ this.domNotification = domNotification;
+ this.controllerContext = controllerContext;
}
- public void setDomNotificationService(final DOMNotificationService service) {
- this.domNotification = service;
+ @Deprecated
+ public static BrokerFacade getInstance() {
+ return BrokerFacade.INSTANCE;
}
- public void setControllerContext(ControllerContext controllerContext) {
- this.controllerContext = controllerContext;
+ public static BrokerFacade newInstance(DOMRpcService rpcService, DOMDataBroker domDataBroker,
+ DOMNotificationService domNotification, ControllerContext controllerContext) {
+ INSTANCE.rpcService = rpcService;
+ INSTANCE.domDataBroker = domDataBroker;
+ INSTANCE.controllerContext = controllerContext;
+ INSTANCE.domNotification = domNotification;
+ return INSTANCE;
+ //return new BrokerFacade(pcService, domDataBroker, controllerContext);
}
- public static BrokerFacade getInstance() {
- return BrokerFacade.INSTANCE;
+ @Override
+ public void close() {
+ domDataBroker = null;
}
private void checkPreconditions() {
tx.merge(datastore, path, payload);
}
- public void setDomDataBroker(final DOMDataBroker domDataBroker) {
- this.domDataBroker = domDataBroker;
- }
-
public void registerToListenNotification(final NotificationListenerAdapter listener) {
checkPreconditions();
import com.google.common.base.Preconditions;
import java.math.BigInteger;
import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
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;
public class RestconfProviderImpl extends AbstractMXBean
implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
- private final DOMDataBroker domDataBroker;
- private final DOMRpcService rpcService;
- private final DOMNotificationService notificationService;
private final IpAddress websocketAddress;
private final PortNumber websocketPort;
private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
- private final ControllerContext controllerContext;
private Thread webSocketServerThread;
- public RestconfProviderImpl(DOMDataBroker domDataBroker, DOMRpcService rpcService,
- DOMNotificationService notificationService, ControllerContext controllerContext,
- IpAddress websocketAddress, PortNumber websocketPort) {
+ public RestconfProviderImpl(IpAddress websocketAddress, PortNumber websocketPort) {
super("Draft02ProviderStatistics", "restconf-connector", null);
- this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
- this.rpcService = Preconditions.checkNotNull(rpcService);
- this.notificationService = Preconditions.checkNotNull(notificationService);
this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
this.websocketPort = Preconditions.checkNotNull(websocketPort);
- this.controllerContext = Preconditions.checkNotNull(controllerContext);
}
public void start() {
- BrokerFacade.getInstance().setDomDataBroker(domDataBroker);
- BrokerFacade.getInstance().setRpcService(rpcService);
- BrokerFacade.getInstance().setDomNotificationService(notificationService);
- BrokerFacade.getInstance().setControllerContext(controllerContext);
-
this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
new String(websocketAddress.getValue()), websocketPort.getValue()));
this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
@Override
public void close() {
- BrokerFacade.getInstance().setDomDataBroker(null);
-
WebSocketServer.destroyInstance();
if (this.webSocketServerThread != null) {
this.webSocketServerThread.interrupt();
<argument ref="domSchemaService"/>
</bean>
- <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
- init-method="start" destroy-method="close">
- <argument ref="domDataBroker"/>
+ <bean id="brokerFacade" class="org.opendaylight.netconf.sal.restconf.impl.BrokerFacade"
+ factory-method="newInstance" destroy-method="close">
<argument ref="domRpcService"/>
+ <argument ref="domDataBroker"/>
<argument ref="domNotificationService"/>
<argument ref="controllerContext"/>
+ </bean>
+
+ <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
+ init-method="start" destroy-method="close">
<argument ref="webSocketAddress"/>
<argument ref="webSocketPort"/>
</bean>
@Mock
private DOMDataReadWriteTransaction rwTransaction;
- private final BrokerFacade brokerFacade = BrokerFacade.getInstance();
+ private BrokerFacade brokerFacade;
private final NormalizedNode<?, ?> dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
private final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> dummyNodeInFuture =
wrapDummyNode(this.dummyNode);
controllerContext = TestRestconfUtils.newControllerContext(
TestUtils.loadSchemaContext("/full-versions/test-module", "/modules"));
- this.brokerFacade.setDomDataBroker(this.domDataBroker);
- this.brokerFacade.setDomNotificationService(this.domNotification);
- this.brokerFacade.setRpcService(this.mockRpcService);
- this.brokerFacade.setControllerContext(controllerContext);
+ brokerFacade = BrokerFacade.newInstance(mockRpcService, domDataBroker, domNotification, controllerContext);
when(this.domDataBroker.newReadOnlyTransaction()).thenReturn(this.readTransaction);
when(this.domDataBroker.newWriteOnlyTransaction()).thenReturn(this.writeTransaction);
@Test(expected = RestconfDocumentedException.class)
public void testReadOperationalDataWithNoDataBroker() {
- this.brokerFacade.setDomDataBroker(null);
+ this.brokerFacade.close();
this.brokerFacade.readOperationalData(this.instanceID);
}
@Test(expected = RestconfDocumentedException.class)
public void testInvokeRpcWithNoConsumerSession() {
- brokerFacade.setDomDataBroker(null);
+ brokerFacade.close();
this.brokerFacade.invokeRpc(this.type, this.dummyNode);
}
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- this.broker.setDomDataBroker(this.domDataBroker);
RestconfImpl.getInstance().setBroker(this.broker);
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);