X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2FRestConnectorProvider.java;h=be7d7a878ec228444f7aa0cc447baaca522e411b;hb=6b8e4f7ee09ed344969ddad8017a7f41ad89f2d0;hp=1fa97116f2f07569ee8dfbb39811f8b5d4000f05;hpb=c9e58b14754cdc059ef63f870f74de65a5e0a15d;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java index 1fa97116f2..be7d7a878e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java @@ -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 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 listenerRegistration; + private final Builder servicesProperties; + private ListenerRegistration 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.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 getServicesProperties() { + return servicesProperties.build(); + } }