From 0cb415cf4cb61d85d545a1940bdde33734fa23a3 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 20 May 2014 16:08:23 -0700 Subject: [PATCH] BUG-620: replace xtend version of classes with Java versions replace xtend versions of classes with java versions where the java was generated by hand based on the source of the xtend file as well as leveraging the code generated from the xtend source Change-Id: I36a3a61608710543f66c36f7d5179cf976257953 Signed-off-by: David K. Bainbridge Signed-off-by: Robert Varga --- opendaylight/md-sal/sal-dom-broker/pom.xml | 8 - .../sal/dom/broker/BrokerConfigActivator.java | 134 +++++++++++ .../dom/broker/BrokerConfigActivator.xtend | 92 -------- .../controller/sal/dom/broker/BrokerImpl.java | 211 ++++++++++++++++++ .../sal/dom/broker/BrokerImpl.xtend | 140 ------------ .../sal/dom/broker/ConsumerContextImpl.java | 114 ++++++++++ .../sal/dom/broker/ConsumerContextImpl.xtend | 76 ------- .../sal/dom/broker/MountPointManagerImpl.java | 89 ++++++++ .../dom/broker/MountPointManagerImpl.xtend | 66 ------ .../sal/dom/broker/ProviderContextImpl.java | 90 ++++++++ .../sal/dom/broker/ProviderContextImpl.xtend | 92 -------- .../dom/broker/RpcRegistrationWrapper.java | 45 ++++ .../sal/dom/broker/impl/DataReaderRouter.java | 149 +++++++++++++ .../dom/broker/impl/DataReaderRouter.xtend | 106 --------- .../sal/dom/broker/impl/HashMapDataStore.java | 125 +++++++++++ .../dom/broker/impl/HashMapDataStore.xtend | 141 ------------ .../impl/HashMapDataStoreTransaction.java | 42 ++++ .../sal/dom/broker/osgi/ProxyFactory.java | 123 ++++++++++ .../sal/dom/broker/osgi/ProxyFactory.xtend | 66 ------ .../dom/broker/util/YangDataOperations.java | 169 ++++++++++++++ .../dom/broker/util/YangDataOperations.xtend | 117 ---------- 21 files changed, 1291 insertions(+), 904 deletions(-) create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/RpcRegistrationWrapper.java create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStoreTransaction.java create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend create mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.java delete mode 100644 opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.xtend diff --git a/opendaylight/md-sal/sal-dom-broker/pom.xml b/opendaylight/md-sal/sal-dom-broker/pom.xml index 162b66bda1..f73ee5c285 100644 --- a/opendaylight/md-sal/sal-dom-broker/pom.xml +++ b/opendaylight/md-sal/sal-dom-broker/pom.xml @@ -18,10 +18,6 @@ junit junit - - org.eclipse.xtend - org.eclipse.xtend.lib - org.opendaylight.controller config-api @@ -91,10 +87,6 @@ - - org.eclipse.xtend - xtend-maven-plugin - org.opendaylight.yangtools diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.java new file mode 100644 index 0000000000..7f834351d3 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import java.util.Hashtable; + +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker; +import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; +import org.opendaylight.controller.sal.core.api.data.DataBrokerService; +import org.opendaylight.controller.sal.core.api.data.DataProviderService; +import org.opendaylight.controller.sal.core.api.data.DataStore; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; +import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter; +import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker; +import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +public class BrokerConfigActivator implements AutoCloseable { + + private static InstanceIdentifier ROOT = InstanceIdentifier.builder() + .toInstance(); + + private DataProviderService dataService; + + private ServiceRegistration dataReg = null; + private ServiceRegistration dataProviderReg = null; + private ServiceRegistration mountReg = null; + private ServiceRegistration mountProviderReg = null; + private SchemaService schemaService = null; + private ServiceRegistration rpcProvisionRegistryReg = null; + private MountPointManagerImpl mountService = null; + + private SchemaAwareDataStoreAdapter wrappedStore = null; + + public void start(final BrokerImpl broker, final DataStore store, + final DOMDataBroker asyncBroker, final BundleContext context) { + + final Hashtable emptyProperties = new Hashtable(); + broker.setBundleContext(context); + + final ServiceReference serviceRef = context + .getServiceReference(SchemaService.class); + schemaService = context. getService(serviceRef); + + broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders + .fromSchemaService(schemaService))); + + if (asyncBroker == null) { + dataService = new DataBrokerImpl(); + dataProviderReg = context.registerService( + DataProviderService.class, dataService, emptyProperties); + + wrappedStore = new SchemaAwareDataStoreAdapter(); + wrappedStore.changeDelegate(store); + wrappedStore.setValidationEnabled(false); + context.registerService(SchemaServiceListener.class, wrappedStore, + emptyProperties); + + dataService.registerConfigurationReader(ROOT, wrappedStore); + dataService.registerCommitHandler(ROOT, wrappedStore); + dataService.registerOperationalReader(ROOT, wrappedStore); + } else { + BackwardsCompatibleDataBroker compatibleDataBroker = new BackwardsCompatibleDataBroker( + asyncBroker); + context.registerService(SchemaServiceListener.class, + compatibleDataBroker, emptyProperties); + dataService = compatibleDataBroker; + } + + mountService = new MountPointManagerImpl(); + dataReg = context.registerService(DataBrokerService.class, dataService, + emptyProperties); + mountReg = context.registerService(MountService.class, mountService, + emptyProperties); + mountProviderReg = context.registerService(MountProvisionService.class, + mountService, emptyProperties); + + rpcProvisionRegistryReg = context + .registerService(RpcProvisionRegistry.class, + broker.getRouter(), emptyProperties); + } + + @Override + public void close() { + + if (dataReg != null) { + dataReg.unregister(); + dataReg = null; + } + if (dataProviderReg != null) { + dataProviderReg.unregister(); + dataProviderReg = null; + } + if (mountReg != null) { + mountReg.unregister(); + mountReg = null; + } + if (mountProviderReg != null) { + mountProviderReg.unregister(); + mountProviderReg = null; + } + if (rpcProvisionRegistryReg != null) { + rpcProvisionRegistryReg.unregister(); + rpcProvisionRegistryReg = null; + } + } + + /** + * @return the dataService + */ + public DataProviderService getDataService() { + return dataService; + } + + /** + * @param dataService + * the dataService to set + */ + public void setDataService(final DataProviderService dataService) { + this.dataService = dataService; + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.xtend deleted file mode 100644 index 357a516b57..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.xtend +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.dom.broker - -import java.util.Hashtable -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker -import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry -import org.opendaylight.controller.sal.core.api.data.DataBrokerService -import org.opendaylight.controller.sal.core.api.data.DataProviderService -import org.opendaylight.controller.sal.core.api.data.DataStore -import org.opendaylight.controller.sal.core.api.model.SchemaService -import org.opendaylight.controller.sal.core.api.mount.MountProvisionService -import org.opendaylight.controller.sal.core.api.mount.MountService -import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter -import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker -import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener -import org.osgi.framework.BundleContext -import org.osgi.framework.ServiceRegistration - -class BrokerConfigActivator implements AutoCloseable { - - private static val ROOT = InstanceIdentifier.builder().toInstance(); - - @Property - private var DataProviderService dataService; - - private var ServiceRegistration dataReg; - private var ServiceRegistration dataProviderReg; - private var ServiceRegistration mountReg; - private var ServiceRegistration mountProviderReg; - private var SchemaService schemaService; - private var ServiceRegistration rpcProvisionRegistryReg; - private var MountPointManagerImpl mountService; - - SchemaAwareDataStoreAdapter wrappedStore - - public def void start(BrokerImpl broker, DataStore store, DOMDataBroker asyncBroker,BundleContext context) { - val emptyProperties = new Hashtable(); - broker.setBundleContext(context); - - val serviceRef = context.getServiceReference(SchemaService); - schemaService = context.getService(serviceRef); - - broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService))); - - - if(asyncBroker == null) { - dataService = new DataBrokerImpl(); - dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties); - - wrappedStore = new SchemaAwareDataStoreAdapter(); - wrappedStore.changeDelegate(store); - wrappedStore.setValidationEnabled(false); - context.registerService(SchemaServiceListener, wrappedStore, emptyProperties) - - dataService.registerConfigurationReader(ROOT, wrappedStore); - dataService.registerCommitHandler(ROOT, wrappedStore); - dataService.registerOperationalReader(ROOT, wrappedStore); - } else { - val compatibleDataBroker = new BackwardsCompatibleDataBroker(asyncBroker); - context.registerService(SchemaServiceListener,compatibleDataBroker,emptyProperties); - dataService = compatibleDataBroker; - } - - -// - - mountService = new MountPointManagerImpl(); - dataReg = context.registerService(DataBrokerService, dataService, emptyProperties); - mountReg = context.registerService(MountService, mountService, emptyProperties); - mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties); - - rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties); - } - - override def close() { - dataReg?.unregister(); - dataProviderReg?.unregister(); - mountReg?.unregister(); - mountProviderReg?.unregister(); - rpcProvisionRegistryReg?.unregister(); - } - -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.java new file mode 100644 index 0000000000..e4bd0343cf --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.java @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.Future; + +import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter; +import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; +import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; +import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.controller.sal.core.api.RpcRoutingContext; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation; + +public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable { + private final static Logger log = LoggerFactory.getLogger(BrokerImpl.class); + + // Broker Generic Context + private final Set sessions = Collections + .synchronizedSet(new HashSet()); + private final Set providerSessions = Collections + .synchronizedSet(new HashSet()); + + private BundleContext bundleContext = null; + + private AutoCloseable deactivator = null; + + private RpcRouter router = null; + + @Override + public ConsumerSession registerConsumer(final Consumer consumer, + final BundleContext ctx) { + checkPredicates(consumer); + log.trace("Registering consumer {}", consumer); + final ConsumerContextImpl session = newSessionFor(consumer, ctx); + consumer.onSessionInitiated(session); + sessions.add(session); + return session; + } + + @Override + public ProviderSession registerProvider(final Provider provider, + final BundleContext ctx) { + checkPredicates(provider); + final ProviderContextImpl session = newSessionFor(provider, ctx); + provider.onSessionInitiated(session); + providerSessions.add(session); + return session; + } + + protected Future> invokeRpcAsync(final QName rpc, + final CompositeNode input) { + return router.invokeRpc(rpc, input); + } + + // Validation + private void checkPredicates(final Provider prov) { + Preconditions.checkNotNull(prov, "Provider should not be null."); + for (ProviderContextImpl session : providerSessions) { + if (prov.equals(session.getProvider())) + throw new IllegalStateException("Provider already registered"); + } + + } + + private void checkPredicates(final Consumer cons) { + Preconditions.checkNotNull(cons, "Consumer should not be null."); + for (ConsumerContextImpl session : sessions) { + if (cons.equals(session.getConsumer())) + throw new IllegalStateException("Consumer already registered"); + } + } + + // Private Factory methods + private ConsumerContextImpl newSessionFor(final Consumer provider, + final BundleContext ctx) { + ConsumerContextImpl ret = new ConsumerContextImpl(provider, ctx); + ret.setBroker(this); + return ret; + } + + private ProviderContextImpl newSessionFor(final Provider provider, + final BundleContext ctx) { + ProviderContextImpl ret = new ProviderContextImpl(provider, ctx); + ret.setBroker(this); + return ret; + } + + protected void consumerSessionClosed( + final ConsumerContextImpl consumerContextImpl) { + sessions.remove(consumerContextImpl); + providerSessions.remove(consumerContextImpl); + } + + @Override + public void close() throws Exception { + if (deactivator != null) { + deactivator.close(); + deactivator = null; + } + } + + @Override + public RpcRegistration addRpcImplementation(final QName rpcType, + final RpcImplementation implementation) + throws IllegalArgumentException { + return router.addRpcImplementation(rpcType, implementation); + } + + @Override + public RoutedRpcRegistration addRoutedRpcImplementation( + final QName rpcType, final RpcImplementation implementation) { + return router.addRoutedRpcImplementation(rpcType, implementation); + } + + @Override + public void setRoutedRpcDefaultDelegate( + final RoutedRpcDefaultImplementation defaultImplementation) { + router.setRoutedRpcDefaultDelegate(defaultImplementation); + } + + @Override + public ListenerRegistration addRpcRegistrationListener( + final RpcRegistrationListener listener) { + return router.addRpcRegistrationListener(listener); + } + + @Override + public > ListenerRegistration registerRouteChangeListener( + final L listener) { + return router.registerRouteChangeListener(listener); + } + + @Override + public Set getSupportedRpcs() { + return router.getSupportedRpcs(); + } + + @Override + public ListenableFuture> invokeRpc( + final QName rpc, final CompositeNode input) { + return router.invokeRpc(rpc, input); + } + + /** + * @return the bundleContext + */ + public BundleContext getBundleContext() { + return bundleContext; + } + + /** + * @param bundleContext + * the bundleContext to set + */ + public void setBundleContext(final BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + + /** + * @return the deactivator + */ + public AutoCloseable getDeactivator() { + return deactivator; + } + + /** + * @param deactivator + * the deactivator to set + */ + public void setDeactivator(final AutoCloseable deactivator) { + this.deactivator = deactivator; + } + + /** + * @return the router + */ + public RpcRouter getRouter() { + return router; + } + + /** + * @param router + * the router to set + */ + public void setRouter(final RpcRouter router) { + this.router = router; + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend deleted file mode 100644 index 0ed14c1027..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.dom.broker; - -import com.google.common.util.concurrent.ListenableFuture -import java.util.Collections -import java.util.HashSet -import java.util.Set -import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener -import org.opendaylight.controller.sal.core.api.Broker -import org.opendaylight.controller.sal.core.api.Consumer -import org.opendaylight.controller.sal.core.api.Provider -import org.opendaylight.yangtools.yang.common.QName -import org.opendaylight.yangtools.yang.common.RpcResult -import org.opendaylight.yangtools.yang.data.api.CompositeNode -import org.osgi.framework.BundleContext -import org.slf4j.LoggerFactory -import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry -import org.opendaylight.controller.sal.core.api.RpcImplementation -import org.opendaylight.controller.sal.core.api.RpcRoutingContext -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation - -public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable { - private static val log = LoggerFactory.getLogger(BrokerImpl); - - // Broker Generic Context - private val Set sessions = Collections.synchronizedSet(new HashSet()); - private val Set providerSessions = Collections.synchronizedSet( - new HashSet()); - - @Property - private var BundleContext bundleContext; - - @Property - private var AutoCloseable deactivator; - - @Property - private var RpcRouter router; - - override registerConsumer(Consumer consumer, BundleContext ctx) { - checkPredicates(consumer); - log.trace("Registering consumer " + consumer); - val session = newSessionFor(consumer, ctx); - consumer.onSessionInitiated(session); - sessions.add(session); - return session; - } - - override registerProvider(Provider provider, BundleContext ctx) { - checkPredicates(provider); - - val session = newSessionFor(provider, ctx); - provider.onSessionInitiated(session); - providerSessions.add(session); - return session; - } - - protected def ListenableFuture> invokeRpcAsync(QName rpc, CompositeNode input) { - return router.invokeRpc(rpc, input); - } - - // Validation - private def void checkPredicates(Provider prov) { - if (prov == null) - throw new IllegalArgumentException("Provider should not be null."); - for (ProviderContextImpl session : providerSessions) { - if (prov.equals(session.getProvider())) - throw new IllegalStateException("Provider already registered"); - } - - } - - private def void checkPredicates(Consumer cons) { - if (cons == null) - throw new IllegalArgumentException("Consumer should not be null."); - for (ConsumerContextImpl session : sessions) { - if (cons.equals(session.getConsumer())) - throw new IllegalStateException("Consumer already registered"); - } - } - - // Private Factory methods - private def ConsumerContextImpl newSessionFor(Consumer provider, BundleContext ctx) { - val ret = new ConsumerContextImpl(provider, ctx); - ret.broker = this; - return ret; - } - - private def ProviderContextImpl newSessionFor(Provider provider, BundleContext ctx) { - val ret = new ProviderContextImpl(provider, ctx); - ret.broker = this; - return ret; - } - - protected def void consumerSessionClosed(ConsumerContextImpl consumerContextImpl) { - sessions.remove(consumerContextImpl); - providerSessions.remove(consumerContextImpl); - } - - override close() throws Exception { - deactivator?.close(); - } - - override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException { - router.addRpcImplementation(rpcType,implementation); - } - - override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) { - router.addRoutedRpcImplementation(rpcType,implementation); - } - - override setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) { - router.setRoutedRpcDefaultDelegate(defaultImplementation); - } - - override addRpcRegistrationListener(RpcRegistrationListener listener) { - return router.addRpcRegistrationListener(listener); - } - - override > registerRouteChangeListener(L listener) { - return router.registerRouteChangeListener(listener); - } - - override getSupportedRpcs() { - return router.getSupportedRpcs(); - } - - override invokeRpc(QName rpc, CompositeNode input) { - return router.invokeRpc(rpc,input) - } - -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.java new file mode 100644 index 0000000000..fa81bc9040 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import java.util.Collection; +import java.util.concurrent.Future; + +import javax.annotation.concurrent.GuardedBy; + +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.dom.broker.osgi.AbstractBrokerServiceProxy; +import org.opendaylight.controller.sal.dom.broker.osgi.ProxyFactory; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import com.google.common.collect.ClassToInstanceMap; +import com.google.common.collect.MutableClassToInstanceMap; + +class ConsumerContextImpl implements ConsumerSession { + + private final ClassToInstanceMap instantiatedServices = MutableClassToInstanceMap + .create(); + private final BundleContext context; + private final Consumer consumer; + + private BrokerImpl broker = null; + @GuardedBy("this") + private boolean closed = false; + + public ConsumerContextImpl(final Consumer consumer, final BundleContext ctx) { + this.consumer = consumer; + this.context = ctx; + } + + @Override + public Future> rpc(final QName rpc, + final CompositeNode input) { + return broker.invokeRpcAsync(rpc, input); + } + + @Override + public T getService(final Class service) { + final T localProxy = instantiatedServices.getInstance(service); + if (localProxy != null) { + return localProxy; + } + final ServiceReference serviceRef = context + .getServiceReference(service); + if (serviceRef == null) { + return null; + } + final T serviceImpl = context.getService(serviceRef); + final T ret = ProxyFactory.createProxy(serviceRef, serviceImpl); + if (ret != null) { + instantiatedServices.putInstance(service, ret); + } + return ret; + } + + @Override + public void close() { + synchronized (this) { + if (closed) { + return; + } + this.closed = true; + } + + Collection toStop = instantiatedServices.values(); + for (BrokerService brokerService : toStop) { + if (brokerService instanceof AbstractBrokerServiceProxy) { + ((AbstractBrokerServiceProxy) brokerService).close(); + } + } + broker.consumerSessionClosed(this); + } + + @Override + public synchronized boolean isClosed() { + return closed; + } + + /** + * @return the broker + */ + public BrokerImpl getBroker() { + return broker; + } + + /** + * @param broker + * the broker to set + */ + public void setBroker(final BrokerImpl broker) { + this.broker = broker; + } + + /** + * @return the _consumer + */ + public Consumer getConsumer() { + return consumer; + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.xtend deleted file mode 100644 index 813f52b67d..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ConsumerContextImpl.xtend +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker - -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession -import org.opendaylight.controller.sal.core.api.BrokerService -import org.opendaylight.controller.sal.core.api.Consumer -import org.osgi.framework.BundleContext -import org.opendaylight.yangtools.yang.common.QName -import org.opendaylight.yangtools.yang.data.api.CompositeNode -import org.opendaylight.controller.sal.dom.broker.osgi.AbstractBrokerServiceProxy -import com.google.common.collect.ClassToInstanceMap -import com.google.common.collect.MutableClassToInstanceMap -import org.opendaylight.controller.sal.dom.broker.osgi.ProxyFactory - -class ConsumerContextImpl implements ConsumerSession { - - @Property - private val Consumer consumer; - - @Property - private var BrokerImpl broker; - - private val ClassToInstanceMap instantiatedServices = MutableClassToInstanceMap.create(); - private boolean closed = false; - - private BundleContext context; - - public new(Consumer consumer, BundleContext ctx) { - this._consumer = consumer; - this.context = ctx; - } - - override rpc(QName rpc, CompositeNode input) { - return broker.invokeRpcAsync(rpc, input); - } - - override T getService(Class service) { - val localProxy = instantiatedServices.getInstance(service); - if(localProxy != null) { - return localProxy; - } - val serviceRef = context.getServiceReference(service); - if(serviceRef == null) { - return null; - } - val serviceImpl = context.getService(serviceRef); - - - val ret = ProxyFactory.createProxy(serviceRef,serviceImpl); - if(ret != null) { - instantiatedServices.putInstance(service, ret); - } - return ret; - } - - override close() { - val toStop = instantiatedServices.values(); - this.closed = true; - for (BrokerService brokerService : toStop) { - if(brokerService instanceof AbstractBrokerServiceProxy) { - (brokerService as AutoCloseable).close(); - } - } - broker.consumerSessionClosed(this); - } - - override isClosed() { - return closed; - } -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java new file mode 100644 index 0000000000..55a6ee77b4 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import static com.google.common.base.Preconditions.checkState; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.opendaylight.controller.sal.core.api.data.DataProviderService; +import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance; +import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.util.ListenerRegistry; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; + +public class MountPointManagerImpl implements MountProvisionService { + + private final ListenerRegistry listeners = + ListenerRegistry.create(); + private final ConcurrentMap mounts = + new ConcurrentHashMap<>(); + private DataProviderService dataBroker = null; + + @Override + public MountProvisionInstance createMountPoint(final InstanceIdentifier path) { + checkState(!mounts.containsKey(path), "Mount already created"); + final MountPointImpl mount = new MountPointImpl(path); + registerMountPoint(mount); + mounts.put(path, mount); + notifyMountCreated(path); + return mount; + } + + public void notifyMountCreated(final InstanceIdentifier identifier) { + for (final ListenerRegistration listener : listeners + .getListeners()) { + listener.getInstance().onMountPointCreated(identifier); + } + } + + public Object registerMountPoint(final MountPointImpl impl) { + // FIXME: Why is thie commented out? Either we need it or we don't + // dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper); + // dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper); + return null; + } + + @Override + public MountProvisionInstance createOrGetMountPoint( + final InstanceIdentifier path) { + final MountPointImpl mount = mounts.get(path); + if (mount == null) { + return createMountPoint(path); + } + return mount; + } + + @Override + public MountProvisionInstance getMountPoint(final InstanceIdentifier path) { + return mounts.get(path); + } + + /** + * @return the dataBroker + */ + public DataProviderService getDataBroker() { + return dataBroker; + } + + /** + * @param dataBroker + * the dataBroker to set + */ + public void setDataBroker(final DataProviderService dataBroker) { + this.dataBroker = dataBroker; + } + + @Override + public ListenerRegistration registerProvisionListener( + final MountProvisionListener listener) { + return listeners.register(listener); + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend deleted file mode 100644 index 023f906a67..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker - - -import org.opendaylight.controller.sal.core.api.mount.MountProvisionService -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import java.util.concurrent.ConcurrentMap -import java.util.concurrent.ConcurrentHashMap -import static com.google.common.base.Preconditions.*; -import org.opendaylight.controller.sal.core.api.data.DataProviderService -import org.opendaylight.controller.sal.core.api.mount.MountProvisionService.MountProvisionListener -import org.opendaylight.yangtools.concepts.util.ListenerRegistry - -class MountPointManagerImpl implements MountProvisionService { - - @Property - DataProviderService dataBroker; - - val ListenerRegistry listeners = ListenerRegistry.create() - - ConcurrentMap mounts = new ConcurrentHashMap(); - - override createMountPoint(InstanceIdentifier path) { - checkState(!mounts.containsKey(path),"Mount already created"); - val mount = new MountPointImpl(path); - registerMountPoint(mount); - mounts.put(path,mount); - notifyMountCreated(path); - return mount; - } - - def notifyMountCreated(InstanceIdentifier identifier) { - for(listener : listeners) { - listener.instance.onMountPointCreated(identifier); - } - } - - def registerMountPoint(MountPointImpl impl) { - //dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper); - //dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper); - } - - override registerProvisionListener(MountProvisionListener listener) { - listeners.register(listener) - } - - - override createOrGetMountPoint(InstanceIdentifier path) { - val mount = mounts.get(path); - if(mount === null) { - return createMountPoint(path) - } - return mount; - } - - - override getMountPoint(InstanceIdentifier path) { - mounts.get(path); - } -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.java new file mode 100644 index 0000000000..5e8c0e8253 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import java.util.HashSet; +import java.util.Set; + +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration; +import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.common.QName; +import org.osgi.framework.BundleContext; + +class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession { + private final Set registrations = new HashSet<>(); + private final Provider provider; + + public ProviderContextImpl(final Provider provider, final BundleContext ctx) { + super(null, ctx); + this.provider = provider; + } + + @Override + public RpcRegistrationWrapper addRpcImplementation(final QName rpcType, + final RpcImplementation implementation) throws IllegalArgumentException { + final RpcRegistration origReg = getBroker().getRouter() + .addRpcImplementation(rpcType, implementation); + final RpcRegistrationWrapper newReg = new RpcRegistrationWrapper( + origReg); + registrations.add(newReg); + return newReg; + } + + protected boolean removeRpcImplementation(final RpcRegistrationWrapper implToRemove) { + return registrations.remove(implToRemove); + } + + @Override + public void close() { + for (final RpcRegistrationWrapper reg : registrations) { + reg.close(); + } + } + + @Override + public RoutedRpcRegistration addMountedRpcImplementation( + final QName rpcType, final RpcImplementation implementation) { + throw new UnsupportedOperationException( + "TODO: auto-generated method stub"); + } + + @Override + public RoutedRpcRegistration addRoutedRpcImplementation( + final QName rpcType, final RpcImplementation implementation) { + throw new UnsupportedOperationException( + "TODO: auto-generated method stub"); + } + + @Override + public Set getSupportedRpcs() { + return getBroker().getRouter().getSupportedRpcs(); + } + + @Override + public ListenerRegistration addRpcRegistrationListener( + final RpcRegistrationListener listener) { + return getBroker().getRouter().addRpcRegistrationListener(listener); + } + + /** + * @return the provider + */ + public Provider getProvider() { + return provider; + } + + /** + * @param provider + * the provider to set + */ +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend deleted file mode 100644 index e641ed1039..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker - -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession -import org.opendaylight.controller.sal.core.api.Provider -import org.opendaylight.controller.sal.core.api.RpcImplementation -import org.opendaylight.yangtools.yang.common.QName -import org.osgi.framework.BundleContext -import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener -import org.opendaylight.yangtools.concepts.Registration - -import java.util.Set -import java.util.HashSet - -class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession { - - @Property - private val Provider provider; - - private val Set> registrations = new HashSet(); - - new(Provider provider, BundleContext ctx) { - super(null, ctx); - this._provider = provider; - } - - override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException { - val origReg = broker.router.addRpcImplementation(rpcType, implementation); - val newReg = new RpcRegistrationWrapper(origReg); - registrations.add(newReg); - return newReg; - } - - protected def removeRpcImplementation(RpcRegistrationWrapper implToRemove) throws IllegalArgumentException { - registrations.remove(implToRemove); - } - - override close() { - - for (reg : registrations) { - reg.close() - } - super.close - } - - override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") - } - - override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") - } - - override getSupportedRpcs() { - broker.router.supportedRpcs; - } - - override addRpcRegistrationListener(RpcRegistrationListener listener) { - broker.router.addRpcRegistrationListener(listener); - } -} - -class RpcRegistrationWrapper implements RpcRegistration { - - - @Property - val RpcRegistration delegate - - new(RpcRegistration delegate) { - _delegate = delegate - } - - override getInstance() { - delegate.instance - } - - override close() { - delegate.close - } - - override getType() { - delegate.type - } -} - diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/RpcRegistrationWrapper.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/RpcRegistrationWrapper.java new file mode 100644 index 0000000000..db6c72e2ff --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/RpcRegistrationWrapper.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker; + +import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; +import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.yangtools.yang.common.QName; + +import com.google.common.base.Preconditions; + +public class RpcRegistrationWrapper implements RpcRegistration { + + private final RpcRegistration delegate; + + public RpcRegistrationWrapper(final RpcRegistration delegate) { + this.delegate = Preconditions.checkNotNull(delegate); + } + + @Override + public RpcImplementation getInstance() { + return delegate.getInstance(); + } + + @Override + public void close() { + delegate.close(); + } + + @Override + public QName getType() { + return delegate.getType(); + } + + /** + * @return the delegate + */ + public RpcRegistration getDelegate() { + return delegate; + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.java new file mode 100644 index 0000000000..53423f6b09 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.impl; + +import static com.google.common.base.Preconditions.checkState; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.Iterables; + +public class DataReaderRouter extends +AbstractDataReadRouter { + private final static Logger LOG = LoggerFactory + .getLogger(DataReaderRouter.class); + private final static URI NETCONF_NAMESPACE = URI + .create("urn:ietf:params:xml:ns:netconf:base:1.0"); + private final static QName NETCONF_DATA = new QName(NETCONF_NAMESPACE, + "data"); + + @Override + protected CompositeNodeTOImpl merge(final InstanceIdentifier path, + final Iterable data) { + PathArgument pathArgument = Iterables.getLast(path.getPath(), null); + boolean empty = true; + QName name = (pathArgument == null ? null : pathArgument.getNodeType()); + final ArrayList> nodes = new ArrayList>(); + final HashMap> keyNodes = new HashMap>(); + for (final CompositeNode dataBit : data) { + try { + if (pathArgument != null && dataBit != null) { + empty = false; + final Map> keyNodesLocal = getKeyNodes( + pathArgument, dataBit); + nodes.addAll(this.childrenWithout(dataBit, + keyNodesLocal.entrySet())); + } else if (dataBit != null) { + empty = false; + nodes.addAll(dataBit.getValue()); + } + } catch (IllegalStateException e) { + LOG.error("BUG: Readed data for path {} was invalid", path, e); + } + } + if (empty) { + return null; + } + /** + * Reading from Root + * + */ + if (pathArgument == null) { + return new CompositeNodeTOImpl(NETCONF_DATA, null, nodes); + } + final ArrayList> finalNodes = new ArrayList>( + nodes.size() + keyNodes.size()); + finalNodes.addAll(keyNodes.values()); + finalNodes.addAll(nodes); + return new CompositeNodeTOImpl(name, null, finalNodes); + } + + protected Map> _getKeyNodes( + final PathArgument argument, final CompositeNode node) { + return Collections.emptyMap(); + } + + protected Map> _getKeyNodes( + final NodeIdentifierWithPredicates argument, + final CompositeNode node) { + final HashMap> ret = new HashMap>(); + for (final Entry keyValue : argument.getKeyValues() + .entrySet()) { + final List> simpleNode = node + .getSimpleNodesByName(keyValue.getKey()); + if (simpleNode != null && !simpleNode.isEmpty()) { + checkState( + simpleNode.size() <= 1, + "Only one simple node for key $s is allowed in node $s", + keyValue.getKey(), node); + checkState( + simpleNode.get(0).getValue() == keyValue.getValue(), + "Key node must equal to instance identifier value in node $s", + node); + ret.put(keyValue.getKey(), simpleNode.get(0)); + } + final List compositeNode = node + .getCompositesByName(keyValue.getKey()); + checkState(compositeNode == null || compositeNode.isEmpty(), + "Key node must be Simple Node, not composite node."); + } + return ret; + } + + public Map> getKeyNodes( + final InstanceIdentifier.PathArgument argument, + final CompositeNode node) { + if (argument instanceof InstanceIdentifier.NodeIdentifierWithPredicates) { + return _getKeyNodes( + (InstanceIdentifier.NodeIdentifierWithPredicates) argument, + node); + } else if (argument != null) { + return _getKeyNodes(argument, node); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays. asList(argument, node).toString()); + } + } + + private Collection> childrenWithout( + final CompositeNode node, + final Set>> entries) { + if (entries.isEmpty()) { + return node.getValue(); + } + final List> filteredNodes = new ArrayList>(); + for (final Node scannedNode : node.getValue()) { + if (!entries.contains(scannedNode.getNodeType())) { + filteredNodes.add(scannedNode); + } + } + return filteredNodes; + } + +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend deleted file mode 100644 index 95d0018b21..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.impl - -import java.net.URI -import java.util.ArrayList -import java.util.Collection -import java.util.Collections -import java.util.HashMap -import java.util.Map -import java.util.Map.Entry -import java.util.Set -import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter -import org.opendaylight.yangtools.yang.common.QName -import org.opendaylight.yangtools.yang.data.api.CompositeNode -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument -import org.opendaylight.yangtools.yang.data.api.Node -import org.opendaylight.yangtools.yang.data.api.SimpleNode -import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl -import org.slf4j.LoggerFactory - -import static com.google.common.base.Preconditions.* - -class DataReaderRouter extends AbstractDataReadRouter { - private static val LOG = LoggerFactory.getLogger(DataReaderRouter); - private static val NETCONF_NAMESPACE = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0") - private static val NETCONF_DATA = new QName(NETCONF_NAMESPACE,"data"); - - override protected merge(InstanceIdentifier path, Iterable data) { - val pathArgument = path.path.last; - var empty = true; - var name = pathArgument?.nodeType; - val nodes = new ArrayList>(); - val keyNodes = new HashMap>(); - for(dataBit : data) { - try { - if(pathArgument != null && dataBit != null) { - empty = false; - val keyNodesLocal = getKeyNodes(pathArgument,dataBit); - nodes.addAll(dataBit.childrenWithout(keyNodesLocal.entrySet)); - } else if (dataBit != null) { - empty = false; - nodes.addAll(dataBit.children) - } - } catch (IllegalStateException e) { - LOG.error("BUG: Readed data for path {} was invalid",path,e); - } - } - if(empty) { - return null; - } - /** - * Reading from Root - * - */ - if(pathArgument == null) { - return new CompositeNodeTOImpl(NETCONF_DATA,null,nodes); - } - val finalNodes = new ArrayList>(); - finalNodes.addAll(keyNodes.values); - finalNodes.addAll(nodes); - return new CompositeNodeTOImpl(name,null,finalNodes); - } - - - - dispatch def Map> getKeyNodes(PathArgument argument, CompositeNode node) { - return Collections.emptyMap(); - } - - dispatch def getKeyNodes(NodeIdentifierWithPredicates argument, CompositeNode node) { - val ret = new HashMap>(); - for (keyValue : argument.keyValues.entrySet) { - val simpleNode = node.getSimpleNodesByName(keyValue.key); - if(simpleNode !== null && !simpleNode.empty) { - checkState(simpleNode.size <= 1,"Only one simple node for key $s is allowed in node $s",keyValue.key,node); - checkState(simpleNode.get(0).value == keyValue.value,"Key node must equal to instance identifier value in node $s",node); - ret.put(keyValue.key,simpleNode.get(0)); - } - val compositeNode = node.getCompositesByName(keyValue.key); - checkState(compositeNode === null || compositeNode.empty,"Key node must be Simple Node, not composite node."); - } - return ret; - } - - def Collection> childrenWithout(CompositeNode node, Set>> entries) { - if(entries.empty) { - return node.children; - } - val filteredNodes = new ArrayList>(); - for(scannedNode : node.children) { - if(!entries.contains(scannedNode.nodeType)) { - filteredNodes.add(scannedNode); - } - } - return filteredNodes; - } - -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.java new file mode 100644 index 0000000000..50dfbe852b --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.impl; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.controller.sal.common.util.Rpcs; +import org.opendaylight.controller.sal.core.api.data.DataStore; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class HashMapDataStore implements DataStore, AutoCloseable { + private static final Logger LOG = LoggerFactory + .getLogger(HashMapDataStore.class); + + private final Map configuration = new ConcurrentHashMap(); + private final Map operational = new ConcurrentHashMap(); + + @Override + public boolean containsConfigurationPath(final InstanceIdentifier path) { + return configuration.containsKey(path); + } + + @Override + public boolean containsOperationalPath(final InstanceIdentifier path) { + return operational.containsKey(path); + } + + @Override + public Iterable getStoredConfigurationPaths() { + return configuration.keySet(); + } + + @Override + public Iterable getStoredOperationalPaths() { + return operational.keySet(); + } + + @Override + public CompositeNode readConfigurationData(final InstanceIdentifier path) { + LOG.trace("Reading configuration path {}", path); + return configuration.get(path); + } + + @Override + public CompositeNode readOperationalData(InstanceIdentifier path) { + LOG.trace("Reading operational path {}", path); + return operational.get(path); + } + + @Override + public DataCommitHandler.DataCommitTransaction requestCommit( + final DataModification modification) { + return new HashMapDataStoreTransaction(modification, this); + } + + public RpcResult rollback(HashMapDataStoreTransaction transaction) { + return Rpcs. getRpcResult(true, null, + Collections. emptySet()); + } + + public RpcResult finish(HashMapDataStoreTransaction transaction) { + final DataModification modification = transaction + .getModification(); + for (final InstanceIdentifier removal : modification + .getRemovedConfigurationData()) { + LOG.trace("Removing configuration path {}", removal); + remove(configuration, removal); + } + for (final InstanceIdentifier removal : modification + .getRemovedOperationalData()) { + LOG.trace("Removing operational path {}", removal); + remove(operational, removal); + } + if (LOG.isTraceEnabled()) { + for (final InstanceIdentifier a : modification + .getUpdatedConfigurationData().keySet()) { + LOG.trace("Adding configuration path {}", a); + } + for (final InstanceIdentifier a : modification + .getUpdatedOperationalData().keySet()) { + LOG.trace("Adding operational path {}", a); + } + } + configuration.putAll(modification.getUpdatedConfigurationData()); + operational.putAll(modification.getUpdatedOperationalData()); + + return Rpcs. getRpcResult(true, null, + Collections. emptySet()); + } + + public void remove(final Map map, + final InstanceIdentifier identifier) { + Set affected = new HashSet(); + for (final InstanceIdentifier path : map.keySet()) { + if (identifier.contains(path)) { + affected.add(path); + } + } + for (final InstanceIdentifier pathToRemove : affected) { + LOG.trace("Removed path {}", pathToRemove); + map.remove(pathToRemove); + } + } + + @Override + public void close() { + // NOOP + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.xtend deleted file mode 100644 index 12835ccf0a..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.xtend +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.impl - -import org.opendaylight.controller.md.sal.common.api.data.DataModification -import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction -import org.opendaylight.yangtools.yang.common.RpcResult -import java.util.Map -import java.util.concurrent.ConcurrentHashMap -import org.opendaylight.controller.sal.common.util.Rpcs -import java.util.Collections -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import org.opendaylight.yangtools.yang.data.api.CompositeNode -import org.opendaylight.controller.sal.core.api.data.DataStore -import java.util.HashSet -import org.slf4j.LoggerFactory -import org.slf4j.Logger - -final class HashMapDataStore implements DataStore, AutoCloseable { - private val Logger LOG = LoggerFactory.getLogger(HashMapDataStore) - - val Map configuration = new ConcurrentHashMap(); - val Map operational = new ConcurrentHashMap(); - - - - override containsConfigurationPath(InstanceIdentifier path) { - return configuration.containsKey(path) - } - - override containsOperationalPath(InstanceIdentifier path) { - return operational.containsKey(path) - } - - override getStoredConfigurationPaths() { - configuration.keySet - } - - override getStoredOperationalPaths() { - operational.keySet - } - - override readConfigurationData(InstanceIdentifier path) { - LOG.trace("Reading configuration path {}", path) - configuration.get(path); - } - - override readOperationalData(InstanceIdentifier path) { - LOG.trace("Reading operational path {}", path) - operational.get(path); - } - - - - override requestCommit(DataModification modification) { - return new HashMapDataStoreTransaction(modification, this); - } - - def RpcResult rollback(HashMapDataStoreTransaction transaction) { - return Rpcs.getRpcResult(true, null, Collections.emptySet); - } - - def RpcResult finish(HashMapDataStoreTransaction transaction) { - val modification = transaction.modification; - for (removal : modification.removedConfigurationData) { - LOG.trace("Removing configuration path {}", removal) - remove(configuration,removal); - } - for (removal : modification.removedOperationalData) { - LOG.trace("Removing operational path {}", removal) - remove(operational,removal); - } - if (LOG.isTraceEnabled()) { - for (a : modification.updatedConfigurationData.keySet) { - LOG.trace("Adding configuration path {}", a) - } - for (a : modification.updatedOperationalData.keySet) { - LOG.trace("Adding operational path {}", a) - } - } - configuration.putAll(modification.updatedConfigurationData); - operational.putAll(modification.updatedOperationalData); - - return Rpcs.getRpcResult(true, null, Collections.emptySet); - } - - def remove(Map map, InstanceIdentifier identifier) { - val affected = new HashSet(); - for(path : map.keySet) { - if(identifier.contains(path)) { - affected.add(path); - } - } - for(pathToRemove : affected) { - LOG.trace("Removed path {}", pathToRemove) - map.remove(pathToRemove); - } - - } - - - override close() { - // NOOP - } - -} - -class HashMapDataStoreTransaction implements // -DataCommitTransaction { - @Property - val DataModification modification - - @Property - val HashMapDataStore datastore; - - new( - DataModification modify, - HashMapDataStore store - ) { - _modification = modify; - _datastore = store; - } - - override finish() throws IllegalStateException { - datastore.finish(this); - - } - - override getModification() { - this._modification; - } - - override rollback() throws IllegalStateException { - datastore.rollback(this); - } -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStoreTransaction.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStoreTransaction.java new file mode 100644 index 0000000000..bb66594ac9 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStoreTransaction.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.impl; + +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; + +public class HashMapDataStoreTransaction implements + DataCommitTransaction { + private final DataModification modification; + private final HashMapDataStore datastore; + + HashMapDataStoreTransaction( + final DataModification modify, + final HashMapDataStore store) { + modification = modify; + datastore = store; + } + + @Override + public RpcResult finish() throws IllegalStateException { + return datastore.finish(this); + } + + @Override + public DataModification getModification() { + return this.modification; + } + + @Override + public RpcResult rollback() throws IllegalStateException { + return datastore.rollback(this); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java new file mode 100644 index 0000000000..c2d6add17a --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.osgi; + +import java.util.Arrays; + +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.osgi.framework.ServiceReference; +import org.opendaylight.controller.sal.core.api.data.DataBrokerService; +import org.opendaylight.controller.sal.core.api.data.DataProviderService; +import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService; +import org.opendaylight.controller.sal.core.api.notify.NotificationService; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; +import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; + +@SuppressWarnings("unchecked") +public class ProxyFactory { + + public static T createProxy( + final ServiceReference serviceRef, final T service) { + + Object _createProxyImpl = ProxyFactory.createProxyImpl(serviceRef, + service); + return ((T) _createProxyImpl); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final DataBrokerService service) { + + return new DataBrokerServiceProxy( + ((ServiceReference) ref), service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final DataProviderService service) { + + return new DataProviderServiceProxy( + ((ServiceReference) ref), service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final NotificationPublishService service) { + + return new NotificationPublishServiceProxy( + ((ServiceReference) ref), service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final NotificationService service) { + + return new NotificationServiceProxy( + ((ServiceReference) ref), service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final MountProvisionService service) { + + return new MountProviderServiceProxy( + ((ServiceReference) ref), service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final SchemaService service) { + + return new SchemaServiceProxy(((ServiceReference) ref), + service); + } + + private static Object _createProxyImpl(final ServiceReference ref, + final RpcProvisionRegistry service) { + + return new RpcProvisionRegistryProxy( + ((ServiceReference) ref), service); + } + + private static DOMDataBrokerProxy _createProxyImpl( + final ServiceReference ref, final DOMDataBroker service) { + + return new DOMDataBrokerProxy(((ServiceReference) ref), + service); + } + + private static Object _createProxyImpl(final ServiceReference reference, + final BrokerService service) { + + throw new IllegalArgumentException("Not supported class: " + + service.getClass().getName()); + } + + private static Object createProxyImpl(final ServiceReference ref, + final BrokerService service) { + + if (service instanceof DOMDataBroker) { + return _createProxyImpl(ref, (DOMDataBroker) service); + } else if (service instanceof RpcProvisionRegistry) { + return _createProxyImpl(ref, (RpcProvisionRegistry) service); + } else if (service instanceof DataProviderService) { + return _createProxyImpl(ref, (DataProviderService) service); + } else if (service instanceof MountProvisionService) { + return _createProxyImpl(ref, (MountProvisionService) service); + } else if (service instanceof NotificationPublishService) { + return _createProxyImpl(ref, (NotificationPublishService) service); + } else if (service instanceof DataBrokerService) { + return _createProxyImpl(ref, (DataBrokerService) service); + } else if (service instanceof SchemaService) { + return _createProxyImpl(ref, (SchemaService) service); + } else if (service instanceof NotificationService) { + return _createProxyImpl(ref, (NotificationService) service); + } else if (service != null) { + return _createProxyImpl(ref, service); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays. asList(ref, service).toString()); + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend deleted file mode 100644 index d0afc3f47d..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.osgi - -import org.opendaylight.controller.sal.core.api.BrokerService -import org.osgi.framework.ServiceReference -import org.opendaylight.controller.sal.core.api.data.DataBrokerService -import org.opendaylight.controller.sal.core.api.data.DataProviderService -import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService -import org.opendaylight.controller.sal.core.api.notify.NotificationService -import org.opendaylight.controller.sal.core.api.model.SchemaService -import org.opendaylight.controller.sal.core.api.mount.MountProvisionService -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker - -class ProxyFactory { - - static def T createProxy(ServiceReference serviceRef, T service) { - return createProxyImpl(serviceRef, service) as T; - } - - - private static def dispatch createProxyImpl(ServiceReference ref, DataBrokerService service) { - new DataBrokerServiceProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, DataProviderService service) { - new DataProviderServiceProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, NotificationPublishService service) { - new NotificationPublishServiceProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, NotificationService service) { - new NotificationServiceProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, MountProvisionService service) { - new MountProviderServiceProxy(ref as ServiceReference, service); - } - - - private static def dispatch createProxyImpl(ServiceReference ref, SchemaService service) { - new SchemaServiceProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, RpcProvisionRegistry service) { - new RpcProvisionRegistryProxy(ref as ServiceReference, service); - } - - private static def dispatch createProxyImpl(ServiceReference ref, DOMDataBroker service) { - new DOMDataBrokerProxy(ref as ServiceReference, service) - } - - - private static def dispatch createProxyImpl(ServiceReference reference, BrokerService service) { - throw new IllegalArgumentException("Not supported class"); - } - -} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.java new file mode 100644 index 0000000000..0f8ce1d95d --- /dev/null +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.util; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; + +public class YangDataOperations { + + public static CompositeNode merge(final DataSchemaNode schema, + final CompositeNode stored, final CompositeNode modified, + final boolean config) { + if (stored == null) { + return modified; + } + + Preconditions.checkArgument(schema instanceof ListSchemaNode + || schema instanceof ContainerSchemaNode, + "Supplied node is not data node container."); + + return YangDataOperations.mergeContainer((DataNodeContainer) schema, + stored, modified, config); + } + + private static Iterable> _mergeMultiple( + final LeafSchemaNode node, final List> original, + final List> modified, final boolean configurational) { + checkArgument(original.size() == 1); + checkArgument(modified.size() == 1); + + return modified; + } + + private static Iterable> _mergeMultiple( + final LeafListSchemaNode node, final List> original, + final List> modified, final boolean configurational) { + return modified; + } + + private static Iterable> _mergeMultiple( + final ContainerSchemaNode node, final List> original, + final List> modified, final boolean configurational) { + checkArgument(original.size() == 1); + checkArgument(modified.size() == 1); + return Collections.singletonList(merge(node, + (CompositeNode) original.get(0), + (CompositeNode) modified.get(0), configurational)); + } + + private static Iterable> _mergeMultiple( + final ListSchemaNode node, final List> original, + final List> modified, final boolean configurational) { + + if (node.getKeyDefinition() == null + || node.getKeyDefinition().isEmpty()) { + return modified; + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Map, CompositeNode> originalMap = YangDataUtils + .toIndexMap((List) original, node.getKeyDefinition()); + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Map, CompositeNode> modifiedMap = YangDataUtils + .toIndexMap((List) modified, node.getKeyDefinition()); + + final List> mergedNodes = new ArrayList>( + original.size() + modified.size()); + for (final Map.Entry, CompositeNode> entry : modifiedMap + .entrySet()) { + final CompositeNode originalEntry = originalMap.get(entry.getKey()); + if (originalEntry != null) { + originalMap.remove(entry.getKey()); + mergedNodes.add(merge(node, originalEntry, entry.getValue(), + configurational)); + } else { + mergedNodes.add(entry.getValue()); + } + } + mergedNodes.addAll(originalMap.values()); + return mergedNodes; + } + + private static Iterable> mergeMultiple( + final DataSchemaNode node, final List> original, + final List> modified, final boolean configurational) { + if (node instanceof ContainerSchemaNode) { + return _mergeMultiple((ContainerSchemaNode) node, original, + modified, configurational); + } else if (node instanceof LeafListSchemaNode) { + return _mergeMultiple((LeafListSchemaNode) node, original, + modified, configurational); + } else if (node instanceof LeafSchemaNode) { + return _mergeMultiple((LeafSchemaNode) node, original, modified, + configurational); + } else if (node instanceof ListSchemaNode) { + return _mergeMultiple((ListSchemaNode) node, original, modified, + configurational); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays. asList(node, original, modified, + configurational).toString()); + } + } + + private static CompositeNode mergeContainer(final DataNodeContainer schema, + final CompositeNode stored, final CompositeNode modified, + final boolean config) { + if (stored == null) { + return modified; + } + Preconditions.checkNotNull(stored); + Preconditions.checkNotNull(modified); + Preconditions.checkArgument(Objects.equals(stored.getNodeType(), + modified.getNodeType())); + + final List> mergedChildNodes = new ArrayList>(stored + .getChildren().size() + modified.getChildren().size()); + final Set toProcess = new HashSet(stored.keySet()); + toProcess.addAll(modified.keySet()); + + for (QName qname : toProcess) { + final DataSchemaNode schemaChild = schema.getDataChildByName(qname); + final List> storedChildren = stored.get(qname); + final List> modifiedChildren = modified.get(qname); + + if (modifiedChildren != null && !modifiedChildren.isEmpty()) { + if (storedChildren == null || storedChildren.isEmpty() + || schemaChild == null) { + mergedChildNodes.addAll(modifiedChildren); + } else { + final Iterable> _mergeMultiple = mergeMultiple( + schemaChild, storedChildren, modifiedChildren, + config); + Iterables.addAll(mergedChildNodes, _mergeMultiple); + } + } else if (storedChildren != null && !storedChildren.isEmpty()) { + mergedChildNodes.addAll(storedChildren); + } + } + return new CompositeNodeTOImpl(stored.getNodeType(), null, + mergedChildNodes); + } +} diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.xtend deleted file mode 100644 index d80e405b4e..0000000000 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataOperations.xtend +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sal.dom.broker.util - -import org.opendaylight.yangtools.yang.data.api.CompositeNode -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode -import static com.google.common.base.Preconditions.*; -import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl -import java.util.ArrayList - -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode -import org.opendaylight.yangtools.yang.data.api.Node -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode -import java.util.List -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode -import java.util.Collections -import java.util.HashSet -import org.opendaylight.yangtools.yang.common.QName -import static extension org.opendaylight.controller.sal.dom.broker.util.YangDataUtils.*; - -class YangDataOperations { - - static def CompositeNode merge(DataSchemaNode schema, CompositeNode stored, CompositeNode modified, boolean config) { - if (stored === null) { - return modified; - } - - if (schema instanceof ListSchemaNode || schema instanceof ContainerSchemaNode) { - return mergeContainer(schema as DataNodeContainer, stored, modified, config); - } - throw new IllegalArgumentException("Supplied node is not data node container."); - } - - private static dispatch def Iterable> mergeMultiple(LeafSchemaNode node, List> original, - List> modified, boolean configurational) { - checkArgument(original.size === 1); - checkArgument(modified.size === 1); - - return modified; - } - - private static dispatch def Iterable> mergeMultiple(LeafListSchemaNode node, - List> original, List> modified, boolean configurational) { - return modified; - } - - private static dispatch def Iterable> mergeMultiple(ContainerSchemaNode node, - List> original, List> modified, boolean configurational) { - checkArgument(original.size === 1); - checkArgument(modified.size === 1); - return Collections.singletonList( - merge(node, original.get(0) as CompositeNode, modified.get(0) as CompositeNode, configurational)); - } - - private static dispatch def Iterable> mergeMultiple(ListSchemaNode node, List> original, - List> modified, boolean configurational) { - - if(node.keyDefinition === null || node.keyDefinition.empty) { - return modified; - } - val originalMap = (original as List).toIndexMap(node.keyDefinition); - val modifiedMap = (modified as List).toIndexMap(node.keyDefinition); - - val List> mergedNodes = new ArrayList(original.size + modified.size); - for(entry : modifiedMap.entrySet) { - val originalEntry = originalMap.get(entry.key); - if(originalEntry != null) { - originalMap.remove(entry.key); - mergedNodes.add(merge(node,originalEntry,entry.value,configurational)); - } else { - mergedNodes.add(entry.value); - } - } - mergedNodes.addAll(originalMap.values); - return mergedNodes; - } - - static private def CompositeNode mergeContainer(DataNodeContainer schema, CompositeNode stored, - CompositeNode modified, boolean config) { - if (stored == null) { - return modified; - } - checkNotNull(stored) - checkNotNull(modified) - checkArgument(stored.nodeType == modified.nodeType); - - val mergedChildNodes = new ArrayList>(stored.children.size + modified.children.size); - - val toProcess = new HashSet(stored.keySet); - toProcess.addAll(modified.keySet); - - for (qname : toProcess) { - val schemaChild = schema.getDataChildByName(qname); - val storedChildren = stored.get(qname); - val modifiedChildren = modified.get(qname); - - if (modifiedChildren !== null && !modifiedChildren.empty) { - if (storedChildren === null || storedChildren.empty || schemaChild === null) { - mergedChildNodes.addAll(modifiedChildren); - } else { - mergedChildNodes.addAll(mergeMultiple(schemaChild, storedChildren, modifiedChildren, config)); - } - } else if (storedChildren !== null && !storedChildren.empty) { - mergedChildNodes.addAll(storedChildren); - } - } - return new CompositeNodeTOImpl(stored.nodeType, null, mergedChildNodes); - } - -} -- 2.36.6