Make ServicesWrapperImpl as argument in provider 54/65254/6
authorJakub Toth <jakub.toth@pantheon.tech>
Tue, 7 Nov 2017 10:41:09 +0000 (11:41 +0100)
committerJakub Toth <jakub.toth@pantheon.tech>
Wed, 8 Nov 2017 15:56:35 +0000 (15:56 +0000)
Change-Id: Id491309eb0f1bc75337ace02072248f25d60a1b9
Signed-off-by: Jakub Toth <jakub.toth@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapperImpl.java
restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProviderTest.java

index 1fa97116f2f07569ee8dfbb39811f8b5d4000f05..6ad199e7aceb1b4e1ab99d0cedec417e67194d12 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.slf4j.Logger;
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
  * Provider for restconf draft18.
  *
  */
-public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
+public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
 
@@ -61,13 +61,16 @@ public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
-    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private final T wrapperServices;
 
+    private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private SchemaContextHandler schemaCtxHandler;
 
-    public RestConnectorProvider(final DOMDataBroker domDataBroker, final SchemaService schemaService,
-            final DOMRpcService rpcService, final DOMNotificationService notificationService,
-            final DOMMountPointService mountPointService) {
+    public RestConnectorProvider(final DOMDataBroker domDataBroker,
+            final SchemaService schemaService, final DOMRpcService rpcService,
+            final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
+            final T wrapperServices) {
+        this.wrapperServices = Preconditions.checkNotNull(wrapperServices);
         this.schemaService = Preconditions.checkNotNull(schemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
@@ -77,8 +80,6 @@ public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
     }
 
     public void start() {
-        final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
-
         mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
 
         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java
new file mode 100644 (file)
index 0000000..ee2538d
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.restconf.nb.rfc8040.services.wrapper;
+
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
+
+public interface ServiceWrapper {
+
+    void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
+            TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
+            RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler);
+}
index 6bef1978af90f000e4cd4689423f87b39ebaff49..1d585c5c8b9ec37248651bfe72ab99ef40c22a87 100644 (file)
@@ -44,7 +44,7 @@ import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaS
  *
  */
 @Path("/")
-public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper {
+public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper, ServiceWrapper {
 
     private RestconfDataService delegRestconfDataService;
     private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
@@ -135,6 +135,7 @@ public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServ
         return this.delegRestService.getLibraryVersion();
     }
 
+    @Override
     public void setHandlers(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
index 7eda5a376f618816915aae124b01a89dd852ab8d..6498a76aa637ee1f383d6ee1bace533379ac4fbf 100644 (file)
@@ -36,6 +36,9 @@
   <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           ext:filter="(type=@{databroker-service-type})"/>
 
+  <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
+          factory-method="getInstance" />
+
   <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
@@ -43,6 +46,7 @@
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
+    <argument ref="wrapper"/>
   </bean>
 
   <service ref="restconfProvider"
   <bean id="jsonRestconfService" depends-on="restconfProvider"
       class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
       destroy-method="close">
-    <argument>
-      <bean class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
-          factory-method="getInstance" />
-    </argument>
+    <argument ref="wrapper"/>
     <argument>
       <bean factory-ref="restconfProvider" factory-method="getMountPointServiceHandler" />
     </argument>
index 6ed6fcff66d42dad81d616cb331a0461c468b0dc..1fcc3e00242aa2661a312cc39bbea355ad5a9dd2 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
@@ -55,7 +56,7 @@ public class RestConnectorProviderTest {
                 Mockito.any(SchemaContextHandler.class));
 
         this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
-                mockNotificationService, mockMountPointService);
+                mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
     }
 
     /**