X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2FRestConnectorProvider.java;h=2aab6df3a243926742c4ca9499bfb30b6c7d878a;hb=c44b3ff43728dae97e039d75d793be187157ce00;hp=37eac281989533265848efcc819ad77f44ff7283;hpb=35ac72f0a7131610b7af7af7135bac89741675cd;p=netconf.git diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java index 37eac28198..2aab6df3a2 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java @@ -9,8 +9,6 @@ package org.opendaylight.restconf; import com.google.common.base.Preconditions; -import java.util.Collection; -import java.util.Collections; 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; @@ -18,8 +16,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.netconf.sal.rest.api.RestConnector; import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException; @@ -39,11 +35,11 @@ import org.slf4j.LoggerFactory; * Provider for restconf draft18. * */ -public class RestConnectorProvider implements Provider, RestConnector, AutoCloseable { +public class RestConnectorProvider implements RestConnector, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class); - public static final TransactionChainListener transactionListener = new TransactionChainListener() { + public static final TransactionChainListener TRANSACTION_CHAIN_LISTENER = new TransactionChainListener() { @Override public void onTransactionChainFailed(final TransactionChain chain, final AsyncTransaction transaction, final Throwable cause) { @@ -58,53 +54,67 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose } }; - private ListenerRegistration listenerRegistration; private static TransactionChainHandler transactionChainHandler; private static DOMDataBroker dataBroker; private static DOMMountPointServiceHandler mountPointServiceHandler; - @Override - public void onSessionInitiated(final ProviderSession session) { - final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class)); + private final SchemaService schemaService; + private final DOMRpcService rpcService; + private final DOMNotificationService notificationService; + private final DOMMountPointService mountPointService; + private ListenerRegistration listenerRegistration; + + private SchemaContextHandler schemaCtxHandler; + + public RestConnectorProvider(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService, + DOMNotificationService notificationService, DOMMountPointService mountPointService) { + this.schemaService = Preconditions.checkNotNull(schemaService); + this.rpcService = Preconditions.checkNotNull(rpcService); + this.notificationService = Preconditions.checkNotNull(notificationService); + this.mountPointService = Preconditions.checkNotNull(mountPointService); + + RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker); + } + public void start() { final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance(); - RestConnectorProvider.mountPointServiceHandler = new DOMMountPointServiceHandler( - session.getService(DOMMountPointService.class)); + mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService); - RestConnectorProvider.dataBroker = session.getService(DOMDataBroker.class); - final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(RestConnectorProvider.dataBroker); + final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker); - RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(RestConnectorProvider.dataBroker - .createTransactionChain(RestConnectorProvider.transactionListener)); + RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker + .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER)); - final SchemaContextHandler schemaCtxHandler = new SchemaContextHandler(transactionChainHandler); - this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler); + this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler); + this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler); - final DOMRpcService rpcService = session.getService(DOMRpcService.class); final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService); - final DOMNotificationService notificationService = session.getService(DOMNotificationService.class); final NotificationServiceHandler notificationServiceHandler = new NotificationServiceHandler(notificationService); - wrapperServices.setHandlers(schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler, + wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler, RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler, notificationServiceHandler); } + public DOMMountPointServiceHandler getMountPointServiceHandler() { + return mountPointServiceHandler; + } + /** * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain. * * @param chain - * - old {@link TransactionChain} + * old {@link TransactionChain} */ public static void resetTransactionChainForAdapaters(final TransactionChain chain) { LOG.trace("Resetting TransactionChain({})", chain); chain.close(); RestConnectorProvider.transactionChainHandler.update( - Preconditions.checkNotNull(RestConnectorProvider.dataBroker).createTransactionChain( - RestConnectorProvider.transactionListener) + Preconditions.checkNotNull(dataBroker).createTransactionChain( + RestConnectorProvider.TRANSACTION_CHAIN_LISTENER) ); } @@ -113,12 +123,7 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose * @return {@link DOMMountPointService} */ public static DOMMountPointService getMountPointService() { - return RestConnectorProvider.mountPointServiceHandler.get(); - } - - @Override - public Collection getProviderFunctionality() { - return Collections.emptySet(); + return mountPointServiceHandler.get(); } @Override @@ -129,8 +134,12 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose } // close transaction chain - if ((transactionChainHandler != null) && (transactionChainHandler.get() != null)) { + if (transactionChainHandler != null && transactionChainHandler.get() != null) { transactionChainHandler.get().close(); } + + transactionChainHandler = null; + mountPointServiceHandler = null; + dataBroker = null; } }