From 42183ad5bfefff7d6de9df467cdaa600a450af29 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 13 Aug 2013 17:30:07 +0200 Subject: [PATCH 1/1] Clean up of binding broker implementation Binding Broker implementation changed from java to xtend, which allows easier extensibility and readability of code without any performance hit (xtend generates java sources, these are compiled with normal java compiler). - Bugfix in RpcDirectProxy generation - Added helper methods to easier configuring a delegate to proxy - Added check for multiple subsequent registrations Signed-off-by: Tony Tkacik Change-Id: I63e248bda99051e5b21ac0a5cbf57bd935ded1bc --- opendaylight/sal/yang-prototype/pom.xml | 6 + opendaylight/sal/yang-prototype/sal/pom.xml | 354 +++++--- .../sal/sal-binding-api/pom.xml | 56 +- .../sal/binding/api/BindingAwareBroker.java | 340 +++---- .../sal/binding/api/BindingAwareConsumer.java | 80 +- .../sal/binding/api/BindingAwareProvider.java | 139 ++- .../sal/binding/api/BindingAwareService.java | 80 +- .../sal/binding/api/NotificationListener.java | 6 + .../api/NotificationProviderService.java | 30 +- .../sal/binding/api/NotificationService.java | 39 +- .../api/{ => data}/DataBrokerService.java | 271 +++--- .../api/{ => data}/DataCommitHandler.java | 474 +++++----- .../DataConsumerService.java} | 132 ++- .../binding/api/{ => data}/DataRefresher.java | 52 +- .../binding/api/{ => data}/DataValidator.java | 36 +- .../binding/api/data/RuntimeDataProvider.java | 10 + .../sal/binding/api/package-info.java | 18 +- .../sal/sal-binding-broker-impl/pom.xml | 153 +++- .../binding/impl/BindingAwareBrokerImpl.xtend | 144 +++ .../sal/binding/impl/BindingBrokerImpl.java | 436 --------- .../sal/binding/impl/BrokerActivator.java | 45 + .../sal/binding/impl/Constants.xtend | 21 + .../sal/binding/impl/DataModule.java | 198 ----- .../binding/impl/NotificationBrokerImpl.xtend | 51 ++ .../sal/binding/impl/NotificationInvoker.java | 16 - .../sal/binding/impl/NotificationModule.java | 276 ------ .../impl/NotificationServiceImpl.xtend | 33 + .../binding/impl/OsgiConsumerContext.xtend | 53 ++ .../binding/impl/OsgiProviderContext.xtend | 42 + .../sal/binding/impl/RpcProxyContext.xtend | 26 + .../impl/RpcServiceRegistrationImpl.xtend | 33 + .../binding/impl/utils/GeneratorUtils.xtend | 23 + .../binding/impl/utils/PropertiesUtils.xtend | 30 + .../sal/binding/impl/utils/package-info.java | 8 + .../sal/sal-binding-spi/pom.xml | 2 +- .../binding/spi/DataDomToJavaTransformer.java | 6 +- .../binding/spi/JavaToDataDomTransformer.java | 4 +- .../controller/sal/binding/spi/Mapper.java | 6 +- .../sal/binding/spi/MappingProvider.java | 8 +- .../controller/sal/binding/spi/RpcMapper.java | 8 +- .../sal/binding/spi/SALBindingModule.java | 31 - .../sal/sal-broker-impl/pom.xml | 4 +- .../controller/sal/core/impl/BrokerImpl.java | 560 ++++++------ .../sal/core/impl/DataBrokerModule.java | 838 +++++++++--------- .../sal/core/impl/NotificationModule.java | 374 ++++---- .../sal/sal-common-util/pom.xml | 41 +- .../controller/sal/common/util/Futures.java | 51 ++ .../controller/sal/common/util/Rpcs.java | 106 +-- .../sal/yang-prototype/sal/sal-common/pom.xml | 23 +- .../yang-prototype/sal/sal-core-api/pom.xml | 4 +- .../controller/sal/core/api/Broker.java | 476 +++++----- .../sal/core/api/BrokerService.java | 78 +- .../controller/sal/core/api/Consumer.java | 118 +-- .../controller/sal/core/api/Provider.java | 138 +-- .../sal/core/api/RpcImplementation.java | 162 ++-- .../sal/core/api/data/DataBrokerService.java | 272 +++--- .../sal/core/api/data/DataCommitHandler.java | 328 +++---- .../core/api/data/DataProviderService.java | 156 ++-- .../sal/core/api/data/DataValidator.java | 114 +-- .../sal/core/api/data/package-info.java | 14 +- .../sal/core/api/model/SchemaService.java | 84 +- .../core/api/notify/NotificationListener.java | 84 +- .../notify/NotificationProviderService.java | 92 +- .../core/api/notify/NotificationService.java | 108 +-- .../sal/core/api/notify/package-info.java | 20 +- .../controller/sal/core/api/package-info.java | 22 +- .../yang-prototype/sal/sal-core-demo/pom.xml | 4 +- .../yang-prototype/sal/sal-core-spi/pom.xml | 2 +- .../yang-prototype/sal/sal-data-api/pom.xml | 2 +- .../sal/sal-schema-repository-api/pom.xml | 2 +- 70 files changed, 3947 insertions(+), 4106 deletions(-) create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java rename opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/{ => data}/DataBrokerService.java (91%) rename opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/{ => data}/DataCommitHandler.java (92%) rename opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/{DataProviderService.java => data/DataConsumerService.java} (76%) rename opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/{ => data}/DataRefresher.java (68%) rename opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/{ => data}/DataValidator.java (67%) create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend delete mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BrokerActivator.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/Constants.xtend delete mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/DataModule.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend delete mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java delete mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationServiceImpl.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcServiceRegistrationImpl.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/GeneratorUtils.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/PropertiesUtils.xtend create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/package-info.java delete mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Futures.java diff --git a/opendaylight/sal/yang-prototype/pom.xml b/opendaylight/sal/yang-prototype/pom.xml index 6cd785cc25..525d8d1795 100644 --- a/opendaylight/sal/yang-prototype/pom.xml +++ b/opendaylight/sal/yang-prototype/pom.xml @@ -12,6 +12,7 @@ + sal concepts-lang @@ -36,6 +37,11 @@ + + central + central + ${nexusproxy}/repositories/central/ + central2 central2 diff --git a/opendaylight/sal/yang-prototype/sal/pom.xml b/opendaylight/sal/yang-prototype/sal/pom.xml index 677372e295..b2ae8d921a 100644 --- a/opendaylight/sal/yang-prototype/sal/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/pom.xml @@ -1,136 +1,232 @@ - 4.0.0 - org.opendaylight.controller - sal - 1.0-SNAPSHOT - pom + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + pom - - sal-common - sal-common-util - sal-core-api - sal-data-api - sal-binding-api - sal-binding-spi - sal-binding-broker-impl - sal-schema-repository-api - sal-core-spi - sal-broker-impl - + + sal-common + sal-common-util + sal-data-api + sal-binding-api + sal-binding-broker-impl + - - 0.5.5-SNAPSHOT - + + UTF-8 + 1.7.2 + http://nexus.opendaylight.org/content + 0.5.7-SNAPSHOT + 2.4.0 + - - - - com.google.guava - guava - 14.0.1 - jar - - - org.slf4j - slf4j-api - 1.7.2 - - - junit - junit - 4.10 - - - org.opendaylight.yangtools - yang-binding - ${yang.version} - - - org.opendaylight.yangtools - yang-common - ${yang.version} - - - org.opendaylight.yangtools - yang-data-api - ${yang.version} - - - org.opendaylight.yangtools - yang-model-api - ${yang.version} - - - org.opendaylight.yangtools - yang-data-util - ${yang.version} - - + + + central + central + ${nexusproxy}/repositories/central/ + + + central2 + central2 + ${nexusproxy}/repositories/central2/ + + + opendaylight.snapshot + opendaylight.snapshot + ${nexusproxy}/repositories/opendaylight.snapshot/ + + - - - - junit - junit - test - true - - - org.mockito - mockito-all - 1.9.5 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.0 - true - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.8.1 - - maven - - - - - aggregate - - site - - - - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 2.4.0 - - Max - Low - site - - - - org.codehaus.mojo - jdepend-maven-plugin - 2.0-beta-2 - - - + + + + + ebr-bundles-release + ebr-bundles-release + ${nexusproxy}/repositories/ebr-bundles-release/ + + + + + ebr-bundles-external + ebr-bundles-external + ${nexusproxy}/repositories/ebr-bundles-external/ + + + + + central2 + central2 + ${nexusproxy}/repositories/central2/ + + + + + central + central + ${nexusproxy}/repositories/central/ + + + + + ops4j-releases + ops4j-releases + ${nexusproxy}/repositories/ops4j-releases/ + + + + thirdparty + thirdparty + ${nexusproxy}/repositories/thirdparty/ + + + + + jboss.releases + jboss.releases + ${nexusproxy}/repositories/jboss.releases/ + + + + opendaylight-release + opendaylight-release + ${nexusproxy}/repositories/opendaylight.release/ + + + + opendaylight-snapshot + opendaylight-snapshot + ${nexusproxy}/repositories/opendaylight.snapshot/ + + + + + + + + + com.google.guava + guava + 14.0.1 + jar + + + org.slf4j + slf4j-api + 1.7.2 + + + junit + junit + 4.10 + + + org.opendaylight.yangtools + yang-binding + ${yang.version} + + + org.opendaylight.yangtools + yang-common + ${yang.version} + + + org.opendaylight.yangtools + yang-data-api + ${yang.version} + + + org.opendaylight.yangtools + yang-model-api + ${yang.version} + + + org.opendaylight.yangtools + yang-data-util + ${yang.version} + + + + + + + + junit + junit + test + true + + + org.mockito + mockito-all + 1.9.5 + test + + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + + ${project.basedir}/META-INF + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0 + true + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8.1 + + maven + + + + + aggregate + + site + + + + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 2.4.0 + + Max + Low + site + + + + org.codehaus.mojo + jdepend-maven-plugin + 2.0-beta-2 + + + diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-binding-api/pom.xml index 92cfc3ba7a..d94a659afa 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/pom.xml @@ -1,28 +1,32 @@ - - 4.0.0 - - org.opendaylight.controller - sal - 1.0-SNAPSHOT - - sal-binding-api - - - - org.opendaylight.controller - yang-common - - - - org.opendaylight.controller - yang-binding - - - - org.opendaylight.controller - sal-common - 1.0-SNAPSHOT - + + 4.0.0 + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + sal-binding-api + bundle + + + + org.opendaylight.yangtools + yang-common + + + org.opendaylight.yangtools + yang-binding + + + org.opendaylight.controller + sal-common + 1.0-SNAPSHOT + + + org.osgi + org.osgi.core + 5.0.0 + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java index 24f5b25a19..fa104882a3 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java @@ -1,168 +1,174 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.yang.binding.RpcService; - -/** - * Binding-aware core of the SAL layer responsible for wiring the SAL consumers. - * - * The responsibility of the broker is to maintain registration of SAL - * functionality {@link Consumer}s and {@link Provider}s, store provider and - * consumer specific context and functionality registration via - * {@link ConsumerSession} and provide access to infrastructure services, which - * removes direct dependencies between providers and consumers. - * - * The Binding-aware broker is also responsible for translation from Java - * classes modeling the functionality and data to binding-indpenedent form which - * is used in SAL Core. - * - * - *

Infrastructure services

Some examples of infrastructure services: - * - *
    - *
  • YANG Module service - see {@link ConsumerSession#getRpcService(Class)}, - * {@link ProviderSession} - *
  • Notification Service - see {@link NotificationService} and - * {@link NotificationProviderService} - *
  • Functionality and Data model - *
  • Data Store access and modification - see {@link DataBrokerService} and - * {@link DataProviderService} - *
- * - * The services are exposed via session. - * - *

Session-based access

- * - * The providers and consumers needs to register in order to use the - * binding-independent SAL layer and to expose functionality via SAL layer. - * - * For more information about session-based access see {@link ConsumerSession} - * and {@link ProviderSession} - * - * - - * - */ -public interface BindingAwareBroker { - /** - * Registers the {@link BindingAwareConsumer}, which will use the SAL layer. - * - *

- * Note that consumer could register additional functionality at later point - * by using service and functionality specific APIs. - * - *

- * The consumer is required to use returned session for all communication - * with broker or one of the broker services. The session is announced to - * the consumer by invoking - * {@link Consumer#onSessionInitiated(ConsumerSession)}. - * - * @param cons - * Consumer to be registered. - * @return a session specific to consumer registration - * @throws IllegalArgumentException - * If the consumer is null. - * @throws IllegalStateException - * If the consumer is already registered. - */ - ConsumerSession registerConsumer(BindingAwareConsumer consumer); - - /** - * Registers the {@link BindingAwareProvider}, which will use the SAL layer. - * - *

- * During the registration, the broker obtains the initial functionality - * from consumer, using the - * {@link BindingAwareProvider#getImplementations()}, and register that - * functionality into system and concrete infrastructure services. - * - *

- * Note that provider could register additional functionality at later point - * by using service and functionality specific APIs. - * - *

- * The consumer is required to use returned session for all - * communication with broker or one of the broker services. The session is - * announced to the consumer by invoking - * {@link BindingAwareProvider#onSessionInitiated(ProviderSession)}. - * - * - * @param prov - * Provider to be registered. - * @return a session unique to the provider registration. - * @throws IllegalArgumentException - * If the provider is null. - * @throws IllegalStateException - * If the consumer is already registered. - */ - ProviderSession registerProvider(BindingAwareProvider provider); - - /** - * {@link BindingAwareConsumer} specific access to the SAL functionality. - * - *

- * ConsumerSession is {@link BindingAwareConsumer}-specific access to the - * SAL functionality and infrastructure services. - * - *

- * The session serves to store SAL context (e.g. registration of - * functionality) for the consumer and provides access to the SAL - * infrastructure services and other functionality provided by - * {@link Provider}s. - * - - * - */ - public interface ConsumerSession { - - /** - * Returns a session specific instance (implementation) of requested - * binding-aware infrastructural service - * - * @param service - * Broker service - * @return Session specific implementation of service - */ - T getSALService(Class service); - - /** - * Returns a session specific instance (implementation) of requested - * YANG module implentation / service provided by consumer. - * - * @param service - * Broker service - * @return Session specific implementation of service - */ - T getRpcService(Class module); - } - - /** - * {@link BindingAwareProvider} specific access to the SAL functionality. - * - *

- * ProviderSession is {@link BindingAwareProvider}-specific access to the - * SAL functionality and infrastructure services, which also allows for - * exposing the provider's functionality to the other - * {@link BindingAwareConsumer}s. - * - *

- * The session serves to store SAL context (e.g. registration of - * functionality) for the providers and exposes access to the SAL - * infrastructure services, dynamic functionality registration and any other - * functionality provided by other {@link BindingAwareConsumer}s. - * - */ - public interface ProviderSession extends ConsumerSession { - - void addRpcImplementation(RpcService implementation); - - void removeRpcImplementation(RpcService implementation); - } -} +/* + * 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.binding.api; +import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; +import org.opendaylight.controller.sal.binding.api.data.DataConsumerService; +import org.opendaylight.yangtools.yang.binding.RpcService; +import org.osgi.framework.BundleContext; + +/** + * Binding-aware core of the SAL layer responsible for wiring the SAL consumers. + * + * The responsibility of the broker is to maintain registration of SAL + * functionality {@link Consumer}s and {@link Provider}s, store provider and + * consumer specific context and functionality registration via + * {@link ConsumerContext} and provide access to infrastructure services, which + * removes direct dependencies between providers and consumers. + * + * The Binding-aware broker is also responsible for translation from Java + * classes modeling the functionality and data to binding-indpenedent form which + * is used in SAL Core. + * + * + *

Infrastructure services

Some examples of infrastructure services: + * + *
    + *
  • YANG Module service - see {@link ConsumerContext#getRpcService(Class)}, + * {@link ProviderContext} + *
  • Notification Service - see {@link NotificationService} and + * {@link NotificationProviderService} + *
  • Functionality and Data model + *
  • Data Store access and modification - see {@link DataBrokerService} and + * {@link DataConsumerService} + *
+ * + * The services are exposed via session. + * + *

Session-based access

+ * + * The providers and consumers needs to register in order to use the + * binding-independent SAL layer and to expose functionality via SAL layer. + * + * For more information about session-based access see {@link ConsumerContext} + * and {@link ProviderContext} + * + * + * + */ +public interface BindingAwareBroker { + /** + * Registers the {@link BindingAwareConsumer}, which will use the SAL layer. + * + *

+ * Note that consumer could register additional functionality at later point + * by using service and functionality specific APIs. + * + *

+ * The consumer is required to use returned session for all communication + * with broker or one of the broker services. The session is announced to + * the consumer by invoking + * {@link Consumer#onSessionInitiated(ConsumerContext)}. + * + * @param cons + * Consumer to be registered. + * @return a session specific to consumer registration + * @throws IllegalArgumentException + * If the consumer is null. + * @throws IllegalStateException + * If the consumer is already registered. + */ + ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx); + + /** + * Registers the {@link BindingAwareProvider}, which will use the SAL layer. + * + *

+ * During the registration, the broker obtains the initial functionality + * from consumer, using the + * {@link BindingAwareProvider#getImplementations()}, and register that + * functionality into system and concrete infrastructure services. + * + *

+ * Note that provider could register additional functionality at later point + * by using service and functionality specific APIs. + * + *

+ * The consumer is required to use returned session for all + * communication with broker or one of the broker services. The session is + * announced to the consumer by invoking + * {@link BindingAwareProvider#onSessionInitiated(ProviderContext)}. + * + * + * @param prov + * Provider to be registered. + * @return a session unique to the provider registration. + * @throws IllegalArgumentException + * If the provider is null. + * @throws IllegalStateException + * If the consumer is already registered. + */ + ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx); + + /** + * {@link BindingAwareConsumer} specific access to the SAL functionality. + * + *

+ * ConsumerSession is {@link BindingAwareConsumer}-specific access to the + * SAL functionality and infrastructure services. + * + *

+ * The session serves to store SAL context (e.g. registration of + * functionality) for the consumer and provides access to the SAL + * infrastructure services and other functionality provided by + * {@link Provider}s. + * + * + * + */ + public interface ConsumerContext { + + /** + * Returns a session specific instance (implementation) of requested + * binding-aware infrastructural service + * + * @param service + * Broker service + * @return Session specific implementation of service + */ + T getSALService(Class service); + + /** + * Returns a session specific instance (implementation) of requested + * YANG module implentation / service provided by consumer. + * + * @param service + * Broker service + * @return Session specific implementation of service + */ + T getRpcService(Class module); + } + + /** + * {@link BindingAwareProvider} specific access to the SAL functionality. + * + *

+ * ProviderSession is {@link BindingAwareProvider}-specific access to the + * SAL functionality and infrastructure services, which also allows for + * exposing the provider's functionality to the other + * {@link BindingAwareConsumer}s. + * + *

+ * The session serves to store SAL context (e.g. registration of + * functionality) for the providers and exposes access to the SAL + * infrastructure services, dynamic functionality registration and any other + * functionality provided by other {@link BindingAwareConsumer}s. + * + */ + public interface ProviderContext extends ConsumerContext { + + RpcServiceRegistration addRpcImplementation(Class type, T implementation); + } + + public interface RpcServiceRegistration { + + T getService(); + + void unregister(); + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java index e32f8bc9f9..fc297261b7 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java @@ -1,40 +1,40 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; - -/** - * - * Defines the component of controller and supplies additional metadata. A - * component of the controller or application supplies a concrete implementation - * of this interface. - * - * A user-implemented component (application) which faciliates the SAL and SAL - * services to access infrastructure services or providers' functionality. - * - - * - */ -public interface BindingAwareConsumer { - - /** - * Callback signaling initialization of the consumer session to the SAL. - * - * The consumer MUST use the session for all communication with SAL or - * retrieving SAL infrastructure services. - * - * This method is invoked by - * {@link BindingAwareBroker#registerConsumer(BindingAwareConsumer)} - * - * @param session - * Unique session between consumer and SAL. - */ - void onSessionInitialized(ConsumerSession session); - -} +/* + * 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.binding.api; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; + +/** + * + * Defines the component of controller and supplies additional metadata. A + * component of the controller or application supplies a concrete implementation + * of this interface. + * + * A user-implemented component (application) which faciliates the SAL and SAL + * services to access infrastructure services or providers' functionality. + * + * + * + */ +public interface BindingAwareConsumer { + + /** + * Callback signaling initialization of the consumer session to the SAL. + * + * The consumer MUST use the session for all communication with SAL or + * retrieving SAL infrastructure services. + * + * This method is invoked by + * {@link BindingAwareBroker#registerConsumer(BindingAwareConsumer)} + * + * @param session + * Unique session between consumer and SAL. + */ + void onSessionInitialized(ConsumerContext session); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java index d324b83c53..3641d76970 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java @@ -1,72 +1,69 @@ -/* - * 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.binding.api; - -import java.util.Collection; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession; -import org.opendaylight.controller.yang.binding.RpcService; - - -/** - * - * Defines the component of controller and supplies additional metadata. A - * component of the controller or application supplies a concrete implementation - * of this interface. - * - *

- * A user-implemented component (application) which facilitates the SAL and SAL - * services to access infrastructure services and to provide functionality to - * {@link Consumer}s and other providers. - * - - * - */ -public interface BindingAwareProvider { - - void onSessionInitialized(ConsumerSession session); - - /** - * Returns a set of provided implementations of YANG modules and their rpcs. - * - * - * @return Set of provided implementation of YANG modules and their Rpcs - */ - Collection getImplementations(); - - /** - * Gets a set of implementations of provider functionality to be registered - * into system during the provider registration to the SAL. - * - *

- * This method is invoked by {@link Broker#registerProvider(Provider)} to - * learn the initial provided functionality - * - * @return Set of provider's functionality. - */ - Collection getFunctionality(); - - /** - * Functionality provided by the {@link BindingAwareProvider} - * - *

- * Marker interface used to mark the interfaces describing specific - * functionality which could be exposed by providers to other components. - * - - * - */ - public interface ProviderFunctionality { - - } - - void onSessionInitiated(ProviderSession session); - -} +/* + * 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.binding.api; +import java.util.Collection; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.yangtools.yang.binding.RpcService; + +/** + * + * Defines the component of controller and supplies additional metadata. A + * component of the controller or application supplies a concrete implementation + * of this interface. + * + *

+ * A user-implemented component (application) which facilitates the SAL and SAL + * services to access infrastructure services and to provide functionality to + * {@link Consumer}s and other providers. + * + * + */ +public interface BindingAwareProvider { + + void onSessionInitialized(ConsumerContext session); + + /** + * Returns a set of provided implementations of YANG modules and their rpcs. + * + * + * @return Set of provided implementation of YANG modules and their Rpcs + */ + Collection getImplementations(); + + /** + * Gets a set of implementations of provider functionality to be registered + * into system during the provider registration to the SAL. + * + *

+ * This method is invoked by {@link Broker#registerProvider(Provider)} to + * learn the initial provided functionality + * + * @return Set of provider's functionality. + */ + Collection getFunctionality(); + + /** + * Functionality provided by the {@link BindingAwareProvider} + * + *

+ * Marker interface used to mark the interfaces describing specific + * functionality which could be exposed by providers to other components. + * + * + * + */ + public interface ProviderFunctionality { + + } + + void onSessionInitiated(ProviderContext session); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java index e4d86e7bfd..b3680568bb 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java @@ -1,40 +1,40 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; - -/** - * - * Session-specific instance of the broker functionality. - * - *

- * BindingAwareService is marker interface for infrastructure services provided - * by the SAL. These services are session-specific, each - * {@link BindingAwareConsumer} and {@link BindingAwareProvider} usually has own - * instance of the service with it's own context. - * - *

- * The consumer's (or provider's) instance of specific service could be obtained - * by invoking {@link ConsumerSession#getSALService(Class)} method on session - * assigned to the consumer. - * - *

- * {@link BindingAwareService} and {@link BindingAwareProvider} may seem - * similar, but provider provides YANG model-based functionality and - * {@link BindingAwareProvider} exposes the necessary supporting functionality - * to implement specific functionality of YANG and to reuse it in the - * development of {@link BindingAwareConsumer}s and {@link BindingAwareProvider} - * s. - * - - * - */ -public interface BindingAwareService { - -} +/* + * 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.binding.api; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; + +/** + * + * Session-specific instance of the broker functionality. + * + *

+ * BindingAwareService is marker interface for infrastructure services provided + * by the SAL. These services are session-specific, each + * {@link BindingAwareConsumer} and {@link BindingAwareProvider} usually has own + * instance of the service with it's own context. + * + *

+ * The consumer's (or provider's) instance of specific service could be obtained + * by invoking {@link ConsumerContext#getSALService(Class)} method on session + * assigned to the consumer. + * + *

+ * {@link BindingAwareService} and {@link BindingAwareProvider} may seem + * similar, but provider provides YANG model-based functionality and + * {@link BindingAwareProvider} exposes the necessary supporting functionality + * to implement specific functionality of YANG and to reuse it in the + * development of {@link BindingAwareConsumer}s and {@link BindingAwareProvider} + * s. + * + * + * + */ +public interface BindingAwareService { + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java new file mode 100644 index 0000000000..ccc73919b6 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java @@ -0,0 +1,6 @@ +package org.opendaylight.controller.sal.binding.api; + +public interface NotificationListener { + + void onNotification(T notification); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationProviderService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationProviderService.java index c5fc405f51..86c9eebecd 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationProviderService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationProviderService.java @@ -1,15 +1,15 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.yang.binding.Notification; - -public interface NotificationProviderService extends NotificationService { - - void notify(Notification notification); -} +/* + * 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.binding.api; + +import org.opendaylight.yangtools.yang.binding.Notification; + +public interface NotificationProviderService extends NotificationService { + + void notify(Notification notification); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationService.java index 92e30a5236..3723c70e8c 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationService.java @@ -1,22 +1,17 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.yang.binding.Notification; -import org.opendaylight.controller.yang.binding.NotificationListener; - -public interface NotificationService extends BindingAwareService { - - void addNotificationListener( - Class notificationType, - NotificationListener listener); - - void removeNotificationListener( - Class notificationType, - NotificationListener listener); -} +/* + * 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.binding.api; + +import org.opendaylight.yangtools.yang.binding.Notification; + +public interface NotificationService extends BindingAwareService { + + void addNotificationListener(Class notificationType, NotificationListener listener); + + void removeNotificationListener(Class notificationType, NotificationListener listener); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataBrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java similarity index 91% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataBrokerService.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java index 9195b6f5c5..250aaf35c0 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataBrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java @@ -1,137 +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.binding.api; - -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.yang.binding.DataRoot; -import org.opendaylight.controller.yang.common.RpcResult; - - -/** - * DataBrokerService provides unified access to the data stores available in the - * system. - * - * - * @see DataProviderService - - */ -public interface DataBrokerService extends BindingAwareService { - - /** - * Returns a data from specified Data Store. - * - * Returns all the data visible to the consumer from specified Data Store. - * - * @param - * Interface generated from YANG module representing root of data - * @param store - * Identifier of the store, from which will be data retrieved - * @return data visible to the consumer - */ - T getData(DataStoreIdentifier store, Class rootType); - - /** - * Returns a filtered subset of data from specified Data Store. - * - *

- * The filter is modeled as an hierarchy of Java TOs starting with - * implementation of {@link DataRoot} representing data root. The semantics - * of the filter tree is the same as filter semantics defined in the NETCONF - * protocol for rpc operations get and get-config - * in Section 6 of RFC6241. - * - * - * @see http://tools.ietf.org/html/rfc6241#section-6 - * @param - * Interface generated from YANG module representing root of data - * @param store - * Identifier of the store, from which will be data retrieved - * @param filter - * Data tree filter similar to the NETCONF filter - * @return - */ - T getData(DataStoreIdentifier store, T filter); - - /** - * Returns a candidate data which are not yet commited. - * - * - * @param - * Interface generated from YANG module representing root of data - * @param store - * Identifier of the store, from which will be data retrieved - * @return - */ - T getCandidateData(DataStoreIdentifier store, - Class rootType); - - /** - * Returns a filtered subset of candidate data from specified Data Store. - * - *

- * The filter is modeled as an hierarchy of {@link Node} starting with - * {@link CompositeNode} representing data root. The semantics of the filter - * tree is the same as filter semantics defined in the NETCONF protocol for - * rpc operations get and get-config in Section 6 - * of RFC6241. - * - * - * @see http://tools.ietf.org/html/rfc6241#section-6 - * @param - * Interface generated from YANG module representing root of data - * @param store - * Identifier of the store, from which will be data retrieved - * @param filter - * A filter data root - * @return - */ - T getCandidateData(DataStoreIdentifier store, T filter); - - /** - * - * @param - * Interface generated from YANG module representing root of data - * @param store - * Identifier of the store, in which will be the candidate data - * modified - * @param changeSet - * Modification of data tree. - * @return Result object containing the modified data tree if the operation - * was successful, otherwise list of the encountered errors. - */ - RpcResult editCandidateData(DataStoreIdentifier store, - DataRoot changeSet); - - /** - * Initiates a two-phase commit of candidate data. - * - *

- * The {@link Consumer} could initiate a commit of candidate data - * - *

- * The successful commit changes the state of the system and may affect - * several components. - * - *

- * The effects of successful commit of data are described in the - * specifications and YANG models describing the {@link Provider} components - * of controller. It is assumed that {@link Consumer} has an understanding - * of this changes. - * - * - * @see DataCommitHandler for further information how two-phase commit is - * processed. - * @param store - * Identifier of the store, where commit should occur. - * @return Result of the commit, containing success information or list of - * encountered errors, if commit was not successful. - */ - Future> commit(DataStoreIdentifier store); -} +/* + * 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.binding.api.data; + +import java.util.concurrent.Future; + +import org.opendaylight.controller.sal.binding.api.BindingAwareService; +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.yangtools.yang.binding.DataRoot; +import org.opendaylight.yangtools.yang.common.RpcResult; + +/** + * DataBrokerService provides unified access to the data stores available in the + * system. + * + * + * @see DataConsumerService + */ +public interface DataBrokerService extends BindingAwareService { + + /** + * Returns a data from specified Data Store. + * + * Returns all the data visible to the consumer from specified Data Store. + * + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @return data visible to the consumer + */ + T getData(DataStoreIdentifier store, Class rootType); + + /** + * Returns a filtered subset of data from specified Data Store. + * + *

+ * The filter is modeled as an hierarchy of Java TOs starting with + * implementation of {@link DataRoot} representing data root. The semantics + * of the filter tree is the same as filter semantics defined in the NETCONF + * protocol for rpc operations get and get-config + * in Section 6 of RFC6241. + * + * + * @see http://tools.ietf.org/html/rfc6241#section-6 + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @param filter + * Data tree filter similar to the NETCONF filter + * @return + */ + T getData(DataStoreIdentifier store, T filter); + + /** + * Returns a candidate data which are not yet commited. + * + * + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @return + */ + T getCandidateData(DataStoreIdentifier store, Class rootType); + + /** + * Returns a filtered subset of candidate data from specified Data Store. + * + *

+ * The filter is modeled as an hierarchy of {@link Node} starting with + * {@link CompositeNode} representing data root. The semantics of the filter + * tree is the same as filter semantics defined in the NETCONF protocol for + * rpc operations get and get-config in Section 6 + * of RFC6241. + * + * + * @see http://tools.ietf.org/html/rfc6241#section-6 + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @param filter + * A filter data root + * @return + */ + T getCandidateData(DataStoreIdentifier store, T filter); + + /** + * + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, in which will be the candidate data + * modified + * @param changeSet + * Modification of data tree. + * @return Result object containing the modified data tree if the operation + * was successful, otherwise list of the encountered errors. + */ + RpcResult editCandidateData(DataStoreIdentifier store, DataRoot changeSet); + + /** + * Initiates a two-phase commit of candidate data. + * + *

+ * The {@link Consumer} could initiate a commit of candidate data + * + *

+ * The successful commit changes the state of the system and may affect + * several components. + * + *

+ * The effects of successful commit of data are described in the + * specifications and YANG models describing the {@link Provider} components + * of controller. It is assumed that {@link Consumer} has an understanding + * of this changes. + * + * + * @see DataCommitHandler for further information how two-phase commit is + * processed. + * @param store + * Identifier of the store, where commit should occur. + * @return Result of the commit, containing success information or list of + * encountered errors, if commit was not successful. + */ + Future> commit(DataStoreIdentifier store); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataCommitHandler.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java similarity index 92% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataCommitHandler.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java index f568524c80..7b965d16f2 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataCommitHandler.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java @@ -1,209 +1,265 @@ -/* - * 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.binding.api; - -import java.util.Set; - -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.yang.common.RpcResult; - - -/** - * Two phase commit handler (cohort) of the two-phase commit protocol of data. - * - *

- * The provider should expose the implementation of DataCommitHandler if it's - * functionality depends on any subset of data stored in data repositories, in - * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier) - * operation. - * - *

- * Operations of two-phase commit handlers should not change data in data store, - * this is responsibility of the coordinator (broker or some component of the - * broker). - * - * The commit handlers are responsible for changing the internal state of the - * provider to reflect the commited changes in data. - * - *

Two-phase commit

- * - *

Commit Request Phase

- * - *
    - *
  1. Consumer edits data by invocation of - * DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot) - *
  2. Consumer starts a commit by invoking - * DataBrokerService.commit(DataStoreIdentifier) - *
  3. Broker retrieves a list of all registered - * DataCommitHandlers - *
  4. For each DataCommitHandler - *
      - *
    1. Broker invokes a - * DataCommitHandler.requestCommit(DataStoreIdentifier) operation. - *
    2. DataCommitHandler returns a RpcResult with - * CommitTransaction - *
    3. If the result was successful, broker adds CommitTransaction - * to the list of opened transactions. If not, brokers stops a commit request - * phase and starts a rollback phase. - *
    - *
  5. Broker starts a commit finish phase - *
- * - *

Commit Finish Phase

- * - *
    - *
  1. For each CommitTransaction from Commit Request phase - *
      - *
    1. Broker broker invokes a - * CommitTransaction.finish() - *
    2. The provider finishes a commit (applies the change) and returns an - * RpcResult. - *
    - *
  2. - *
      - *
    • If all returned results means successful, the brokers end two-phase - * commit by returning a success commit result to the Consumer. - *
    • If error occured, the broker starts a commit rollback phase. - *
    - *
- * - *

Commit Rollback Phase

- *
  • For each CommitTransaction from Commit Request phase - *
      - *
    1. Broker - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * broker invokes a {@link CommitTransaction#finish()} - *
    2. The provider rollbacks a commit and returns an {@link RpcResult} of - * rollback.
    - *
  • Broker returns a error result to the consumer. - * - * - *

    Registration of functionality

    - * The registration could be done by : - *
      - *
    • returning an instance of implementation in the return value of - * {@link Provider#getProviderFunctionality()} - *
    • passing an instance of implementation and {@link DataStoreIdentifier} of - * rpc as arguments to the - * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} - *
    - * - - * - */ -public interface DataCommitHandler extends ProviderFunctionality { - /** - * A set of Data Stores supported by implementation. - * - * The set of {@link DataStoreIdentifier}s which identifies target data - * stores which are supported by this commit handler. This set is used, when - * {@link Provider} is registered to the SAL, to register and expose the - * commit handler functionality to affected data stores. - * - * @return Set of Data Store identifiers - */ - Set getSupportedDataStores(); - - /** - * The provider (commit handler) starts a commit transaction. - * - *

    - * The commit handler (provider) prepares an commit scenario, rollback - * scenario and validates data. - * - *

    - * If the provider is aware that at this point the commit would not be - * successful, the transaction is not created, but list of errors which - * prevented the start of transaction are returned. - * - * @param store - * @return Transaction object representing this commit, errors otherwise. - */ - RpcResult requestCommit(DataStoreIdentifier store); - - public interface CommitTransaction { - /** - * - * @return Data store affected by the transaction - */ - DataStoreIdentifier getDataStore(); - - /** - * Returns the handler associated with this transaction. - * - * @return Handler - */ - DataCommitHandler getHandler(); - - /** - * - * Finishes a commit. - * - * The provider (commit handler) should apply all changes to its state - * which are a result of data change- - * - * @return - */ - RpcResult finish() throws IllegalStateException; - - /** - * Rollbacks a commit. - * - * @return - * @throws IllegalStateException - * If the method is invoked after {@link #finish()} - */ - RpcResult rollback() throws IllegalStateException; - } - -} +/* + * 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.binding.api.data; + +import java.util.Set; + +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; + +/** + * Two phase commit handler (cohort) of the two-phase commit protocol of data. + * + *

    + * The provider should expose the implementation of DataCommitHandler if it's + * functionality depends on any subset of data stored in data repositories, in + * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier) + * operation. + * + *

    + * Operations of two-phase commit handlers should not change data in data store, + * this is responsibility of the coordinator (broker or some component of the + * broker). + * + * The commit handlers are responsible for changing the internal state of the + * provider to reflect the commited changes in data. + * + *

    Two-phase commit

    + * + *

    Commit Request Phase

    + * + *
      + *
    1. Consumer edits data by invocation of + * DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot) + *
    2. Consumer starts a commit by invoking + * DataBrokerService.commit(DataStoreIdentifier) + *
    3. Broker retrieves a list of all registered + * DataCommitHandlers + *
    4. For each DataCommitHandler + *
        + *
      1. Broker invokes a + * DataCommitHandler.requestCommit(DataStoreIdentifier) operation. + *
      2. DataCommitHandler returns a RpcResult with + * CommitTransaction + *
      3. If the result was successful, broker adds CommitTransaction + * to the list of opened transactions. If not, brokers stops a commit request + * phase and starts a rollback phase. + *
      + *
    5. Broker starts a commit finish phase + *
    + * + *

    Commit Finish Phase

    + * + *
      + *
    1. For each CommitTransaction from Commit Request phase + *
        + *
      1. Broker broker invokes a + * CommitTransaction.finish() + *
      2. The provider finishes a commit (applies the change) and returns an + * RpcResult. + *
      + *
    2. + *
        + *
      • If all returned results means successful, the brokers end two-phase + * commit by returning a success commit result to the Consumer. + *
      • If error occured, the broker starts a commit rollback phase. + *
      + *
    + * + *

    Commit Rollback Phase

    + *
  • For each CommitTransaction from Commit Request phase + *
      + *
    1. Broker + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * broker invokes a {@link CommitTransaction#finish()} + *
    2. The provider rollbacks a commit and returns an {@link RpcResult} of + * rollback.
    + *
  • Broker returns a error result to the consumer. + * + * + *

    Registration of functionality

    + * The registration could be done by : + *
      + *
    • returning an instance of implementation in the return value of + * {@link Provider#getProviderFunctionality()} + *
    • passing an instance of implementation and {@link DataStoreIdentifier} of + * rpc as arguments to the + * {@link DataConsumerService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} + *
    + * + * + * + */ +public interface DataCommitHandler extends ProviderFunctionality { + /** + * A set of Data Stores supported by implementation. + * + * The set of {@link DataStoreIdentifier}s which identifies target data + * stores which are supported by this commit handler. This set is used, when + * {@link Provider} is registered to the SAL, to register and expose the + * commit handler functionality to affected data stores. + * + * @return Set of Data Store identifiers + */ + Set getSupportedDataStores(); + + /** + * The provider (commit handler) starts a commit transaction. + * + *

    + * The commit handler (provider) prepares an commit scenario, rollback + * scenario and validates data. + * + *

    + * If the provider is aware that at this point the commit would not be + * successful, the transaction is not created, but list of errors which + * prevented the start of transaction are returned. + * + * @param store + * @return Transaction object representing this commit, errors otherwise. + */ + RpcResult requestCommit(DataStoreIdentifier store); + + public interface CommitTransaction { + /** + * + * @return Data store affected by the transaction + */ + DataStoreIdentifier getDataStore(); + + /** + * Returns the handler associated with this transaction. + * + * @return Handler + */ + DataCommitHandler getHandler(); + + /** + * + * Finishes a commit. + * + * The provider (commit handler) should apply all changes to its state + * which are a result of data change- + * + * @return + */ + RpcResult finish() throws IllegalStateException; + + /** + * Rollbacks a commit. + * + * @return + * @throws IllegalStateException + * If the method is invoked after {@link #finish()} + */ + RpcResult rollback() throws IllegalStateException; + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataProviderService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java similarity index 76% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataProviderService.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java index 8f90ddbbea..e57ce4d9ba 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataProviderService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java @@ -1,67 +1,65 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; - -public interface DataProviderService extends DataBrokerService { - - /** - * Adds {@link DataValidator} for specified Data Store - * - * @param store - * Data Store - * @param validator - * Validator - */ - public void addValidator(DataStoreIdentifier store, DataValidator validator); - - /** - * Removes {@link DataValidator} from specified Data Store - * - * @param store - * @param validator - * Validator - */ - public void removeValidator(DataStoreIdentifier store, - DataValidator validator); - - /** - * Adds {@link DataCommitHandler} for specified data store - * - * @param store - * @param provider - */ - void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider); - - /** - * Removes {@link DataCommitHandler} from specified data store - * - * @param store - * @param provider - */ - void removeCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider); - - /** - * Adds {@link DataRefresher} for specified data store - * - * @param store - * @param refresher - */ - void addRefresher(DataStoreIdentifier store, DataRefresher refresher); - - /** - * Removes {@link DataRefresher} from specified data store - * - * @param store - * @param refresher - */ - void removeRefresher(DataStoreIdentifier store, DataRefresher refresher); - -} +/* + * 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.binding.api.data; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; + +public interface DataConsumerService extends DataBrokerService { + + /** + * Adds {@link DataValidator} for specified Data Store + * + * @param store + * Data Store + * @param validator + * Validator + */ + public void addValidator(DataStoreIdentifier store, DataValidator validator); + + /** + * Removes {@link DataValidator} from specified Data Store + * + * @param store + * @param validator + * Validator + */ + public void removeValidator(DataStoreIdentifier store, DataValidator validator); + + /** + * Adds {@link DataCommitHandler} for specified data store + * + * @param store + * @param provider + */ + void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider); + + /** + * Removes {@link DataCommitHandler} from specified data store + * + * @param store + * @param provider + */ + void removeCommitHandler(DataStoreIdentifier store, DataCommitHandler provider); + + /** + * Adds {@link DataRefresher} for specified data store + * + * @param store + * @param refresher + */ + void addRefresher(DataStoreIdentifier store, DataRefresher refresher); + + /** + * Removes {@link DataRefresher} from specified data store + * + * @param store + * @param refresher + */ + void removeRefresher(DataStoreIdentifier store, DataRefresher refresher); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataRefresher.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataRefresher.java similarity index 68% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataRefresher.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataRefresher.java index 0f9997651f..f54e1315be 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataRefresher.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataRefresher.java @@ -1,26 +1,28 @@ -/* - * 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.binding.api; - -/** - * Trigger for refreshing of the data exposed by the {@link Provider} - * - * - * - */ -public interface DataRefresher extends - BindingAwareProvider.ProviderFunctionality { - - /** - * Fired when some component explicitly requested the data refresh. - * - * The provider which exposed the {@link DataRefresher} should republish its - * provided data by editing the data in all affected data stores. - */ - void refreshData(); +/* + * 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.binding.api.data; + +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; + +/** + * Trigger for refreshing of the data exposed by the {@link Provider} + * + * + * + */ +public interface DataRefresher extends BindingAwareProvider.ProviderFunctionality { + + /** + * Fired when some component explicitly requested the data refresh. + * + * The provider which exposed the {@link DataRefresher} should republish its + * provided data by editing the data in all affected data stores. + */ + void refreshData(); } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataValidator.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataValidator.java similarity index 67% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataValidator.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataValidator.java index f2ad68869a..8099600828 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataValidator.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataValidator.java @@ -1,18 +1,18 @@ -/* - * 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.binding.api; - -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; -import org.opendaylight.controller.yang.binding.DataRoot; -import org.opendaylight.controller.yang.common.RpcResult; - - -public interface DataValidator extends ProviderFunctionality { - - RpcResult validate(DataRoot data); -} +/* + * 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.binding.api.data; + +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; +import org.opendaylight.yangtools.yang.binding.DataRoot; +import org.opendaylight.yangtools.yang.common.RpcResult; + +public interface DataValidator extends ProviderFunctionality { + + RpcResult validate(DataRoot data); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java new file mode 100644 index 0000000000..b9f5d5aa27 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java @@ -0,0 +1,10 @@ +package org.opendaylight.controller.sal.binding.api.data; + +import java.util.Set; + +import org.opendaylight.yangtools.yang.binding.DataRoot; + +public interface RuntimeDataProvider { + + Set> getProvidedDataRoots(); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/package-info.java index 552ac6a450..31eec6b5e8 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/package-info.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/package-info.java @@ -1,9 +1,9 @@ -/* - * 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.binding.api; - +/* + * 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.binding.api; + diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml index 3073bec988..70f2e6c378 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml @@ -1,46 +1,109 @@ - - 4.0.0 - - org.opendaylight.controller - sal - 1.0-SNAPSHOT - - sal-binding-broker-impl - - - - - - org.opendaylight.controller - sal-common-util - 1.0-SNAPSHOT - - - org.opendaylight.controller - sal-binding-api - 1.0-SNAPSHOT - - - org.opendaylight.controller - sal-binding-spi - 1.0-SNAPSHOT - - - org.opendaylight.controller - sal-core-api - 1.0-SNAPSHOT - - - - org.slf4j - slf4j-api - - - - com.google.guava - guava - jar - - + + 4.0.0 + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + sal-binding-broker-impl + bundle + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + org.opendaylight.controller.sal.binding.impl.BrokerActivator + + org.opendaylight.controller.sal.binding.impl, + org.opendaylight.controller.sal.binding.impl.utils, + org.eclipse.xtend2.lib, + org.eclipse.xtext.xbase.* + + + + + + + org.eclipse.xtend + xtend-maven-plugin + 2.4.2 + + + + compile + + + ${basedir}/src/main/xtend-gen + + + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir}/src/main/xtend-gen + + ** + + + + + + + + + + + org.opendaylight.controller + sal-common-util + 1.0-SNAPSHOT + + + org.opendaylight.controller + sal-binding-api + 1.0-SNAPSHOT + + + + + org.slf4j + slf4j-api + + + org.osgi + org.osgi.core + 5.0.0 + + + com.google.guava + guava + jar + + + org.reflections + reflections + 0.9.9-RC1 + + + org.javassist + javassist + 3.17.1-GA + + + org.eclipse.xtend + org.eclipse.xtend.lib + 2.4.2 + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend new file mode 100644 index 0000000000..74ef87ae5a --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend @@ -0,0 +1,144 @@ +/* + * 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.binding.impl + +import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider +import org.opendaylight.yangtools.yang.binding.RpcService +import javassist.ClassPool +import javassist.CtMethod +import javassist.CtField +import org.osgi.framework.BundleContext +import java.util.Map +import java.util.HashMap +import javassist.LoaderClassPath +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker +import java.util.Hashtable + +import static extension org.opendaylight.controller.sal.binding.impl.utils.PropertiesUtils.* +import static extension org.opendaylight.controller.sal.binding.impl.utils.GeneratorUtils.* +import org.opendaylight.controller.sal.binding.api.NotificationProviderService +import org.osgi.framework.ServiceRegistration +import org.opendaylight.controller.sal.binding.impl.utils.PropertiesUtils +import org.opendaylight.controller.sal.binding.api.NotificationService +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext +import javassist.Modifier +import org.slf4j.LoggerFactory + +class BindingAwareBrokerImpl implements BindingAwareBroker { + private static val DELEGATE_FIELD = "_delegate" + private static val log = LoggerFactory.getLogger(BindingAwareBrokerImpl) + + private val clsPool = ClassPool.getDefault() + private Map, RpcProxyContext> managedProxies = new HashMap(); + private var NotificationBrokerImpl notifyBroker + private var ServiceRegistration notifyBrokerRegistration + + @Property + var BundleContext brokerBundleContext + + def start() { + initGenerator(); + + // Initialization of notificationBroker + notifyBroker = new NotificationBrokerImpl(null); + val brokerProperties = PropertiesUtils.newProperties(); + notifyBrokerRegistration = brokerBundleContext.registerService(NotificationProviderService, notifyBroker, + brokerProperties) + brokerBundleContext.registerService(NotificationService, notifyBroker, brokerProperties) + } + + def initGenerator() { + + // YANG Binding Class Loader + clsPool.appendClassPath(new LoaderClassPath(RpcService.classLoader)) + } + + override registerConsumer(BindingAwareConsumer consumer, BundleContext bundleCtx) { + val ctx = consumer.createContext(bundleCtx) + consumer.onSessionInitialized(ctx) + return ctx + } + + override registerProvider(BindingAwareProvider provider, BundleContext bundleCtx) { + val ctx = provider.createContext(bundleCtx) + provider.onSessionInitialized(ctx) + provider.onSessionInitiated(ctx as ProviderContext) + return ctx + } + + private def createContext(BindingAwareConsumer consumer, BundleContext consumerCtx) { + new OsgiConsumerContext(consumerCtx, this) + } + + private def createContext(BindingAwareProvider provider, BundleContext providerCtx) { + new OsgiProviderContext(providerCtx, this) + } + + def getManagedDirectProxy(Class service) { + + var RpcProxyContext existing = null + if ((existing = managedProxies.get(service)) != null) { + return existing.proxy + } + val proxyClass = service.generateDirectProxy() + val rpcProxyCtx = new RpcProxyContext(proxyClass) + val properties = new Hashtable() + rpcProxyCtx.proxy = proxyClass.newInstance as RpcService + + properties.salServiceType = Constants.SAL_SERVICE_TYPE_CONSUMER_PROXY + rpcProxyCtx.registration = brokerBundleContext.registerService(service, rpcProxyCtx.proxy as T, properties) + managedProxies.put(service, rpcProxyCtx) + return rpcProxyCtx.proxy + } + + protected def generateDirectProxy(Class delegate) { + val targetFqn = delegate.generatedName(Constants.PROXY_DIRECT_SUFFIX) + log.debug("Generating DirectProxy for {} Proxy name: {}",delegate,targetFqn); + val objCls = clsPool.get(Object) + val delegateCls = clsPool.get(delegate) + val proxyCls = clsPool.makeClass(targetFqn) + proxyCls.addInterface(delegateCls) + val delField = new CtField(delegateCls, DELEGATE_FIELD, proxyCls); + delField.modifiers = Modifier.PUBLIC + proxyCls.addField(delField) + delegateCls.methods.filter[it.declaringClass != objCls].forEach [ + val proxyMethod = new CtMethod(it, proxyCls, null); + proxyMethod.body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);''' + proxyCls.addMethod(proxyMethod) + ] + return proxyCls.toClass(delegate.classLoader) + } + + def registerRpcImplementation(Class type, T service, OsgiProviderContext context, + Hashtable properties) { + val proxy = getManagedDirectProxy(type) + if(proxy.delegate != null) { + throw new IllegalStateException("Service " + type + "is already registered"); + } + val osgiReg = context.bundleContext.registerService(type, service, properties); + proxy.delegate = service; + return new RpcServiceRegistrationImpl(type, service, osgiReg); + } + + def getDelegate(RpcService proxy) { + val field = proxy.class.getField(DELEGATE_FIELD) + if(field == null) throw new UnsupportedOperationException("Unable to get delegate from proxy"); + return field.get(proxy) as T + } + + def void setDelegate(RpcService proxy, RpcService delegate) { + val field = proxy.class.getField(DELEGATE_FIELD) + if(field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy"); + if (field.type.isAssignableFrom(delegate.class)) { + field.set(proxy,delegate) + } else throw new IllegalArgumentException("delegate class is not assignable to proxy"); + } + + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java deleted file mode 100644 index 32eff18d4a..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java +++ /dev/null @@ -1,436 +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.binding.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; -import org.opendaylight.controller.sal.binding.api.BindingAwareService; -import org.opendaylight.controller.sal.binding.spi.Mapper; -import org.opendaylight.controller.sal.binding.spi.MappingProvider; -import org.opendaylight.controller.sal.binding.spi.RpcMapper; -import org.opendaylight.controller.sal.binding.spi.RpcMapper.RpcProxyInvocationHandler; -import org.opendaylight.controller.sal.binding.spi.SALBindingModule; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.binding.RpcService; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BindingBrokerImpl implements BindingAwareBroker { - - private static Logger log = LoggerFactory - .getLogger(BindingBrokerImpl.class); - - private Set sessions = new HashSet(); - private Set providerSessions = new HashSet(); - - private Set modules = new HashSet(); - private Map, SALBindingModule> salServiceProviders = new HashMap, SALBindingModule>(); - private MappingProvider mapping; - private BIFacade biFacade = new BIFacade(); - private org.opendaylight.controller.sal.core.api.Broker.ProviderSession biSession; - private ExecutorService executor; - - Map, RpcService> rpcImpls = Collections - .synchronizedMap(new HashMap, RpcService>()); - - private RpcProxyInvocationHandler rpcProxyHandler = new RpcProxyInvocationHandler() { - - @Override - public Future> invokeRpc( - RpcService proxy, QName rpc, DataObject input) { - return rpcProxyInvoked(proxy, rpc, input); - } - }; - - @Override - public ConsumerSession registerConsumer(BindingAwareConsumer consumer) { - checkPredicates(consumer); - log.info("Registering consumer " + consumer); - - ConsumerSessionImpl session = newSessionFor(consumer); - consumer.onSessionInitialized(session); - - sessions.add(session); - return session; - } - - @Override - public ProviderSession registerProvider(BindingAwareProvider provider) { - checkPredicates(provider); - - ProviderSessionImpl session = newSessionFor(provider); - provider.onSessionInitiated(session); - - providerSessions.add(session); - return session; - } - - public void addModule(SALBindingModule module) { - log.info("Registering broker module " + module); - if (modules.contains(module)) { - log.error("Module already registered"); - throw new IllegalArgumentException("Module already exists."); - } - - Set> provServices = module - .getProvidedServices(); - for (Class serviceType : provServices) { - log.info(" Registering session service implementation: " - + serviceType.getCanonicalName()); - salServiceProviders.put(serviceType, module); - } - } - - public void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { - sessions.remove(consumerSessionImpl); - providerSessions.remove(consumerSessionImpl); - } - - private void checkPredicates(BindingAwareProvider prov) { - if (prov == null) - throw new IllegalArgumentException("Provider should not be null."); - for (ProviderSessionImpl session : providerSessions) { - if (prov.equals(session.getProvider())) - throw new IllegalStateException("Provider already registered"); - } - - } - - private void checkPredicates(BindingAwareConsumer cons) { - if (cons == null) - throw new IllegalArgumentException("Consumer should not be null."); - for (ConsumerSessionImpl session : sessions) { - if (cons.equals(session.getConsumer())) - throw new IllegalStateException("Consumer already registered"); - } - } - - private ConsumerSessionImpl newSessionFor(BindingAwareConsumer cons) { - return new ConsumerSessionImpl(cons); - } - - private ProviderSessionImpl newSessionFor(BindingAwareProvider provider) { - return new ProviderSessionImpl(provider); - } - - private T newSALServiceForSession( - Class service, ConsumerSession session) { - - SALBindingModule serviceProvider = salServiceProviders.get(service); - if (serviceProvider == null) { - return null; - } - return serviceProvider.getServiceForSession(service, session); - - } - - private T newRpcProxyForSession(Class service) { - - RpcMapper mapper = mapping.rpcMapperForClass(service); - if (mapper == null) { - log.error("Mapper for " + service + "is unavailable."); - return null; - } - T proxy = mapper.getConsumerProxy(rpcProxyHandler); - - return proxy; - } - - private Future> rpcProxyInvoked( - RpcService rpcProxy, QName rpcType, DataObject inputData) { - if (rpcProxy == null) { - throw new IllegalArgumentException("Proxy must not be null"); - } - if (rpcType == null) { - throw new IllegalArgumentException( - "rpcType (QName) should not be null"); - } - Future> ret = null; - - // Real invocation starts here - RpcMapper mapper = mapping - .rpcMapperForProxy(rpcProxy); - RpcService impl = rpcImpls.get(mapper.getServiceClass()); - - if (impl == null) { - // RPC is probably remote - CompositeNode inputNode = null; - Mapper inputMapper = mapper.getInputMapper(); - if (inputMapper != null) { - inputNode = inputMapper.domFromObject(inputData); - } - Future> biResult = biSession.rpc(rpcType, - inputNode); - ret = new TranslatedFuture(biResult, mapper); - - } else { - // RPC is local - Callable> invocation = localRpcCallableFor( - impl, mapper, rpcType, inputData); - ret = executor.submit(invocation); - } - return ret; - } - - private Callable> localRpcCallableFor( - final RpcService impl, - final RpcMapper mapper, final QName rpcType, - final DataObject inputData) { - - return new Callable>() { - - @Override - public RpcResult call() throws Exception { - return mapper.invokeRpcImplementation(rpcType, impl, inputData); - } - }; - } - - // Binding Independent invocation of Binding Aware RPC - private RpcResult invokeLocalRpc(QName rpc, - CompositeNode inputNode) { - RpcMapper mapper = mapping.rpcMapperForData(rpc, - inputNode); - - DataObject inputTO = mapper.getInputMapper().objectFromDom(inputNode); - - RpcService impl = rpcImpls.get(mapper.getServiceClass()); - if (impl == null) { - log.warn("Implementation for rpc: " + rpc + "not available."); - } - RpcResult result = mapper - .invokeRpcImplementation(rpc, impl, inputTO); - DataObject outputTO = result.getResult(); - - CompositeNode outputNode = null; - if (outputTO != null) { - outputNode = mapper.getOutputMapper().domFromObject(outputTO); - } - return Rpcs.getRpcResult(result.isSuccessful(), outputNode, - result.getErrors()); - } - - private class ConsumerSessionImpl implements - BindingAwareBroker.ConsumerSession { - - private final BindingAwareConsumer consumer; - private Map, BindingAwareService> sessionSalServices = Collections - .synchronizedMap(new HashMap, BindingAwareService>()); - - private Map, RpcService> sessionRpcProxies = Collections - .synchronizedMap(new HashMap, RpcService>()); - - public ConsumerSessionImpl(BindingAwareConsumer cons) { - this.consumer = cons; - } - - @Override - public T getSALService(Class service) { - - BindingAwareService serv = sessionSalServices.get(service); - if (serv != null) { - if (service.isInstance(serv)) { - @SuppressWarnings("unchecked") - T ret = (T) serv; - return ret; - } else { - log.error("Implementation for service " + service.getName() - + " does not implement the service interface"); - throw new IllegalStateException("Service implementation " - + serv.getClass().getName() + "does not implement " - + service.getName()); - } - } else { - T ret = BindingBrokerImpl.this.newSALServiceForSession(service, - this); - if (ret != null) { - sessionSalServices.put(service, ret); - } - return ret; - } - } - - @Override - public T getRpcService(Class service) { - RpcService current = sessionRpcProxies.get(service); - if (current != null) { - if (service.isInstance(current)) { - @SuppressWarnings("unchecked") - T ret = (T) current; - return ret; - } else { - log.error("Proxy for rpc service " + service.getName() - + " does not implement the service interface"); - throw new IllegalStateException("Service implementation " - + current.getClass().getName() - + "does not implement " + service.getName()); - } - } else { - T ret = BindingBrokerImpl.this.newRpcProxyForSession(service); - if (ret != null) { - sessionRpcProxies.put(service, ret); - } - return ret; - } - } - - public BindingAwareConsumer getConsumer() { - return this.consumer; - } - - } - - private class ProviderSessionImpl extends ConsumerSessionImpl implements - BindingAwareBroker.ProviderSession { - - private final BindingAwareProvider provider; - - public ProviderSessionImpl(BindingAwareProvider provider2) { - super(null); - this.provider = provider2; - } - - @Override - public void addRpcImplementation(RpcService implementation) { - if (implementation == null) { - throw new IllegalArgumentException( - "Implementation should not be null"); - } - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public void removeRpcImplementation(RpcService implementation) { - if (implementation == null) { - throw new IllegalArgumentException( - "Implementation should not be null"); - } - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - public BindingAwareProvider getProvider() { - return this.provider; - } - - } - - private class BIFacade implements Provider,RpcImplementation { - - @Override - public Set getSupportedRpcs() { - return Collections.emptySet(); - } - - @Override - public RpcResult invokeRpc(QName rpc, CompositeNode input) { - if (rpc == null) { - throw new IllegalArgumentException( - "Rpc type should not be null"); - } - - return BindingBrokerImpl.this.invokeLocalRpc(rpc, input); - } - - @Override - public void onSessionInitiated( - org.opendaylight.controller.sal.core.api.Broker.ProviderSession session) { - - BindingBrokerImpl.this.biSession = session; - for (SALBindingModule module : modules) { - try { - module.onBISessionAvailable(biSession); - } catch(Exception e) { - log.error("Module " +module +" throwed unexpected exception",e); - } - } - } - - @Override - public Collection getProviderFunctionality() { - return Collections.emptySet(); - } - - } - - private static class TranslatedFuture implements - Future> { - private final Future> realFuture; - private final RpcMapper mapper; - - public TranslatedFuture(Future> future, - RpcMapper mapper) { - realFuture = future; - this.mapper = mapper; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return realFuture.cancel(mayInterruptIfRunning); - } - - @Override - public boolean isCancelled() { - return realFuture.isCancelled(); - } - - @Override - public boolean isDone() { - return realFuture.isDone(); - } - - @Override - public RpcResult get() - throws InterruptedException, ExecutionException { - RpcResult val = realFuture.get(); - return tranlate(val); - } - - @Override - public RpcResult get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, - TimeoutException { - RpcResult val = realFuture.get(timeout, unit); - return tranlate(val); - } - - private RpcResult tranlate( - RpcResult result) { - CompositeNode outputNode = result.getResult(); - DataObject outputTO = null; - if (outputNode != null) { - Mapper outputMapper = mapper.getOutputMapper(); - outputTO = outputMapper.objectFromDom(outputNode); - } - return Rpcs.getRpcResult(result.isSuccessful(), outputTO, - result.getErrors()); - } - - } -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BrokerActivator.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BrokerActivator.java new file mode 100644 index 0000000000..c5d54ecba9 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BrokerActivator.java @@ -0,0 +1,45 @@ +/* + * 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.binding.impl; + +import java.util.Hashtable; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BrokerActivator implements BundleActivator { + + private static final Logger log = LoggerFactory.getLogger(BrokerActivator.class); + private BindingAwareBrokerImpl baSal; + private ServiceRegistration baSalRegistration; + + + @Override + public void start(BundleContext context) throws Exception { + log.info("Binding Aware Broker initialized"); + baSal = new BindingAwareBrokerImpl(); + baSal.setBrokerBundleContext(context); + baSal.start(); + + BindingAwareBroker baSalService = baSal; + Hashtable properties = new Hashtable<>(); + this.baSalRegistration = context.registerService(BindingAwareBroker.class,baSalService, properties); + + } + + @Override + public void stop(BundleContext context) throws Exception { + log.info("Binding Aware Broker stopped"); + baSalRegistration.unregister(); + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/Constants.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/Constants.xtend new file mode 100644 index 0000000000..668635a39e --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/Constants.xtend @@ -0,0 +1,21 @@ +/* + * 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.binding.impl + +class Constants { + + private new() { + } + + public static val SAL_SERVICE_TYPE = "salServiceType" + public static val SAL_SERVICE_TYPE_CONSUMER_PROXY = "consumerProxy" + public static val SAL_SERVICE_TYPE_PROVIDER = "provider" + public static val SAL_SERVICE_TYPE_CONNECTOR = "connector" + + public static val PROXY_DIRECT_SUFFIX = "DirectProxy"; +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/DataModule.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/DataModule.java deleted file mode 100644 index cbd6b00570..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/DataModule.java +++ /dev/null @@ -1,198 +0,0 @@ -package org.opendaylight.controller.sal.binding.impl; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; -import org.opendaylight.controller.sal.binding.api.BindingAwareService; -import org.opendaylight.controller.sal.binding.api.DataBrokerService; -import org.opendaylight.controller.sal.binding.api.DataCommitHandler; -import org.opendaylight.controller.sal.binding.api.DataProviderService; -import org.opendaylight.controller.sal.binding.api.DataValidator; -import org.opendaylight.controller.sal.binding.spi.MappingProvider; -import org.opendaylight.controller.sal.binding.spi.SALBindingModule; -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.binding.api.DataRefresher; -import org.opendaylight.controller.yang.binding.DataRoot; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - -public class DataModule implements SALBindingModule { - - private BindingAwareBroker broker; - private org.opendaylight.controller.sal.core.api.Broker.ProviderSession biSession; - private MappingProvider mappingProvider; - private final BIFacade biFacade = new BIFacade(); - private org.opendaylight.controller.sal.core.api.data.DataProviderService biDataService; - - @Override - public void setBroker(BindingAwareBroker broker) { - this.broker = broker; - } - - @Override - public void onBISessionAvailable( - org.opendaylight.controller.sal.core.api.Broker.ProviderSession session) { - this.biSession = session; - this.biDataService = session - .getService(org.opendaylight.controller.sal.core.api.data.DataProviderService.class); - // biDataService.addRefresher(store, refresher) - - } - - @Override - public void setMappingProvider(MappingProvider provider) { - this.mappingProvider = provider; - - } - - @Override - public Set> getProvidedServices() { - Set> ret = new HashSet>(); - ret.add(DataBrokerService.class); - ret.add(DataProviderService.class); - return ret; - } - - @Override - public T getServiceForSession( - Class service, ConsumerSession session) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Set> getSupportedProviderFunctionality() { - // TODO Auto-generated method stub - return null; - } - - private class DataBrokerSession implements DataBrokerService { - - @Override - public T getData(DataStoreIdentifier store, - Class rootType) { - // TODO Auto-generated method stub - return null; - } - - @Override - public T getData(DataStoreIdentifier store, - T filter) { - // TODO Auto-generated method stub - return null; - } - - @Override - public T getCandidateData( - DataStoreIdentifier store, Class rootType) { - // TODO Auto-generated method stub - return null; - } - - @Override - public T getCandidateData( - DataStoreIdentifier store, T filter) { - // TODO Auto-generated method stub - return null; - } - - @Override - public RpcResult editCandidateData(DataStoreIdentifier store, - DataRoot changeSet) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Future> commit(DataStoreIdentifier store) { - // TODO Auto-generated method stub - return null; - } - - } - - private class DataProviderSession extends DataBrokerSession implements - DataProviderService { - - @Override - public void addValidator(DataStoreIdentifier store, - DataValidator validator) { - // TODO Auto-generated method stub - - } - - @Override - public void removeValidator(DataStoreIdentifier store, - DataValidator validator) { - // TODO Auto-generated method stub - - } - - @Override - public void addCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider) { - // TODO Auto-generated method stub - - } - - @Override - public void removeCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider) { - // TODO Auto-generated method stub - - } - - @Override - public void addRefresher(DataStoreIdentifier store, - DataRefresher refresher) { - // TODO Auto-generated method stub - - } - - @Override - public void removeRefresher(DataStoreIdentifier store, - DataRefresher refresher) { - // TODO Auto-generated method stub - - } - - } - - private class BIFacade - implements - org.opendaylight.controller.sal.core.api.data.DataCommitHandler, - org.opendaylight.controller.sal.core.api.data.DataValidator, - org.opendaylight.controller.sal.core.api.data.DataProviderService.DataRefresher { - - @Override - public RpcResult validate(CompositeNode toValidate) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Set getSupportedDataStores() { - // TODO Auto-generated method stub - return null; - } - - @Override - public RpcResult requestCommit( - DataStoreIdentifier store) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void refreshData() { - // TODO Auto-generated method stub - - } - - } - -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend new file mode 100644 index 0000000000..da1ba79997 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend @@ -0,0 +1,51 @@ +/* + * 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.binding.impl + +import org.opendaylight.controller.sal.binding.api.NotificationProviderService +import org.opendaylight.yangtools.yang.binding.Notification +import com.google.common.collect.Multimap +import org.opendaylight.controller.sal.binding.api.NotificationListener +import com.google.common.collect.HashMultimap +import java.util.concurrent.ExecutorService +import java.util.Collection + +class NotificationBrokerImpl implements NotificationProviderService { + + val Multimap, NotificationListener> listeners; + val ExecutorService executor; + + new(ExecutorService executor) { + listeners = HashMultimap.create() + this.executor = executor; + } + + override addNotificationListener(Class notificationType, + NotificationListener listener) { + listeners.put(notificationType, listener) + } + + override removeNotificationListener(Class notificationType, + NotificationListener listener) { + listeners.remove(notificationType, listener) + } + + override notify(Notification notification) { + notification.notificationTypes.forEach [ + listeners.get(it as Class)?.notifyAll(notification) + ] + } + + def getNotificationTypes(Notification notification) { + notification.class.interfaces.filter[it != Notification && Notification.isAssignableFrom(it)] + } + + def notifyAll(Collection> listeners, Notification notification) { + listeners.forEach[(it as NotificationListener).onNotification(notification)] + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java deleted file mode 100644 index 640089affb..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java +++ /dev/null @@ -1,16 +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.binding.impl; - -import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtension; -import org.opendaylight.controller.yang.binding.Notification; -import org.opendaylight.controller.yang.binding.NotificationListener; - -public interface NotificationInvoker extends MappingExtension { - void notify(Notification notification, NotificationListener listener); -} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java deleted file mode 100644 index 89c44643ed..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java +++ /dev/null @@ -1,276 +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.binding.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareService; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.binding.api.NotificationService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; -import org.opendaylight.controller.sal.binding.spi.SALBindingModule; -import org.opendaylight.controller.sal.binding.spi.Mapper; -import org.opendaylight.controller.sal.binding.spi.MappingProvider; -import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtensionFactory; - -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.binding.Notification; -import org.opendaylight.controller.yang.binding.NotificationListener; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - -public class NotificationModule implements SALBindingModule { - - private ProviderSession biSession; - private org.opendaylight.controller.sal.core.api.notify.NotificationProviderService biNotifyService; - private MappingProvider mappingProvider; - - private Multimap, NotificationListener> listeners = HashMultimap - .create(); - private Set biNotifications = new HashSet(); - private static final Logger log = LoggerFactory - .getLogger(NotificationModule.class); - private final BindingIndependentListener biListener = new BindingIndependentListener(); - private BindingAwareBroker broker; - - @Override - public Set> getProvidedServices() { - - Set> ret = new HashSet>(); - ret.add(NotificationService.class); - ret.add(NotificationProviderService.class); - return ret; - } - - @Override - public T getServiceForSession( - Class service, ConsumerSession session) { - if (service == null) - throw new IllegalArgumentException("Service should not be null"); - if (session == null) - throw new IllegalArgumentException("Session should not be null"); - - if (NotificationProviderSession.class.equals(service)) { - if (session instanceof org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession) { - @SuppressWarnings("unchecked") - T ret = (T) new NotificationProviderSession(session); - return ret; - } else { - throw new IllegalArgumentException( - "NotificationProviderService is available only to ProviderSession"); - } - } - - if (NotificationService.class.equals(service)) { - @SuppressWarnings("unchecked") - T ret = (T) new NotificationSession(session); - return ret; - } - return null; - } - - @Override - public Set> getSupportedProviderFunctionality() { - return Collections.emptySet(); - } - - @Override - public void setBroker(BindingAwareBroker broker) { - this.broker = broker; - } - - @Override - public void setMappingProvider(MappingProvider provider) { - this.mappingProvider = provider; - } - - @Override - public void onBISessionAvailable(ProviderSession session) { - biSession = session; - if (biSession != null) { - biNotifyService = session - .getService(org.opendaylight.controller.sal.core.api.notify.NotificationProviderService.class); - } - } - - private void notify(Notification notification) { - notifyBindingIndependent(notification); - notifyBindingAware(notification); - } - - private void notifyBindingAware(Notification notification) { - Class type = notification.getClass(); - Collection toNotify = listeners.get(type); - - // Invocation of notification on registered listeners - if (toNotify != null) { - - // We get factory for Notification Invoker - MappingExtensionFactory invokerFactory = mappingProvider - .getExtensionFactory(NotificationInvoker.class); - - // We get generated invoker for NoficiationListener interface - // associated to Notification Type - NotificationInvoker invoker = invokerFactory.forClass(type); - for (NotificationListener listener : toNotify) { - try { - // Invoker invokes the right method on subtype of - // NotificationListener - // associated to the type of notification - invoker.notify(notification, listener); - } catch (Exception e) { - - } - } - } - } - - private void notifyBindingIndependent(Notification notification) { - Class type = notification.getClass(); - - if (biSession == null) { - return; - } - if (biSession.isClosed()) { - return; - } - if (biNotifyService == null) { - return; - } - - // FIXME: Somehow we need to resolve this for class hierarchy. - // probably use type.getInterfaces() - Mapper mapper = mappingProvider - .mapperForClass(type); - CompositeNode domNotification = mapper.domFromObject(notification); - - biNotifyService.sendNotification(domNotification); - } - - private void addBAListener(Class notificationType, - NotificationListener listener) { - - listeners.put(notificationType, listener); - Mapper mapper = mappingProvider - .mapperForClass(notificationType); - QName biType = mapper.getQName(); - if (false == biNotifications.contains(biType)) { - // The listener is not registered for binding independent - // notification - biNotifications.add(biType); - - if (biNotifyService != null) { - biNotifyService.addNotificationListener(biType, biListener); - } - } - - } - - private void removeBAListener( - Class notificationType, - NotificationListener listener) { - listeners.remove(notificationType, listener); - } - - private class NotificationSession implements NotificationService { - private final ConsumerSession session; - private Multimap, NotificationListener> sessionListeners = HashMultimap - .create(); - - public NotificationSession(ConsumerSession session) { - this.session = session; - } - - @Override - public void addNotificationListener( - Class notificationType, - NotificationListener listener) { - - NotificationModule.this.addBAListener(notificationType, listener); - sessionListeners.put(notificationType, listener); - - } - - @Override - public void removeNotificationListener( - Class notificationType, - NotificationListener listener) { - sessionListeners.remove(notificationType, listener); - NotificationModule.this - .removeBAListener(notificationType, listener); - } - - } - - private class NotificationProviderSession extends NotificationSession - implements NotificationProviderService { - - public NotificationProviderSession(ConsumerSession session) { - super(session); - } - - @Override - public void notify(Notification notification) { - NotificationModule.this.notify(notification); - } - - } - - private class BindingIndependentListener - implements - org.opendaylight.controller.sal.core.api.notify.NotificationListener { - - @Override - public Set getSupportedNotifications() { - return biNotifications; - } - - @Override - public void onNotification(CompositeNode notification) { - NotificationModule.this - .onBindingIndependentNotification(notification); - } - - } - - private void onBindingIndependentNotification(CompositeNode biNotification) { - QName biType = biNotification.getNodeType(); - - Mapper mapper = mappingProvider.mapperForQName(biType); - if (mapper == null) { - log.info("Received notification does not have a binding defined."); - return; - } - Class type = mapper.getDataObjectClass(); - - // We check if the received QName / type is really Notification - if (Notification.class.isAssignableFrom(type)) { - Notification notification = (Notification) mapper - .objectFromDom(biNotification); - notifyBindingAware(notification); - } else { - // The generated type for this QName does not inherits from - // notification something went wrong - generated APIs and/or - // provider sending notification - // which was incorectly described in the YANG schema. - log.error("Received notification " + biType - + " is not binded as notification"); - } - - } -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationServiceImpl.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationServiceImpl.xtend new file mode 100644 index 0000000000..fb35ee3779 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationServiceImpl.xtend @@ -0,0 +1,33 @@ +/* + * 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.binding.impl + +import org.opendaylight.controller.sal.binding.api.NotificationService +import org.opendaylight.controller.sal.binding.api.NotificationListener +import org.opendaylight.yangtools.yang.binding.Notification +import com.google.common.collect.Multimap +import com.google.common.collect.HashMultimap + +class NotificationServiceImpl implements NotificationService { + val Multimap, NotificationListener> listeners; + + new() { + listeners = HashMultimap.create() + } + + override addNotificationListener(Class notificationType, + NotificationListener listener) { + listeners.put(notificationType, listener) + } + + override removeNotificationListener(Class notificationType, + NotificationListener listener) { + listeners.remove(notificationType, listener) + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend new file mode 100644 index 0000000000..a87fa0642a --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend @@ -0,0 +1,53 @@ +package org.opendaylight.controller.sal.binding.impl; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareService; +import org.opendaylight.yangtools.yang.binding.RpcService; +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; +import org.slf4j.LoggerFactory + +class OsgiConsumerContext implements ConsumerContext { + + static val log = LoggerFactory.getLogger(OsgiConsumerContext) + protected val BundleContext bundleContext; + protected val BindingAwareBrokerImpl broker; + + new(BundleContext ctx,BindingAwareBrokerImpl broker) { + this.bundleContext = ctx; + this.broker = broker; + } + + + override def getSALService(Class service) { + // SAL Services are global + var ref = bundleContext.getServiceReference(service); + return bundleContext.getService(ref) as T; + } + + + + override def T getRpcService(Class module) { + try { + + val services = bundleContext.getServiceReferences(module, getProxyFilter()); + + // Proxy service found / using first implementation + // FIXME: Add advanced logic to retrieve service with right set of models + if(false == services.empty) { + val ref = services.iterator().next() as ServiceReference; + return bundleContext.getService(ref) as T; + } + } catch (InvalidSyntaxException e) { + log.error("Created filter was invalid:", e.message,e) + } + return null; + + + } + + private def getProxyFilter() { + return '''(«Constants.SAL_SERVICE_TYPE»=«Constants.SAL_SERVICE_TYPE_CONSUMER_PROXY»)''' + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend new file mode 100644 index 0000000000..195fa8b959 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend @@ -0,0 +1,42 @@ +/* + * 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.binding.impl; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcServiceRegistration; +import org.opendaylight.yangtools.yang.binding.RpcService; +import org.osgi.framework.BundleContext; + +import static extension org.opendaylight.controller.sal.binding.impl.utils.PropertiesUtils.*; + +class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext { + + @Property + val Map, RpcServiceRegistrationImpl> registeredServices + + new(BundleContext ctx, BindingAwareBrokerImpl broker) { + super(ctx, broker); + _registeredServices = new HashMap(); + } + + override def RpcServiceRegistration addRpcImplementation(Class type, T implementation) { + + // TODO Auto-generated method stub + val properties = new Hashtable(); + properties.salServiceType = Constants.SAL_SERVICE_TYPE_PROVIDER + + // Fill requirements + val salReg = broker.registerRpcImplementation(type, implementation, this, properties) + registeredServices.put(type, salReg) + return salReg; + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend new file mode 100644 index 0000000000..07494599f8 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend @@ -0,0 +1,26 @@ +/* + * 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.binding.impl + +import org.opendaylight.yangtools.yang.binding.RpcService +import org.osgi.framework.ServiceRegistration + +class RpcProxyContext { + + new(Class proxyClass) { + this.proxyClass = proxyClass + } + + protected val Class proxyClass; + + @Property + protected var RpcService proxy; + + @Property + protected var ServiceRegistration registration; +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcServiceRegistrationImpl.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcServiceRegistrationImpl.xtend new file mode 100644 index 0000000000..afb27b47c6 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcServiceRegistrationImpl.xtend @@ -0,0 +1,33 @@ +/* + * 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.binding.impl + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcServiceRegistration +import org.osgi.framework.ServiceRegistration +import org.opendaylight.yangtools.yang.binding.RpcService + +class RpcServiceRegistrationImpl implements RpcServiceRegistration { + + val ServiceRegistration osgiRegistration; + private val T service; + val Class cls; + + public new(Class type, T service, ServiceRegistration osgiReg) { + this.cls = type; + this.osgiRegistration = osgiReg; + this.service = service; + } + + override getService() { + this.service + } + + override unregister() { + throw new UnsupportedOperationException("TODO: auto-generated method stub") + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/GeneratorUtils.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/GeneratorUtils.xtend new file mode 100644 index 0000000000..e94c3759a9 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/GeneratorUtils.xtend @@ -0,0 +1,23 @@ +/* + * 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.binding.impl.utils + +import javassist.ClassPool + +class GeneratorUtils { + + static val PREFIX = "_gen."; + + public static def generatedName(Class cls, String suffix) { + '''«PREFIX»«cls.package.name».«cls.simpleName»$«suffix»'''.toString() + } + + public static def get(ClassPool pool,Class cls) { + pool.get(cls.name); + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/PropertiesUtils.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/PropertiesUtils.xtend new file mode 100644 index 0000000000..7ba62f5ca1 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/PropertiesUtils.xtend @@ -0,0 +1,30 @@ +/* + * 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.binding.impl.utils + +import java.util.Hashtable +import org.opendaylight.controller.sal.binding.impl.Constants + +class PropertiesUtils { + + private new() {} + + static def setSalServiceType(Hashtable properties, String value) { + properties.put(Constants.SAL_SERVICE_TYPE,value) + return properties + } + + static def getSalServiceType(Hashtable properties) { + return properties.get(Constants.SAL_SERVICE_TYPE) + } + + static def newProperties() { + new Hashtable() + } + +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/package-info.java new file mode 100644 index 0000000000..511023860e --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/package-info.java @@ -0,0 +1,8 @@ +/* + * 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.binding.impl.utils; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml index fd7fad6f14..8d0ddad9fe 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-binding-spi diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/DataDomToJavaTransformer.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/DataDomToJavaTransformer.java index db35de1ab7..bdcb2c2171 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/DataDomToJavaTransformer.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/DataDomToJavaTransformer.java @@ -8,9 +8,9 @@ package org.opendaylight.controller.sal.binding.spi; import org.opendaylight.controller.concepts.lang.Transformer; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; public interface DataDomToJavaTransformer

    extends Transformer { diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/JavaToDataDomTransformer.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/JavaToDataDomTransformer.java index 3c4d486012..21154b4078 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/JavaToDataDomTransformer.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/JavaToDataDomTransformer.java @@ -8,8 +8,8 @@ package org.opendaylight.controller.sal.binding.spi; import org.opendaylight.controller.concepts.lang.InputClassBasedTransformer; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; public interface JavaToDataDomTransformer extends InputClassBasedTransformer { diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java index 701e72c9dc..44ca27e89f 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java @@ -7,9 +7,9 @@ */ package org.opendaylight.controller.sal.binding.spi; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; /** * Translator between Binding-Independent format and generated Binding Data Objects * diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java index b29eac2871..b3eded9939 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java @@ -7,10 +7,10 @@ */ package org.opendaylight.controller.sal.binding.spi; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.binding.RpcService; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.RpcService; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; public interface MappingProvider { diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcMapper.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcMapper.java index 0db1bc2775..3e32ebc479 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcMapper.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcMapper.java @@ -11,10 +11,10 @@ import java.util.Set; import java.util.concurrent.Future; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.yang.binding.DataObject; -import org.opendaylight.controller.yang.binding.RpcService; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.RpcService; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; public interface RpcMapper { diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java deleted file mode 100644 index f3ecf8004c..0000000000 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java +++ /dev/null @@ -1,31 +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.binding.spi; - -import java.util.Set; - -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; - -public interface SALBindingModule { - - void setBroker(BindingAwareBroker broker); - void onBISessionAvailable(ProviderSession session); - - void setMappingProvider(MappingProvider provider); - - Set> getProvidedServices(); - - T getServiceForSession(Class service, - ConsumerSession session); - - Set> getSupportedProviderFunctionality(); -} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml index 779a6dc6ab..0bb4041b9f 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-broker-impl @@ -32,5 +32,5 @@ guava jar - + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java index b8a0b97eab..f0d1cc609d 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java @@ -1,280 +1,280 @@ -/* - * 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.core.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.spi.BrokerModule; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BrokerImpl implements Broker { - private static Logger log = LoggerFactory.getLogger(BrokerImpl.class); - - // Broker Generic Context - private Set sessions = Collections - .synchronizedSet(new HashSet()); - private Set providerSessions = Collections - .synchronizedSet(new HashSet()); - private Set modules = Collections - .synchronizedSet(new HashSet()); - private Map, BrokerModule> serviceProviders = Collections - .synchronizedMap(new HashMap, BrokerModule>()); - - // RPC Context - private Map rpcImpls = Collections - .synchronizedMap(new HashMap()); - - // Implementation specific - private ExecutorService executor; - - @Override - public ConsumerSession registerConsumer(Consumer consumer) { - checkPredicates(consumer); - log.info("Registering consumer " + consumer); - ConsumerSessionImpl session = newSessionFor(consumer); - consumer.onSessionInitiated(session); - sessions.add(session); - return session; - } - - @Override - public ProviderSession registerProvider(Provider provider) { - checkPredicates(provider); - - ProviderSessionImpl session = newSessionFor(provider); - provider.onSessionInitiated(session); - providerSessions.add(session); - return session; - } - - public void addModule(BrokerModule module) { - log.info("Registering broker module " + module); - if (modules.contains(module)) { - log.error("Module already registered"); - throw new IllegalArgumentException("Module already exists."); - } - - Set> provServices = module - .getProvidedServices(); - for (Class serviceType : provServices) { - log.info(" Registering session service implementation: " - + serviceType.getCanonicalName()); - serviceProviders.put(serviceType, module); - } - } - - public T serviceFor(Class service, - ConsumerSessionImpl session) { - BrokerModule prov = serviceProviders.get(service); - if (prov == null) { - log.warn("Service " + service.toString() + " is not supported"); - return null; - } - return prov.getServiceForSession(service, session); - } - - // RPC Functionality - - private void addRpcImplementation(QName rpcType, - RpcImplementation implementation) { - synchronized (rpcImpls) { - if (rpcImpls.get(rpcType) != null) { - throw new IllegalStateException("Implementation for rpc " - + rpcType + " is already registered."); - } - rpcImpls.put(rpcType, implementation); - } - // TODO Add notification for availability of Rpc Implementation - } - - private void removeRpcImplementation(QName rpcType, - RpcImplementation implToRemove) { - synchronized (rpcImpls) { - if (implToRemove == rpcImpls.get(rpcType)) { - rpcImpls.remove(rpcType); - } - } - // TODO Add notification for removal of Rpc Implementation - } - - private Future> invokeRpc(QName rpc, - CompositeNode input) { - RpcImplementation impl = rpcImpls.get(rpc); - // if() - - Callable> call = callableFor(impl, - rpc, input); - Future> result = executor.submit(call); - - return result; - } - - // Validation - - private void checkPredicates(Provider prov) { - if (prov == null) - throw new IllegalArgumentException("Provider should not be null."); - for (ProviderSessionImpl session : providerSessions) { - if (prov.equals(session.getProvider())) - throw new IllegalStateException("Provider already registered"); - } - - } - - private void checkPredicates(Consumer cons) { - if (cons == null) - throw new IllegalArgumentException("Consumer should not be null."); - for (ConsumerSessionImpl session : sessions) { - if (cons.equals(session.getConsumer())) - throw new IllegalStateException("Consumer already registered"); - } - } - - // Private Factory methods - - private ConsumerSessionImpl newSessionFor(Consumer cons) { - return new ConsumerSessionImpl(cons); - } - - private ProviderSessionImpl newSessionFor(Provider provider) { - return new ProviderSessionImpl(provider); - } - - private void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { - sessions.remove(consumerSessionImpl); - providerSessions.remove(consumerSessionImpl); - } - - private static Callable> callableFor( - final RpcImplementation implemenation, final QName rpc, - final CompositeNode input) { - - return new Callable>() { - - @Override - public RpcResult call() throws Exception { - return implemenation.invokeRpc(rpc, input); - } - }; - } - - private class ConsumerSessionImpl implements ConsumerSession { - - private final Consumer consumer; - - private Map, BrokerService> instantiatedServices = Collections - .synchronizedMap(new HashMap, BrokerService>()); - private boolean closed = false; - - public Consumer getConsumer() { - return consumer; - } - - public ConsumerSessionImpl(Consumer consumer) { - this.consumer = consumer; - } - - @Override - public Future> rpc(QName rpc, - CompositeNode input) { - return BrokerImpl.this.invokeRpc(rpc, input); - } - - @Override - public T getService(Class service) { - BrokerService potential = instantiatedServices.get(service); - if (potential != null) { - @SuppressWarnings("unchecked") - T ret = (T) potential; - return ret; - } - T ret = BrokerImpl.this.serviceFor(service, this); - if (ret != null) { - instantiatedServices.put(service, ret); - } - return ret; - } - - @Override - public void close() { - Collection toStop = instantiatedServices.values(); - this.closed = true; - for (BrokerService brokerService : toStop) { - brokerService.closeSession(); - } - BrokerImpl.this.consumerSessionClosed(this); - } - - @Override - public boolean isClosed() { - return closed; - } - - } - - private class ProviderSessionImpl extends ConsumerSessionImpl implements - ProviderSession { - - private Provider provider; - private Map sessionRpcImpls = Collections.synchronizedMap(new HashMap()); - - public ProviderSessionImpl(Provider provider) { - super(null); - this.provider = provider; - } - - @Override - public void addRpcImplementation(QName rpcType, - RpcImplementation implementation) - throws IllegalArgumentException { - if (rpcType == null) { - throw new IllegalArgumentException("rpcType must not be null"); - } - if (implementation == null) { - throw new IllegalArgumentException( - "Implementation must not be null"); - } - BrokerImpl.this.addRpcImplementation(rpcType, implementation); - sessionRpcImpls.put(rpcType, implementation); - } - - @Override - public void removeRpcImplementation(QName rpcType, - RpcImplementation implToRemove) throws IllegalArgumentException { - RpcImplementation localImpl = rpcImpls.get(rpcType); - if (localImpl != implToRemove) { - throw new IllegalStateException( - "Implementation was not registered in this session"); - } - - BrokerImpl.this.removeRpcImplementation(rpcType, implToRemove); - sessionRpcImpls.remove(rpcType); - } - - public Provider getProvider() { - return this.provider; - } - - } -} +/* + * 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.core.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.controller.sal.core.spi.BrokerModule; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BrokerImpl implements Broker { + private static Logger log = LoggerFactory.getLogger(BrokerImpl.class); + + // Broker Generic Context + private Set sessions = Collections + .synchronizedSet(new HashSet()); + private Set providerSessions = Collections + .synchronizedSet(new HashSet()); + private Set modules = Collections + .synchronizedSet(new HashSet()); + private Map, BrokerModule> serviceProviders = Collections + .synchronizedMap(new HashMap, BrokerModule>()); + + // RPC Context + private Map rpcImpls = Collections + .synchronizedMap(new HashMap()); + + // Implementation specific + private ExecutorService executor; + + @Override + public ConsumerSession registerConsumer(Consumer consumer) { + checkPredicates(consumer); + log.info("Registering consumer " + consumer); + ConsumerSessionImpl session = newSessionFor(consumer); + consumer.onSessionInitiated(session); + sessions.add(session); + return session; + } + + @Override + public ProviderSession registerProvider(Provider provider) { + checkPredicates(provider); + + ProviderSessionImpl session = newSessionFor(provider); + provider.onSessionInitiated(session); + providerSessions.add(session); + return session; + } + + public void addModule(BrokerModule module) { + log.info("Registering broker module " + module); + if (modules.contains(module)) { + log.error("Module already registered"); + throw new IllegalArgumentException("Module already exists."); + } + + Set> provServices = module + .getProvidedServices(); + for (Class serviceType : provServices) { + log.info(" Registering session service implementation: " + + serviceType.getCanonicalName()); + serviceProviders.put(serviceType, module); + } + } + + public T serviceFor(Class service, + ConsumerSessionImpl session) { + BrokerModule prov = serviceProviders.get(service); + if (prov == null) { + log.warn("Service " + service.toString() + " is not supported"); + return null; + } + return prov.getServiceForSession(service, session); + } + + // RPC Functionality + + private void addRpcImplementation(QName rpcType, + RpcImplementation implementation) { + synchronized (rpcImpls) { + if (rpcImpls.get(rpcType) != null) { + throw new IllegalStateException("Implementation for rpc " + + rpcType + " is already registered."); + } + rpcImpls.put(rpcType, implementation); + } + // TODO Add notification for availability of Rpc Implementation + } + + private void removeRpcImplementation(QName rpcType, + RpcImplementation implToRemove) { + synchronized (rpcImpls) { + if (implToRemove == rpcImpls.get(rpcType)) { + rpcImpls.remove(rpcType); + } + } + // TODO Add notification for removal of Rpc Implementation + } + + private Future> invokeRpc(QName rpc, + CompositeNode input) { + RpcImplementation impl = rpcImpls.get(rpc); + // if() + + Callable> call = callableFor(impl, + rpc, input); + Future> result = executor.submit(call); + + return result; + } + + // Validation + + private void checkPredicates(Provider prov) { + if (prov == null) + throw new IllegalArgumentException("Provider should not be null."); + for (ProviderSessionImpl session : providerSessions) { + if (prov.equals(session.getProvider())) + throw new IllegalStateException("Provider already registered"); + } + + } + + private void checkPredicates(Consumer cons) { + if (cons == null) + throw new IllegalArgumentException("Consumer should not be null."); + for (ConsumerSessionImpl session : sessions) { + if (cons.equals(session.getConsumer())) + throw new IllegalStateException("Consumer already registered"); + } + } + + // Private Factory methods + + private ConsumerSessionImpl newSessionFor(Consumer cons) { + return new ConsumerSessionImpl(cons); + } + + private ProviderSessionImpl newSessionFor(Provider provider) { + return new ProviderSessionImpl(provider); + } + + private void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { + sessions.remove(consumerSessionImpl); + providerSessions.remove(consumerSessionImpl); + } + + private static Callable> callableFor( + final RpcImplementation implemenation, final QName rpc, + final CompositeNode input) { + + return new Callable>() { + + @Override + public RpcResult call() throws Exception { + return implemenation.invokeRpc(rpc, input); + } + }; + } + + private class ConsumerSessionImpl implements ConsumerSession { + + private final Consumer consumer; + + private Map, BrokerService> instantiatedServices = Collections + .synchronizedMap(new HashMap, BrokerService>()); + private boolean closed = false; + + public Consumer getConsumer() { + return consumer; + } + + public ConsumerSessionImpl(Consumer consumer) { + this.consumer = consumer; + } + + @Override + public Future> rpc(QName rpc, + CompositeNode input) { + return BrokerImpl.this.invokeRpc(rpc, input); + } + + @Override + public T getService(Class service) { + BrokerService potential = instantiatedServices.get(service); + if (potential != null) { + @SuppressWarnings("unchecked") + T ret = (T) potential; + return ret; + } + T ret = BrokerImpl.this.serviceFor(service, this); + if (ret != null) { + instantiatedServices.put(service, ret); + } + return ret; + } + + @Override + public void close() { + Collection toStop = instantiatedServices.values(); + this.closed = true; + for (BrokerService brokerService : toStop) { + brokerService.closeSession(); + } + BrokerImpl.this.consumerSessionClosed(this); + } + + @Override + public boolean isClosed() { + return closed; + } + + } + + private class ProviderSessionImpl extends ConsumerSessionImpl implements + ProviderSession { + + private Provider provider; + private Map sessionRpcImpls = Collections.synchronizedMap(new HashMap()); + + public ProviderSessionImpl(Provider provider) { + super(null); + this.provider = provider; + } + + @Override + public void addRpcImplementation(QName rpcType, + RpcImplementation implementation) + throws IllegalArgumentException { + if (rpcType == null) { + throw new IllegalArgumentException("rpcType must not be null"); + } + if (implementation == null) { + throw new IllegalArgumentException( + "Implementation must not be null"); + } + BrokerImpl.this.addRpcImplementation(rpcType, implementation); + sessionRpcImpls.put(rpcType, implementation); + } + + @Override + public void removeRpcImplementation(QName rpcType, + RpcImplementation implToRemove) throws IllegalArgumentException { + RpcImplementation localImpl = rpcImpls.get(rpcType); + if (localImpl != implToRemove) { + throw new IllegalStateException( + "Implementation was not registered in this session"); + } + + BrokerImpl.this.removeRpcImplementation(rpcType, implToRemove); + sessionRpcImpls.remove(rpcType); + } + + public Provider getProvider() { + return this.provider; + } + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java index 852f6b6e87..34eba18fce 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java @@ -1,419 +1,419 @@ -/* - * 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.core.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality; -import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality; -import org.opendaylight.controller.sal.core.api.data.DataBrokerService; -import org.opendaylight.controller.sal.core.api.data.DataCommitHandler; -import org.opendaylight.controller.sal.core.api.data.DataProviderService; -import org.opendaylight.controller.sal.core.api.data.DataValidator; -import org.opendaylight.controller.sal.core.api.data.DataCommitHandler.CommitTransaction; -import org.opendaylight.controller.sal.core.api.data.DataProviderService.DataRefresher; -import org.opendaylight.controller.sal.core.spi.BrokerModule; -import org.opendaylight.controller.yang.common.RpcError; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.opendaylight.controller.yang.data.api.CompositeNodeModification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableSet; - -public class DataBrokerModule implements BrokerModule { - - private static final Logger log = LoggerFactory - .getLogger(DataBrokerModule.class); - - private static final Set> SUPPORTED_PROVIDER_FUNCTIONALITY = ImmutableSet - .of((Class) DataValidator.class, - DataRefresher.class, DataCommitHandler.class); - - private static final Set> PROVIDED_SESSION_SERVICES = ImmutableSet - .of((Class) DataBrokerService.class, - DataProviderService.class); - - private Map storeContext; - - private ExecutorService executor; - - private SequentialCommitHandlerCoordinator coordinator = new SequentialCommitHandlerCoordinator(); - - @Override - public Set> getProvidedServices() { - return PROVIDED_SESSION_SERVICES; - } - - @Override - public Set> getSupportedProviderFunctionality() { - return SUPPORTED_PROVIDER_FUNCTIONALITY; - } - - @Override - public Set> getSupportedConsumerFunctionality() { - return Collections.emptySet(); - } - - @Override - public T getServiceForSession(Class service, - ConsumerSession session) { - if (DataProviderService.class.equals(service) - && session instanceof ProviderSession) { - @SuppressWarnings("unchecked") - T ret = (T) newDataProviderService(session); - return ret; - } else if (DataBrokerService.class.equals(service)) { - - @SuppressWarnings("unchecked") - T ret = (T) newDataConsumerService(session); - return ret; - } - - throw new IllegalArgumentException( - "The requested session-specific service is not provided by this module."); - } - - private DataProviderService newDataProviderService(ConsumerSession session) { - return new DataProviderSession(); - } - - private DataBrokerService newDataConsumerService(ConsumerSession session) { - return new DataConsumerSession(); - } - - private StoreContext context(DataStoreIdentifier store) { - return storeContext.get(store); - } - - private static class StoreContext { - private Set commitHandlers = Collections - .synchronizedSet(new HashSet()); - private Set validators = Collections - .synchronizedSet(new HashSet()); - private Set refreshers = Collections - .synchronizedSet(new HashSet()); - } - - private class DataConsumerSession implements DataBrokerService { - - @Override - public CompositeNode getData(DataStoreIdentifier store) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public CompositeNode getData(DataStoreIdentifier store, - CompositeNode filter) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public CompositeNode getCandidateData(DataStoreIdentifier store) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public CompositeNode getCandidateData(DataStoreIdentifier store, - CompositeNode filter) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public RpcResult editCandidateData( - DataStoreIdentifier store, CompositeNodeModification changeSet) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public Future> commit(DataStoreIdentifier store) { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public void closeSession() { - // TODO Implement this method - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public Set getDataStores() { - // TODO Auto-generated method stub - return null; - } - - } - - private class DataProviderSession extends DataConsumerSession implements - DataProviderService { - - private Set providerCommitHandlers = new HashSet(); - private Set providerValidators = new HashSet(); - private Set providerRefreshers = new HashSet(); - - @Override - public void addValidator(DataStoreIdentifier store, - DataValidator validator) { - if (validator == null) - throw new IllegalArgumentException( - "Validator should not be null"); - - providerValidators.add(validator); - context(store).validators.add(validator); - } - - @Override - public void removeValidator(DataStoreIdentifier store, - DataValidator validator) { - if (validator == null) - throw new IllegalArgumentException( - "Validator should not be null"); - - providerValidators.remove(validator); - context(store).validators.remove(validator); - } - - @Override - public void addCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider) { - if (provider == null) - throw new IllegalArgumentException( - "CommitHandler should not be null"); - - providerCommitHandlers.add(provider); - context(store).commitHandlers.add(provider); - } - - @Override - public void removeCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider) { - if (provider == null) - throw new IllegalArgumentException( - "CommitHandler should not be null"); - - providerCommitHandlers.remove(provider); - context(store).commitHandlers.remove(provider); - } - - @Override - public void addRefresher(DataStoreIdentifier store, - DataRefresher provider) { - if (provider == null) - throw new IllegalArgumentException( - "Refresher should not be null"); - - providerRefreshers.add(provider); - context(store).refreshers.add(provider); - } - - @Override - public void removeRefresher(DataStoreIdentifier store, - DataRefresher provider) { - if (provider == null) - throw new IllegalArgumentException( - "Refresher should not be null"); - - providerRefreshers.remove(provider); - context(store).refreshers.remove(provider); - } - - } - - private class SequentialCommitHandlerCoordinator implements - DataCommitHandler { - - @Override - public RpcResult requestCommit( - DataStoreIdentifier store) { - List errors = new ArrayList(); - Set transactions = new HashSet(); - boolean successful = true; - - for (DataCommitHandler commitHandler : context(store).commitHandlers) { - try { - RpcResult partialResult = commitHandler - .requestCommit(store); - successful = partialResult.isSuccessful() & successful; - if (partialResult.isSuccessful()) { - transactions.add(partialResult.getResult()); - } - - errors.addAll(partialResult.getErrors()); - } catch (Exception e) { - log.error("Uncaught exception prevented commit request." - + e.getMessage(), e); - successful = false; - // FIXME: Add RPC Error with exception. - } - if (successful == false) - break; - } - CommitTransaction transaction = new SequentialCommitTransaction( - store, transactions); - return Rpcs.getRpcResult(successful, transaction, errors); - } - - @Override - public Set getSupportedDataStores() { - return Collections.emptySet(); - } - } - - private class SequentialCommitTransaction implements CommitTransaction { - - final Set transactions; - final DataStoreIdentifier store; - - public SequentialCommitTransaction(DataStoreIdentifier s, - Set t) { - transactions = t; - store = s; - } - - @Override - public RpcResult finish() { - List errors = new ArrayList(); - boolean successful = true; - - for (CommitTransaction commitHandler : transactions) { - try { - RpcResult partialResult = commitHandler.finish(); - successful = partialResult.isSuccessful() & successful; - errors.addAll(partialResult.getErrors()); - } catch (Exception e) { - log.error( - "Uncaught exception prevented finishing of commit." - + e.getMessage(), e); - successful = false; - // FIXME: Add RPC Error with exception. - } - if (successful == false) - break; - } - - return Rpcs.getRpcResult(successful, null, errors); - } - - @Override - public RpcResult rollback() { - List errors = new ArrayList(); - boolean successful = true; - - for (CommitTransaction commitHandler : transactions) { - try { - RpcResult partialResult = commitHandler.rollback(); - successful = partialResult.isSuccessful() & successful; - errors.addAll(partialResult.getErrors()); - } catch (Exception e) { - log.error( - "Uncaught exception prevented rollback of commit." - + e.getMessage(), e); - successful = false; - // FIXME: Add RPC Error with exception. - } - if (successful == false) - break; - } - - return Rpcs.getRpcResult(successful, null, errors); - } - - @Override - public DataStoreIdentifier getDataStore() { - return this.store; - } - - @Override - public DataCommitHandler getHandler() { - return coordinator; - } - } - - private class ValidationCoordinator implements DataValidator { - - private final DataStoreIdentifier store; - - ValidationCoordinator(DataStoreIdentifier store) { - this.store = store; - } - - @Override - public RpcResult validate(CompositeNode toValidate) { - List errors = new ArrayList(); - boolean successful = true; - - for (DataValidator validator : context(store).validators) { - try { - RpcResult partialResult = validator - .validate(toValidate); - successful = partialResult.isSuccessful() & successful; - errors.addAll(partialResult.getErrors()); - } catch (Exception e) { - log.error( - "Uncaught exception prevented validation." - + e.getMessage(), e); - successful = false; - // FIXME: Add RPC Error with exception. - } - if (successful == false) - break; - } - - return Rpcs.getRpcResult(successful, null, errors); - } - - @Override - public Set getSupportedDataStores() { - return Collections.emptySet(); - } - - } - - private class DataRefreshCoordinator implements DataRefresher { - - private final DataStoreIdentifier store; - - DataRefreshCoordinator(DataStoreIdentifier store) { - this.store = store; - } - - @Override - public void refreshData() { - - for (DataRefresher refresher : context(store).refreshers) { - try { - refresher.refreshData(); - } catch (Exception e) { - log.error( - "Uncaught exception during refresh of data: " - + e.getMessage(), e); - } - - } - } - } -} +/* + * 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.core.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.common.util.Rpcs; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality; +import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality; +import org.opendaylight.controller.sal.core.api.data.DataBrokerService; +import org.opendaylight.controller.sal.core.api.data.DataCommitHandler; +import org.opendaylight.controller.sal.core.api.data.DataProviderService; +import org.opendaylight.controller.sal.core.api.data.DataValidator; +import org.opendaylight.controller.sal.core.api.data.DataCommitHandler.CommitTransaction; +import org.opendaylight.controller.sal.core.api.data.DataProviderService.DataRefresher; +import org.opendaylight.controller.sal.core.spi.BrokerModule; +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.MutableCompositeNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableSet; + +public class DataBrokerModule implements BrokerModule { + + private static final Logger log = LoggerFactory + .getLogger(DataBrokerModule.class); + + private static final Set> SUPPORTED_PROVIDER_FUNCTIONALITY = ImmutableSet + .of((Class) DataValidator.class, + DataRefresher.class, DataCommitHandler.class); + + private static final Set> PROVIDED_SESSION_SERVICES = ImmutableSet + .of((Class) DataBrokerService.class, + DataProviderService.class); + + private Map storeContext; + + private ExecutorService executor; + + private SequentialCommitHandlerCoordinator coordinator = new SequentialCommitHandlerCoordinator(); + + @Override + public Set> getProvidedServices() { + return PROVIDED_SESSION_SERVICES; + } + + @Override + public Set> getSupportedProviderFunctionality() { + return SUPPORTED_PROVIDER_FUNCTIONALITY; + } + + @Override + public Set> getSupportedConsumerFunctionality() { + return Collections.emptySet(); + } + + @Override + public T getServiceForSession(Class service, + ConsumerSession session) { + if (DataProviderService.class.equals(service) + && session instanceof ProviderSession) { + @SuppressWarnings("unchecked") + T ret = (T) newDataProviderService(session); + return ret; + } else if (DataBrokerService.class.equals(service)) { + + @SuppressWarnings("unchecked") + T ret = (T) newDataConsumerService(session); + return ret; + } + + throw new IllegalArgumentException( + "The requested session-specific service is not provided by this module."); + } + + private DataProviderService newDataProviderService(ConsumerSession session) { + return new DataProviderSession(); + } + + private DataBrokerService newDataConsumerService(ConsumerSession session) { + return new DataConsumerSession(); + } + + private StoreContext context(DataStoreIdentifier store) { + return storeContext.get(store); + } + + private static class StoreContext { + private Set commitHandlers = Collections + .synchronizedSet(new HashSet()); + private Set validators = Collections + .synchronizedSet(new HashSet()); + private Set refreshers = Collections + .synchronizedSet(new HashSet()); + } + + private class DataConsumerSession implements DataBrokerService { + + @Override + public CompositeNode getData(DataStoreIdentifier store) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public CompositeNode getData(DataStoreIdentifier store, + CompositeNode filter) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public CompositeNode getCandidateData(DataStoreIdentifier store) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public CompositeNode getCandidateData(DataStoreIdentifier store, + CompositeNode filter) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public RpcResult editCandidateData( + DataStoreIdentifier store, MutableCompositeNode changeSet) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Future> commit(DataStoreIdentifier store) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void closeSession() { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Set getDataStores() { + // TODO Auto-generated method stub + return null; + } + + } + + private class DataProviderSession extends DataConsumerSession implements + DataProviderService { + + private Set providerCommitHandlers = new HashSet(); + private Set providerValidators = new HashSet(); + private Set providerRefreshers = new HashSet(); + + @Override + public void addValidator(DataStoreIdentifier store, + DataValidator validator) { + if (validator == null) + throw new IllegalArgumentException( + "Validator should not be null"); + + providerValidators.add(validator); + context(store).validators.add(validator); + } + + @Override + public void removeValidator(DataStoreIdentifier store, + DataValidator validator) { + if (validator == null) + throw new IllegalArgumentException( + "Validator should not be null"); + + providerValidators.remove(validator); + context(store).validators.remove(validator); + } + + @Override + public void addCommitHandler(DataStoreIdentifier store, + DataCommitHandler provider) { + if (provider == null) + throw new IllegalArgumentException( + "CommitHandler should not be null"); + + providerCommitHandlers.add(provider); + context(store).commitHandlers.add(provider); + } + + @Override + public void removeCommitHandler(DataStoreIdentifier store, + DataCommitHandler provider) { + if (provider == null) + throw new IllegalArgumentException( + "CommitHandler should not be null"); + + providerCommitHandlers.remove(provider); + context(store).commitHandlers.remove(provider); + } + + @Override + public void addRefresher(DataStoreIdentifier store, + DataRefresher provider) { + if (provider == null) + throw new IllegalArgumentException( + "Refresher should not be null"); + + providerRefreshers.add(provider); + context(store).refreshers.add(provider); + } + + @Override + public void removeRefresher(DataStoreIdentifier store, + DataRefresher provider) { + if (provider == null) + throw new IllegalArgumentException( + "Refresher should not be null"); + + providerRefreshers.remove(provider); + context(store).refreshers.remove(provider); + } + + } + + private class SequentialCommitHandlerCoordinator implements + DataCommitHandler { + + @Override + public RpcResult requestCommit( + DataStoreIdentifier store) { + List errors = new ArrayList(); + Set transactions = new HashSet(); + boolean successful = true; + + for (DataCommitHandler commitHandler : context(store).commitHandlers) { + try { + RpcResult partialResult = commitHandler + .requestCommit(store); + successful = partialResult.isSuccessful() & successful; + if (partialResult.isSuccessful()) { + transactions.add(partialResult.getResult()); + } + + errors.addAll(partialResult.getErrors()); + } catch (Exception e) { + log.error("Uncaught exception prevented commit request." + + e.getMessage(), e); + successful = false; + // FIXME: Add RPC Error with exception. + } + if (successful == false) + break; + } + CommitTransaction transaction = new SequentialCommitTransaction( + store, transactions); + return Rpcs.getRpcResult(successful, transaction, errors); + } + + @Override + public Set getSupportedDataStores() { + return Collections.emptySet(); + } + } + + private class SequentialCommitTransaction implements CommitTransaction { + + final Set transactions; + final DataStoreIdentifier store; + + public SequentialCommitTransaction(DataStoreIdentifier s, + Set t) { + transactions = t; + store = s; + } + + @Override + public RpcResult finish() { + List errors = new ArrayList(); + boolean successful = true; + + for (CommitTransaction commitHandler : transactions) { + try { + RpcResult partialResult = commitHandler.finish(); + successful = partialResult.isSuccessful() & successful; + errors.addAll(partialResult.getErrors()); + } catch (Exception e) { + log.error( + "Uncaught exception prevented finishing of commit." + + e.getMessage(), e); + successful = false; + // FIXME: Add RPC Error with exception. + } + if (successful == false) + break; + } + + return Rpcs.getRpcResult(successful, null, errors); + } + + @Override + public RpcResult rollback() { + List errors = new ArrayList(); + boolean successful = true; + + for (CommitTransaction commitHandler : transactions) { + try { + RpcResult partialResult = commitHandler.rollback(); + successful = partialResult.isSuccessful() & successful; + errors.addAll(partialResult.getErrors()); + } catch (Exception e) { + log.error( + "Uncaught exception prevented rollback of commit." + + e.getMessage(), e); + successful = false; + // FIXME: Add RPC Error with exception. + } + if (successful == false) + break; + } + + return Rpcs.getRpcResult(successful, null, errors); + } + + @Override + public DataStoreIdentifier getDataStore() { + return this.store; + } + + @Override + public DataCommitHandler getHandler() { + return coordinator; + } + } + + private class ValidationCoordinator implements DataValidator { + + private final DataStoreIdentifier store; + + ValidationCoordinator(DataStoreIdentifier store) { + this.store = store; + } + + @Override + public RpcResult validate(CompositeNode toValidate) { + List errors = new ArrayList(); + boolean successful = true; + + for (DataValidator validator : context(store).validators) { + try { + RpcResult partialResult = validator + .validate(toValidate); + successful = partialResult.isSuccessful() & successful; + errors.addAll(partialResult.getErrors()); + } catch (Exception e) { + log.error( + "Uncaught exception prevented validation." + + e.getMessage(), e); + successful = false; + // FIXME: Add RPC Error with exception. + } + if (successful == false) + break; + } + + return Rpcs.getRpcResult(successful, null, errors); + } + + @Override + public Set getSupportedDataStores() { + return Collections.emptySet(); + } + + } + + private class DataRefreshCoordinator implements DataRefresher { + + private final DataStoreIdentifier store; + + DataRefreshCoordinator(DataStoreIdentifier store) { + this.store = store; + } + + @Override + public void refreshData() { + + for (DataRefresher refresher : context(store).refreshers) { + try { + refresher.refreshData(); + } catch (Exception e) { + log.error( + "Uncaught exception during refresh of data: " + + e.getMessage(), e); + } + + } + } + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java index bd70ee14a5..2bbbde632b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java @@ -1,187 +1,187 @@ -/* - * 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.core.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality; -import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality; -import org.opendaylight.controller.sal.core.api.notify.NotificationListener; -import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService; -import org.opendaylight.controller.sal.core.api.notify.NotificationService; -import org.opendaylight.controller.sal.core.spi.BrokerModule; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; - -public class NotificationModule implements BrokerModule { - private static Logger log = LoggerFactory - .getLogger(NotificationModule.class); - - private Multimap listeners = HashMultimap - .create(); - - private static final Set> PROVIDED_SERVICE_TYPE = ImmutableSet - .of((Class) NotificationService.class, - NotificationProviderService.class); - - private static final Set> SUPPORTED_CONSUMER_FUNCTIONALITY = ImmutableSet - .of((Class) NotificationListener.class, - NotificationListener.class); // Workaround: if we use the - // version of method with only - // one argument, the generics - // inference will not work - - @Override - public Set> getProvidedServices() { - return PROVIDED_SERVICE_TYPE; - } - - @Override - public Set> getSupportedConsumerFunctionality() { - return SUPPORTED_CONSUMER_FUNCTIONALITY; - } - - @Override - public T getServiceForSession(Class service, - ConsumerSession session) { - if (NotificationProviderService.class.equals(service) - && session instanceof ProviderSession) { - @SuppressWarnings("unchecked") - T ret = (T) newNotificationProviderService(session); - return ret; - } else if (NotificationService.class.equals(service)) { - - @SuppressWarnings("unchecked") - T ret = (T) newNotificationConsumerService(session); - return ret; - } - - throw new IllegalArgumentException( - "The requested session-specific service is not provided by this module."); - } - - private void sendNotification(CompositeNode notification) { - QName type = notification.getNodeType(); - Collection toNotify = listeners.get(type); - log.info("Publishing notification " + type); - - if (toNotify == null) { - // No listeners were registered - returns. - return; - } - - for (NotificationListener listener : toNotify) { - try { - // FIXME: ensure that notification is immutable - listener.onNotification(notification); - } catch (Exception e) { - log.error("Uncaught exception in NotificationListener", e); - } - } - - } - - private NotificationService newNotificationConsumerService( - ConsumerSession session) { - return new NotificationConsumerSessionImpl(); - } - - private NotificationProviderService newNotificationProviderService( - ConsumerSession session) { - return new NotificationProviderSessionImpl(); - } - - private class NotificationConsumerSessionImpl implements - NotificationService { - - private Multimap consumerListeners = HashMultimap - .create(); - private boolean closed = false; - - @Override - public void addNotificationListener(QName notification, - NotificationListener listener) { - checkSessionState(); - if (notification == null) { - throw new IllegalArgumentException( - "Notification type must not be null."); - } - if (listener == null) { - throw new IllegalArgumentException("Listener must not be null."); - } - - consumerListeners.put(notification, listener); - listeners.put(notification, listener); - log.info("Registered listener for notification: " + notification); - } - - @Override - public void removeNotificationListener(QName notification, - NotificationListener listener) { - checkSessionState(); - if (notification == null) { - throw new IllegalArgumentException( - "Notification type must not be null."); - } - if (listener == null) { - throw new IllegalArgumentException("Listener must not be null."); - } - consumerListeners.remove(notification, listener); - listeners.remove(notification, listener); - } - - @Override - public void closeSession() { - closed = true; - Map> toRemove = consumerListeners - .asMap(); - for (Entry> entry : toRemove - .entrySet()) { - listeners.remove(entry.getKey(), entry.getValue()); - } - } - - protected void checkSessionState() { - if (closed) - throw new IllegalStateException("Session is closed"); - } - } - - private class NotificationProviderSessionImpl extends - NotificationConsumerSessionImpl implements - NotificationProviderService { - - @Override - public void sendNotification(CompositeNode notification) { - checkSessionState(); - if (notification == null) - throw new IllegalArgumentException( - "Notification must not be null."); - NotificationModule.this.sendNotification(notification); - } - } - - @Override - public Set> getSupportedProviderFunctionality() { - return Collections.emptySet(); - } -} +/* + * 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.core.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality; +import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality; +import org.opendaylight.controller.sal.core.api.notify.NotificationListener; +import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService; +import org.opendaylight.controller.sal.core.api.notify.NotificationService; +import org.opendaylight.controller.sal.core.spi.BrokerModule; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; + +public class NotificationModule implements BrokerModule { + private static Logger log = LoggerFactory + .getLogger(NotificationModule.class); + + private Multimap listeners = HashMultimap + .create(); + + private static final Set> PROVIDED_SERVICE_TYPE = ImmutableSet + .of((Class) NotificationService.class, + NotificationProviderService.class); + + private static final Set> SUPPORTED_CONSUMER_FUNCTIONALITY = ImmutableSet + .of((Class) NotificationListener.class, + NotificationListener.class); // Workaround: if we use the + // version of method with only + // one argument, the generics + // inference will not work + + @Override + public Set> getProvidedServices() { + return PROVIDED_SERVICE_TYPE; + } + + @Override + public Set> getSupportedConsumerFunctionality() { + return SUPPORTED_CONSUMER_FUNCTIONALITY; + } + + @Override + public T getServiceForSession(Class service, + ConsumerSession session) { + if (NotificationProviderService.class.equals(service) + && session instanceof ProviderSession) { + @SuppressWarnings("unchecked") + T ret = (T) newNotificationProviderService(session); + return ret; + } else if (NotificationService.class.equals(service)) { + + @SuppressWarnings("unchecked") + T ret = (T) newNotificationConsumerService(session); + return ret; + } + + throw new IllegalArgumentException( + "The requested session-specific service is not provided by this module."); + } + + private void sendNotification(CompositeNode notification) { + QName type = notification.getNodeType(); + Collection toNotify = listeners.get(type); + log.info("Publishing notification " + type); + + if (toNotify == null) { + // No listeners were registered - returns. + return; + } + + for (NotificationListener listener : toNotify) { + try { + // FIXME: ensure that notification is immutable + listener.onNotification(notification); + } catch (Exception e) { + log.error("Uncaught exception in NotificationListener", e); + } + } + + } + + private NotificationService newNotificationConsumerService( + ConsumerSession session) { + return new NotificationConsumerSessionImpl(); + } + + private NotificationProviderService newNotificationProviderService( + ConsumerSession session) { + return new NotificationProviderSessionImpl(); + } + + private class NotificationConsumerSessionImpl implements + NotificationService { + + private Multimap consumerListeners = HashMultimap + .create(); + private boolean closed = false; + + @Override + public void addNotificationListener(QName notification, + NotificationListener listener) { + checkSessionState(); + if (notification == null) { + throw new IllegalArgumentException( + "Notification type must not be null."); + } + if (listener == null) { + throw new IllegalArgumentException("Listener must not be null."); + } + + consumerListeners.put(notification, listener); + listeners.put(notification, listener); + log.info("Registered listener for notification: " + notification); + } + + @Override + public void removeNotificationListener(QName notification, + NotificationListener listener) { + checkSessionState(); + if (notification == null) { + throw new IllegalArgumentException( + "Notification type must not be null."); + } + if (listener == null) { + throw new IllegalArgumentException("Listener must not be null."); + } + consumerListeners.remove(notification, listener); + listeners.remove(notification, listener); + } + + @Override + public void closeSession() { + closed = true; + Map> toRemove = consumerListeners + .asMap(); + for (Entry> entry : toRemove + .entrySet()) { + listeners.remove(entry.getKey(), entry.getValue()); + } + } + + protected void checkSessionState() { + if (closed) + throw new IllegalStateException("Session is closed"); + } + } + + private class NotificationProviderSessionImpl extends + NotificationConsumerSessionImpl implements + NotificationProviderService { + + @Override + public void sendNotification(CompositeNode notification) { + checkSessionState(); + if (notification == null) + throw new IllegalArgumentException( + "Notification must not be null."); + NotificationModule.this.sendNotification(notification); + } + } + + @Override + public Set> getSupportedProviderFunctionality() { + return Collections.emptySet(); + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml index fedd6d12f0..f1bed65fd1 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml @@ -1,23 +1,24 @@ - - 4.0.0 - - org.opendaylight.controller - sal - 1.0-SNAPSHOT - - sal-common-util - - - - org.opendaylight.controller - yang-common - - - org.opendaylight.controller - sal-common - 1.0-SNAPSHOT - + + 4.0.0 + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + sal-common-util + + + + org.opendaylight.yangtools + yang-common + + + org.opendaylight.controller + sal-common + 1.0-SNAPSHOT + + bundle \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Futures.java b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Futures.java new file mode 100644 index 0000000000..c942159f49 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Futures.java @@ -0,0 +1,51 @@ +package org.opendaylight.controller.sal.common.util; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class Futures { + + private Futures(){} + + public static Future immediateFuture(T result) { + return new ImmediateFuture(result); + } + + private static class ImmediateFuture implements Future { + + private final T result; + + public ImmediateFuture(T result) { + this.result = result; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public T get() throws InterruptedException, ExecutionException { + return result; + } + + @Override + public T get(long timeout, TimeUnit unit) throws InterruptedException, + ExecutionException, TimeoutException { + return result; + } + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java index d397bff0d6..e46b566522 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java +++ b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java @@ -1,53 +1,53 @@ -/* - * 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.common.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import org.opendaylight.controller.yang.common.RpcError; -import org.opendaylight.controller.yang.common.RpcResult; - -public class Rpcs { - public static RpcResult getRpcResult(boolean successful, T result, - Collection errors) { - RpcResult ret = new RpcResultTO(successful, result, errors); - return ret; - } - - private static class RpcResultTO implements RpcResult { - - private final Collection errors; - private final T result; - private final boolean successful; - - public RpcResultTO(boolean successful, T result, - Collection errors) { - this.successful = successful; - this.result = result; - this.errors = Collections.unmodifiableList(new ArrayList( - errors)); - } - - @Override - public boolean isSuccessful() { - return successful; - } - - @Override - public T getResult() { - return result; - } - - @Override - public Collection getErrors() { - return errors; - } - - } -} +/* + * 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.common.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; + +public class Rpcs { + public static RpcResult getRpcResult(boolean successful, T result, + Collection errors) { + RpcResult ret = new RpcResultTO(successful, result, errors); + return ret; + } + + private static class RpcResultTO implements RpcResult { + + private final Collection errors; + private final T result; + private final boolean successful; + + public RpcResultTO(boolean successful, T result, + Collection errors) { + this.successful = successful; + this.result = result; + this.errors = Collections.unmodifiableList(new ArrayList( + errors)); + } + + @Override + public boolean isSuccessful() { + return successful; + } + + @Override + public T getResult() { + return result; + } + + @Override + public Collection getErrors() { + return errors; + } + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-common/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-common/pom.xml index 89cf5207ed..a4b2c7d51b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-common/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-common/pom.xml @@ -1,14 +1,15 @@ - - 4.0.0 - - org.opendaylight.controller - sal - 1.0-SNAPSHOT - - sal-common - - + + 4.0.0 + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + sal-common + + + bundle \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml index e82392d24a..e3ded1a679 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-core-api @@ -23,5 +23,5 @@ org.opendaylight.controller yang-model-api - + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java index 9b3b47f8b1..f26ed901a5 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java @@ -1,238 +1,238 @@ -/* - * 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.core.api; - -import java.util.concurrent.Future; - -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.NotificationProviderService; -import org.opendaylight.controller.sal.core.api.notify.NotificationService; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -/** - * Core component of the SAL layer responsible for wiring the SAL consumers. - * - * The responsibility of the broker is to maintain registration of SAL - * functionality {@link Consumer}s and {@link Provider}s, store provider and - * consumer specific context and functionality registration via - * {@link ConsumerSession} and provide access to infrastructure services, which - * removes direct dependencies between providers and consumers. - * - * - *

    Infrastructure services

    Some examples of infrastructure services: - * - *
      - *
    • RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)}, - * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and - * {@link RpcImplementation} - *
    • Notification Service - see {@link NotificationService} and - * {@link NotificationProviderService} - *
    • Functionality and Data model - *
    • Data Store access and modification - see {@link DataBrokerService} and - * {@link DataProviderService} - *
    - * - * The services are exposed via session. - * - *

    Session-based access

    - * - * The providers and consumers needs to register in order to use the - * binding-independent SAL layer and to expose functionality via SAL layer. - * - * For more information about session-based access see {@link ConsumerSession} - * and {@link ProviderSession} - * - * - * - */ -public interface Broker { - - /** - * Registers the {@link Consumer}, which will use the SAL layer. - * - *

    - * During the registration, the broker obtains the initial functionality - * from consumer, using the {@link Consumer#getConsumerFunctionality()}, and - * register that functionality into system and concrete infrastructure - * services. - * - *

    - * Note that consumer could register additional functionality at later point - * by using service and functionality specific APIs. - * - *

    - * The consumer is required to use returned session for all communication - * with broker or one of the broker services. The session is announced to - * the consumer by invoking - * {@link Consumer#onSessionInitiated(ConsumerSession)}. - * - * @param cons - * Consumer to be registered. - * @return a session specific to consumer registration - * @throws IllegalArgumentException - * If the consumer is null. - * @throws IllegalStateException - * If the consumer is already registered. - */ - ConsumerSession registerConsumer(Consumer cons); - - /** - * Registers the {@link Provider}, which will use the SAL layer. - * - *

    - * During the registration, the broker obtains the initial functionality - * from consumer, using the {@link Provider#getProviderFunctionality()}, and - * register that functionality into system and concrete infrastructure - * services. - * - *

    - * Note that consumer could register additional functionality at later point - * by using service and functionality specific APIs (e.g. - * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} - * - *

    - * The consumer is required to use returned session for all - * communication with broker or one of the broker services. The session is - * announced to the consumer by invoking - * {@link Provider#onSessionInitiated(ProviderSession)}. - * - * - * @param prov - * Provider to be registered. - * @return a session unique to the provider registration. - * @throws IllegalArgumentException - * If the provider is null. - * @throws IllegalStateException - * If the consumer is already registered. - */ - ProviderSession registerProvider(Provider prov); - - /** - * {@link Consumer} specific access to the SAL functionality. - * - *

    - * ConsumerSession is {@link Consumer}-specific access to the SAL - * functionality and infrastructure services. - * - *

    - * The session serves to store SAL context (e.g. registration of - * functionality) for the consumer and provides access to the SAL - * infrastructure services and other functionality provided by - * {@link Provider}s. - * - - * - */ - public interface ConsumerSession { - - /** - * Sends an RPC to other components registered to the broker. - * - * @see RpcImplementation - * @param rpc - * Name of RPC - * @param input - * Input data to the RPC - * @return Result of the RPC call - */ - Future> rpc(QName rpc, CompositeNode input); - - boolean isClosed(); - - /** - * Returns a session specific instance (implementation) of requested - * service - * - * @param service - * Broker service - * @return Session specific implementation of service - */ - T getService(Class service); - - /** - * Closes a session between consumer and broker. - * - *

    - * The close operation unregisters a consumer and remove all registered - * functionality of the consumer from the system. - * - */ - void close(); - } - - /** - * {@link Provider} specific access to the SAL functionality. - * - *

    - * ProviderSession is {@link Provider}-specific access to the SAL - * functionality and infrastructure services, which also allows for exposing - * the provider's functionality to the other {@link Consumer}s. - * - *

    - * The session serves to store SAL context (e.g. registration of - * functionality) for the providers and exposes access to the SAL - * infrastructure services, dynamic functionality registration and any other - * functionality provided by other {@link Provider}s. - * - */ - public interface ProviderSession extends ConsumerSession { - /** - * Registers an implementation of the rpc. - * - *

    - * The registered rpc functionality will be available to all other - * consumers and providers registered to the broker, which are aware of - * the {@link QName} assigned to the rpc. - * - *

    - * There is no assumption that rpc type is in the set returned by - * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows - * for dynamic rpc implementations. - * - * @param rpcType - * Name of Rpc - * @param implementation - * Provider's Implementation of the RPC functionality - * @throws IllegalArgumentException - * If the name of RPC is invalid - */ - void addRpcImplementation(QName rpcType, - RpcImplementation implementation) - throws IllegalArgumentException; - - /** - * Unregisters an Rpc implementation - * - * @param rpcType - * Name of Rpc - * @param implementation - * Registered Implementation of the Rpc functionality - * @throws IllegalArgumentException - */ - void removeRpcImplementation(QName rpcType, - RpcImplementation implementation) - throws IllegalArgumentException; - - /** - * Closes a session between provider and SAL. - * - *

    - * The close operation unregisters a provider and remove all registered - * functionality of the provider from the system. - */ - @Override - public void close(); - - @Override - boolean isClosed(); - } -} +/* + * 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.core.api; + +import java.util.concurrent.Future; + +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.NotificationProviderService; +import org.opendaylight.controller.sal.core.api.notify.NotificationService; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; + + +/** + * Core component of the SAL layer responsible for wiring the SAL consumers. + * + * The responsibility of the broker is to maintain registration of SAL + * functionality {@link Consumer}s and {@link Provider}s, store provider and + * consumer specific context and functionality registration via + * {@link ConsumerSession} and provide access to infrastructure services, which + * removes direct dependencies between providers and consumers. + * + * + *

    Infrastructure services

    Some examples of infrastructure services: + * + *
      + *
    • RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)}, + * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and + * {@link RpcImplementation} + *
    • Notification Service - see {@link NotificationService} and + * {@link NotificationProviderService} + *
    • Functionality and Data model + *
    • Data Store access and modification - see {@link DataBrokerService} and + * {@link DataProviderService} + *
    + * + * The services are exposed via session. + * + *

    Session-based access

    + * + * The providers and consumers needs to register in order to use the + * binding-independent SAL layer and to expose functionality via SAL layer. + * + * For more information about session-based access see {@link ConsumerSession} + * and {@link ProviderSession} + * + * + * + */ +public interface Broker { + + /** + * Registers the {@link Consumer}, which will use the SAL layer. + * + *

    + * During the registration, the broker obtains the initial functionality + * from consumer, using the {@link Consumer#getConsumerFunctionality()}, and + * register that functionality into system and concrete infrastructure + * services. + * + *

    + * Note that consumer could register additional functionality at later point + * by using service and functionality specific APIs. + * + *

    + * The consumer is required to use returned session for all communication + * with broker or one of the broker services. The session is announced to + * the consumer by invoking + * {@link Consumer#onSessionInitiated(ConsumerSession)}. + * + * @param cons + * Consumer to be registered. + * @return a session specific to consumer registration + * @throws IllegalArgumentException + * If the consumer is null. + * @throws IllegalStateException + * If the consumer is already registered. + */ + ConsumerSession registerConsumer(Consumer cons); + + /** + * Registers the {@link Provider}, which will use the SAL layer. + * + *

    + * During the registration, the broker obtains the initial functionality + * from consumer, using the {@link Provider#getProviderFunctionality()}, and + * register that functionality into system and concrete infrastructure + * services. + * + *

    + * Note that consumer could register additional functionality at later point + * by using service and functionality specific APIs (e.g. + * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} + * + *

    + * The consumer is required to use returned session for all + * communication with broker or one of the broker services. The session is + * announced to the consumer by invoking + * {@link Provider#onSessionInitiated(ProviderSession)}. + * + * + * @param prov + * Provider to be registered. + * @return a session unique to the provider registration. + * @throws IllegalArgumentException + * If the provider is null. + * @throws IllegalStateException + * If the consumer is already registered. + */ + ProviderSession registerProvider(Provider prov); + + /** + * {@link Consumer} specific access to the SAL functionality. + * + *

    + * ConsumerSession is {@link Consumer}-specific access to the SAL + * functionality and infrastructure services. + * + *

    + * The session serves to store SAL context (e.g. registration of + * functionality) for the consumer and provides access to the SAL + * infrastructure services and other functionality provided by + * {@link Provider}s. + * + + * + */ + public interface ConsumerSession { + + /** + * Sends an RPC to other components registered to the broker. + * + * @see RpcImplementation + * @param rpc + * Name of RPC + * @param input + * Input data to the RPC + * @return Result of the RPC call + */ + Future> rpc(QName rpc, CompositeNode input); + + boolean isClosed(); + + /** + * Returns a session specific instance (implementation) of requested + * service + * + * @param service + * Broker service + * @return Session specific implementation of service + */ + T getService(Class service); + + /** + * Closes a session between consumer and broker. + * + *

    + * The close operation unregisters a consumer and remove all registered + * functionality of the consumer from the system. + * + */ + void close(); + } + + /** + * {@link Provider} specific access to the SAL functionality. + * + *

    + * ProviderSession is {@link Provider}-specific access to the SAL + * functionality and infrastructure services, which also allows for exposing + * the provider's functionality to the other {@link Consumer}s. + * + *

    + * The session serves to store SAL context (e.g. registration of + * functionality) for the providers and exposes access to the SAL + * infrastructure services, dynamic functionality registration and any other + * functionality provided by other {@link Provider}s. + * + */ + public interface ProviderSession extends ConsumerSession { + /** + * Registers an implementation of the rpc. + * + *

    + * The registered rpc functionality will be available to all other + * consumers and providers registered to the broker, which are aware of + * the {@link QName} assigned to the rpc. + * + *

    + * There is no assumption that rpc type is in the set returned by + * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows + * for dynamic rpc implementations. + * + * @param rpcType + * Name of Rpc + * @param implementation + * Provider's Implementation of the RPC functionality + * @throws IllegalArgumentException + * If the name of RPC is invalid + */ + void addRpcImplementation(QName rpcType, + RpcImplementation implementation) + throws IllegalArgumentException; + + /** + * Unregisters an Rpc implementation + * + * @param rpcType + * Name of Rpc + * @param implementation + * Registered Implementation of the Rpc functionality + * @throws IllegalArgumentException + */ + void removeRpcImplementation(QName rpcType, + RpcImplementation implementation) + throws IllegalArgumentException; + + /** + * Closes a session between provider and SAL. + * + *

    + * The close operation unregisters a provider and remove all registered + * functionality of the provider from the system. + */ + @Override + public void close(); + + @Override + boolean isClosed(); + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java index b854188f61..b425368052 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java @@ -1,39 +1,39 @@ -/* - * 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.core.api; - -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; - -/** - * - * Session-specific instance of the broker functionality. - * - *

    - * BrokerService is marker interface for infrastructure services provided by the - * SAL. These services are session-specific, each {@link Provider} and - * {@link Consumer} usually has own instance of the service with it's own - * context. - * - *

    - * The consumer's (or provider's) instance of specific service could be obtained - * by invoking {@link ConsumerSession#getService(Class)} method on session - * assigned to the consumer. - * - *

    - * {@link BrokerService} and {@link Provider} may seem similar, but provider - * provides YANG model-based functionality and {@link BrokerService} exposes the - * necessary supporting functionality to implement specific functionality of - * YANG and to reuse it in the development of {@link Consumer}s and - * {@link Provider}s. - * - * - */ -public interface BrokerService { - - void closeSession(); -} +/* + * 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.core.api; + +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; + +/** + * + * Session-specific instance of the broker functionality. + * + *

    + * BrokerService is marker interface for infrastructure services provided by the + * SAL. These services are session-specific, each {@link Provider} and + * {@link Consumer} usually has own instance of the service with it's own + * context. + * + *

    + * The consumer's (or provider's) instance of specific service could be obtained + * by invoking {@link ConsumerSession#getService(Class)} method on session + * assigned to the consumer. + * + *

    + * {@link BrokerService} and {@link Provider} may seem similar, but provider + * provides YANG model-based functionality and {@link BrokerService} exposes the + * necessary supporting functionality to implement specific functionality of + * YANG and to reuse it in the development of {@link Consumer}s and + * {@link Provider}s. + * + * + */ +public interface BrokerService { + + void closeSession(); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java index 1b223f9e66..0006953542 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java @@ -1,59 +1,59 @@ -/* - * 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.core.api; - -import java.util.Collection; - -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; - -/** - * - * Defines the component of controller and supplies additional metadata. A - * component of the controller or application supplies a concrete implementation - * of this interface. - * - * A user-implemented component (application) which faciliates the SAL and SAL - * services to access infrastructure services or providers' functionality. - * - * - */ -public interface Consumer { - - /** - * Callback signaling initialization of the consumer session to the SAL. - * - * The consumer MUST use the session for all communication with SAL or - * retrieving SAL infrastructure services. - * - * This method is invoked by {@link Broker#registerConsumer(Consumer)} - * - * @param session - * Unique session between consumer and SAL. - */ - public void onSessionInitiated(ConsumerSession session); - - /** - * Get a set of implementations of consumer functionality to be registered - * into system during the consumer registration to the SAL. - * - * This method is invoked by {@link Broker#registerConsumer(Consumer)}. - * - * @return Set of consumer functionality. - */ - public Collection getConsumerFunctionality(); - - /** - * The marker interface for the interfaces describing the consumer - * functionality contracts. - * - * - */ - public interface ConsumerFunctionality { - - } -} +/* + * 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.core.api; + +import java.util.Collection; + +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; + +/** + * + * Defines the component of controller and supplies additional metadata. A + * component of the controller or application supplies a concrete implementation + * of this interface. + * + * A user-implemented component (application) which faciliates the SAL and SAL + * services to access infrastructure services or providers' functionality. + * + * + */ +public interface Consumer { + + /** + * Callback signaling initialization of the consumer session to the SAL. + * + * The consumer MUST use the session for all communication with SAL or + * retrieving SAL infrastructure services. + * + * This method is invoked by {@link Broker#registerConsumer(Consumer)} + * + * @param session + * Unique session between consumer and SAL. + */ + public void onSessionInitiated(ConsumerSession session); + + /** + * Get a set of implementations of consumer functionality to be registered + * into system during the consumer registration to the SAL. + * + * This method is invoked by {@link Broker#registerConsumer(Consumer)}. + * + * @return Set of consumer functionality. + */ + public Collection getConsumerFunctionality(); + + /** + * The marker interface for the interfaces describing the consumer + * functionality contracts. + * + * + */ + public interface ConsumerFunctionality { + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java index dff636fd4b..e2df70baea 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java @@ -1,69 +1,69 @@ -/* - * 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.core.api; - -import java.util.Collection; - -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; - -/** - * - * Defines the component of controller and supplies additional metadata. A - * component of the controller or application supplies a concrete implementation - * of this interface. - * - *

    - * A user-implemented component (application) which faciliates the SAL and SAL - * services to access infrastructure services and to provide functionality to - * {@link Consumer}s and other providers. - * - * - */ -public interface Provider { - - /** - * Callback signaling initialization of the provider session to the SAL. - * - *

    - * The provider MUST use the session for all communication with SAL - * or retrieving SAL infrastructure services. - * - *

    - * This method is invoked by {@link Broker#registerConsumer(Consumer)} - * - * @param session - * Unique session between provider and SAL. - */ - public void onSessionInitiated(ProviderSession session); - - /** - * Gets a set of implementations of provider functionality to be registered - * into system during the provider registration to the SAL. - * - *

    - * This method is invoked by {@link Broker#registerProvider(Provider)} to - * learn the initial provided functionality - * - * @return Set of provider's functionality. - */ - public Collection getProviderFunctionality(); - - /** - * Functionality provided by the {@link Provider} - * - *

    - * Marker interface used to mark the interfaces describing specific - * functionality which could be exposed by providers to other components. - * - - * - */ - public interface ProviderFunctionality { - - } -} +/* + * 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.core.api; + +import java.util.Collection; + +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; + +/** + * + * Defines the component of controller and supplies additional metadata. A + * component of the controller or application supplies a concrete implementation + * of this interface. + * + *

    + * A user-implemented component (application) which faciliates the SAL and SAL + * services to access infrastructure services and to provide functionality to + * {@link Consumer}s and other providers. + * + * + */ +public interface Provider { + + /** + * Callback signaling initialization of the provider session to the SAL. + * + *

    + * The provider MUST use the session for all communication with SAL + * or retrieving SAL infrastructure services. + * + *

    + * This method is invoked by {@link Broker#registerConsumer(Consumer)} + * + * @param session + * Unique session between provider and SAL. + */ + public void onSessionInitiated(ProviderSession session); + + /** + * Gets a set of implementations of provider functionality to be registered + * into system during the provider registration to the SAL. + * + *

    + * This method is invoked by {@link Broker#registerProvider(Provider)} to + * learn the initial provided functionality + * + * @return Set of provider's functionality. + */ + public Collection getProviderFunctionality(); + + /** + * Functionality provided by the {@link Provider} + * + *

    + * Marker interface used to mark the interfaces describing specific + * functionality which could be exposed by providers to other components. + * + + * + */ + public interface ProviderFunctionality { + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java index ef5aa703b9..0299505cde 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java @@ -1,81 +1,81 @@ -/* - * 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.core.api; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - -/** - * {@link Provider}'s implementation of rpc. - * - * In order to expose the rpc to other components, the provider MUST register - * concrete implementation of this interface - * - * The registration could be done by : - *

      - *
    • returning an instance of implementation in the return value of - * {@link Provider#getProviderFunctionality()} - *
    • passing an instance of implementation and {@link QName} of rpc as - * arguments to the - * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} - *
    - * - * The simplified process of the invocation of rpc is following: - * - *
      - *
    1. {@link Consumer} invokes - * {@link ConsumerSession#rpc(QName, CompositeNode)} - *
    2. {@link Broker} finds registered {@link RpcImplementation}s - *
    3. {@link Broker} invokes - * {@link RpcImplementation#invokeRpc(QName, CompositeNode)} - *
    4. {@link RpcImplementation} processes the data and returns a - * {@link RpcResult} - *
    5. {@link Broker} returns the {@link RpcResult} to {@link Consumer} - *
    - * - * - */ -public interface RpcImplementation extends Provider.ProviderFunctionality { - - /** - * A set of rpc types supported by implementation. - * - * The set of rpc {@link QName}s which are supported by this implementation. - * This set is used, when {@link Provider} is registered to the SAL, to - * register and expose the implementation of the returned rpcs. - * - * @return Set of QNames identifying supported RPCs - */ - Set getSupportedRpcs(); - - /** - * Invokes a implementation of specified rpc. - * - * - * @param rpc - * Rpc to be invoked - * @param input - * Input data for rpc. - * - * @throws IllegalArgumentException - *
      - *
    • If rpc is null. - *
    • If input is not null and - * false == rpc.equals(input.getNodeType) - *
    - * @return RpcResult containing the output of rpc if was executed - * successfully, the list of errors otherwise. - */ - RpcResult invokeRpc(QName rpc, CompositeNode input); - -} +/* + * 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.core.api; + +import java.util.Set; + +import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; + +/** + * {@link Provider}'s implementation of rpc. + * + * In order to expose the rpc to other components, the provider MUST register + * concrete implementation of this interface + * + * The registration could be done by : + *
      + *
    • returning an instance of implementation in the return value of + * {@link Provider#getProviderFunctionality()} + *
    • passing an instance of implementation and {@link QName} of rpc as + * arguments to the + * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} + *
    + * + * The simplified process of the invocation of rpc is following: + * + *
      + *
    1. {@link Consumer} invokes + * {@link ConsumerSession#rpc(QName, CompositeNode)} + *
    2. {@link Broker} finds registered {@link RpcImplementation}s + *
    3. {@link Broker} invokes + * {@link RpcImplementation#invokeRpc(QName, CompositeNode)} + *
    4. {@link RpcImplementation} processes the data and returns a + * {@link RpcResult} + *
    5. {@link Broker} returns the {@link RpcResult} to {@link Consumer} + *
    + * + * + */ +public interface RpcImplementation extends Provider.ProviderFunctionality { + + /** + * A set of rpc types supported by implementation. + * + * The set of rpc {@link QName}s which are supported by this implementation. + * This set is used, when {@link Provider} is registered to the SAL, to + * register and expose the implementation of the returned rpcs. + * + * @return Set of QNames identifying supported RPCs + */ + Set getSupportedRpcs(); + + /** + * Invokes a implementation of specified rpc. + * + * + * @param rpc + * Rpc to be invoked + * @param input + * Input data for rpc. + * + * @throws IllegalArgumentException + *
      + *
    • If rpc is null. + *
    • If input is not null and + * false == rpc.equals(input.getNodeType) + *
    + * @return RpcResult containing the output of rpc if was executed + * successfully, the list of errors otherwise. + */ + RpcResult invokeRpc(QName rpc, CompositeNode input); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java index d74a7d146d..f4bc71142a 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java @@ -1,136 +1,136 @@ -/* - * 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.core.api.data; - -import java.util.Set; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; -import org.opendaylight.controller.yang.data.api.CompositeNodeModification; -import org.opendaylight.controller.yang.data.api.Node; - - -/** - * DataBrokerService provides unified access to the data stores available in the - * system. - * - * - * @see DataProviderService - * - */ -public interface DataBrokerService extends BrokerService { - - - Set getDataStores(); - - /** - * Returns a data from specified Data Store. - * - * Returns all the data visible to the consumer from specified Data Store. - * - * @param store - * Identifier of the store, from which will be data retrieved - * @return data visible to the consumer - */ - CompositeNode getData(DataStoreIdentifier store); - - /** - * Returns a filtered subset of data from specified Data Store. - * - *

    - * The filter is modeled as an hierarchy of {@link Node} starting with - * {@link CompositeNode} representing data root. The semantics of the filter - * tree is the same as filter semantics defined in the NETCONF protocol for - * rpc operations get and get-config in Section 6 - * of RFC6241. - * - * - * @see http://tools.ietf.org/html/rfc6241#section-6 - * @param store - * Identifier of the store, from which will be data retrieved - * @param filter - * Data tree filter similar to the NETCONF filter - * @return - */ - CompositeNode getData(DataStoreIdentifier store, CompositeNode filter); - - /** - * Returns a candidate data which are not yet commited. - * - * - * @param store - * Identifier of the store, from which will be data retrieved - * @return - */ - CompositeNode getCandidateData(DataStoreIdentifier store); - - /** - * Returns a filtered subset of candidate data from specified Data Store. - * - *

    - * The filter is modeled as an hierarchy of {@link Node} starting with - * {@link CompositeNode} representing data root. The semantics of the filter - * tree is the same as filter semantics defined in the NETCONF protocol for - * rpc operations get and get-config in Section 6 - * of RFC6241. - * - * - * @see http://tools.ietf.org/html/rfc6241#section-6 - * @param store - * Identifier of the store, from which will be data retrieved - * @param filter - * A CompositeNode filter - * @return - */ - CompositeNode getCandidateData(DataStoreIdentifier store, - CompositeNode filter); - - /** - * - * @param store - * Identifier of the store, in which will be the candidate data - * modified - * @param changeSet - * Modification of data tree. - * @return Result object containing the modified data tree if the operation - * was successful, otherwise list of the encountered errors. - */ - RpcResult editCandidateData(DataStoreIdentifier store, - CompositeNodeModification changeSet); - - /** - * Initiates a two-phase commit of candidate data. - * - *

    - * The {@link Consumer} could initiate a commit of candidate data - * - *

    - * The successful commit changes the state of the system and may affect - * several components. - * - *

    - * The effects of successful commit of data are described in the - * specifications and YANG models describing the {@link Provider} components - * of controller. It is assumed that {@link Consumer} has an understanding - * of this changes. - * - * - * @see DataCommitHandler for further information how two-phase commit is - * processed. - * @param store - * Identifier of the store, where commit should occur. - * @return Result of the commit, containing success information or list of - * encountered errors, if commit was not successful. - */ - Future> commit(DataStoreIdentifier store); -} +/* + * 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.core.api.data; + +import java.util.Set; +import java.util.concurrent.Future; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.CompositeNodeModification; +import org.opendaylight.yangtools.yang.data.api.Node; + + +/** + * DataBrokerService provides unified access to the data stores available in the + * system. + * + * + * @see DataProviderService + * + */ +public interface DataBrokerService extends BrokerService { + + + Set getDataStores(); + + /** + * Returns a data from specified Data Store. + * + * Returns all the data visible to the consumer from specified Data Store. + * + * @param store + * Identifier of the store, from which will be data retrieved + * @return data visible to the consumer + */ + CompositeNode getData(DataStoreIdentifier store); + + /** + * Returns a filtered subset of data from specified Data Store. + * + *

    + * The filter is modeled as an hierarchy of {@link Node} starting with + * {@link CompositeNode} representing data root. The semantics of the filter + * tree is the same as filter semantics defined in the NETCONF protocol for + * rpc operations get and get-config in Section 6 + * of RFC6241. + * + * + * @see http://tools.ietf.org/html/rfc6241#section-6 + * @param store + * Identifier of the store, from which will be data retrieved + * @param filter + * Data tree filter similar to the NETCONF filter + * @return + */ + CompositeNode getData(DataStoreIdentifier store, CompositeNode filter); + + /** + * Returns a candidate data which are not yet commited. + * + * + * @param store + * Identifier of the store, from which will be data retrieved + * @return + */ + CompositeNode getCandidateData(DataStoreIdentifier store); + + /** + * Returns a filtered subset of candidate data from specified Data Store. + * + *

    + * The filter is modeled as an hierarchy of {@link Node} starting with + * {@link CompositeNode} representing data root. The semantics of the filter + * tree is the same as filter semantics defined in the NETCONF protocol for + * rpc operations get and get-config in Section 6 + * of RFC6241. + * + * + * @see http://tools.ietf.org/html/rfc6241#section-6 + * @param store + * Identifier of the store, from which will be data retrieved + * @param filter + * A CompositeNode filter + * @return + */ + CompositeNode getCandidateData(DataStoreIdentifier store, + CompositeNode filter); + + /** + * + * @param store + * Identifier of the store, in which will be the candidate data + * modified + * @param changeSet + * Modification of data tree. + * @return Result object containing the modified data tree if the operation + * was successful, otherwise list of the encountered errors. + */ + RpcResult editCandidateData(DataStoreIdentifier store, + CompositeNodeModification changeSet); + + /** + * Initiates a two-phase commit of candidate data. + * + *

    + * The {@link Consumer} could initiate a commit of candidate data + * + *

    + * The successful commit changes the state of the system and may affect + * several components. + * + *

    + * The effects of successful commit of data are described in the + * specifications and YANG models describing the {@link Provider} components + * of controller. It is assumed that {@link Consumer} has an understanding + * of this changes. + * + * + * @see DataCommitHandler for further information how two-phase commit is + * processed. + * @param store + * Identifier of the store, where commit should occur. + * @return Result of the commit, containing success information or list of + * encountered errors, if commit was not successful. + */ + Future> commit(DataStoreIdentifier store); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataCommitHandler.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataCommitHandler.java index f0cc02d3ce..fc1894a3d9 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataCommitHandler.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataCommitHandler.java @@ -1,164 +1,164 @@ -/* - * 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.core.api.data; - -import java.util.Set; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.yang.common.RpcResult; - - -/** - * Two phase commit handler (cohort) of the two-phase commit protocol of data. - * - *

    - * The provider should expose the implementation of DataCommitHandler if it's - * functionality depends on any subset of data stored in data repositories, in - * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier) - * operation. - * - *

    - * Operations of two-phase commit handlers should not change data in data store, - * this is responsibility of the coordinator (broker or some component of the - * broker). - * - * The commit handlers are responsible for changing the internal state of the - * provider to reflect the commited changes in data. - * - *

    Two-phase commit

    - * - *

    Commit Request Phase

    - * - *
      - *
    1. Consumer edits data by invocation of - * DataBrokerService.editCandidateData(DataStoreIdentifier, CompositeNodeModification) - *
    2. Consumer starts a commit by invoking - * DataBrokerService.commit(DataStoreIdentifier) - *
    3. Broker retrieves a list of all registered - * DataCommitHandlers - *
    4. For each DataCommitHandler - *
        - *
      1. Broker invokes a - * DataCommitHandler.requestCommit(DataStoreIdentifier) operation. - *
      2. DataCommitHandler returns a RpcResult with - * CommitTransaction - *
      3. If the result was successful, broker adds CommitTransaction - * to the list of opened transactions. If not, brokers stops a commit request - * phase and starts a rollback phase. - *
      - *
    5. Broker starts a commit finish phase - *
    - * - *

    Commit Finish Phase

    - * - *
      - *
    1. For each CommitTransaction from Commit Request phase - *
        - *
      1. Broker broker invokes a - * CommitTransaction.finish() - *
      2. The provider finishes a commit (applies the change) and returns an - * RpcResult. - *
      - *
    2. - *
        - *
      • If all returned results means successful, the brokers end two-phase - * commit by returning a success commit result to the Consumer. - *
      • If error occured, the broker starts a commit rollback phase. - *
      - *
    - * - *

    Commit Rollback Phase

    - *
  • For each CommitTransaction from Commit Request phase - *
      - *
    1. Broker - * - * broker invokes a {@link CommitTransaction#finish()} - *
    2. The provider rollbacks a commit and returns an {@link RpcResult} of - * rollback.
    - *
  • Broker returns a error result to the consumer. - * - * - *

    Registration of functionality

    - * The registration could be done by : - *
      - *
    • returning an instance of implementation in the return value of - * {@link Provider#getProviderFunctionality()} - *
    • passing an instance of implementation and {@link DataStoreIdentifier} of - * rpc as arguments to the - * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} - *
    - * - * - */ -public interface DataCommitHandler extends Provider.ProviderFunctionality { - - /** - * A set of Data Stores supported by implementation. - * - * The set of {@link DataStoreIdentifier}s which identifies target data - * stores which are supported by this commit handler. This set is used, when - * {@link Provider} is registered to the SAL, to register and expose the - * commit handler functionality to affected data stores. - * - * @return Set of Data Store identifiers - */ - Set getSupportedDataStores(); - - /** - * The provider (commit handler) starts a commit transaction. - * - *

    - * The commit handler (provider) prepares an commit scenario, rollback - * scenario and validates data. - * - *

    - * If the provider is aware that at this point the commit would not be - * successful, the transaction is not created, but list of errors which - * prevented the start of transaction are returned. - * - * @param store - * @return Transaction object representing this commit, errors otherwise. - */ - RpcResult requestCommit(DataStoreIdentifier store); - - public interface CommitTransaction { - /** - * - * @return Data store affected by the transaction - */ - DataStoreIdentifier getDataStore(); - - /** - * Returns the handler associated with this transaction. - * - * @return Handler - */ - DataCommitHandler getHandler(); - - /** - * - * Finishes a commit. - * - * The provider (commit handler) should apply all changes to its state - * which are a result of data change- - * - * @return - */ - RpcResult finish() throws IllegalStateException; - - /** - * Rollbacks a commit. - * - * @return - * @throws IllegalStateException - * If the method is invoked after {@link #finish()} - */ - RpcResult rollback() throws IllegalStateException; - } -} +/* + * 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.core.api.data; + +import java.util.Set; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.yang.common.RpcResult; + + +/** + * Two phase commit handler (cohort) of the two-phase commit protocol of data. + * + *

    + * The provider should expose the implementation of DataCommitHandler if it's + * functionality depends on any subset of data stored in data repositories, in + * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier) + * operation. + * + *

    + * Operations of two-phase commit handlers should not change data in data store, + * this is responsibility of the coordinator (broker or some component of the + * broker). + * + * The commit handlers are responsible for changing the internal state of the + * provider to reflect the commited changes in data. + * + *

    Two-phase commit

    + * + *

    Commit Request Phase

    + * + *
      + *
    1. Consumer edits data by invocation of + * DataBrokerService.editCandidateData(DataStoreIdentifier, CompositeNodeModification) + *
    2. Consumer starts a commit by invoking + * DataBrokerService.commit(DataStoreIdentifier) + *
    3. Broker retrieves a list of all registered + * DataCommitHandlers + *
    4. For each DataCommitHandler + *
        + *
      1. Broker invokes a + * DataCommitHandler.requestCommit(DataStoreIdentifier) operation. + *
      2. DataCommitHandler returns a RpcResult with + * CommitTransaction + *
      3. If the result was successful, broker adds CommitTransaction + * to the list of opened transactions. If not, brokers stops a commit request + * phase and starts a rollback phase. + *
      + *
    5. Broker starts a commit finish phase + *
    + * + *

    Commit Finish Phase

    + * + *
      + *
    1. For each CommitTransaction from Commit Request phase + *
        + *
      1. Broker broker invokes a + * CommitTransaction.finish() + *
      2. The provider finishes a commit (applies the change) and returns an + * RpcResult. + *
      + *
    2. + *
        + *
      • If all returned results means successful, the brokers end two-phase + * commit by returning a success commit result to the Consumer. + *
      • If error occured, the broker starts a commit rollback phase. + *
      + *
    + * + *

    Commit Rollback Phase

    + *
  • For each CommitTransaction from Commit Request phase + *
      + *
    1. Broker + * + * broker invokes a {@link CommitTransaction#finish()} + *
    2. The provider rollbacks a commit and returns an {@link RpcResult} of + * rollback.
    + *
  • Broker returns a error result to the consumer. + * + * + *

    Registration of functionality

    + * The registration could be done by : + *
      + *
    • returning an instance of implementation in the return value of + * {@link Provider#getProviderFunctionality()} + *
    • passing an instance of implementation and {@link DataStoreIdentifier} of + * rpc as arguments to the + * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} + *
    + * + * + */ +public interface DataCommitHandler extends Provider.ProviderFunctionality { + + /** + * A set of Data Stores supported by implementation. + * + * The set of {@link DataStoreIdentifier}s which identifies target data + * stores which are supported by this commit handler. This set is used, when + * {@link Provider} is registered to the SAL, to register and expose the + * commit handler functionality to affected data stores. + * + * @return Set of Data Store identifiers + */ + Set getSupportedDataStores(); + + /** + * The provider (commit handler) starts a commit transaction. + * + *

    + * The commit handler (provider) prepares an commit scenario, rollback + * scenario and validates data. + * + *

    + * If the provider is aware that at this point the commit would not be + * successful, the transaction is not created, but list of errors which + * prevented the start of transaction are returned. + * + * @param store + * @return Transaction object representing this commit, errors otherwise. + */ + RpcResult requestCommit(DataStoreIdentifier store); + + public interface CommitTransaction { + /** + * + * @return Data store affected by the transaction + */ + DataStoreIdentifier getDataStore(); + + /** + * Returns the handler associated with this transaction. + * + * @return Handler + */ + DataCommitHandler getHandler(); + + /** + * + * Finishes a commit. + * + * The provider (commit handler) should apply all changes to its state + * which are a result of data change- + * + * @return + */ + RpcResult finish() throws IllegalStateException; + + /** + * Rollbacks a commit. + * + * @return + * @throws IllegalStateException + * If the method is invoked after {@link #finish()} + */ + RpcResult rollback() throws IllegalStateException; + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java index 5c5423d80f..32035ea489 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java @@ -1,78 +1,78 @@ -/* - * 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.core.api.data; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.core.api.Provider; - -public interface DataProviderService extends DataBrokerService { - - /** - * Adds {@link DataValidator} for specified Data Store - * - * @param store - * Data Store - * @param validator - * Validator - */ - public void addValidator(DataStoreIdentifier store, DataValidator validator); - - /** - * Removes {@link DataValidator} from specified Data Store - * - * @param store - * @param validator - * Validator - */ - public void removeValidator(DataStoreIdentifier store, - DataValidator validator); - - /** - * Adds {@link DataCommitHandler} for specified data store - * - * @param store - * @param provider - */ - void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider); - - /** - * Removes {@link DataCommitHandler} from specified data store - * - * @param store - * @param provider - */ - void removeCommitHandler(DataStoreIdentifier store, - DataCommitHandler provider); - - /** - * Adds {@link DataRefresher} for specified data store - * - * @param store - * @param refresher - */ - void addRefresher(DataStoreIdentifier store, DataRefresher refresher); - - /** - * Removes {@link DataRefresher} from specified data store - * - * @param store - * @param refresher - */ - void removeRefresher(DataStoreIdentifier store, DataRefresher refresher); - - public interface DataRefresher extends Provider.ProviderFunctionality { - - /** - * Fired when some component explicitly requested the data refresh. - * - * The provider which exposed the {@link DataRefresher} should republish - * its provided data by editing the data in all affected data stores. - */ - void refreshData(); - } -} +/* + * 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.core.api.data; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.core.api.Provider; + +public interface DataProviderService extends DataBrokerService { + + /** + * Adds {@link DataValidator} for specified Data Store + * + * @param store + * Data Store + * @param validator + * Validator + */ + public void addValidator(DataStoreIdentifier store, DataValidator validator); + + /** + * Removes {@link DataValidator} from specified Data Store + * + * @param store + * @param validator + * Validator + */ + public void removeValidator(DataStoreIdentifier store, + DataValidator validator); + + /** + * Adds {@link DataCommitHandler} for specified data store + * + * @param store + * @param provider + */ + void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider); + + /** + * Removes {@link DataCommitHandler} from specified data store + * + * @param store + * @param provider + */ + void removeCommitHandler(DataStoreIdentifier store, + DataCommitHandler provider); + + /** + * Adds {@link DataRefresher} for specified data store + * + * @param store + * @param refresher + */ + void addRefresher(DataStoreIdentifier store, DataRefresher refresher); + + /** + * Removes {@link DataRefresher} from specified data store + * + * @param store + * @param refresher + */ + void removeRefresher(DataStoreIdentifier store, DataRefresher refresher); + + public interface DataRefresher extends Provider.ProviderFunctionality { + + /** + * Fired when some component explicitly requested the data refresh. + * + * The provider which exposed the {@link DataRefresher} should republish + * its provided data by editing the data in all affected data stores. + */ + void refreshData(); + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java index a2105b41d7..2bcb84be34 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java @@ -1,57 +1,57 @@ -/* - * 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.core.api.data; - -import java.util.Set; - -import org.opendaylight.controller.sal.common.DataStoreIdentifier; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.yang.common.RpcResult; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -/** - * {@link Provider}-supplied Validator of the data. - * - *

    - * The registration could be done by : - *

      - *
    • returning an instance of implementation in the return value of - * {@link Provider#getProviderFunctionality()} - *
    • passing an instance of implementation and {@link DataStoreIdentifier} rpc - * as arguments to the - * {@link DataProviderService#addValidator(DataStoreIdentifier, DataValidator)} - *
    - * - **/ -public interface DataValidator extends Provider.ProviderFunctionality { - - /** - * A set of Data Stores supported by implementation. - * - * The set of {@link DataStoreIdentifier}s which identifies target data - * stores which are supported by this implementation. This set is used, when - * {@link Provider} is registered to the SAL, to register and expose the - * validation functionality to affected data stores. - * - * @return Set of Data Store identifiers - */ - Set getSupportedDataStores(); - - /** - * Performs validation on supplied data. - * - * @param toValidate - * Data to validate - * @return Validation result. The - * {@link RpcResult#isSuccessful()} == true if the data - * passed validation, otherwise contains list of errors. - */ - RpcResult validate(CompositeNode toValidate); - -} +/* + * 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.core.api.data; + +import java.util.Set; + +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; + + +/** + * {@link Provider}-supplied Validator of the data. + * + *

    + * The registration could be done by : + *

      + *
    • returning an instance of implementation in the return value of + * {@link Provider#getProviderFunctionality()} + *
    • passing an instance of implementation and {@link DataStoreIdentifier} rpc + * as arguments to the + * {@link DataProviderService#addValidator(DataStoreIdentifier, DataValidator)} + *
    + * + **/ +public interface DataValidator extends Provider.ProviderFunctionality { + + /** + * A set of Data Stores supported by implementation. + * + * The set of {@link DataStoreIdentifier}s which identifies target data + * stores which are supported by this implementation. This set is used, when + * {@link Provider} is registered to the SAL, to register and expose the + * validation functionality to affected data stores. + * + * @return Set of Data Store identifiers + */ + Set getSupportedDataStores(); + + /** + * Performs validation on supplied data. + * + * @param toValidate + * Data to validate + * @return Validation result. The + * {@link RpcResult#isSuccessful()} == true if the data + * passed validation, otherwise contains list of errors. + */ + RpcResult validate(CompositeNode toValidate); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/package-info.java index b58659a726..17911962ff 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/package-info.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/package-info.java @@ -1,8 +1,8 @@ -/* - * 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 - */ +/* + * 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.core.api.data; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java index 22abdc2a00..52f60b3cc2 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java @@ -1,42 +1,42 @@ -/* - * 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.core.api.model; - -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.api.SchemaContext; - -public interface SchemaService extends BrokerService { - - /** - * Registers a YANG module to session and global context - * - * @param module - */ - void addModule(Module module); - - /** - * Unregisters a YANG module from session context - * - * @param module - */ - void removeModule(Module module); - - /** - * Returns session specific YANG schema context - * @return - */ - SchemaContext getSessionContext(); - - /** - * Returns global schema context - * - * @return - */ - SchemaContext getGlobalContext(); -} +/* + * 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.core.api.model; + +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public interface SchemaService extends BrokerService { + + /** + * Registers a YANG module to session and global context + * + * @param module + */ + void addModule(Module module); + + /** + * Unregisters a YANG module from session context + * + * @param module + */ + void removeModule(Module module); + + /** + * Returns session specific YANG schema context + * @return + */ + SchemaContext getSessionContext(); + + /** + * Returns global schema context + * + * @return + */ + SchemaContext getGlobalContext(); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java index 5f72c62805..5b0c992a00 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java @@ -1,42 +1,42 @@ -/* - * 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.core.api.notify; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -/** - * Notification listener for SAL notifications. - */ -public interface NotificationListener extends Consumer.ConsumerFunctionality { - /** - * A set of notification types supported by listeners. - * - * The set of notification {@link QName}s which are supported by this - * listener. This set is used, when {@link Consumer} is registered to the - * SAL, to automatically register the listener. - * - * @return Set of QNames identifying supported notifications. - */ - Set getSupportedNotifications(); - - /** - * Fired when the notification occurs. - * - * The type of the notification could be learned by - * QName type = notification.getNodeType(); - * - * @param notification - * Notification content - */ - void onNotification(CompositeNode notification); -} +/* + * 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.core.api.notify; + +import java.util.Set; + +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; + + +/** + * Notification listener for SAL notifications. + */ +public interface NotificationListener extends Consumer.ConsumerFunctionality { + /** + * A set of notification types supported by listeners. + * + * The set of notification {@link QName}s which are supported by this + * listener. This set is used, when {@link Consumer} is registered to the + * SAL, to automatically register the listener. + * + * @return Set of QNames identifying supported notifications. + */ + Set getSupportedNotifications(); + + /** + * Fired when the notification occurs. + * + * The type of the notification could be learned by + * QName type = notification.getNodeType(); + * + * @param notification + * Notification content + */ + void onNotification(CompositeNode notification); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationProviderService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationProviderService.java index 6f7e740cdf..51871a770b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationProviderService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationProviderService.java @@ -1,46 +1,46 @@ -/* - * 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.core.api.notify; - -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.yang.data.api.CompositeNode; - - -/** - * Notification Publishing Service - * - * The simplified process of the notification publishing is following: - * - *
      - *
    1. {@link Provider} invokes {@link #sendNotification(CompositeNode)} - *
    2. {@link Broker} finds {@link NotificationListener}s which subscribed for - * the notification type. - * - *
    3. For each subscriber {@link Broker} invokes - * {@link NotificationListener#onNotification(CompositeNode)} - *
    - * - * - * - */ -public interface NotificationProviderService extends NotificationService { - - /** - * Publishes a notification. - * - * Notification type is determined by the - * {@link CompositeNode#getNodeType()} of the - * notification parameter. - * - * @param notification - * Notification to publish - */ - void sendNotification(CompositeNode notification); - -} +/* + * 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.core.api.notify; + +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; + + +/** + * Notification Publishing Service + * + * The simplified process of the notification publishing is following: + * + *
      + *
    1. {@link Provider} invokes {@link #sendNotification(CompositeNode)} + *
    2. {@link Broker} finds {@link NotificationListener}s which subscribed for + * the notification type. + * + *
    3. For each subscriber {@link Broker} invokes + * {@link NotificationListener#onNotification(CompositeNode)} + *
    + * + * + * + */ +public interface NotificationProviderService extends NotificationService { + + /** + * Publishes a notification. + * + * Notification type is determined by the + * {@link CompositeNode#getNodeType()} of the + * notification parameter. + * + * @param notification + * Notification to publish + */ + void sendNotification(CompositeNode notification); + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java index 98a4925afb..3bf10546e5 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java @@ -1,54 +1,54 @@ -/* - * 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.core.api.notify; - -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.yang.common.QName; - - -/** - * NotificationService provides access to the notification functionality of the - * SAL. - * - * NotificationService allows for consumption of notifications by registering - * implementations of NotificationListener. - * - * The registration of notification listeners could be done by: - *
      - *
    • returning an instance of implementation in the return value of - * {@link Provider#getProviderFunctionality()} - *
    • passing an instance of implementation and {@link QName} of rpc as an - * arguments to the - * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} - *
    - * - * - */ -public interface NotificationService extends BrokerService { - - /** - * Registers a notification listener for supplied notification type. - * - * @param notification - * @param listener - */ - void addNotificationListener(QName notification, - NotificationListener listener); - - /** - * Removes a notification listener for supplied notification type. - * - * @param notification - * @param listener - */ - void removeNotificationListener(QName notification, - NotificationListener listener); -} +/* + * 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.core.api.notify; + +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.yangtools.yang.common.QName; + + +/** + * NotificationService provides access to the notification functionality of the + * SAL. + * + * NotificationService allows for consumption of notifications by registering + * implementations of NotificationListener. + * + * The registration of notification listeners could be done by: + *
      + *
    • returning an instance of implementation in the return value of + * {@link Provider#getProviderFunctionality()} + *
    • passing an instance of implementation and {@link QName} of rpc as an + * arguments to the + * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} + *
    + * + * + */ +public interface NotificationService extends BrokerService { + + /** + * Registers a notification listener for supplied notification type. + * + * @param notification + * @param listener + */ + void addNotificationListener(QName notification, + NotificationListener listener); + + /** + * Removes a notification listener for supplied notification type. + * + * @param notification + * @param listener + */ + void removeNotificationListener(QName notification, + NotificationListener listener); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/package-info.java index b6868340bb..61426a3fd8 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/package-info.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/package-info.java @@ -1,11 +1,11 @@ -/* - * 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 - */ -/** - * SAL Notification functionality - */ +/* + * 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 + */ +/** + * SAL Notification functionality + */ package org.opendaylight.controller.sal.core.api.notify; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/package-info.java index a058df363d..395c09a40f 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/package-info.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/package-info.java @@ -1,11 +1,11 @@ -/* - * 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 - */ -/** - * Core binding-independent SAL contracts and components - */ -package org.opendaylight.controller.sal.core.api; +/* + * 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 + */ +/** + * Core binding-independent SAL contracts and components + */ +package org.opendaylight.controller.sal.core.api; diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml index 96af32bc7a..1162b0d99a 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-core-demo @@ -54,5 +54,5 @@ - + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-spi/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-spi/pom.xml index 3378a36fbc..aab58123f4 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-spi/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-spi/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-core-spi diff --git a/opendaylight/sal/yang-prototype/sal/sal-data-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-data-api/pom.xml index 74230e5f7c..eeea2920d5 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-data-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-data-api/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-data-api diff --git a/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/pom.xml index b67529ac35..b5c42ed74a 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.opendaylight.controller - sal + sal-parent 1.0-SNAPSHOT sal-schema-repository-api -- 2.36.6