Add update method of handlers for REST services
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / RestConnectorProvider.java
index 1fa97116f2f07569ee8dfbb39811f8b5d4000f05..be7d7a878ec228444f7aa0cc447baaca522e411b 100644 (file)
@@ -9,6 +9,9 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
@@ -24,7 +27,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 +37,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 +64,26 @@ public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
-    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private final Builder<Object> servicesProperties;
 
+    private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private SchemaContextHandler schemaCtxHandler;
+    private T wrapperServices;
+
+    // FIXME: refactor this class and its users to interact via builder pattern, where individual
+    // services are injected and then the provider is created
+    public RestConnectorProvider(final DOMDataBroker domDataBroker,
+            final SchemaService schemaService, final DOMRpcService rpcService,
+            final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
+        this(domDataBroker, schemaService, rpcService, notificationService, mountPointService, null);
+    }
 
     public RestConnectorProvider(final DOMDataBroker domDataBroker, final SchemaService schemaService,
-            final DOMRpcService rpcService, final DOMNotificationService notificationService,
-            final DOMMountPointService mountPointService) {
+            final DOMRpcService rpcService,
+            final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
+            final T wrapperServices) {
+        this.servicesProperties = ImmutableSet.<Object>builder();
+        this.wrapperServices = wrapperServices;
         this.schemaService = Preconditions.checkNotNull(schemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
@@ -76,27 +92,33 @@ public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
         RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
     }
 
-    public void start() {
-        final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
-
+    public synchronized void start() {
         mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
+        servicesProperties.add(mountPointServiceHandler);
 
         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
+        servicesProperties.add(brokerHandler);
 
         RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
                 .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
+        servicesProperties.add(transactionChainHandler);
 
         this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
+        servicesProperties.add(schemaCtxHandler);
         this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
 
         final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
+        servicesProperties.add(rpcServiceHandler);
 
         final NotificationServiceHandler notificationServiceHandler =
                 new NotificationServiceHandler(notificationService);
+        servicesProperties.add(notificationServiceHandler);
 
-        wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
+        if (wrapperServices != null) {
+            wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
                 RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
                 notificationServiceHandler);
+        }
     }
 
     public DOMMountPointServiceHandler getMountPointServiceHandler() {
@@ -142,4 +164,8 @@ public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
         mountPointServiceHandler = null;
         dataBroker = null;
     }
+
+    public final synchronized Set<Object> getServicesProperties() {
+        return servicesProperties.build();
+    }
 }