Merge changes I8293baab,I63e248bd
authorEd Warnicke <eaw@cisco.com>
Fri, 16 Aug 2013 12:41:08 +0000 (12:41 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 16 Aug 2013 12:41:08 +0000 (12:41 +0000)
* changes:
  Added sample provider and consumer for MD SAL
  Clean up of binding broker implementation

82 files changed:
opendaylight/sal/yang-prototype/pom.xml
opendaylight/sal/yang-prototype/sal/pom.xml
opendaylight/sal/yang-prototype/sal/sal-binding-api/pom.xml
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationProviderService.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationService.java
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java [moved from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataBrokerService.java with 91% similarity]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java [moved from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataCommitHandler.java with 92% similarity]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java [moved from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataProviderService.java with 76% similarity]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataRefresher.java [moved from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataRefresher.java with 68% similarity]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataValidator.java [moved from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/DataValidator.java with 67% similarity]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/package-info.java
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BrokerActivator.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/Constants.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/DataModule.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationServiceImpl.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiProviderContext.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcServiceRegistrationImpl.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/GeneratorUtils.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/PropertiesUtils.xtend [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/utils/package-info.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/DataDomToJavaTransformer.java
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/JavaToDataDomTransformer.java
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcMapper.java
opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/pom.xml
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerImpl.java
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java
opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml
opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Futures.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java
opendaylight/sal/yang-prototype/sal/sal-common/pom.xml
opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataCommitHandler.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/package-info.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationProviderService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/package-info.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/package-info.java
opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml
opendaylight/sal/yang-prototype/sal/sal-core-spi/pom.xml
opendaylight/sal/yang-prototype/sal/sal-data-api/pom.xml
opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/pom.xml
opendaylight/sal/yang-prototype/sal/samples/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang [new file with mode: 0644]

index 6cd785cc2584638d4d08a380d55a3177f848f36c..525d8d179556b6dc031a4f61d1dcba687f6fc791 100644 (file)
@@ -12,6 +12,7 @@
     </description>
 
     <modules>
+        <module>sal</module>
         <module>concepts-lang</module>
     </modules>
 
     </properties>
 
     <pluginRepositories>
+        <pluginRepository>
+            <id>central</id>
+            <name>central</name>
+            <url>${nexusproxy}/repositories/central/</url>
+        </pluginRepository>
         <pluginRepository>
             <id>central2</id>
             <name>central2</name>
index 677372e295eab8d2479bbeef086f82b433736658..a3d95bdf3087727884ea53a2134cd5eee0649134 100644 (file)
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <groupId>org.opendaylight.controller</groupId>
-    <artifactId>sal</artifactId>
-    <version>1.0-SNAPSHOT</version>
-    <packaging>pom</packaging>
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.opendaylight.controller</groupId>
+       <artifactId>sal-parent</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <packaging>pom</packaging>
 
-    <modules>
-        <module>sal-common</module>
-        <module>sal-common-util</module>
-        <module>sal-core-api</module>
-        <module>sal-data-api</module>
-        <module>sal-binding-api</module>
-        <module>sal-binding-spi</module>
-        <module>sal-binding-broker-impl</module>
-        <module>sal-schema-repository-api</module>
-        <module>sal-core-spi</module>
-        <module>sal-broker-impl</module>
-    </modules>
+       <modules>
+               <module>sal-common</module>
+               <module>sal-common-util</module>
+               <module>sal-data-api</module>
+               <module>sal-binding-api</module>
+               <module>sal-binding-broker-impl</module>
+        <module>samples</module>
+       </modules>
 
-    <properties>
-        <yang.version>0.5.5-SNAPSHOT</yang.version>
-    </properties>
+       <properties>
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+               <slf4j.version>1.7.2</slf4j.version>
+               <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
+               <yang.version>0.5.7-SNAPSHOT</yang.version>
+               <maven.bundle.version>2.4.0</maven.bundle.version>
+       </properties>
 
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>com.google.guava</groupId>
-                <artifactId>guava</artifactId>
-                <version>14.0.1</version>
-                <type>jar</type>
-            </dependency>
-            <dependency>
-                <groupId>org.slf4j</groupId>
-                <artifactId>slf4j-api</artifactId>
-                <version>1.7.2</version>
-            </dependency>
-            <dependency>
-                <groupId>junit</groupId>
-                <artifactId>junit</artifactId>
-                <version>4.10</version>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-binding</artifactId>
-                <version>${yang.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-common</artifactId>
-                <version>${yang.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-data-api</artifactId>
-                <version>${yang.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-model-api</artifactId>
-                <version>${yang.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-data-util</artifactId>
-                <version>${yang.version}</version>
-            </dependency>
-        </dependencies>
+    <pluginRepositories>
+        <pluginRepository>
+            <id>central</id>
+            <name>central</name>
+            <url>${nexusproxy}/repositories/central/</url>
+        </pluginRepository>
+        <pluginRepository>
+            <id>central2</id>
+            <name>central2</name>
+            <url>${nexusproxy}/repositories/central2/</url>
+        </pluginRepository>
+        <pluginRepository>
+            <id>opendaylight.snapshot</id>
+            <name>opendaylight.snapshot</name>
+            <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+        </pluginRepository>
+    </pluginRepositories>
 
-    </dependencyManagement>
 
-    <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-all</artifactId>
-            <version>1.9.5</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>2.0</version>
-                <inherited>true</inherited>
-                <configuration>
-                    <source>1.7</source>
-                    <target>1.7</target>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-javadoc-plugin</artifactId>
-                <version>2.8.1</version>
-                <configuration>
-                    <stylesheet>maven</stylesheet>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>aggregate</goal>
-                        </goals>
-                        <phase>site</phase>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-    <reporting>
-        <plugins>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>findbugs-maven-plugin</artifactId>
-                <version>2.4.0</version>
-                <configuration>
-                    <effort>Max</effort>
-                    <threshold>Low</threshold>
-                    <goal>site</goal>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>jdepend-maven-plugin</artifactId>
-                <version>2.0-beta-2</version>
-            </plugin>
-        </plugins>
-    </reporting>
+       <repositories>
+               <!-- EBR release -->
+               <!-- http://repository.springsource.com/maven/bundles/release -->
+               <repository>
+                       <id>ebr-bundles-release</id>
+                       <name>ebr-bundles-release</name>
+                       <url>${nexusproxy}/repositories/ebr-bundles-release/</url>
+               </repository>
+               <!-- EBR external -->
+               <!-- http://repository.springsource.com/maven/bundles/external -->
+               <repository>
+                       <id>ebr-bundles-external</id>
+                       <name>ebr-bundles-external</name>
+                       <url>${nexusproxy}/repositories/ebr-bundles-external/</url>
+               </repository>
+               <!-- Maven repo2 mirror -->
+               <!-- http://repo2.maven.org/maven2 -->
+               <repository>
+                       <id>central2</id>
+                       <name>central2</name>
+                       <url>${nexusproxy}/repositories/central2/</url>
+               </repository>
+               <!-- Maven repo1 mirror -->
+               <!-- http://repo1.maven.org/maven2 -->
+               <repository>
+                       <id>central</id>
+                       <name>central</name>
+                       <url>${nexusproxy}/repositories/central/</url>
+               </repository>
+               <!-- Pax mirror -->
+               <!-- https://oss.sonatype.org/content/repositories/ops4j-releases -->
+               <repository>
+                       <id>ops4j-releases</id>
+                       <name>ops4j-releases</name>
+                       <url>${nexusproxy}/repositories/ops4j-releases/</url>
+               </repository>
+               <!-- Third Packages hosted in local maven because not available in other 
+                       places -->
+               <repository>
+                       <id>thirdparty</id>
+                       <name>thirdparty</name>
+                       <url>${nexusproxy}/repositories/thirdparty/</url>
+               </repository>
+               <!-- Jboss mirror -->
+               <!-- https://repository.jboss.org/nexus/content/repositories/releases -->
+               <repository>
+                       <id>jboss.releases</id>
+                       <name>jboss.releases</name>
+                       <url>${nexusproxy}/repositories/jboss.releases/</url>
+               </repository>
+               <!-- OpenDayLight Released artifact -->
+               <repository>
+                       <id>opendaylight-release</id>
+                       <name>opendaylight-release</name>
+                       <url>${nexusproxy}/repositories/opendaylight.release/</url>
+               </repository>
+               <!-- OpenDayLight Snapshot artifact -->
+               <repository>
+                       <id>opendaylight-snapshot</id>
+                       <name>opendaylight-snapshot</name>
+                       <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+               </repository>
+       </repositories>
+
+
+
+       <dependencyManagement>
+               <dependencies>
+                       <dependency>
+                               <groupId>com.google.guava</groupId>
+                               <artifactId>guava</artifactId>
+                               <version>14.0.1</version>
+                               <type>jar</type>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.slf4j</groupId>
+                               <artifactId>slf4j-api</artifactId>
+                               <version>1.7.2</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>junit</groupId>
+                               <artifactId>junit</artifactId>
+                               <version>4.10</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.opendaylight.yangtools</groupId>
+                               <artifactId>yang-binding</artifactId>
+                               <version>${yang.version}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.opendaylight.yangtools</groupId>
+                               <artifactId>yang-common</artifactId>
+                               <version>${yang.version}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.opendaylight.yangtools</groupId>
+                               <artifactId>yang-data-api</artifactId>
+                               <version>${yang.version}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.opendaylight.yangtools</groupId>
+                               <artifactId>yang-model-api</artifactId>
+                               <version>${yang.version}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.opendaylight.yangtools</groupId>
+                               <artifactId>yang-data-util</artifactId>
+                               <version>${yang.version}</version>
+                       </dependency>
+               </dependencies>
+
+       </dependencyManagement>
+
+       <dependencies>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+                       <optional>true</optional>
+               </dependency>
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-all</artifactId>
+                       <version>1.9.5</version>
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <version>${maven.bundle.version}</version>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                                       </instructions>
+                                       <manifestLocation>${project.basedir}/META-INF</manifestLocation>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <version>2.0</version>
+                               <inherited>true</inherited>
+                               <configuration>
+                                       <source>1.7</source>
+                                       <target>1.7</target>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-javadoc-plugin</artifactId>
+                               <version>2.8.1</version>
+                               <configuration>
+                                       <stylesheet>maven</stylesheet>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>aggregate</goal>
+                                               </goals>
+                                               <phase>site</phase>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+       <reporting>
+               <plugins>
+                       <plugin>
+                               <groupId>org.codehaus.mojo</groupId>
+                               <artifactId>findbugs-maven-plugin</artifactId>
+                               <version>2.4.0</version>
+                               <configuration>
+                                       <effort>Max</effort>
+                                       <threshold>Low</threshold>
+                                       <goal>site</goal>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.codehaus.mojo</groupId>
+                               <artifactId>jdepend-maven-plugin</artifactId>
+                               <version>2.0-beta-2</version>
+                       </plugin>
+               </plugins>
+       </reporting>
 </project>
index 92cfc3ba7aa61c46c72d8b6a9640663999dfeaa5..d94a659afac56781a7ec4f6fb9943e7384d28183 100644 (file)
@@ -1,28 +1,32 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-    <modelVersion>4.0.0</modelVersion>\r
-    <parent>\r
-        <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
-        <version>1.0-SNAPSHOT</version>\r
-    </parent>\r
-    <artifactId>sal-binding-api</artifactId>\r
-\r
-    <dependencies>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>yang-common</artifactId>\r
-\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>yang-binding</artifactId>\r
-\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-common</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-parent</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>sal-binding-api</artifactId>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>5.0.0</version>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
index 24f5b25a190b2e4d8d4876ee5eb9e9a5bd794eab..fa104882a372bf173a283406f506c7011385aa34 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.yang.binding.RpcService;\r
-\r
-/**\r
- * Binding-aware core of the SAL layer responsible for wiring the SAL consumers.\r
- * \r
- * The responsibility of the broker is to maintain registration of SAL\r
- * functionality {@link Consumer}s and {@link Provider}s, store provider and\r
- * consumer specific context and functionality registration via\r
- * {@link ConsumerSession} and provide access to infrastructure services, which\r
- * removes direct dependencies between providers and consumers.\r
- * \r
- * The Binding-aware broker is also responsible for translation from Java\r
- * classes modeling the functionality and data to binding-indpenedent form which\r
- * is used in SAL Core.\r
- * \r
- * \r
- * <h3>Infrastructure services</h3> Some examples of infrastructure services:\r
- * \r
- * <ul>\r
- * <li>YANG Module service - see {@link ConsumerSession#getRpcService(Class)},\r
- * {@link ProviderSession}\r
- * <li>Notification Service - see {@link NotificationService} and\r
- * {@link NotificationProviderService}\r
- * <li>Functionality and Data model\r
- * <li>Data Store access and modification - see {@link DataBrokerService} and\r
- * {@link DataProviderService}\r
- * </ul>\r
- * \r
- * The services are exposed via session.\r
- * \r
- * <h3>Session-based access</h3>\r
- * \r
- * The providers and consumers needs to register in order to use the\r
- * binding-independent SAL layer and to expose functionality via SAL layer.\r
- * \r
- * For more information about session-based access see {@link ConsumerSession}\r
- * and {@link ProviderSession}\r
- * \r
- * \r
-\r
- * \r
- */\r
-public interface BindingAwareBroker {\r
-    /**\r
-     * Registers the {@link BindingAwareConsumer}, which will use the SAL layer.\r
-     * \r
-     * <p>\r
-     * Note that consumer could register additional functionality at later point\r
-     * by using service and functionality specific APIs.\r
-     * \r
-     * <p>\r
-     * The consumer is required to use returned session for all communication\r
-     * with broker or one of the broker services. The session is announced to\r
-     * the consumer by invoking\r
-     * {@link Consumer#onSessionInitiated(ConsumerSession)}.\r
-     * \r
-     * @param cons\r
-     *            Consumer to be registered.\r
-     * @return a session specific to consumer registration\r
-     * @throws IllegalArgumentException\r
-     *             If the consumer is <code>null</code>.\r
-     * @throws IllegalStateException\r
-     *             If the consumer is already registered.\r
-     */\r
-    ConsumerSession registerConsumer(BindingAwareConsumer consumer);\r
-\r
-    /**\r
-     * Registers the {@link BindingAwareProvider}, which will use the SAL layer.\r
-     * \r
-     * <p>\r
-     * During the registration, the broker obtains the initial functionality\r
-     * from consumer, using the\r
-     * {@link BindingAwareProvider#getImplementations()}, and register that\r
-     * functionality into system and concrete infrastructure services.\r
-     * \r
-     * <p>\r
-     * Note that provider could register additional functionality at later point\r
-     * by using service and functionality specific APIs.\r
-     * \r
-     * <p>\r
-     * The consumer is <b>required to use</b> returned session for all\r
-     * communication with broker or one of the broker services. The session is\r
-     * announced to the consumer by invoking\r
-     * {@link BindingAwareProvider#onSessionInitiated(ProviderSession)}.\r
-     * \r
-     * \r
-     * @param prov\r
-     *            Provider to be registered.\r
-     * @return a session unique to the provider registration.\r
-     * @throws IllegalArgumentException\r
-     *             If the provider is <code>null</code>.\r
-     * @throws IllegalStateException\r
-     *             If the consumer is already registered.\r
-     */\r
-    ProviderSession registerProvider(BindingAwareProvider provider);\r
-\r
-    /**\r
-     * {@link BindingAwareConsumer} specific access to the SAL functionality.\r
-     * \r
-     * <p>\r
-     * ConsumerSession is {@link BindingAwareConsumer}-specific access to the\r
-     * SAL functionality and infrastructure services.\r
-     * \r
-     * <p>\r
-     * The session serves to store SAL context (e.g. registration of\r
-     * functionality) for the consumer and provides access to the SAL\r
-     * infrastructure services and other functionality provided by\r
-     * {@link Provider}s.\r
-     * \r
-\r
-     * \r
-     */\r
-    public interface ConsumerSession {\r
-\r
-        /**\r
-         * Returns a session specific instance (implementation) of requested\r
-         * binding-aware infrastructural service\r
-         * \r
-         * @param service\r
-         *            Broker service\r
-         * @return Session specific implementation of service\r
-         */\r
-        <T extends BindingAwareService> T getSALService(Class<T> service);\r
-\r
-        /**\r
-         * Returns a session specific instance (implementation) of requested\r
-         * YANG module implentation / service provided by consumer.\r
-         * \r
-         * @param service\r
-         *            Broker service\r
-         * @return Session specific implementation of service\r
-         */\r
-        <T extends RpcService> T getRpcService(Class<T> module);\r
-    }\r
-\r
-    /**\r
-     * {@link BindingAwareProvider} specific access to the SAL functionality.\r
-     * \r
-     * <p>\r
-     * ProviderSession is {@link BindingAwareProvider}-specific access to the\r
-     * SAL functionality and infrastructure services, which also allows for\r
-     * exposing the provider's functionality to the other\r
-     * {@link BindingAwareConsumer}s.\r
-     * \r
-     * <p>\r
-     * The session serves to store SAL context (e.g. registration of\r
-     * functionality) for the providers and exposes access to the SAL\r
-     * infrastructure services, dynamic functionality registration and any other\r
-     * functionality provided by other {@link BindingAwareConsumer}s.\r
-     * \r
-     */\r
-    public interface ProviderSession extends ConsumerSession {\r
-\r
-        void addRpcImplementation(RpcService implementation);\r
-\r
-        void removeRpcImplementation(RpcService implementation);\r
-    }\r
-}\r
+/*
+ * 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.
+ * 
+ * 
+ * <h3>Infrastructure services</h3> Some examples of infrastructure services:
+ * 
+ * <ul>
+ * <li>YANG Module service - see {@link ConsumerContext#getRpcService(Class)},
+ * {@link ProviderContext}
+ * <li>Notification Service - see {@link NotificationService} and
+ * {@link NotificationProviderService}
+ * <li>Functionality and Data model
+ * <li>Data Store access and modification - see {@link DataBrokerService} and
+ * {@link DataConsumerService}
+ * </ul>
+ * 
+ * The services are exposed via session.
+ * 
+ * <h3>Session-based access</h3>
+ * 
+ * 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.
+     * 
+     * <p>
+     * Note that consumer could register additional functionality at later point
+     * by using service and functionality specific APIs.
+     * 
+     * <p>
+     * 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 <code>null</code>.
+     * @throws IllegalStateException
+     *             If the consumer is already registered.
+     */
+    ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx);
+
+    /**
+     * Registers the {@link BindingAwareProvider}, which will use the SAL layer.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * Note that provider could register additional functionality at later point
+     * by using service and functionality specific APIs.
+     * 
+     * <p>
+     * The consumer is <b>required to use</b> 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 <code>null</code>.
+     * @throws IllegalStateException
+     *             If the consumer is already registered.
+     */
+    ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx);
+
+    /**
+     * {@link BindingAwareConsumer} specific access to the SAL functionality.
+     * 
+     * <p>
+     * ConsumerSession is {@link BindingAwareConsumer}-specific access to the
+     * SAL functionality and infrastructure services.
+     * 
+     * <p>
+     * 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 extends BindingAwareService> T getSALService(Class<T> 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 extends RpcService> T getRpcService(Class<T> module);
+    }
+
+    /**
+     * {@link BindingAwareProvider} specific access to the SAL functionality.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * 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 {
+
+        <T extends RpcService> RpcServiceRegistration<T> addRpcImplementation(Class<T> type, T implementation);
+    }
+
+    public interface RpcServiceRegistration<T extends RpcService> {
+
+        T getService();
+
+        void unregister();
+    }
+}
index e32f8bc9f9fd23e29e722da7d6b221d143bded5f..fc297261b780f3b173604be2c9c4ca751324e2cc 100644 (file)
@@ -1,40 +1,40 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession;\r
-\r
-/**\r
- * \r
- * Defines the component of controller and supplies additional metadata. A\r
- * component of the controller or application supplies a concrete implementation\r
- * of this interface.\r
- * \r
- * A user-implemented component (application) which faciliates the SAL and SAL\r
- * services to access infrastructure services or providers' functionality.\r
- * \r
-\r
- * \r
- */\r
-public interface BindingAwareConsumer {\r
-\r
-    /**\r
-     * Callback signaling initialization of the consumer session to the SAL.\r
-     * \r
-     * The consumer MUST use the session for all communication with SAL or\r
-     * retrieving SAL infrastructure services.\r
-     * \r
-     * This method is invoked by\r
-     * {@link BindingAwareBroker#registerConsumer(BindingAwareConsumer)}\r
-     * \r
-     * @param session\r
-     *            Unique session between consumer and SAL.\r
-     */\r
-    void onSessionInitialized(ConsumerSession session);\r
-\r
-}\r
+/*
+ * 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);
+
+}
index d324b83c5330b517d34447442313577c4163fd5a..3641d7697042a7f53d8f5f01058dcd8c724d4be4 100644 (file)
@@ -1,72 +1,69 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import java.util.Collection;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession;\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession;\r
-import org.opendaylight.controller.yang.binding.RpcService;\r
-\r
-\r
-/**\r
- * \r
- * Defines the component of controller and supplies additional metadata. A\r
- * component of the controller or application supplies a concrete implementation\r
- * of this interface.\r
- * \r
- * <p>\r
- * A user-implemented component (application) which facilitates the SAL and SAL\r
- * services to access infrastructure services and to provide functionality to\r
- * {@link Consumer}s and other providers.\r
- * \r
-\r
- * \r
- */\r
-public interface BindingAwareProvider {\r
-\r
-    void onSessionInitialized(ConsumerSession session);\r
-\r
-    /**\r
-     * Returns a set of provided implementations of YANG modules and their rpcs.\r
-     * \r
-     * \r
-     * @return Set of provided implementation of YANG modules and their Rpcs\r
-     */\r
-    Collection<? extends RpcService> getImplementations();\r
-\r
-    /**\r
-     * Gets a set of implementations of provider functionality to be registered\r
-     * into system during the provider registration to the SAL.\r
-     * \r
-     * <p>\r
-     * This method is invoked by {@link Broker#registerProvider(Provider)} to\r
-     * learn the initial provided functionality\r
-     * \r
-     * @return Set of provider's functionality.\r
-     */\r
-    Collection<? extends ProviderFunctionality> getFunctionality();\r
-\r
-    /**\r
-     * Functionality provided by the {@link BindingAwareProvider}\r
-     * \r
-     * <p>\r
-     * Marker interface used to mark the interfaces describing specific\r
-     * functionality which could be exposed by providers to other components.\r
-     * \r
-\r
-     * \r
-     */\r
-    public interface ProviderFunctionality {\r
-\r
-    }\r
-\r
-    void onSessionInitiated(ProviderSession session);\r
-\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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<? extends RpcService> getImplementations();
+
+    /**
+     * Gets a set of implementations of provider functionality to be registered
+     * into system during the provider registration to the SAL.
+     * 
+     * <p>
+     * This method is invoked by {@link Broker#registerProvider(Provider)} to
+     * learn the initial provided functionality
+     * 
+     * @return Set of provider's functionality.
+     */
+    Collection<? extends ProviderFunctionality> getFunctionality();
+
+    /**
+     * Functionality provided by the {@link BindingAwareProvider}
+     * 
+     * <p>
+     * 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);
+
+}
index e4d86e7bfdab8c7418ae8ffde41bf4b532baf09f..b3680568bba9a9d1ed3ae59bc3eb0e03d4eaf17a 100644 (file)
@@ -1,40 +1,40 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession;\r
-\r
-/**\r
- * \r
- * Session-specific instance of the broker functionality.\r
- * \r
- * <p>\r
- * BindingAwareService is marker interface for infrastructure services provided\r
- * by the SAL. These services are session-specific, each\r
- * {@link BindingAwareConsumer} and {@link BindingAwareProvider} usually has own\r
- * instance of the service with it's own context.\r
- * \r
- * <p>\r
- * The consumer's (or provider's) instance of specific service could be obtained\r
- * by invoking {@link ConsumerSession#getSALService(Class)} method on session\r
- * assigned to the consumer.\r
- * \r
- * <p>\r
- * {@link BindingAwareService} and {@link BindingAwareProvider} may seem\r
- * similar, but provider provides YANG model-based functionality and\r
- * {@link BindingAwareProvider} exposes the necessary supporting functionality\r
- * to implement specific functionality of YANG and to reuse it in the\r
- * development of {@link BindingAwareConsumer}s and {@link BindingAwareProvider}\r
- * s.\r
- * \r
-\r
- * \r
- */\r
-public interface BindingAwareService {\r
-\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * {@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 (file)
index 0000000..ccc7391
--- /dev/null
@@ -0,0 +1,6 @@
+package org.opendaylight.controller.sal.binding.api;
+
+public interface NotificationListener<T> {
+
+    void onNotification(T notification);
+}
index c5fc405f512a5260f0e948292a7759780195bedd..86c9eebecd0b9b17b78c957e7ef30ecead94a0a5 100644 (file)
@@ -1,15 +1,15 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.yang.binding.Notification;\r
-\r
-public interface NotificationProviderService extends NotificationService {\r
-\r
-    void notify(Notification notification);\r
-}\r
+/*
+ * 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);
+}
index 92e30a52361de9f3650ed5c8dc281f1e2d9c31d6..3723c70e8c371115e44b1bf5f0bbeaa9e7da225a 100644 (file)
@@ -1,22 +1,17 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.yang.binding.Notification;\r
-import org.opendaylight.controller.yang.binding.NotificationListener;\r
-\r
-public interface NotificationService extends BindingAwareService {\r
-\r
-    void addNotificationListener(\r
-            Class<? extends Notification> notificationType,\r
-            NotificationListener listener);\r
-\r
-    void removeNotificationListener(\r
-            Class<? extends Notification> notificationType,\r
-            NotificationListener listener);\r
-}\r
+/*
+ * 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 {
+
+    <T extends Notification> void addNotificationListener(Class<T> notificationType, NotificationListener<T> listener);
+
+    <T extends Notification> void removeNotificationListener(Class<T> notificationType, NotificationListener<T> listener);
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import java.util.concurrent.Future;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.yang.binding.DataRoot;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-\r
-\r
-/**\r
- * DataBrokerService provides unified access to the data stores available in the\r
- * system.\r
- * \r
- * \r
- * @see DataProviderService\r
-\r
- */\r
-public interface DataBrokerService extends BindingAwareService {\r
-\r
-    /**\r
-     * Returns a data from specified Data Store.\r
-     * \r
-     * Returns all the data visible to the consumer from specified Data Store.\r
-     * \r
-     * @param <T>\r
-     *            Interface generated from YANG module representing root of data\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @return data visible to the consumer\r
-     */\r
-    <T extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType);\r
-\r
-    /**\r
-     * Returns a filtered subset of data from specified Data Store.\r
-     * \r
-     * <p>\r
-     * The filter is modeled as an hierarchy of Java TOs starting with\r
-     * implementation of {@link DataRoot} representing data root. The semantics\r
-     * of the filter tree is the same as filter semantics defined in the NETCONF\r
-     * protocol for rpc operations <code>get</code> and <code>get-config</code>\r
-     * in Section 6 of RFC6241.\r
-     * \r
-     * \r
-     * @see http://tools.ietf.org/html/rfc6241#section-6\r
-     * @param <T>\r
-     *            Interface generated from YANG module representing root of data\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @param filter\r
-     *            Data tree filter similar to the NETCONF filter\r
-     * @return\r
-     */\r
-    <T extends DataRoot> T getData(DataStoreIdentifier store, T filter);\r
-\r
-    /**\r
-     * Returns a candidate data which are not yet commited.\r
-     * \r
-     * \r
-     * @param <T>\r
-     *            Interface generated from YANG module representing root of data\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @return\r
-     */\r
-    <T extends DataRoot> T getCandidateData(DataStoreIdentifier store,\r
-            Class<T> rootType);\r
-\r
-    /**\r
-     * Returns a filtered subset of candidate data from specified Data Store.\r
-     * \r
-     * <p>\r
-     * The filter is modeled as an hierarchy of {@link Node} starting with\r
-     * {@link CompositeNode} representing data root. The semantics of the filter\r
-     * tree is the same as filter semantics defined in the NETCONF protocol for\r
-     * rpc operations <code>get</code> and <code>get-config</code> in Section 6\r
-     * of RFC6241.\r
-     * \r
-     * \r
-     * @see http://tools.ietf.org/html/rfc6241#section-6\r
-     * @param <T>\r
-     *            Interface generated from YANG module representing root of data\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @param filter\r
-     *            A filter data root\r
-     * @return\r
-     */\r
-    <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter);\r
-\r
-    /**\r
-     * \r
-     * @param <T>\r
-     *            Interface generated from YANG module representing root of data\r
-     * @param store\r
-     *            Identifier of the store, in which will be the candidate data\r
-     *            modified\r
-     * @param changeSet\r
-     *            Modification of data tree.\r
-     * @return Result object containing the modified data tree if the operation\r
-     *         was successful, otherwise list of the encountered errors.\r
-     */\r
-    RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store,\r
-            DataRoot changeSet);\r
-\r
-    /**\r
-     * Initiates a two-phase commit of candidate data.\r
-     * \r
-     * <p>\r
-     * The {@link Consumer} could initiate a commit of candidate data\r
-     * \r
-     * <p>\r
-     * The successful commit changes the state of the system and may affect\r
-     * several components.\r
-     * \r
-     * <p>\r
-     * The effects of successful commit of data are described in the\r
-     * specifications and YANG models describing the {@link Provider} components\r
-     * of controller. It is assumed that {@link Consumer} has an understanding\r
-     * of this changes.\r
-     * \r
-     * \r
-     * @see DataCommitHandler for further information how two-phase commit is\r
-     *      processed.\r
-     * @param store\r
-     *            Identifier of the store, where commit should occur.\r
-     * @return Result of the commit, containing success information or list of\r
-     *         encountered errors, if commit was not successful.\r
-     */\r
-    Future<RpcResult<Void>> commit(DataStoreIdentifier store);\r
-}\r
+/*
+ * 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 <T>
+     *            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 extends DataRoot> T getData(DataStoreIdentifier store, Class<T> rootType);
+
+    /**
+     * Returns a filtered subset of data from specified Data Store.
+     * 
+     * <p>
+     * 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 <code>get</code> and <code>get-config</code>
+     * in Section 6 of RFC6241.
+     * 
+     * 
+     * @see http://tools.ietf.org/html/rfc6241#section-6
+     * @param <T>
+     *            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 extends DataRoot> T getData(DataStoreIdentifier store, T filter);
+
+    /**
+     * Returns a candidate data which are not yet commited.
+     * 
+     * 
+     * @param <T>
+     *            Interface generated from YANG module representing root of data
+     * @param store
+     *            Identifier of the store, from which will be data retrieved
+     * @return
+     */
+    <T extends DataRoot> T getCandidateData(DataStoreIdentifier store, Class<T> rootType);
+
+    /**
+     * Returns a filtered subset of candidate data from specified Data Store.
+     * 
+     * <p>
+     * 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 <code>get</code> and <code>get-config</code> in Section 6
+     * of RFC6241.
+     * 
+     * 
+     * @see http://tools.ietf.org/html/rfc6241#section-6
+     * @param <T>
+     *            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 extends DataRoot> T getCandidateData(DataStoreIdentifier store, T filter);
+
+    /**
+     * 
+     * @param <T>
+     *            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<DataRoot> editCandidateData(DataStoreIdentifier store, DataRoot changeSet);
+
+    /**
+     * Initiates a two-phase commit of candidate data.
+     * 
+     * <p>
+     * The {@link Consumer} could initiate a commit of candidate data
+     * 
+     * <p>
+     * The successful commit changes the state of the system and may affect
+     * several components.
+     * 
+     * <p>
+     * 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<RpcResult<Void>> commit(DataStoreIdentifier store);
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality;\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-\r
-\r
-/**\r
- * Two phase commit handler (cohort) of the two-phase commit protocol of data.\r
- * \r
- * <p>\r
- * The provider should expose the implementation of DataCommitHandler if it's\r
- * functionality depends on any subset of data stored in data repositories, in\r
- * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier)\r
- * operation.\r
- * \r
- * <p>\r
- * Operations of two-phase commit handlers should not change data in data store,\r
- * this is responsibility of the coordinator (broker or some component of the\r
- * broker).\r
- * \r
- * The commit handlers are responsible for changing the internal state of the\r
- * provider to reflect the commited changes in data.\r
- * \r
- * <h3>Two-phase commit</h3>\r
- * \r
- * <h4>Commit Request Phase</h4>\r
- * \r
- * <ol>\r
- * <li> <code>Consumer</code> edits data by invocation of\r
- * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot)</code>\r
- * <li> <code>Consumer</code> starts a commit by invoking\r
- * <code>DataBrokerService.commit(DataStoreIdentifier)</code>\r
- * <li> <code>Broker</code> retrieves a list of all registered\r
- * <code>DataCommitHandlers</code>\r
- * <li>For each <code>DataCommitHandler</code>\r
- * <ol>\r
- * <li><code>Broker</code> invokes a\r
- * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.\r
- * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with\r
- * <code>CommitTransaction</code>\r
- * <li>If the result was successful, broker adds <code>CommitTransaction</code>\r
- * to the list of opened transactions. If not, brokers stops a commit request\r
- * phase and starts a rollback phase.\r
- * </ol>\r
- * <li><code>Broker</code> starts a commit finish phase\r
- * </ol>\r
- * \r
- * <h4>Commit Finish Phase</h4>\r
- * \r
- * <ol>\r
- * <li>For each <code>CommitTransaction</code> from Commit Request phase\r
- * <ol>\r
- * <li><code>Broker</code> broker invokes a\r
- * <code>CommitTransaction.finish()</code>\r
- * <li>The provider finishes a commit (applies the change) and returns an\r
- * <code>RpcResult</code>.\r
- * </ol>\r
- * <li>\r
- * <ul>\r
- * <li>If all returned results means successful, the brokers end two-phase\r
- * commit by returning a success commit result to the Consumer.\r
- * <li>If error occured, the broker starts a commit rollback phase.\r
- * </ul>\r
- * </ol>\r
- * \r
- * <h4>Commit Rollback Phase</h4>\r
- * <li>For each <code>CommitTransaction</code> from Commit Request phase\r
- * <ol>\r
- * <li><code>Broker</code>\r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * \r
- * broker invokes a {@link CommitTransaction#finish()}\r
- * <li>The provider rollbacks a commit and returns an {@link RpcResult} of\r
- * rollback. </ol>\r
- * <li>Broker returns a error result to the consumer.\r
- * \r
- * \r
- * <h3>Registration of functionality</h3>\r
- * The registration could be done by :\r
- * <ul>\r
- * <li>returning an instance of implementation in the return value of\r
- * {@link Provider#getProviderFunctionality()}\r
- * <li>passing an instance of implementation and {@link DataStoreIdentifier} of\r
- * rpc as arguments to the\r
- * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)}\r
- * </ul>\r
- * \r
-\r
- * \r
- */\r
-public interface DataCommitHandler extends ProviderFunctionality {\r
-    /**\r
-     * A set of Data Stores supported by implementation.\r
-     * \r
-     * The set of {@link DataStoreIdentifier}s which identifies target data\r
-     * stores which are supported by this commit handler. This set is used, when\r
-     * {@link Provider} is registered to the SAL, to register and expose the\r
-     * commit handler functionality to affected data stores.\r
-     * \r
-     * @return Set of Data Store identifiers\r
-     */\r
-    Set<DataStoreIdentifier> getSupportedDataStores();\r
-\r
-    /**\r
-     * The provider (commit handler) starts a commit transaction.\r
-     * \r
-     * <p>\r
-     * The commit handler (provider) prepares an commit scenario, rollback\r
-     * scenario and validates data.\r
-     * \r
-     * <p>\r
-     * If the provider is aware that at this point the commit would not be\r
-     * successful, the transaction is not created, but list of errors which\r
-     * prevented the start of transaction are returned.\r
-     * \r
-     * @param store\r
-     * @return Transaction object representing this commit, errors otherwise.\r
-     */\r
-    RpcResult<CommitTransaction> requestCommit(DataStoreIdentifier store);\r
-\r
-    public interface CommitTransaction {\r
-        /**\r
-         * \r
-         * @return Data store affected by the transaction\r
-         */\r
-        DataStoreIdentifier getDataStore();\r
-\r
-        /**\r
-         * Returns the handler associated with this transaction.\r
-         * \r
-         * @return Handler\r
-         */\r
-        DataCommitHandler getHandler();\r
-\r
-        /**\r
-         * \r
-         * Finishes a commit.\r
-         * \r
-         * The provider (commit handler) should apply all changes to its state\r
-         * which are a result of data change-\r
-         * \r
-         * @return\r
-         */\r
-        RpcResult<Void> finish() throws IllegalStateException;\r
-\r
-        /**\r
-         * Rollbacks a commit.\r
-         * \r
-         * @return\r
-         * @throws IllegalStateException\r
-         *             If the method is invoked after {@link #finish()}\r
-         */\r
-        RpcResult<Void> rollback() throws IllegalStateException;\r
-    }\r
-\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <h3>Two-phase commit</h3>
+ * 
+ * <h4>Commit Request Phase</h4>
+ * 
+ * <ol>
+ * <li> <code>Consumer</code> edits data by invocation of
+ * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot)</code>
+ * <li> <code>Consumer</code> starts a commit by invoking
+ * <code>DataBrokerService.commit(DataStoreIdentifier)</code>
+ * <li> <code>Broker</code> retrieves a list of all registered
+ * <code>DataCommitHandlers</code>
+ * <li>For each <code>DataCommitHandler</code>
+ * <ol>
+ * <li><code>Broker</code> invokes a
+ * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.
+ * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with
+ * <code>CommitTransaction</code>
+ * <li>If the result was successful, broker adds <code>CommitTransaction</code>
+ * to the list of opened transactions. If not, brokers stops a commit request
+ * phase and starts a rollback phase.
+ * </ol>
+ * <li><code>Broker</code> starts a commit finish phase
+ * </ol>
+ * 
+ * <h4>Commit Finish Phase</h4>
+ * 
+ * <ol>
+ * <li>For each <code>CommitTransaction</code> from Commit Request phase
+ * <ol>
+ * <li><code>Broker</code> broker invokes a
+ * <code>CommitTransaction.finish()</code>
+ * <li>The provider finishes a commit (applies the change) and returns an
+ * <code>RpcResult</code>.
+ * </ol>
+ * <li>
+ * <ul>
+ * <li>If all returned results means successful, the brokers end two-phase
+ * commit by returning a success commit result to the Consumer.
+ * <li>If error occured, the broker starts a commit rollback phase.
+ * </ul>
+ * </ol>
+ * 
+ * <h4>Commit Rollback Phase</h4>
+ * <li>For each <code>CommitTransaction</code> from Commit Request phase
+ * <ol>
+ * <li><code>Broker</code>
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * 
+ * broker invokes a {@link CommitTransaction#finish()}
+ * <li>The provider rollbacks a commit and returns an {@link RpcResult} of
+ * rollback. </ol>
+ * <li>Broker returns a error result to the consumer.
+ * 
+ * 
+ * <h3>Registration of functionality</h3>
+ * The registration could be done by :
+ * <ul>
+ * <li>returning an instance of implementation in the return value of
+ * {@link Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link DataStoreIdentifier} of
+ * rpc as arguments to the
+ * {@link DataConsumerService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)}
+ * </ul>
+ * 
+ * 
+ * 
+ */
+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<DataStoreIdentifier> getSupportedDataStores();
+
+    /**
+     * The provider (commit handler) starts a commit transaction.
+     * 
+     * <p>
+     * The commit handler (provider) prepares an commit scenario, rollback
+     * scenario and validates data.
+     * 
+     * <p>
+     * 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<CommitTransaction> 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<Void> finish() throws IllegalStateException;
+
+        /**
+         * Rollbacks a commit.
+         * 
+         * @return
+         * @throws IllegalStateException
+         *             If the method is invoked after {@link #finish()}
+         */
+        RpcResult<Void> rollback() throws IllegalStateException;
+    }
+
+}
@@ -1,67 +1,65 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-\r
-public interface DataProviderService extends DataBrokerService {\r
-\r
-    /**\r
-     * Adds {@link DataValidator} for specified Data Store\r
-     * \r
-     * @param store\r
-     *            Data Store\r
-     * @param validator\r
-     *            Validator\r
-     */\r
-    public void addValidator(DataStoreIdentifier store, DataValidator validator);\r
-\r
-    /**\r
-     * Removes {@link DataValidator} from specified Data Store\r
-     * \r
-     * @param store\r
-     * @param validator\r
-     *            Validator\r
-     */\r
-    public void removeValidator(DataStoreIdentifier store,\r
-            DataValidator validator);\r
-\r
-    /**\r
-     * Adds {@link DataCommitHandler} for specified data store\r
-     * \r
-     * @param store\r
-     * @param provider\r
-     */\r
-    void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider);\r
-\r
-    /**\r
-     * Removes {@link DataCommitHandler} from specified data store\r
-     * \r
-     * @param store\r
-     * @param provider\r
-     */\r
-    void removeCommitHandler(DataStoreIdentifier store,\r
-            DataCommitHandler provider);\r
-\r
-    /**\r
-     * Adds {@link DataRefresher} for specified data store\r
-     * \r
-     * @param store\r
-     * @param refresher\r
-     */\r
-    void addRefresher(DataStoreIdentifier store, DataRefresher refresher);\r
-\r
-    /**\r
-     * Removes {@link DataRefresher} from specified data store\r
-     * \r
-     * @param store\r
-     * @param refresher\r
-     */\r
-   void removeRefresher(DataStoreIdentifier store, DataRefresher refresher);\r
-\r
-}\r
+/*
+ * 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);
+
+}
@@ -1,26 +1,28 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-/**\r
- * Trigger for refreshing of the data exposed by the {@link Provider}\r
- * \r
- * \r
- * \r
- */\r
-public interface DataRefresher extends\r
-        BindingAwareProvider.ProviderFunctionality {\r
-\r
-    /**\r
-     * Fired when some component explicitly requested the data refresh.\r
-     * \r
-     * The provider which exposed the {@link DataRefresher} should republish its\r
-     * provided data by editing the data in all affected data stores.\r
-     */\r
-    void refreshData();\r
+/*
+ * 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
@@ -1,18 +1,18 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality;\r
-import org.opendaylight.controller.yang.binding.DataRoot;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-\r
-\r
-public interface DataValidator extends ProviderFunctionality {\r
-\r
-    RpcResult<Void> validate(DataRoot data);\r
-}\r
+/*
+ * 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<Void> 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 (file)
index 0000000..b9f5d5a
--- /dev/null
@@ -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<Class<? extends DataRoot>> getProvidedDataRoots();
+}
index 552ac6a450c916bcd3943b34e992ddaf3f832e01..31eec6b5e8a79702f3088292bbd6dcefc1d15cb9 100644 (file)
@@ -1,9 +1,9 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.api;\r
-\r
+/*
+ * 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;
+
index 3073bec988c128f307c82b2d7fdcc87eaa39a87a..70f2e6c3789c3880eb304c40ba84ee4c233bb1c2 100644 (file)
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-    <modelVersion>4.0.0</modelVersion>\r
-    <parent>\r
-        <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
-        <version>1.0-SNAPSHOT</version>\r
-    </parent>\r
-    <artifactId>sal-binding-broker-impl</artifactId>\r
-\r
-\r
-\r
-    <dependencies>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-common-util</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-binding-api</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-binding-spi</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-core-api</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
-\r
-        <dependency>\r
-            <groupId>org.slf4j</groupId>\r
-            <artifactId>slf4j-api</artifactId>\r
-        </dependency>\r
-\r
-        <dependency>\r
-            <groupId>com.google.guava</groupId>\r
-            <artifactId>guava</artifactId>\r
-            <type>jar</type>\r
-        </dependency>\r
-    </dependencies>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.opendaylight.controller</groupId>
+               <artifactId>sal-parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sal-binding-broker-impl</artifactId>
+       <packaging>bundle</packaging>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <version>${maven.bundle.version}</version>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                                               <Bundle-Activator>org.opendaylight.controller.sal.binding.impl.BrokerActivator</Bundle-Activator>
+                                               <Private-Package>
+                                                       org.opendaylight.controller.sal.binding.impl,
+                                                       org.opendaylight.controller.sal.binding.impl.utils,
+                                                       org.eclipse.xtend2.lib,
+                                                       org.eclipse.xtext.xbase.*
+                                               </Private-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+
+                       <plugin>
+                               <groupId>org.eclipse.xtend</groupId>
+                               <artifactId>xtend-maven-plugin</artifactId>
+                               <version>2.4.2</version>
+                               <executions>
+                                       <execution>
+                                               <goals>
+                                                       <goal>compile</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <plugin>
+                               <artifactId>maven-clean-plugin</artifactId>
+                               <version>2.4.1</version>
+                               <configuration>
+                                       <filesets>
+                                               <fileset>
+                                                       <directory>${basedir}/src/main/xtend-gen</directory>
+                                                       <includes>
+                                                               <include>**</include>
+                                                       </includes>
+                                               </fileset>
+                                       </filesets>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-common-util</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <!-- >dependency> <groupId>org.opendaylight.controller</groupId> <artifactId>sal-core-api</artifactId> 
+                       <version>1.0-SNAPSHOT</version> </dependency -->
+
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+                       <version>5.0.0</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <type>jar</type>
+               </dependency>
+               <dependency>
+                       <groupId>org.reflections</groupId>
+                       <artifactId>reflections</artifactId>
+                       <version>0.9.9-RC1</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.javassist</groupId>
+                       <artifactId>javassist</artifactId>
+                       <version>3.17.1-GA</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.eclipse.xtend</groupId>
+                       <artifactId>org.eclipse.xtend.lib</artifactId>
+                       <version>2.4.2</version>
+               </dependency>
+       </dependencies>
 </project>
\ 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 (file)
index 0000000..74ef87a
--- /dev/null
@@ -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<Class<? extends RpcService>, RpcProxyContext> managedProxies = new HashMap();
+    private var NotificationBrokerImpl notifyBroker
+    private var ServiceRegistration<NotificationProviderService> 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 <T extends RpcService> getManagedDirectProxy(Class<T> 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<String, String>()
+        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<? extends RpcService> 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 <T extends RpcService> registerRpcImplementation(Class<T> type, T service, OsgiProviderContext context,
+        Hashtable<String, String> 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<T>(type, service, osgiReg);
+    }
+    
+    def <T extends RpcService> 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 (file)
index 32eff18..0000000
+++ /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<ConsumerSessionImpl> sessions = new HashSet<ConsumerSessionImpl>();
-    private Set<ProviderSessionImpl> providerSessions = new HashSet<ProviderSessionImpl>();
-
-    private Set<SALBindingModule> modules = new HashSet<SALBindingModule>();
-    private Map<Class<? extends BindingAwareService>, SALBindingModule> salServiceProviders = new HashMap<Class<? extends BindingAwareService>, SALBindingModule>();
-    private MappingProvider mapping;
-    private BIFacade biFacade = new BIFacade();
-    private org.opendaylight.controller.sal.core.api.Broker.ProviderSession biSession;
-    private ExecutorService executor;
-
-    Map<Class<? extends RpcService>, RpcService> rpcImpls = Collections
-            .synchronizedMap(new HashMap<Class<? extends RpcService>, RpcService>());
-
-    private RpcProxyInvocationHandler rpcProxyHandler = new RpcProxyInvocationHandler() {
-
-        @Override
-        public Future<RpcResult<? extends DataObject>> 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<Class<? extends BindingAwareService>> provServices = module
-                .getProvidedServices();
-        for (Class<? extends BindingAwareService> 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 extends BindingAwareService> T newSALServiceForSession(
-            Class<T> service, ConsumerSession session) {
-
-        SALBindingModule serviceProvider = salServiceProviders.get(service);
-        if (serviceProvider == null) {
-            return null;
-        }
-        return serviceProvider.getServiceForSession(service, session);
-
-    }
-
-    private <T extends RpcService> T newRpcProxyForSession(Class<T> service) {
-
-        RpcMapper<T> 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<RpcResult<? extends DataObject>> 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<RpcResult<? extends DataObject>> ret = null;
-
-        // Real invocation starts here
-        RpcMapper<? extends RpcService> mapper = mapping
-                .rpcMapperForProxy(rpcProxy);
-        RpcService impl = rpcImpls.get(mapper.getServiceClass());
-
-        if (impl == null) {
-            // RPC is probably remote
-            CompositeNode inputNode = null;
-            Mapper<? extends DataObject> inputMapper = mapper.getInputMapper();
-            if (inputMapper != null) {
-                inputNode = inputMapper.domFromObject(inputData);
-            }
-            Future<RpcResult<CompositeNode>> biResult = biSession.rpc(rpcType,
-                    inputNode);
-            ret = new TranslatedFuture(biResult, mapper);
-
-        } else {
-            // RPC is local
-            Callable<RpcResult<? extends DataObject>> invocation = localRpcCallableFor(
-                    impl, mapper, rpcType, inputData);
-            ret = executor.submit(invocation);
-        }
-        return ret;
-    }
-
-    private Callable<RpcResult<? extends DataObject>> localRpcCallableFor(
-            final RpcService impl,
-            final RpcMapper<? extends RpcService> mapper, final QName rpcType,
-            final DataObject inputData) {
-
-        return new Callable<RpcResult<? extends DataObject>>() {
-
-            @Override
-            public RpcResult<? extends DataObject> call() throws Exception {
-                return mapper.invokeRpcImplementation(rpcType, impl, inputData);
-            }
-        };
-    }
-
-    // Binding Independent invocation of Binding Aware RPC
-    private RpcResult<CompositeNode> invokeLocalRpc(QName rpc,
-            CompositeNode inputNode) {
-        RpcMapper<? extends RpcService> 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<? extends DataObject> 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<Class<? extends BindingAwareService>, BindingAwareService> sessionSalServices = Collections
-                .synchronizedMap(new HashMap<Class<? extends BindingAwareService>, BindingAwareService>());
-
-        private Map<Class<? extends RpcService>, RpcService> sessionRpcProxies = Collections
-                .synchronizedMap(new HashMap<Class<? extends RpcService>, RpcService>());
-
-        public ConsumerSessionImpl(BindingAwareConsumer cons) {
-            this.consumer = cons;
-        }
-
-        @Override
-        public <T extends BindingAwareService> T getSALService(Class<T> 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 extends RpcService> T getRpcService(Class<T> 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<QName> getSupportedRpcs() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        public RpcResult<CompositeNode> 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<ProviderFunctionality> getProviderFunctionality() {
-            return Collections.emptySet();
-        }
-
-    }
-
-    private static class TranslatedFuture implements
-            Future<RpcResult<? extends DataObject>> {
-        private final Future<RpcResult<CompositeNode>> realFuture;
-        private final RpcMapper<?> mapper;
-
-        public TranslatedFuture(Future<RpcResult<CompositeNode>> 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<? extends DataObject> get()
-                throws InterruptedException, ExecutionException {
-            RpcResult<CompositeNode> val = realFuture.get();
-            return tranlate(val);
-        }
-
-        @Override
-        public RpcResult<? extends DataObject> get(long timeout, TimeUnit unit)
-                throws InterruptedException, ExecutionException,
-                TimeoutException {
-            RpcResult<CompositeNode> val = realFuture.get(timeout, unit);
-            return tranlate(val);
-        }
-
-        private RpcResult<? extends DataObject> tranlate(
-                RpcResult<CompositeNode> 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 (file)
index 0000000..c5d54ec
--- /dev/null
@@ -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<BindingAwareBroker> 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<String, String> 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 (file)
index 0000000..668635a
--- /dev/null
@@ -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 (file)
index cbd6b00..0000000
+++ /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<Class<? extends BindingAwareService>> getProvidedServices() {
-        Set<Class<? extends BindingAwareService>> ret = new HashSet<Class<? extends BindingAwareService>>();
-        ret.add(DataBrokerService.class);
-        ret.add(DataProviderService.class);
-        return ret;
-    }
-
-    @Override
-    public <T extends BindingAwareService> T getServiceForSession(
-            Class<T> service, ConsumerSession session) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    private class DataBrokerSession implements DataBrokerService {
-
-        @Override
-        public <T extends DataRoot> T getData(DataStoreIdentifier store,
-                Class<T> rootType) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public <T extends DataRoot> T getData(DataStoreIdentifier store,
-                T filter) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public <T extends DataRoot> T getCandidateData(
-                DataStoreIdentifier store, Class<T> rootType) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public <T extends DataRoot> T getCandidateData(
-                DataStoreIdentifier store, T filter) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public RpcResult<DataRoot> editCandidateData(DataStoreIdentifier store,
-                DataRoot changeSet) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public Future<RpcResult<Void>> 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<Void> validate(CompositeNode toValidate) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public Set<DataStoreIdentifier> getSupportedDataStores() {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        @Override
-        public RpcResult<CommitTransaction> 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 (file)
index 0000000..da1ba79
--- /dev/null
@@ -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<Class<? extends Notification>, NotificationListener<?>> listeners;
+    val ExecutorService executor;
+
+    new(ExecutorService executor) {
+        listeners = HashMultimap.create()
+        this.executor = executor;
+    }
+
+    override <T extends Notification> addNotificationListener(Class<T> notificationType,
+        NotificationListener<T> listener) {
+        listeners.put(notificationType, listener)
+    }
+
+    override <T extends Notification> removeNotificationListener(Class<T> notificationType,
+        NotificationListener<T> listener) {
+        listeners.remove(notificationType, listener)
+    }
+
+    override notify(Notification notification) {
+        notification.notificationTypes.forEach [
+            listeners.get(it as Class<? extends Notification>)?.notifyAll(notification)
+        ]
+    }
+
+    def getNotificationTypes(Notification notification) {
+        notification.class.interfaces.filter[it != Notification && Notification.isAssignableFrom(it)]
+    }
+
+    def notifyAll(Collection<NotificationListener<?>> 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 (file)
index 640089a..0000000
+++ /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 (file)
index 89c4464..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.impl;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareService;\r
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;\r
-import org.opendaylight.controller.sal.binding.api.NotificationService;\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession;\r
-import org.opendaylight.controller.sal.binding.spi.SALBindingModule;\r
-import org.opendaylight.controller.sal.binding.spi.Mapper;\r
-import org.opendaylight.controller.sal.binding.spi.MappingProvider;\r
-import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtensionFactory;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-import org.opendaylight.controller.yang.binding.DataObject;\r
-import org.opendaylight.controller.yang.binding.Notification;\r
-import org.opendaylight.controller.yang.binding.NotificationListener;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.collect.HashMultimap;\r
-import com.google.common.collect.Multimap;\r
-\r
-public class NotificationModule implements SALBindingModule {\r
-\r
-    private ProviderSession biSession;\r
-    private org.opendaylight.controller.sal.core.api.notify.NotificationProviderService biNotifyService;\r
-    private MappingProvider mappingProvider;\r
-\r
-    private Multimap<Class<? extends Notification>, NotificationListener> listeners = HashMultimap\r
-            .create();\r
-    private Set<QName> biNotifications = new HashSet<QName>();\r
-    private static final Logger log = LoggerFactory\r
-            .getLogger(NotificationModule.class);\r
-    private final BindingIndependentListener biListener = new BindingIndependentListener();\r
-    private BindingAwareBroker broker;\r
-\r
-    @Override\r
-    public Set<Class<? extends BindingAwareService>> getProvidedServices() {\r
-\r
-        Set<Class<? extends BindingAwareService>> ret = new HashSet<Class<? extends BindingAwareService>>();\r
-        ret.add(NotificationService.class);\r
-        ret.add(NotificationProviderService.class);\r
-        return ret;\r
-    }\r
-\r
-    @Override\r
-    public <T extends BindingAwareService> T getServiceForSession(\r
-            Class<T> service, ConsumerSession session) {\r
-        if (service == null)\r
-            throw new IllegalArgumentException("Service should not be null");\r
-        if (session == null)\r
-            throw new IllegalArgumentException("Session should not be null");\r
-\r
-        if (NotificationProviderSession.class.equals(service)) {\r
-            if (session instanceof org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession) {\r
-                @SuppressWarnings("unchecked")\r
-                T ret = (T) new NotificationProviderSession(session);\r
-                return ret;\r
-            } else {\r
-                throw new IllegalArgumentException(\r
-                        "NotificationProviderService is available only to ProviderSession");\r
-            }\r
-        }\r
-\r
-        if (NotificationService.class.equals(service)) {\r
-            @SuppressWarnings("unchecked")\r
-            T ret = (T) new NotificationSession(session);\r
-            return ret;\r
-        }\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public Set<Class<? extends org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality>> getSupportedProviderFunctionality() {\r
-        return Collections.emptySet();\r
-    }\r
-\r
-    @Override\r
-    public void setBroker(BindingAwareBroker broker) {\r
-        this.broker = broker;\r
-    }\r
-\r
-    @Override\r
-    public void setMappingProvider(MappingProvider provider) {\r
-        this.mappingProvider = provider;\r
-    }\r
-\r
-    @Override\r
-    public void onBISessionAvailable(ProviderSession session) {\r
-        biSession = session;\r
-        if (biSession != null) {\r
-            biNotifyService = session\r
-                    .getService(org.opendaylight.controller.sal.core.api.notify.NotificationProviderService.class);\r
-        }\r
-    }\r
-\r
-    private void notify(Notification notification) {\r
-        notifyBindingIndependent(notification);\r
-        notifyBindingAware(notification);\r
-    }\r
-\r
-    private void notifyBindingAware(Notification notification) {\r
-        Class<? extends Notification> type = notification.getClass();\r
-        Collection<NotificationListener> toNotify = listeners.get(type);\r
-\r
-        // Invocation of notification on registered listeners\r
-        if (toNotify != null) {\r
-\r
-            // We get factory for Notification Invoker\r
-            MappingExtensionFactory<NotificationInvoker> invokerFactory = mappingProvider\r
-                    .getExtensionFactory(NotificationInvoker.class);\r
-\r
-            // We get generated invoker for NoficiationListener interface\r
-            // associated to Notification Type\r
-            NotificationInvoker invoker = invokerFactory.forClass(type);\r
-            for (NotificationListener listener : toNotify) {\r
-                try {\r
-                    // Invoker invokes the right method on subtype of\r
-                    // NotificationListener\r
-                    // associated to the type of notification\r
-                    invoker.notify(notification, listener);\r
-                } catch (Exception e) {\r
-\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
-    private void notifyBindingIndependent(Notification notification) {\r
-        Class<? extends Notification> type = notification.getClass();\r
-\r
-        if (biSession == null) {\r
-            return;\r
-        }\r
-        if (biSession.isClosed()) {\r
-            return;\r
-        }\r
-        if (biNotifyService == null) {\r
-            return;\r
-        }\r
-\r
-        // FIXME: Somehow we need to resolve this for class hierarchy.\r
-        // probably use type.getInterfaces()\r
-        Mapper<? extends Notification> mapper = mappingProvider\r
-                .mapperForClass(type);\r
-        CompositeNode domNotification = mapper.domFromObject(notification);\r
-\r
-        biNotifyService.sendNotification(domNotification);\r
-    }\r
-\r
-    private void addBAListener(Class<? extends Notification> notificationType,\r
-            NotificationListener listener) {\r
-\r
-        listeners.put(notificationType, listener);\r
-        Mapper<? extends Notification> mapper = mappingProvider\r
-                .mapperForClass(notificationType);\r
-        QName biType = mapper.getQName();\r
-        if (false == biNotifications.contains(biType)) {\r
-            // The listener is not registered for binding independent\r
-            // notification\r
-            biNotifications.add(biType);\r
-\r
-            if (biNotifyService != null) {\r
-                biNotifyService.addNotificationListener(biType, biListener);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    private void removeBAListener(\r
-            Class<? extends Notification> notificationType,\r
-            NotificationListener listener) {\r
-        listeners.remove(notificationType, listener);\r
-    }\r
-\r
-    private class NotificationSession implements NotificationService {\r
-        private final ConsumerSession session;\r
-        private Multimap<Class<? extends Notification>, NotificationListener> sessionListeners = HashMultimap\r
-                .create();\r
-\r
-        public NotificationSession(ConsumerSession session) {\r
-            this.session = session;\r
-        }\r
-\r
-        @Override\r
-        public void addNotificationListener(\r
-                Class<? extends Notification> notificationType,\r
-                NotificationListener listener) {\r
-\r
-            NotificationModule.this.addBAListener(notificationType, listener);\r
-            sessionListeners.put(notificationType, listener);\r
-\r
-        }\r
-\r
-        @Override\r
-        public void removeNotificationListener(\r
-                Class<? extends Notification> notificationType,\r
-                NotificationListener listener) {\r
-            sessionListeners.remove(notificationType, listener);\r
-            NotificationModule.this\r
-                    .removeBAListener(notificationType, listener);\r
-        }\r
-\r
-    }\r
-\r
-    private class NotificationProviderSession extends NotificationSession\r
-            implements NotificationProviderService {\r
-\r
-        public NotificationProviderSession(ConsumerSession session) {\r
-            super(session);\r
-        }\r
-\r
-        @Override\r
-        public void notify(Notification notification) {\r
-            NotificationModule.this.notify(notification);\r
-        }\r
-\r
-    }\r
-\r
-    private class BindingIndependentListener\r
-            implements\r
-            org.opendaylight.controller.sal.core.api.notify.NotificationListener {\r
-\r
-        @Override\r
-        public Set<QName> getSupportedNotifications() {\r
-            return biNotifications;\r
-        }\r
-\r
-        @Override\r
-        public void onNotification(CompositeNode notification) {\r
-            NotificationModule.this\r
-                    .onBindingIndependentNotification(notification);\r
-        }\r
-\r
-    }\r
-\r
-    private void onBindingIndependentNotification(CompositeNode biNotification) {\r
-        QName biType = biNotification.getNodeType();\r
-\r
-        Mapper<DataObject> mapper = mappingProvider.mapperForQName(biType);\r
-        if (mapper == null) {\r
-            log.info("Received notification does not have a binding defined.");\r
-            return;\r
-        }\r
-        Class<DataObject> type = mapper.getDataObjectClass();\r
-\r
-        // We check if the received QName / type is really Notification\r
-        if (Notification.class.isAssignableFrom(type)) {\r
-            Notification notification = (Notification) mapper\r
-                    .objectFromDom(biNotification);\r
-            notifyBindingAware(notification);\r
-        } else {\r
-            // The generated type for this QName does not inherits from\r
-            // notification something went wrong - generated APIs and/or\r
-            // provider sending notification\r
-            // which was incorectly described in the YANG schema.\r
-            log.error("Received notification " + biType\r
-                    + " is not binded as notification");\r
-        }\r
-\r
-    }\r
-}\r
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 (file)
index 0000000..fb35ee3
--- /dev/null
@@ -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<Class<? extends Notification>, NotificationListener<?>> listeners;
+
+    new() {
+        listeners = HashMultimap.create()
+    }
+
+    override <T extends Notification> addNotificationListener(Class<T> notificationType,
+        NotificationListener<T> listener) {
+        listeners.put(notificationType, listener)
+    }
+
+    override <T extends Notification> removeNotificationListener(Class<T> notificationType,
+        NotificationListener<T> 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 (file)
index 0000000..a87fa06
--- /dev/null
@@ -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 <T extends BindingAwareService> getSALService(Class<T> service) {
+               // SAL Services are global
+               var ref =  bundleContext.getServiceReference(service);
+               return bundleContext.getService(ref) as T;
+       }
+       
+       
+
+       override def <T extends RpcService> T getRpcService(Class<T> 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<T>;
+                               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 (file)
index 0000000..195fa8b
--- /dev/null
@@ -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<Class<? extends RpcService>, RpcServiceRegistrationImpl<? extends RpcService>> registeredServices
+
+    new(BundleContext ctx, BindingAwareBrokerImpl broker) {
+        super(ctx, broker);
+        _registeredServices = new HashMap();
+    }
+
+    override def <T extends RpcService> RpcServiceRegistration<T> addRpcImplementation(Class<T> type, T implementation) {
+
+        // TODO Auto-generated method stub
+        val properties = new Hashtable<String, String>();
+        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 (file)
index 0000000..0749459
--- /dev/null
@@ -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<? extends RpcService> proxyClass) {
+               this.proxyClass = proxyClass
+       }
+       
+       protected val Class<? extends RpcService> proxyClass;
+       
+       @Property
+       protected var RpcService proxy;
+       
+       @Property
+       protected var ServiceRegistration<? extends RpcService> 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 (file)
index 0000000..afb27b4
--- /dev/null
@@ -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<T extends RpcService> implements RpcServiceRegistration<T> {
+
+    val ServiceRegistration<T> osgiRegistration;
+    private val T service;
+    val Class<T> cls;
+
+    public new(Class<T> type, T service, ServiceRegistration<T> 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 (file)
index 0000000..e94c375
--- /dev/null
@@ -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 (file)
index 0000000..7ba62f5
--- /dev/null
@@ -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<String,String> properties, String value) {
+               properties.put(Constants.SAL_SERVICE_TYPE,value)
+               return properties
+       }
+       
+       static def getSalServiceType(Hashtable<String,String> properties) {
+               return properties.get(Constants.SAL_SERVICE_TYPE)
+       }
+       
+       static def newProperties() {
+               new Hashtable<String,String>()
+       }
+       
+}
\ 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 (file)
index 0000000..5110238
--- /dev/null
@@ -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
index fd7fad6f14f411c8195b8e5c292c350859b04c55..8d0ddad9fef8bbb154217ef8bde1c5d969ee1017 100644 (file)
@@ -3,7 +3,7 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.opendaylight.controller</groupId>
-        <artifactId>sal</artifactId>
+        <artifactId>sal-parent</artifactId>
         <version>1.0-SNAPSHOT</version>
     </parent>
     <artifactId>sal-binding-spi</artifactId>
index db35de1ab75901d95e8e6a8dc8ef454c8f0a5045..bdcb2c21716d32aff9ca0131ff4ca30e0f83b450 100644 (file)
@@ -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<P extends DataObject> extends Transformer<CompositeNode, P> {
 
index 3c4d48601253de8011523e20dd772ba65c27d338..21154b4078faaddc7158d123526666768c49a2ed 100644 (file)
@@ -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<I extends DataObject> extends
         InputClassBasedTransformer<DataObject, I, CompositeNode> {
index 701e72c9dc64e2a5e806531efe4343da3c7980d2..44ca27e89fbceb496dac60e32d186990ba738864 100644 (file)
@@ -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
  * 
index b29eac2871c2a1534ead86f552a4acf5a3ddabf9..b3eded9939b98380584ce97581fb5f60f15d2451 100644 (file)
@@ -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 {
 
index 0db1bc277571ca7dde8da1bbb2c27d1d525fdf0e..3e32ebc4792004fe609f045ed5823a7b5bbcdf87 100644 (file)
@@ -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<T extends RpcService> {
     
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 (file)
index f3ecf80..0000000
+++ /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<Class<? extends BindingAwareService>> getProvidedServices();
-
-    <T extends BindingAwareService> T getServiceForSession(Class<T> service,
-            ConsumerSession session);
-
-    Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality();
-}
index 779a6dc6ab9fffe8092a7ef9af49becce3e1b948..0bb4041b9f336190f2d2c7b4640b485ee0d4df52 100644 (file)
@@ -3,7 +3,7 @@
     <modelVersion>4.0.0</modelVersion>\r
     <parent>\r
         <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
+        <artifactId>sal-parent</artifactId>\r
         <version>1.0-SNAPSHOT</version>\r
     </parent>\r
     <artifactId>sal-broker-impl</artifactId>\r
@@ -32,5 +32,5 @@
             <artifactId>guava</artifactId>\r
             <type>jar</type>\r
         </dependency>\r
-    </dependencies>
+    </dependencies>\r
 </project>
\ No newline at end of file
index b8a0b97eab9abb81b851eeda349ec6156709442a..f0d1cc609d22a54230bed5c2136ae2f32ba701e7 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.impl;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.concurrent.Callable;\r
-import java.util.concurrent.ExecutorService;\r
-import java.util.concurrent.Future;\r
-import org.opendaylight.controller.sal.core.api.Broker;\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.sal.core.api.Consumer;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.sal.core.api.RpcImplementation;\r
-import org.opendaylight.controller.sal.core.spi.BrokerModule;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class BrokerImpl implements Broker {\r
-    private static Logger log = LoggerFactory.getLogger(BrokerImpl.class);\r
-\r
-    // Broker Generic Context\r
-    private Set<ConsumerSessionImpl> sessions = Collections\r
-            .synchronizedSet(new HashSet<ConsumerSessionImpl>());\r
-    private Set<ProviderSessionImpl> providerSessions = Collections\r
-            .synchronizedSet(new HashSet<ProviderSessionImpl>());\r
-    private Set<BrokerModule> modules = Collections\r
-            .synchronizedSet(new HashSet<BrokerModule>());\r
-    private Map<Class<? extends BrokerService>, BrokerModule> serviceProviders = Collections\r
-            .synchronizedMap(new HashMap<Class<? extends BrokerService>, BrokerModule>());\r
-\r
-    // RPC Context\r
-    private Map<QName, RpcImplementation> rpcImpls = Collections\r
-            .synchronizedMap(new HashMap<QName, RpcImplementation>());\r
-\r
-    // Implementation specific\r
-    private ExecutorService executor;\r
-\r
-    @Override\r
-    public ConsumerSession registerConsumer(Consumer consumer) {\r
-        checkPredicates(consumer);\r
-        log.info("Registering consumer " + consumer);\r
-        ConsumerSessionImpl session = newSessionFor(consumer);\r
-        consumer.onSessionInitiated(session);\r
-        sessions.add(session);\r
-        return session;\r
-    }\r
-\r
-    @Override\r
-    public ProviderSession registerProvider(Provider provider) {\r
-        checkPredicates(provider);\r
-\r
-        ProviderSessionImpl session = newSessionFor(provider);\r
-        provider.onSessionInitiated(session);\r
-        providerSessions.add(session);\r
-        return session;\r
-    }\r
-\r
-    public void addModule(BrokerModule module) {\r
-        log.info("Registering broker module " + module);\r
-        if (modules.contains(module)) {\r
-            log.error("Module already registered");\r
-            throw new IllegalArgumentException("Module already exists.");\r
-        }\r
-    \r
-        Set<Class<? extends BrokerService>> provServices = module\r
-                .getProvidedServices();\r
-        for (Class<? extends BrokerService> serviceType : provServices) {\r
-            log.info("  Registering session service implementation: "\r
-                    + serviceType.getCanonicalName());\r
-            serviceProviders.put(serviceType, module);\r
-        }\r
-    }\r
-\r
-    public <T extends BrokerService> T serviceFor(Class<T> service,\r
-            ConsumerSessionImpl session) {\r
-        BrokerModule prov = serviceProviders.get(service);\r
-        if (prov == null) {\r
-            log.warn("Service " + service.toString() + " is not supported");\r
-            return null;\r
-        }\r
-        return prov.getServiceForSession(service, session);\r
-    }\r
-\r
-    // RPC Functionality\r
-    \r
-    private void addRpcImplementation(QName rpcType,\r
-            RpcImplementation implementation) {\r
-        synchronized (rpcImpls) {\r
-            if (rpcImpls.get(rpcType) != null) {\r
-                throw new IllegalStateException("Implementation for rpc "\r
-                        + rpcType + " is already registered.");\r
-            }\r
-            rpcImpls.put(rpcType, implementation);\r
-        }\r
-        // TODO Add notification for availability of Rpc Implementation\r
-    }\r
-\r
-    private void removeRpcImplementation(QName rpcType,\r
-            RpcImplementation implToRemove) {\r
-        synchronized (rpcImpls) {\r
-            if (implToRemove == rpcImpls.get(rpcType)) {\r
-                rpcImpls.remove(rpcType);\r
-            }\r
-        }\r
-        // TODO Add notification for removal of Rpc Implementation\r
-    }\r
-\r
-    private Future<RpcResult<CompositeNode>> invokeRpc(QName rpc,\r
-            CompositeNode input) {\r
-        RpcImplementation impl = rpcImpls.get(rpc);\r
-        // if()\r
-\r
-        Callable<RpcResult<CompositeNode>> call = callableFor(impl,\r
-                rpc, input);\r
-        Future<RpcResult<CompositeNode>> result = executor.submit(call);\r
-\r
-        return result;\r
-    }\r
-    \r
-    // Validation\r
-\r
-    private void checkPredicates(Provider prov) {\r
-        if (prov == null)\r
-            throw new IllegalArgumentException("Provider should not be null.");\r
-        for (ProviderSessionImpl session : providerSessions) {\r
-            if (prov.equals(session.getProvider()))\r
-                throw new IllegalStateException("Provider already registered");\r
-        }\r
-\r
-    }\r
-\r
-    private void checkPredicates(Consumer cons) {\r
-        if (cons == null)\r
-            throw new IllegalArgumentException("Consumer should not be null.");\r
-        for (ConsumerSessionImpl session : sessions) {\r
-            if (cons.equals(session.getConsumer()))\r
-                throw new IllegalStateException("Consumer already registered");\r
-        }\r
-    }\r
-\r
-    // Private Factory methods\r
-    \r
-    private ConsumerSessionImpl newSessionFor(Consumer cons) {\r
-        return new ConsumerSessionImpl(cons);\r
-    }\r
-\r
-    private ProviderSessionImpl newSessionFor(Provider provider) {\r
-        return new ProviderSessionImpl(provider);\r
-    }\r
-\r
-    private void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) {\r
-        sessions.remove(consumerSessionImpl);\r
-        providerSessions.remove(consumerSessionImpl);\r
-    }\r
-\r
-    private static Callable<RpcResult<CompositeNode>> callableFor(\r
-            final RpcImplementation implemenation, final QName rpc,\r
-            final CompositeNode input) {\r
-\r
-        return new Callable<RpcResult<CompositeNode>>() {\r
-\r
-            @Override\r
-            public RpcResult<CompositeNode> call() throws Exception {\r
-                return implemenation.invokeRpc(rpc, input);\r
-            }\r
-        };\r
-    }\r
-    \r
-    private class ConsumerSessionImpl implements ConsumerSession {\r
-\r
-        private final Consumer consumer;\r
-\r
-        private Map<Class<? extends BrokerService>, BrokerService> instantiatedServices = Collections\r
-                .synchronizedMap(new HashMap<Class<? extends BrokerService>, BrokerService>());\r
-        private boolean closed = false;\r
-\r
-        public Consumer getConsumer() {\r
-            return consumer;\r
-        }\r
-\r
-        public ConsumerSessionImpl(Consumer consumer) {\r
-            this.consumer = consumer;\r
-        }\r
-\r
-        @Override\r
-        public Future<RpcResult<CompositeNode>> rpc(QName rpc,\r
-                CompositeNode input) {\r
-            return BrokerImpl.this.invokeRpc(rpc, input);\r
-        }\r
-\r
-        @Override\r
-        public <T extends BrokerService> T getService(Class<T> service) {\r
-            BrokerService potential = instantiatedServices.get(service);\r
-            if (potential != null) {\r
-                @SuppressWarnings("unchecked")\r
-                T ret = (T) potential;\r
-                return ret;\r
-            }\r
-            T ret = BrokerImpl.this.serviceFor(service, this);\r
-            if (ret != null) {\r
-                instantiatedServices.put(service, ret);\r
-            }\r
-            return ret;\r
-        }\r
-\r
-        @Override\r
-        public void close() {\r
-            Collection<BrokerService> toStop = instantiatedServices.values();\r
-            this.closed = true;\r
-            for (BrokerService brokerService : toStop) {\r
-                brokerService.closeSession();\r
-            }\r
-            BrokerImpl.this.consumerSessionClosed(this);\r
-        }\r
-\r
-        @Override\r
-        public boolean isClosed() {\r
-            return closed;\r
-        }\r
-\r
-    }\r
-\r
-    private class ProviderSessionImpl extends ConsumerSessionImpl implements\r
-            ProviderSession {\r
-\r
-        private Provider provider;\r
-        private Map<QName, RpcImplementation> sessionRpcImpls = Collections.synchronizedMap(new HashMap<QName, RpcImplementation>());\r
-\r
-        public ProviderSessionImpl(Provider provider) {\r
-            super(null);\r
-            this.provider = provider;\r
-        }\r
-\r
-        @Override\r
-        public void addRpcImplementation(QName rpcType,\r
-                RpcImplementation implementation)\r
-                throws IllegalArgumentException {\r
-            if (rpcType == null) {\r
-                throw new IllegalArgumentException("rpcType must not be null");\r
-            }\r
-            if (implementation == null) {\r
-                throw new IllegalArgumentException(\r
-                        "Implementation must not be null");\r
-            }\r
-            BrokerImpl.this.addRpcImplementation(rpcType, implementation);\r
-            sessionRpcImpls.put(rpcType, implementation);\r
-        }\r
-\r
-        @Override\r
-        public void removeRpcImplementation(QName rpcType,\r
-                RpcImplementation implToRemove) throws IllegalArgumentException {\r
-            RpcImplementation localImpl = rpcImpls.get(rpcType);\r
-            if (localImpl != implToRemove) {\r
-                throw new IllegalStateException(\r
-                        "Implementation was not registered in this session");\r
-            }\r
-\r
-            BrokerImpl.this.removeRpcImplementation(rpcType, implToRemove);\r
-            sessionRpcImpls.remove(rpcType);\r
-        }\r
-\r
-        public Provider getProvider() {\r
-            return this.provider;\r
-        }\r
-\r
-    }\r
-}\r
+/*
+ * 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<ConsumerSessionImpl> sessions = Collections
+            .synchronizedSet(new HashSet<ConsumerSessionImpl>());
+    private Set<ProviderSessionImpl> providerSessions = Collections
+            .synchronizedSet(new HashSet<ProviderSessionImpl>());
+    private Set<BrokerModule> modules = Collections
+            .synchronizedSet(new HashSet<BrokerModule>());
+    private Map<Class<? extends BrokerService>, BrokerModule> serviceProviders = Collections
+            .synchronizedMap(new HashMap<Class<? extends BrokerService>, BrokerModule>());
+
+    // RPC Context
+    private Map<QName, RpcImplementation> rpcImpls = Collections
+            .synchronizedMap(new HashMap<QName, RpcImplementation>());
+
+    // 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<Class<? extends BrokerService>> provServices = module
+                .getProvidedServices();
+        for (Class<? extends BrokerService> serviceType : provServices) {
+            log.info("  Registering session service implementation: "
+                    + serviceType.getCanonicalName());
+            serviceProviders.put(serviceType, module);
+        }
+    }
+
+    public <T extends BrokerService> T serviceFor(Class<T> 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<RpcResult<CompositeNode>> invokeRpc(QName rpc,
+            CompositeNode input) {
+        RpcImplementation impl = rpcImpls.get(rpc);
+        // if()
+
+        Callable<RpcResult<CompositeNode>> call = callableFor(impl,
+                rpc, input);
+        Future<RpcResult<CompositeNode>> 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<RpcResult<CompositeNode>> callableFor(
+            final RpcImplementation implemenation, final QName rpc,
+            final CompositeNode input) {
+
+        return new Callable<RpcResult<CompositeNode>>() {
+
+            @Override
+            public RpcResult<CompositeNode> call() throws Exception {
+                return implemenation.invokeRpc(rpc, input);
+            }
+        };
+    }
+    
+    private class ConsumerSessionImpl implements ConsumerSession {
+
+        private final Consumer consumer;
+
+        private Map<Class<? extends BrokerService>, BrokerService> instantiatedServices = Collections
+                .synchronizedMap(new HashMap<Class<? extends BrokerService>, BrokerService>());
+        private boolean closed = false;
+
+        public Consumer getConsumer() {
+            return consumer;
+        }
+
+        public ConsumerSessionImpl(Consumer consumer) {
+            this.consumer = consumer;
+        }
+
+        @Override
+        public Future<RpcResult<CompositeNode>> rpc(QName rpc,
+                CompositeNode input) {
+            return BrokerImpl.this.invokeRpc(rpc, input);
+        }
+
+        @Override
+        public <T extends BrokerService> T getService(Class<T> 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<BrokerService> 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<QName, RpcImplementation> sessionRpcImpls = Collections.synchronizedMap(new HashMap<QName, RpcImplementation>());
+
+        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;
+        }
+
+    }
+}
index 852f6b6e879bb3d26799a9ae12f2265d774aa7f8..34eba18fcecaa6add7f6bcfe93d844928faec879 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.concurrent.ExecutorService;\r
-import java.util.concurrent.Future;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.sal.common.util.Rpcs;\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality;\r
-import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality;\r
-import org.opendaylight.controller.sal.core.api.data.DataBrokerService;\r
-import org.opendaylight.controller.sal.core.api.data.DataCommitHandler;\r
-import org.opendaylight.controller.sal.core.api.data.DataProviderService;\r
-import org.opendaylight.controller.sal.core.api.data.DataValidator;\r
-import org.opendaylight.controller.sal.core.api.data.DataCommitHandler.CommitTransaction;\r
-import org.opendaylight.controller.sal.core.api.data.DataProviderService.DataRefresher;\r
-import org.opendaylight.controller.sal.core.spi.BrokerModule;\r
-import org.opendaylight.controller.yang.common.RpcError;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-import org.opendaylight.controller.yang.data.api.CompositeNodeModification;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-\r
-public class DataBrokerModule implements BrokerModule {\r
-\r
-    private static final Logger log = LoggerFactory\r
-            .getLogger(DataBrokerModule.class);\r
-\r
-    private static final Set<Class<? extends ProviderFunctionality>> SUPPORTED_PROVIDER_FUNCTIONALITY = ImmutableSet\r
-            .of((Class<? extends ProviderFunctionality>) DataValidator.class,\r
-                    DataRefresher.class, DataCommitHandler.class);\r
-\r
-    private static final Set<Class<? extends BrokerService>> PROVIDED_SESSION_SERVICES = ImmutableSet\r
-            .of((Class<? extends BrokerService>) DataBrokerService.class,\r
-                    DataProviderService.class);\r
-\r
-    private Map<DataStoreIdentifier, StoreContext> storeContext;\r
-\r
-    private ExecutorService executor;\r
-    \r
-    private SequentialCommitHandlerCoordinator coordinator = new SequentialCommitHandlerCoordinator();\r
-\r
-    @Override\r
-    public Set<Class<? extends BrokerService>> getProvidedServices() {\r
-        return PROVIDED_SESSION_SERVICES;\r
-    }\r
-\r
-    @Override\r
-    public Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {\r
-        return SUPPORTED_PROVIDER_FUNCTIONALITY;\r
-    }\r
-\r
-    @Override\r
-    public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {\r
-        return Collections.emptySet();\r
-    }\r
-\r
-    @Override\r
-    public <T extends BrokerService> T getServiceForSession(Class<T> service,\r
-            ConsumerSession session) {\r
-        if (DataProviderService.class.equals(service)\r
-                && session instanceof ProviderSession) {\r
-            @SuppressWarnings("unchecked")\r
-            T ret = (T) newDataProviderService(session);\r
-            return ret;\r
-        } else if (DataBrokerService.class.equals(service)) {\r
-\r
-            @SuppressWarnings("unchecked")\r
-            T ret = (T) newDataConsumerService(session);\r
-            return ret;\r
-        }\r
-\r
-        throw new IllegalArgumentException(\r
-                "The requested session-specific service is not provided by this module.");\r
-    }\r
-\r
-    private DataProviderService newDataProviderService(ConsumerSession session) {\r
-        return new DataProviderSession();\r
-    }\r
-\r
-    private DataBrokerService newDataConsumerService(ConsumerSession session) {\r
-        return new DataConsumerSession();\r
-    }\r
-\r
-    private StoreContext context(DataStoreIdentifier store) {\r
-        return storeContext.get(store);\r
-    }\r
-\r
-    private static class StoreContext {\r
-        private Set<DataCommitHandler> commitHandlers = Collections\r
-                .synchronizedSet(new HashSet<DataCommitHandler>());\r
-        private Set<DataValidator> validators = Collections\r
-                .synchronizedSet(new HashSet<DataValidator>());\r
-        private Set<DataRefresher> refreshers = Collections\r
-                .synchronizedSet(new HashSet<DataRefresher>());\r
-    }\r
-\r
-    private class DataConsumerSession implements DataBrokerService {\r
-\r
-        @Override\r
-        public CompositeNode getData(DataStoreIdentifier store) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public CompositeNode getData(DataStoreIdentifier store,\r
-                CompositeNode filter) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public CompositeNode getCandidateData(DataStoreIdentifier store) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public CompositeNode getCandidateData(DataStoreIdentifier store,\r
-                CompositeNode filter) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public RpcResult<CompositeNode> editCandidateData(\r
-                DataStoreIdentifier store, CompositeNodeModification changeSet) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public Future<RpcResult<Void>> commit(DataStoreIdentifier store) {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public void closeSession() {\r
-            // TODO Implement this method\r
-            throw new UnsupportedOperationException("Not implemented");\r
-        }\r
-\r
-        @Override\r
-        public Set<DataStoreIdentifier> getDataStores() {\r
-            // TODO Auto-generated method stub\r
-            return null;\r
-        }\r
-\r
-    }\r
-\r
-    private class DataProviderSession extends DataConsumerSession implements\r
-            DataProviderService {\r
-\r
-        private Set<DataCommitHandler> providerCommitHandlers = new HashSet<DataCommitHandler>();\r
-        private Set<DataValidator> providerValidators = new HashSet<DataValidator>();\r
-        private Set<DataRefresher> providerRefreshers = new HashSet<DataRefresher>();\r
-\r
-        @Override\r
-        public void addValidator(DataStoreIdentifier store,\r
-                DataValidator validator) {\r
-            if (validator == null)\r
-                throw new IllegalArgumentException(\r
-                        "Validator should not be null");\r
-\r
-            providerValidators.add(validator);\r
-            context(store).validators.add(validator);\r
-        }\r
-\r
-        @Override\r
-        public void removeValidator(DataStoreIdentifier store,\r
-                DataValidator validator) {\r
-            if (validator == null)\r
-                throw new IllegalArgumentException(\r
-                        "Validator should not be null");\r
-\r
-            providerValidators.remove(validator);\r
-            context(store).validators.remove(validator);\r
-        }\r
-\r
-        @Override\r
-        public void addCommitHandler(DataStoreIdentifier store,\r
-                DataCommitHandler provider) {\r
-            if (provider == null)\r
-                throw new IllegalArgumentException(\r
-                        "CommitHandler should not be null");\r
-\r
-            providerCommitHandlers.add(provider);\r
-            context(store).commitHandlers.add(provider);\r
-        }\r
-\r
-        @Override\r
-        public void removeCommitHandler(DataStoreIdentifier store,\r
-                DataCommitHandler provider) {\r
-            if (provider == null)\r
-                throw new IllegalArgumentException(\r
-                        "CommitHandler should not be null");\r
-\r
-            providerCommitHandlers.remove(provider);\r
-            context(store).commitHandlers.remove(provider);\r
-        }\r
-\r
-        @Override\r
-        public void addRefresher(DataStoreIdentifier store,\r
-                DataRefresher provider) {\r
-            if (provider == null)\r
-                throw new IllegalArgumentException(\r
-                        "Refresher should not be null");\r
-\r
-            providerRefreshers.add(provider);\r
-            context(store).refreshers.add(provider);\r
-        }\r
-\r
-        @Override\r
-        public void removeRefresher(DataStoreIdentifier store,\r
-                DataRefresher provider) {\r
-            if (provider == null)\r
-                throw new IllegalArgumentException(\r
-                        "Refresher should not be null");\r
-\r
-            providerRefreshers.remove(provider);\r
-            context(store).refreshers.remove(provider);\r
-        }\r
-\r
-    }\r
-\r
-    private class SequentialCommitHandlerCoordinator implements\r
-            DataCommitHandler {\r
-\r
-        @Override\r
-        public RpcResult<CommitTransaction> requestCommit(\r
-                DataStoreIdentifier store) {\r
-            List<RpcError> errors = new ArrayList<RpcError>();\r
-            Set<CommitTransaction> transactions = new HashSet<DataCommitHandler.CommitTransaction>();\r
-            boolean successful = true;\r
-\r
-            for (DataCommitHandler commitHandler : context(store).commitHandlers) {\r
-                try {\r
-                    RpcResult<CommitTransaction> partialResult = commitHandler\r
-                            .requestCommit(store);\r
-                    successful = partialResult.isSuccessful() & successful;\r
-                    if (partialResult.isSuccessful()) {\r
-                        transactions.add(partialResult.getResult());\r
-                    }\r
-\r
-                    errors.addAll(partialResult.getErrors());\r
-                } catch (Exception e) {\r
-                    log.error("Uncaught exception prevented commit request."\r
-                            + e.getMessage(), e);\r
-                    successful = false;\r
-                    // FIXME: Add RPC Error with exception.\r
-                }\r
-                if (successful == false)\r
-                    break;\r
-            }\r
-            CommitTransaction transaction = new SequentialCommitTransaction(\r
-                    store, transactions);\r
-            return Rpcs.getRpcResult(successful, transaction, errors);\r
-        }\r
-\r
-        @Override\r
-        public Set<DataStoreIdentifier> getSupportedDataStores() {\r
-            return Collections.emptySet();\r
-        }\r
-    }\r
-\r
-    private class SequentialCommitTransaction implements CommitTransaction {\r
-\r
-        final Set<CommitTransaction> transactions;\r
-        final DataStoreIdentifier store;\r
-\r
-        public SequentialCommitTransaction(DataStoreIdentifier s,\r
-                Set<CommitTransaction> t) {\r
-            transactions = t;\r
-            store = s;\r
-        }\r
-\r
-        @Override\r
-        public RpcResult<Void> finish() {\r
-            List<RpcError> errors = new ArrayList<RpcError>();\r
-            boolean successful = true;\r
-\r
-            for (CommitTransaction commitHandler : transactions) {\r
-                try {\r
-                    RpcResult<Void> partialResult = commitHandler.finish();\r
-                    successful = partialResult.isSuccessful() & successful;\r
-                    errors.addAll(partialResult.getErrors());\r
-                } catch (Exception e) {\r
-                    log.error(\r
-                            "Uncaught exception prevented finishing of commit."\r
-                                    + e.getMessage(), e);\r
-                    successful = false;\r
-                    // FIXME: Add RPC Error with exception.\r
-                }\r
-                if (successful == false)\r
-                    break;\r
-            }\r
-\r
-            return Rpcs.getRpcResult(successful, null, errors);\r
-        }\r
-\r
-        @Override\r
-        public RpcResult<Void> rollback() {\r
-            List<RpcError> errors = new ArrayList<RpcError>();\r
-            boolean successful = true;\r
-\r
-            for (CommitTransaction commitHandler : transactions) {\r
-                try {\r
-                    RpcResult<Void> partialResult = commitHandler.rollback();\r
-                    successful = partialResult.isSuccessful() & successful;\r
-                    errors.addAll(partialResult.getErrors());\r
-                } catch (Exception e) {\r
-                    log.error(\r
-                            "Uncaught exception prevented rollback of commit."\r
-                                    + e.getMessage(), e);\r
-                    successful = false;\r
-                    // FIXME: Add RPC Error with exception.\r
-                }\r
-                if (successful == false)\r
-                    break;\r
-            }\r
-\r
-            return Rpcs.getRpcResult(successful, null, errors);\r
-        }\r
-\r
-        @Override\r
-        public DataStoreIdentifier getDataStore() {\r
-            return this.store;\r
-        }\r
-\r
-        @Override\r
-        public DataCommitHandler getHandler() {\r
-            return coordinator;\r
-        }\r
-    }\r
-\r
-    private class ValidationCoordinator implements DataValidator {\r
-\r
-        private final DataStoreIdentifier store;\r
-\r
-        ValidationCoordinator(DataStoreIdentifier store) {\r
-            this.store = store;\r
-        }\r
-\r
-        @Override\r
-        public RpcResult<Void> validate(CompositeNode toValidate) {\r
-            List<RpcError> errors = new ArrayList<RpcError>();\r
-            boolean successful = true;\r
-\r
-            for (DataValidator validator : context(store).validators) {\r
-                try {\r
-                    RpcResult<Void> partialResult = validator\r
-                            .validate(toValidate);\r
-                    successful = partialResult.isSuccessful() & successful;\r
-                    errors.addAll(partialResult.getErrors());\r
-                } catch (Exception e) {\r
-                    log.error(\r
-                            "Uncaught exception prevented validation."\r
-                                    + e.getMessage(), e);\r
-                    successful = false;\r
-                    // FIXME: Add RPC Error with exception.\r
-                }\r
-                if (successful == false)\r
-                    break;\r
-            }\r
-\r
-            return Rpcs.getRpcResult(successful, null, errors);\r
-        }\r
-\r
-        @Override\r
-        public Set<DataStoreIdentifier> getSupportedDataStores() {\r
-            return Collections.emptySet();\r
-        }\r
-\r
-    }\r
-\r
-    private class DataRefreshCoordinator implements DataRefresher {\r
-\r
-        private final DataStoreIdentifier store;\r
-\r
-        DataRefreshCoordinator(DataStoreIdentifier store) {\r
-            this.store = store;\r
-        }\r
-\r
-        @Override\r
-        public void refreshData() {\r
-\r
-            for (DataRefresher refresher : context(store).refreshers) {\r
-                try {\r
-                    refresher.refreshData();\r
-                } catch (Exception e) {\r
-                    log.error(\r
-                            "Uncaught exception during refresh of data: "\r
-                                    + e.getMessage(), e);\r
-                }\r
-\r
-            }\r
-        }\r
-    }\r
-}\r
+/*
+ * 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<Class<? extends ProviderFunctionality>> SUPPORTED_PROVIDER_FUNCTIONALITY = ImmutableSet
+            .of((Class<? extends ProviderFunctionality>) DataValidator.class,
+                    DataRefresher.class, DataCommitHandler.class);
+
+    private static final Set<Class<? extends BrokerService>> PROVIDED_SESSION_SERVICES = ImmutableSet
+            .of((Class<? extends BrokerService>) DataBrokerService.class,
+                    DataProviderService.class);
+
+    private Map<DataStoreIdentifier, StoreContext> storeContext;
+
+    private ExecutorService executor;
+    
+    private SequentialCommitHandlerCoordinator coordinator = new SequentialCommitHandlerCoordinator();
+
+    @Override
+    public Set<Class<? extends BrokerService>> getProvidedServices() {
+        return PROVIDED_SESSION_SERVICES;
+    }
+
+    @Override
+    public Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {
+        return SUPPORTED_PROVIDER_FUNCTIONALITY;
+    }
+
+    @Override
+    public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public <T extends BrokerService> T getServiceForSession(Class<T> 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<DataCommitHandler> commitHandlers = Collections
+                .synchronizedSet(new HashSet<DataCommitHandler>());
+        private Set<DataValidator> validators = Collections
+                .synchronizedSet(new HashSet<DataValidator>());
+        private Set<DataRefresher> refreshers = Collections
+                .synchronizedSet(new HashSet<DataRefresher>());
+    }
+
+    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<CompositeNode> editCandidateData(
+                DataStoreIdentifier store, MutableCompositeNode changeSet) {
+            // TODO Implement this method
+            throw new UnsupportedOperationException("Not implemented");
+        }
+
+        @Override
+        public Future<RpcResult<Void>> 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<DataStoreIdentifier> getDataStores() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+    }
+
+    private class DataProviderSession extends DataConsumerSession implements
+            DataProviderService {
+
+        private Set<DataCommitHandler> providerCommitHandlers = new HashSet<DataCommitHandler>();
+        private Set<DataValidator> providerValidators = new HashSet<DataValidator>();
+        private Set<DataRefresher> providerRefreshers = new HashSet<DataRefresher>();
+
+        @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<CommitTransaction> requestCommit(
+                DataStoreIdentifier store) {
+            List<RpcError> errors = new ArrayList<RpcError>();
+            Set<CommitTransaction> transactions = new HashSet<DataCommitHandler.CommitTransaction>();
+            boolean successful = true;
+
+            for (DataCommitHandler commitHandler : context(store).commitHandlers) {
+                try {
+                    RpcResult<CommitTransaction> 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<DataStoreIdentifier> getSupportedDataStores() {
+            return Collections.emptySet();
+        }
+    }
+
+    private class SequentialCommitTransaction implements CommitTransaction {
+
+        final Set<CommitTransaction> transactions;
+        final DataStoreIdentifier store;
+
+        public SequentialCommitTransaction(DataStoreIdentifier s,
+                Set<CommitTransaction> t) {
+            transactions = t;
+            store = s;
+        }
+
+        @Override
+        public RpcResult<Void> finish() {
+            List<RpcError> errors = new ArrayList<RpcError>();
+            boolean successful = true;
+
+            for (CommitTransaction commitHandler : transactions) {
+                try {
+                    RpcResult<Void> 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<Void> rollback() {
+            List<RpcError> errors = new ArrayList<RpcError>();
+            boolean successful = true;
+
+            for (CommitTransaction commitHandler : transactions) {
+                try {
+                    RpcResult<Void> 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<Void> validate(CompositeNode toValidate) {
+            List<RpcError> errors = new ArrayList<RpcError>();
+            boolean successful = true;
+
+            for (DataValidator validator : context(store).validators) {
+                try {
+                    RpcResult<Void> 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<DataStoreIdentifier> 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);
+                }
+
+            }
+        }
+    }
+}
index bd70ee14a58dfc0c85340243897b508feb4a2ab1..2bbbde632b73a34364cded77aed1e4a5644c85e7 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.impl;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality;\r
-import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality;\r
-import org.opendaylight.controller.sal.core.api.notify.NotificationListener;\r
-import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;\r
-import org.opendaylight.controller.sal.core.api.notify.NotificationService;\r
-import org.opendaylight.controller.sal.core.spi.BrokerModule;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.collect.HashMultimap;\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.collect.Multimap;\r
-\r
-public class NotificationModule implements BrokerModule {\r
-    private static Logger log = LoggerFactory\r
-            .getLogger(NotificationModule.class);\r
-\r
-    private Multimap<QName, NotificationListener> listeners = HashMultimap\r
-            .create();\r
-\r
-    private static final Set<Class<? extends BrokerService>> PROVIDED_SERVICE_TYPE = ImmutableSet\r
-            .of((Class<? extends BrokerService>) NotificationService.class,\r
-                    NotificationProviderService.class);\r
-\r
-    private static final Set<Class<? extends ConsumerFunctionality>> SUPPORTED_CONSUMER_FUNCTIONALITY = ImmutableSet\r
-            .of((Class<? extends ConsumerFunctionality>) NotificationListener.class,\r
-                    NotificationListener.class); // Workaround: if we use the\r
-                                                 // version of method with only\r
-                                                 // one argument, the generics\r
-                                                 // inference will not work\r
-\r
-    @Override\r
-    public Set<Class<? extends BrokerService>> getProvidedServices() {\r
-        return PROVIDED_SERVICE_TYPE;\r
-    }\r
-\r
-    @Override\r
-    public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {\r
-        return SUPPORTED_CONSUMER_FUNCTIONALITY;\r
-    }\r
-\r
-    @Override\r
-    public <T extends BrokerService> T getServiceForSession(Class<T> service,\r
-            ConsumerSession session) {\r
-        if (NotificationProviderService.class.equals(service)\r
-                && session instanceof ProviderSession) {\r
-            @SuppressWarnings("unchecked")\r
-            T ret = (T) newNotificationProviderService(session);\r
-            return ret;\r
-        } else if (NotificationService.class.equals(service)) {\r
-\r
-            @SuppressWarnings("unchecked")\r
-            T ret = (T) newNotificationConsumerService(session);\r
-            return ret;\r
-        }\r
-\r
-        throw new IllegalArgumentException(\r
-                "The requested session-specific service is not provided by this module.");\r
-    }\r
-\r
-    private void sendNotification(CompositeNode notification) {\r
-        QName type = notification.getNodeType();\r
-        Collection<NotificationListener> toNotify = listeners.get(type);\r
-        log.info("Publishing notification " + type);\r
-\r
-        if (toNotify == null) {\r
-            // No listeners were registered - returns.\r
-            return;\r
-        }\r
-\r
-        for (NotificationListener listener : toNotify) {\r
-            try {\r
-                // FIXME: ensure that notification is immutable\r
-                listener.onNotification(notification);\r
-            } catch (Exception e) {\r
-                log.error("Uncaught exception in NotificationListener", e);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    private NotificationService newNotificationConsumerService(\r
-            ConsumerSession session) {\r
-        return new NotificationConsumerSessionImpl();\r
-    }\r
-\r
-    private NotificationProviderService newNotificationProviderService(\r
-            ConsumerSession session) {\r
-        return new NotificationProviderSessionImpl();\r
-    }\r
-\r
-    private class NotificationConsumerSessionImpl implements\r
-            NotificationService {\r
-\r
-        private Multimap<QName, NotificationListener> consumerListeners = HashMultimap\r
-                .create();\r
-        private boolean closed = false;\r
-\r
-        @Override\r
-        public void addNotificationListener(QName notification,\r
-                NotificationListener listener) {\r
-            checkSessionState();\r
-            if (notification == null) {\r
-                throw new IllegalArgumentException(\r
-                        "Notification type must not be null.");\r
-            }\r
-            if (listener == null) {\r
-                throw new IllegalArgumentException("Listener must not be null.");\r
-            }\r
-\r
-            consumerListeners.put(notification, listener);\r
-            listeners.put(notification, listener);\r
-            log.info("Registered listener for notification: " + notification);\r
-        }\r
-\r
-        @Override\r
-        public void removeNotificationListener(QName notification,\r
-                NotificationListener listener) {\r
-            checkSessionState();\r
-            if (notification == null) {\r
-                throw new IllegalArgumentException(\r
-                        "Notification type must not be null.");\r
-            }\r
-            if (listener == null) {\r
-                throw new IllegalArgumentException("Listener must not be null.");\r
-            }\r
-            consumerListeners.remove(notification, listener);\r
-            listeners.remove(notification, listener);\r
-        }\r
-\r
-        @Override\r
-        public void closeSession() {\r
-            closed = true;\r
-            Map<QName, Collection<NotificationListener>> toRemove = consumerListeners\r
-                    .asMap();\r
-            for (Entry<QName, Collection<NotificationListener>> entry : toRemove\r
-                    .entrySet()) {\r
-                listeners.remove(entry.getKey(), entry.getValue());\r
-            }\r
-        }\r
-\r
-        protected void checkSessionState() {\r
-            if (closed)\r
-                throw new IllegalStateException("Session is closed");\r
-        }\r
-    }\r
-\r
-    private class NotificationProviderSessionImpl extends\r
-            NotificationConsumerSessionImpl implements\r
-            NotificationProviderService {\r
-\r
-        @Override\r
-        public void sendNotification(CompositeNode notification) {\r
-            checkSessionState();\r
-            if (notification == null)\r
-                throw new IllegalArgumentException(\r
-                        "Notification must not be null.");\r
-            NotificationModule.this.sendNotification(notification);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {\r
-        return Collections.emptySet();\r
-    }\r
-}\r
+/*
+ * 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<QName, NotificationListener> listeners = HashMultimap
+            .create();
+
+    private static final Set<Class<? extends BrokerService>> PROVIDED_SERVICE_TYPE = ImmutableSet
+            .of((Class<? extends BrokerService>) NotificationService.class,
+                    NotificationProviderService.class);
+
+    private static final Set<Class<? extends ConsumerFunctionality>> SUPPORTED_CONSUMER_FUNCTIONALITY = ImmutableSet
+            .of((Class<? extends ConsumerFunctionality>) 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<Class<? extends BrokerService>> getProvidedServices() {
+        return PROVIDED_SERVICE_TYPE;
+    }
+
+    @Override
+    public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {
+        return SUPPORTED_CONSUMER_FUNCTIONALITY;
+    }
+
+    @Override
+    public <T extends BrokerService> T getServiceForSession(Class<T> 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<NotificationListener> 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<QName, NotificationListener> 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<QName, Collection<NotificationListener>> toRemove = consumerListeners
+                    .asMap();
+            for (Entry<QName, Collection<NotificationListener>> 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<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {
+        return Collections.emptySet();
+    }
+}
index fedd6d12f05af7d95e1569313b304a4c990c5773..f1bed65fd108c9360dfe7ce7b8e6b1675ae6d65d 100644 (file)
@@ -1,23 +1,24 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-    <modelVersion>4.0.0</modelVersion>\r
-    <parent>\r
-        <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
-        <version>1.0-SNAPSHOT</version>\r
-    </parent>\r
-    <artifactId>sal-common-util</artifactId>\r
-\r
-    <dependencies>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>yang-common</artifactId>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>org.opendaylight.controller</groupId>\r
-            <artifactId>sal-common</artifactId>\r
-            <version>1.0-SNAPSHOT</version>\r
-        </dependency>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-parent</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>sal-common-util</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-common</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
+    <packaging>bundle</packaging>
 </project>
\ 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 (file)
index 0000000..c942159
--- /dev/null
@@ -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 <T> Future<T> immediateFuture(T result) {
+               return new ImmediateFuture<T>(result);
+       }
+       
+       private static class ImmediateFuture<T> implements Future<T> {
+
+               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;
+               }
+               
+       }
+}
index d397bff0d64533a0944134c3c799da3fb30ca294..e46b566522e26232081cd1fd72a96d873bdebae5 100644 (file)
@@ -1,53 +1,53 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.common.util;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import org.opendaylight.controller.yang.common.RpcError;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-\r
-public class Rpcs {\r
-    public static <T> RpcResult<T> getRpcResult(boolean successful, T result,\r
-            Collection<RpcError> errors) {\r
-        RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);\r
-        return ret;\r
-    }\r
-\r
-    private static class RpcResultTO<T> implements RpcResult<T> {\r
-\r
-        private final Collection<RpcError> errors;\r
-        private final T result;\r
-        private final boolean successful;\r
-\r
-        public RpcResultTO(boolean successful, T result,\r
-                Collection<RpcError> errors) {\r
-            this.successful = successful;\r
-            this.result = result;\r
-            this.errors = Collections.unmodifiableList(new ArrayList<RpcError>(\r
-                    errors));\r
-        }\r
-\r
-        @Override\r
-        public boolean isSuccessful() {\r
-            return successful;\r
-        }\r
-\r
-        @Override\r
-        public T getResult() {\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public Collection<RpcError> getErrors() {\r
-            return errors;\r
-        }\r
-\r
-    }\r
-}\r
+/*
+ * 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 <T> RpcResult<T> getRpcResult(boolean successful, T result,
+            Collection<RpcError> errors) {
+        RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
+        return ret;
+    }
+
+    private static class RpcResultTO<T> implements RpcResult<T> {
+
+        private final Collection<RpcError> errors;
+        private final T result;
+        private final boolean successful;
+
+        public RpcResultTO(boolean successful, T result,
+                Collection<RpcError> errors) {
+            this.successful = successful;
+            this.result = result;
+            this.errors = Collections.unmodifiableList(new ArrayList<RpcError>(
+                    errors));
+        }
+
+        @Override
+        public boolean isSuccessful() {
+            return successful;
+        }
+
+        @Override
+        public T getResult() {
+            return result;
+        }
+
+        @Override
+        public Collection<RpcError> getErrors() {
+            return errors;
+        }
+
+    }
+}
index 89cf5207edda8be9125f8af4bebf501c228a8864..a4b2c7d51b083a32020247e19aa9d0afe761482f 100644 (file)
@@ -1,14 +1,15 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-    <modelVersion>4.0.0</modelVersion>\r
-    <parent>\r
-        <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
-        <version>1.0-SNAPSHOT</version>\r
-    </parent>\r
-    <artifactId>sal-common</artifactId>\r
-\r
-    <dependencies>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-parent</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>sal-common</artifactId>
+
+    <dependencies>
     </dependencies>
 
+    <packaging>bundle</packaging>
 </project>
\ No newline at end of file
index e82392d24aef70827f20838cd5e798758f63bcd7..e3ded1a6795b706df56980a5db452a0d76944428 100644 (file)
@@ -3,7 +3,7 @@
     <modelVersion>4.0.0</modelVersion>\r
     <parent>\r
         <groupId>org.opendaylight.controller</groupId>\r
-        <artifactId>sal</artifactId>\r
+        <artifactId>sal-parent</artifactId>\r
         <version>1.0-SNAPSHOT</version>\r
     </parent>\r
     <artifactId>sal-core-api</artifactId>\r
@@ -23,5 +23,5 @@
             <groupId>org.opendaylight.controller</groupId>\r
             <artifactId>yang-model-api</artifactId>\r
         </dependency>\r
-    </dependencies>
+    </dependencies>\r
 </project>
\ No newline at end of file
index 9b3b47f8b17e8f312cb77b0688973b0d702e129a..f26ed901a569f9c585b9b18be456acbb055de257 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
-\r
-import java.util.concurrent.Future;\r
-\r
-import org.opendaylight.controller.sal.core.api.data.DataBrokerService;\r
-import org.opendaylight.controller.sal.core.api.data.DataProviderService;\r
-import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;\r
-import org.opendaylight.controller.sal.core.api.notify.NotificationService;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-\r
-\r
-/**\r
- * Core component of the SAL layer responsible for wiring the SAL consumers.\r
- * \r
- * The responsibility of the broker is to maintain registration of SAL\r
- * functionality {@link Consumer}s and {@link Provider}s, store provider and\r
- * consumer specific context and functionality registration via\r
- * {@link ConsumerSession} and provide access to infrastructure services, which\r
- * removes direct dependencies between providers and consumers.\r
- * \r
- * \r
- * <h3>Infrastructure services</h3> Some examples of infrastructure services:\r
- * \r
- * <ul>\r
- * <li>RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)},\r
- * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and\r
- * {@link RpcImplementation}\r
- * <li>Notification Service - see {@link NotificationService} and\r
- * {@link NotificationProviderService}\r
- * <li>Functionality and Data model\r
- * <li>Data Store access and modification - see {@link DataBrokerService} and\r
- * {@link DataProviderService}\r
- * </ul>\r
- * \r
- * The services are exposed via session.\r
- * \r
- * <h3>Session-based access</h3>\r
- * \r
- * The providers and consumers needs to register in order to use the\r
- * binding-independent SAL layer and to expose functionality via SAL layer.\r
- * \r
- * For more information about session-based access see {@link ConsumerSession}\r
- * and {@link ProviderSession}\r
- * \r
- * \r
- * \r
- */\r
-public interface Broker {\r
-\r
-    /**\r
-     * Registers the {@link Consumer}, which will use the SAL layer.\r
-     * \r
-     * <p>\r
-     * During the registration, the broker obtains the initial functionality\r
-     * from consumer, using the {@link Consumer#getConsumerFunctionality()}, and\r
-     * register that functionality into system and concrete infrastructure\r
-     * services.\r
-     * \r
-     * <p>\r
-     * Note that consumer could register additional functionality at later point\r
-     * by using service and functionality specific APIs.\r
-     * \r
-     * <p>\r
-     * The consumer is required to use returned session for all communication\r
-     * with broker or one of the broker services. The session is announced to\r
-     * the consumer by invoking\r
-     * {@link Consumer#onSessionInitiated(ConsumerSession)}.\r
-     * \r
-     * @param cons\r
-     *            Consumer to be registered.\r
-     * @return a session specific to consumer registration\r
-     * @throws IllegalArgumentException\r
-     *             If the consumer is <code>null</code>.\r
-     * @throws IllegalStateException\r
-     *             If the consumer is already registered.\r
-     */\r
-    ConsumerSession registerConsumer(Consumer cons);\r
-\r
-    /**\r
-     * Registers the {@link Provider}, which will use the SAL layer.\r
-     * \r
-     * <p>\r
-     * During the registration, the broker obtains the initial functionality\r
-     * from consumer, using the {@link Provider#getProviderFunctionality()}, and\r
-     * register that functionality into system and concrete infrastructure\r
-     * services.\r
-     * \r
-     * <p>\r
-     * Note that consumer could register additional functionality at later point\r
-     * by using service and functionality specific APIs (e.g.\r
-     * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}\r
-     * \r
-     * <p>\r
-     * The consumer is <b>required to use</b> returned session for all\r
-     * communication with broker or one of the broker services. The session is\r
-     * announced to the consumer by invoking\r
-     * {@link Provider#onSessionInitiated(ProviderSession)}.\r
-     * \r
-     * \r
-     * @param prov\r
-     *            Provider to be registered.\r
-     * @return a session unique to the provider registration.\r
-     * @throws IllegalArgumentException\r
-     *             If the provider is <code>null</code>.\r
-     * @throws IllegalStateException\r
-     *             If the consumer is already registered.\r
-     */\r
-    ProviderSession registerProvider(Provider prov);\r
-\r
-    /**\r
-     * {@link Consumer} specific access to the SAL functionality.\r
-     * \r
-     * <p>\r
-     * ConsumerSession is {@link Consumer}-specific access to the SAL\r
-     * functionality and infrastructure services.\r
-     * \r
-     * <p>\r
-     * The session serves to store SAL context (e.g. registration of\r
-     * functionality) for the consumer and provides access to the SAL\r
-     * infrastructure services and other functionality provided by\r
-     * {@link Provider}s.\r
-     * \r
-\r
-     * \r
-     */\r
-    public interface ConsumerSession {\r
-\r
-        /**\r
-         * Sends an RPC to other components registered to the broker.\r
-         * \r
-         * @see RpcImplementation\r
-         * @param rpc\r
-         *            Name of RPC\r
-         * @param input\r
-         *            Input data to the RPC\r
-         * @return Result of the RPC call\r
-         */\r
-        Future<RpcResult<CompositeNode>> rpc(QName rpc, CompositeNode input);\r
-\r
-        boolean isClosed();\r
-\r
-        /**\r
-         * Returns a session specific instance (implementation) of requested\r
-         * service\r
-         * \r
-         * @param service\r
-         *            Broker service\r
-         * @return Session specific implementation of service\r
-         */\r
-        <T extends BrokerService> T getService(Class<T> service);\r
-\r
-        /**\r
-         * Closes a session between consumer and broker.\r
-         * \r
-         * <p>\r
-         * The close operation unregisters a consumer and remove all registered\r
-         * functionality of the consumer from the system.\r
-         * \r
-         */\r
-        void close();\r
-    }\r
-\r
-    /**\r
-     * {@link Provider} specific access to the SAL functionality.\r
-     * \r
-     * <p>\r
-     * ProviderSession is {@link Provider}-specific access to the SAL\r
-     * functionality and infrastructure services, which also allows for exposing\r
-     * the provider's functionality to the other {@link Consumer}s.\r
-     * \r
-     * <p>\r
-     * The session serves to store SAL context (e.g. registration of\r
-     * functionality) for the providers and exposes access to the SAL\r
-     * infrastructure services, dynamic functionality registration and any other\r
-     * functionality provided by other {@link Provider}s.\r
-     * \r
-     */\r
-    public interface ProviderSession extends ConsumerSession {\r
-        /**\r
-         * Registers an implementation of the rpc.\r
-         * \r
-         * <p>\r
-         * The registered rpc functionality will be available to all other\r
-         * consumers and providers registered to the broker, which are aware of\r
-         * the {@link QName} assigned to the rpc.\r
-         * \r
-         * <p>\r
-         * There is no assumption that rpc type is in the set returned by\r
-         * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows\r
-         * for dynamic rpc implementations.\r
-         * \r
-         * @param rpcType\r
-         *            Name of Rpc\r
-         * @param implementation\r
-         *            Provider's Implementation of the RPC functionality\r
-         * @throws IllegalArgumentException\r
-         *             If the name of RPC is invalid\r
-         */\r
-        void addRpcImplementation(QName rpcType,\r
-                RpcImplementation implementation)\r
-                throws IllegalArgumentException;\r
-\r
-        /**\r
-         * Unregisters an Rpc implementation\r
-         * \r
-         * @param rpcType\r
-         *            Name of Rpc\r
-         * @param implementation\r
-         *            Registered Implementation of the Rpc functionality\r
-         * @throws IllegalArgumentException\r
-         */\r
-        void removeRpcImplementation(QName rpcType,\r
-                RpcImplementation implementation)\r
-                throws IllegalArgumentException;\r
-\r
-        /**\r
-         * Closes a session between provider and SAL.\r
-         * \r
-         * <p>\r
-         * The close operation unregisters a provider and remove all registered\r
-         * functionality of the provider from the system.\r
-         */\r
-        @Override\r
-        public void close();\r
-\r
-        @Override\r
-        boolean isClosed();\r
-    }\r
-}\r
+/*
+ * 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.
+ * 
+ * 
+ * <h3>Infrastructure services</h3> Some examples of infrastructure services:
+ * 
+ * <ul>
+ * <li>RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)},
+ * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and
+ * {@link RpcImplementation}
+ * <li>Notification Service - see {@link NotificationService} and
+ * {@link NotificationProviderService}
+ * <li>Functionality and Data model
+ * <li>Data Store access and modification - see {@link DataBrokerService} and
+ * {@link DataProviderService}
+ * </ul>
+ * 
+ * The services are exposed via session.
+ * 
+ * <h3>Session-based access</h3>
+ * 
+ * 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.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * Note that consumer could register additional functionality at later point
+     * by using service and functionality specific APIs.
+     * 
+     * <p>
+     * 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 <code>null</code>.
+     * @throws IllegalStateException
+     *             If the consumer is already registered.
+     */
+    ConsumerSession registerConsumer(Consumer cons);
+
+    /**
+     * Registers the {@link Provider}, which will use the SAL layer.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * Note that consumer could register additional functionality at later point
+     * by using service and functionality specific APIs (e.g.
+     * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
+     * 
+     * <p>
+     * The consumer is <b>required to use</b> 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 <code>null</code>.
+     * @throws IllegalStateException
+     *             If the consumer is already registered.
+     */
+    ProviderSession registerProvider(Provider prov);
+
+    /**
+     * {@link Consumer} specific access to the SAL functionality.
+     * 
+     * <p>
+     * ConsumerSession is {@link Consumer}-specific access to the SAL
+     * functionality and infrastructure services.
+     * 
+     * <p>
+     * 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<RpcResult<CompositeNode>> 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 extends BrokerService> T getService(Class<T> service);
+
+        /**
+         * Closes a session between consumer and broker.
+         * 
+         * <p>
+         * 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.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * 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.
+         * 
+         * <p>
+         * 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.
+         * 
+         * <p>
+         * 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.
+         * 
+         * <p>
+         * The close operation unregisters a provider and remove all registered
+         * functionality of the provider from the system.
+         */
+        @Override
+        public void close();
+
+        @Override
+        boolean isClosed();
+    }
+}
index b854188f616248809f1f422ef85285006b0261d4..b4253680528f1b4d029dff2ad88eae8230946d66 100644 (file)
@@ -1,39 +1,39 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;\r
-\r
-/**\r
- * \r
- * Session-specific instance of the broker functionality.\r
- * \r
- * <p>\r
- * BrokerService is marker interface for infrastructure services provided by the\r
- * SAL. These services are session-specific, each {@link Provider} and\r
- * {@link Consumer} usually has own instance of the service with it's own\r
- * context.\r
- * \r
- * <p>\r
- * The consumer's (or provider's) instance of specific service could be obtained\r
- * by invoking {@link ConsumerSession#getService(Class)} method on session\r
- * assigned to the consumer.\r
- * \r
- * <p>\r
- * {@link BrokerService} and {@link Provider} may seem similar, but provider\r
- * provides YANG model-based functionality and {@link BrokerService} exposes the\r
- * necessary supporting functionality to implement specific functionality of\r
- * YANG and to reuse it in the development of {@link Consumer}s and\r
- * {@link Provider}s.\r
- * \r
- * \r
- */\r
-public interface BrokerService {\r
-\r
-    void closeSession();\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * {@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();
+}
index 1b223f9e667656926e924cc6f0c21a43ecfa6d2a..0006953542bb698cff7bd06fe4c85133012da047 100644 (file)
@@ -1,59 +1,59 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
-\r
-import java.util.Collection;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;\r
-\r
-/**\r
- * \r
- * Defines the component of controller and supplies additional metadata. A\r
- * component of the controller or application supplies a concrete implementation\r
- * of this interface.\r
- * \r
- * A user-implemented component (application) which faciliates the SAL and SAL\r
- * services to access infrastructure services or providers' functionality.\r
- * \r
- * \r
- */\r
-public interface Consumer {\r
-\r
-    /**\r
-     * Callback signaling initialization of the consumer session to the SAL.\r
-     * \r
-     * The consumer MUST use the session for all communication with SAL or\r
-     * retrieving SAL infrastructure services.\r
-     * \r
-     * This method is invoked by {@link Broker#registerConsumer(Consumer)}\r
-     * \r
-     * @param session\r
-     *            Unique session between consumer and SAL.\r
-     */\r
-    public void onSessionInitiated(ConsumerSession session);\r
-\r
-    /**\r
-     * Get a set of implementations of consumer functionality to be registered\r
-     * into system during the consumer registration to the SAL.\r
-     * \r
-     * This method is invoked by {@link Broker#registerConsumer(Consumer)}.\r
-     * \r
-     * @return Set of consumer functionality.\r
-     */\r
-    public Collection<ConsumerFunctionality> getConsumerFunctionality();\r
-\r
-    /**\r
-     * The marker interface for the interfaces describing the consumer\r
-     * functionality contracts.\r
-     * \r
-     * \r
-     */\r
-    public interface ConsumerFunctionality {\r
-\r
-    }\r
-}\r
+/*
+ * 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<ConsumerFunctionality> getConsumerFunctionality();
+
+    /**
+     * The marker interface for the interfaces describing the consumer
+     * functionality contracts.
+     * 
+     * 
+     */
+    public interface ConsumerFunctionality {
+
+    }
+}
index dff636fd4b14a01ffcdc6bb01df2de5b9be7aa52..e2df70baeac05a3a1fc113de6205a0ccc504206c 100644 (file)
@@ -1,69 +1,69 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
-\r
-import java.util.Collection;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-\r
-/**\r
- * \r
- * Defines the component of controller and supplies additional metadata. A\r
- * component of the controller or application supplies a concrete implementation\r
- * of this interface.\r
- * \r
- * <p>\r
- * A user-implemented component (application) which faciliates the SAL and SAL\r
- * services to access infrastructure services and to provide functionality to\r
- * {@link Consumer}s and other providers.\r
- * \r
- * \r
- */\r
-public interface Provider {\r
-\r
-    /**\r
-     * Callback signaling initialization of the provider session to the SAL.\r
-     * \r
-     * <p>\r
-     * The provider <b>MUST use the session</b> for all communication with SAL\r
-     * or retrieving SAL infrastructure services.\r
-     * \r
-     * <p>\r
-     * This method is invoked by {@link Broker#registerConsumer(Consumer)}\r
-     * \r
-     * @param session\r
-     *            Unique session between provider and SAL.\r
-     */\r
-    public void onSessionInitiated(ProviderSession session);\r
-\r
-    /**\r
-     * Gets a set of implementations of provider functionality to be registered\r
-     * into system during the provider registration to the SAL.\r
-     * \r
-     * <p>\r
-     * This method is invoked by {@link Broker#registerProvider(Provider)} to\r
-     * learn the initial provided functionality\r
-     * \r
-     * @return Set of provider's functionality.\r
-     */\r
-    public Collection<ProviderFunctionality> getProviderFunctionality();\r
-\r
-    /**\r
-     * Functionality provided by the {@link Provider}\r
-     * \r
-     * <p>\r
-     * Marker interface used to mark the interfaces describing specific\r
-     * functionality which could be exposed by providers to other components.\r
-     * \r
-\r
-     * \r
-     */\r
-    public interface ProviderFunctionality {\r
-\r
-    }\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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.
+     * 
+     * <p>
+     * The provider <b>MUST use the session</b> for all communication with SAL
+     * or retrieving SAL infrastructure services.
+     * 
+     * <p>
+     * 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.
+     * 
+     * <p>
+     * This method is invoked by {@link Broker#registerProvider(Provider)} to
+     * learn the initial provided functionality
+     * 
+     * @return Set of provider's functionality.
+     */
+    public Collection<ProviderFunctionality> getProviderFunctionality();
+
+    /**
+     * Functionality provided by the {@link Provider}
+     * 
+     * <p>
+     * Marker interface used to mark the interfaces describing specific
+     * functionality which could be exposed by providers to other components.
+     * 
+
+     * 
+     */
+    public interface ProviderFunctionality {
+
+    }
+}
index ef5aa703b9b33e21889af7e225d1e0288299da19..0299505cdeee6bcef00315507012cbd030f384c1 100644 (file)
@@ -1,81 +1,81 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
-\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-\r
-/**\r
- * {@link Provider}'s implementation of rpc.\r
- * \r
- * In order to expose the rpc to other components, the provider MUST register\r
- * concrete implementation of this interface\r
- * \r
- * The registration could be done by :\r
- * <ul>\r
- * <li>returning an instance of implementation in the return value of\r
- * {@link Provider#getProviderFunctionality()}\r
- * <li>passing an instance of implementation and {@link QName} of rpc as\r
- * arguments to the\r
- * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}\r
- * </ul>\r
- * \r
- * The simplified process of the invocation of rpc is following:\r
- * \r
- * <ol>\r
- * <li> {@link Consumer} invokes\r
- * {@link ConsumerSession#rpc(QName, CompositeNode)}\r
- * <li> {@link Broker} finds registered {@link RpcImplementation}s\r
- * <li> {@link Broker} invokes\r
- * {@link RpcImplementation#invokeRpc(QName, CompositeNode)}\r
- * <li> {@link RpcImplementation} processes the data and returns a\r
- * {@link RpcResult}\r
- * <li> {@link Broker} returns the {@link RpcResult} to {@link Consumer}\r
- * </ol>\r
- * \r
- * \r
- */\r
-public interface RpcImplementation extends Provider.ProviderFunctionality {\r
-\r
-    /**\r
-     * A set of rpc types supported by implementation.\r
-     * \r
-     * The set of rpc {@link QName}s which are supported by this implementation.\r
-     * This set is used, when {@link Provider} is registered to the SAL, to\r
-     * register and expose the implementation of the returned rpcs.\r
-     * \r
-     * @return Set of QNames identifying supported RPCs\r
-     */\r
-    Set<QName> getSupportedRpcs();\r
-\r
-    /**\r
-     * Invokes a implementation of specified rpc.\r
-     * \r
-     * \r
-     * @param rpc\r
-     *            Rpc to be invoked\r
-     * @param input\r
-     *            Input data for rpc.\r
-     * \r
-     * @throws IllegalArgumentException\r
-     *             <ul>\r
-     *             <li>If rpc is null.\r
-     *             <li>If input is not <code>null</code> and\r
-     *             <code>false == rpc.equals(input.getNodeType)</code>\r
-     *             </ul>\r
-     * @return RpcResult containing the output of rpc if was executed\r
-     *         successfully, the list of errors otherwise.\r
-     */\r
-    RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input);\r
-\r
-}\r
+/*
+ * 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 :
+ * <ul>
+ * <li>returning an instance of implementation in the return value of
+ * {@link Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link QName} of rpc as
+ * arguments to the
+ * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
+ * </ul>
+ * 
+ * The simplified process of the invocation of rpc is following:
+ * 
+ * <ol>
+ * <li> {@link Consumer} invokes
+ * {@link ConsumerSession#rpc(QName, CompositeNode)}
+ * <li> {@link Broker} finds registered {@link RpcImplementation}s
+ * <li> {@link Broker} invokes
+ * {@link RpcImplementation#invokeRpc(QName, CompositeNode)}
+ * <li> {@link RpcImplementation} processes the data and returns a
+ * {@link RpcResult}
+ * <li> {@link Broker} returns the {@link RpcResult} to {@link Consumer}
+ * </ol>
+ * 
+ * 
+ */
+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<QName> getSupportedRpcs();
+
+    /**
+     * Invokes a implementation of specified rpc.
+     * 
+     * 
+     * @param rpc
+     *            Rpc to be invoked
+     * @param input
+     *            Input data for rpc.
+     * 
+     * @throws IllegalArgumentException
+     *             <ul>
+     *             <li>If rpc is null.
+     *             <li>If input is not <code>null</code> and
+     *             <code>false == rpc.equals(input.getNodeType)</code>
+     *             </ul>
+     * @return RpcResult containing the output of rpc if was executed
+     *         successfully, the list of errors otherwise.
+     */
+    RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input);
+
+}
index d74a7d146ddf7dd63d502aab9d720624566105d9..f4bc71142a4bfe36daf9eeec39d04e95285c0a05 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.data;\r
-\r
-import java.util.Set;\r
-import java.util.concurrent.Future;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.sal.core.api.Consumer;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-import org.opendaylight.controller.yang.data.api.CompositeNodeModification;\r
-import org.opendaylight.controller.yang.data.api.Node;\r
-\r
-\r
-/**\r
- * DataBrokerService provides unified access to the data stores available in the\r
- * system.\r
- * \r
- * \r
- * @see DataProviderService\r
- * \r
- */\r
-public interface DataBrokerService extends BrokerService {\r
-\r
-    \r
-    Set<DataStoreIdentifier> getDataStores();\r
-    \r
-    /**\r
-     * Returns a data from specified Data Store.\r
-     * \r
-     * Returns all the data visible to the consumer from specified Data Store.\r
-     * \r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @return data visible to the consumer\r
-     */\r
-    CompositeNode getData(DataStoreIdentifier store);\r
-\r
-    /**\r
-     * Returns a filtered subset of data from specified Data Store.\r
-     * \r
-     * <p>\r
-     * The filter is modeled as an hierarchy of {@link Node} starting with\r
-     * {@link CompositeNode} representing data root. The semantics of the filter\r
-     * tree is the same as filter semantics defined in the NETCONF protocol for\r
-     * rpc operations <code>get</code> and <code>get-config</code> in Section 6\r
-     * of RFC6241.\r
-     * \r
-     * \r
-     * @see http://tools.ietf.org/html/rfc6241#section-6\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @param filter\r
-     *            Data tree filter similar to the NETCONF filter\r
-     * @return\r
-     */\r
-    CompositeNode getData(DataStoreIdentifier store, CompositeNode filter);\r
-\r
-    /**\r
-     * Returns a candidate data which are not yet commited.\r
-     * \r
-     * \r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @return\r
-     */\r
-    CompositeNode getCandidateData(DataStoreIdentifier store);\r
-\r
-    /**\r
-     * Returns a filtered subset of candidate data from specified Data Store.\r
-     * \r
-     * <p>\r
-     * The filter is modeled as an hierarchy of {@link Node} starting with\r
-     * {@link CompositeNode} representing data root. The semantics of the filter\r
-     * tree is the same as filter semantics defined in the NETCONF protocol for\r
-     * rpc operations <code>get</code> and <code>get-config</code> in Section 6\r
-     * of RFC6241.\r
-     * \r
-     * \r
-     * @see http://tools.ietf.org/html/rfc6241#section-6\r
-     * @param store\r
-     *            Identifier of the store, from which will be data retrieved\r
-     * @param filter\r
-     *            A CompositeNode filter\r
-     * @return\r
-     */\r
-    CompositeNode getCandidateData(DataStoreIdentifier store,\r
-            CompositeNode filter);\r
-\r
-    /**\r
-     * \r
-     * @param store\r
-     *            Identifier of the store, in which will be the candidate data\r
-     *            modified\r
-     * @param changeSet\r
-     *            Modification of data tree.\r
-     * @return Result object containing the modified data tree if the operation\r
-     *         was successful, otherwise list of the encountered errors.\r
-     */\r
-    RpcResult<CompositeNode> editCandidateData(DataStoreIdentifier store,\r
-            CompositeNodeModification changeSet);\r
-\r
-    /**\r
-     * Initiates a two-phase commit of candidate data.\r
-     * \r
-     * <p>\r
-     * The {@link Consumer} could initiate a commit of candidate data\r
-     * \r
-     * <p>\r
-     * The successful commit changes the state of the system and may affect\r
-     * several components.\r
-     * \r
-     * <p>\r
-     * The effects of successful commit of data are described in the\r
-     * specifications and YANG models describing the {@link Provider} components\r
-     * of controller. It is assumed that {@link Consumer} has an understanding\r
-     * of this changes.\r
-     * \r
-     * \r
-     * @see DataCommitHandler for further information how two-phase commit is\r
-     *      processed.\r
-     * @param store\r
-     *            Identifier of the store, where commit should occur.\r
-     * @return Result of the commit, containing success information or list of\r
-     *         encountered errors, if commit was not successful.\r
-     */\r
-    Future<RpcResult<Void>> commit(DataStoreIdentifier store);\r
-}\r
+/*
+ * 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<DataStoreIdentifier> 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.
+     * 
+     * <p>
+     * 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 <code>get</code> and <code>get-config</code> 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.
+     * 
+     * <p>
+     * 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 <code>get</code> and <code>get-config</code> 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<CompositeNode> editCandidateData(DataStoreIdentifier store,
+            CompositeNodeModification changeSet);
+
+    /**
+     * Initiates a two-phase commit of candidate data.
+     * 
+     * <p>
+     * The {@link Consumer} could initiate a commit of candidate data
+     * 
+     * <p>
+     * The successful commit changes the state of the system and may affect
+     * several components.
+     * 
+     * <p>
+     * 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<RpcResult<Void>> commit(DataStoreIdentifier store);
+}
index f0cc02d3cebf019b8762136f95dfebffe2b6ce9e..fc1894a3d9100f2895048da54b9e9d4c927e4a71 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.data;\r
-\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-\r
-\r
-/**\r
- * Two phase commit handler (cohort) of the two-phase commit protocol of data.\r
- * \r
- * <p>\r
- * The provider should expose the implementation of DataCommitHandler if it's\r
- * functionality depends on any subset of data stored in data repositories, in\r
- * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier)\r
- * operation.\r
- * \r
- * <p>\r
- * Operations of two-phase commit handlers should not change data in data store,\r
- * this is responsibility of the coordinator (broker or some component of the\r
- * broker).\r
- * \r
- * The commit handlers are responsible for changing the internal state of the\r
- * provider to reflect the commited changes in data.\r
- * \r
- * <h3>Two-phase commit</h3>\r
- * \r
- * <h4>Commit Request Phase</h4>\r
- * \r
- * <ol>\r
- * <li> <code>Consumer</code> edits data by invocation of\r
- * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, CompositeNodeModification)</code>\r
- * <li> <code>Consumer</code> starts a commit by invoking\r
- * <code>DataBrokerService.commit(DataStoreIdentifier)</code>\r
- * <li> <code>Broker</code> retrieves a list of all registered\r
- * <code>DataCommitHandlers</code>\r
- * <li>For each <code>DataCommitHandler</code>\r
- * <ol>\r
- * <li><code>Broker</code> invokes a\r
- * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.\r
- * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with\r
- * <code>CommitTransaction</code>\r
- * <li>If the result was successful, broker adds <code>CommitTransaction</code>\r
- * to the list of opened transactions. If not, brokers stops a commit request\r
- * phase and starts a rollback phase.\r
- * </ol>\r
- * <li><code>Broker</code> starts a commit finish phase\r
- * </ol>\r
- * \r
- * <h4>Commit Finish Phase</h4>\r
- * \r
- * <ol>\r
- * <li>For each <code>CommitTransaction</code> from Commit Request phase\r
- * <ol>\r
- * <li><code>Broker</code> broker invokes a\r
- * <code>CommitTransaction.finish()</code>\r
- * <li>The provider finishes a commit (applies the change) and returns an\r
- * <code>RpcResult</code>.\r
- * </ol>\r
- * <li>\r
- * <ul>\r
- * <li>If all returned results means successful, the brokers end two-phase\r
- * commit by returning a success commit result to the Consumer.\r
- * <li>If error occured, the broker starts a commit rollback phase.\r
- * </ul>\r
- * </ol>\r
- * \r
- * <h4>Commit Rollback Phase</h4>\r
- * <li>For each <code>CommitTransaction</code> from Commit Request phase\r
- * <ol>\r
- * <li><code>Broker</code>\r
- * \r
- * broker invokes a {@link CommitTransaction#finish()}\r
- * <li>The provider rollbacks a commit and returns an {@link RpcResult} of\r
- * rollback. </ol>\r
- * <li>Broker returns a error result to the consumer.\r
- * \r
- * \r
- * <h3>Registration of functionality</h3>\r
- * The registration could be done by :\r
- * <ul>\r
- * <li>returning an instance of implementation in the return value of\r
- * {@link Provider#getProviderFunctionality()}\r
- * <li>passing an instance of implementation and {@link DataStoreIdentifier} of\r
- * rpc as arguments to the\r
- * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)}\r
- * </ul>\r
- * \r
- * \r
- */\r
-public interface DataCommitHandler extends Provider.ProviderFunctionality {\r
-\r
-    /**\r
-     * A set of Data Stores supported by implementation.\r
-     * \r
-     * The set of {@link DataStoreIdentifier}s which identifies target data\r
-     * stores which are supported by this commit handler. This set is used, when\r
-     * {@link Provider} is registered to the SAL, to register and expose the\r
-     * commit handler functionality to affected data stores.\r
-     * \r
-     * @return Set of Data Store identifiers\r
-     */\r
-    Set<DataStoreIdentifier> getSupportedDataStores();\r
-\r
-    /**\r
-     * The provider (commit handler) starts a commit transaction.\r
-     * \r
-     * <p>\r
-     * The commit handler (provider) prepares an commit scenario, rollback\r
-     * scenario and validates data.\r
-     * \r
-     * <p>\r
-     * If the provider is aware that at this point the commit would not be\r
-     * successful, the transaction is not created, but list of errors which\r
-     * prevented the start of transaction are returned.\r
-     * \r
-     * @param store\r
-     * @return Transaction object representing this commit, errors otherwise.\r
-     */\r
-    RpcResult<CommitTransaction> requestCommit(DataStoreIdentifier store);\r
-\r
-    public interface CommitTransaction {\r
-        /**\r
-         * \r
-         * @return Data store affected by the transaction\r
-         */\r
-        DataStoreIdentifier getDataStore();\r
-\r
-        /**\r
-         * Returns the handler associated with this transaction.\r
-         * \r
-         * @return Handler\r
-         */\r
-        DataCommitHandler getHandler();\r
-\r
-        /**\r
-         * \r
-         * Finishes a commit.\r
-         * \r
-         * The provider (commit handler) should apply all changes to its state\r
-         * which are a result of data change-\r
-         * \r
-         * @return\r
-         */\r
-        RpcResult<Void> finish() throws IllegalStateException;\r
-\r
-        /**\r
-         * Rollbacks a commit.\r
-         * \r
-         * @return\r
-         * @throws IllegalStateException\r
-         *             If the method is invoked after {@link #finish()}\r
-         */\r
-        RpcResult<Void> rollback() throws IllegalStateException;\r
-    }\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <p>
+ * 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.
+ * 
+ * <h3>Two-phase commit</h3>
+ * 
+ * <h4>Commit Request Phase</h4>
+ * 
+ * <ol>
+ * <li> <code>Consumer</code> edits data by invocation of
+ * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, CompositeNodeModification)</code>
+ * <li> <code>Consumer</code> starts a commit by invoking
+ * <code>DataBrokerService.commit(DataStoreIdentifier)</code>
+ * <li> <code>Broker</code> retrieves a list of all registered
+ * <code>DataCommitHandlers</code>
+ * <li>For each <code>DataCommitHandler</code>
+ * <ol>
+ * <li><code>Broker</code> invokes a
+ * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.
+ * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with
+ * <code>CommitTransaction</code>
+ * <li>If the result was successful, broker adds <code>CommitTransaction</code>
+ * to the list of opened transactions. If not, brokers stops a commit request
+ * phase and starts a rollback phase.
+ * </ol>
+ * <li><code>Broker</code> starts a commit finish phase
+ * </ol>
+ * 
+ * <h4>Commit Finish Phase</h4>
+ * 
+ * <ol>
+ * <li>For each <code>CommitTransaction</code> from Commit Request phase
+ * <ol>
+ * <li><code>Broker</code> broker invokes a
+ * <code>CommitTransaction.finish()</code>
+ * <li>The provider finishes a commit (applies the change) and returns an
+ * <code>RpcResult</code>.
+ * </ol>
+ * <li>
+ * <ul>
+ * <li>If all returned results means successful, the brokers end two-phase
+ * commit by returning a success commit result to the Consumer.
+ * <li>If error occured, the broker starts a commit rollback phase.
+ * </ul>
+ * </ol>
+ * 
+ * <h4>Commit Rollback Phase</h4>
+ * <li>For each <code>CommitTransaction</code> from Commit Request phase
+ * <ol>
+ * <li><code>Broker</code>
+ * 
+ * broker invokes a {@link CommitTransaction#finish()}
+ * <li>The provider rollbacks a commit and returns an {@link RpcResult} of
+ * rollback. </ol>
+ * <li>Broker returns a error result to the consumer.
+ * 
+ * 
+ * <h3>Registration of functionality</h3>
+ * The registration could be done by :
+ * <ul>
+ * <li>returning an instance of implementation in the return value of
+ * {@link Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link DataStoreIdentifier} of
+ * rpc as arguments to the
+ * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)}
+ * </ul>
+ * 
+ * 
+ */
+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<DataStoreIdentifier> getSupportedDataStores();
+
+    /**
+     * The provider (commit handler) starts a commit transaction.
+     * 
+     * <p>
+     * The commit handler (provider) prepares an commit scenario, rollback
+     * scenario and validates data.
+     * 
+     * <p>
+     * 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<CommitTransaction> 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<Void> finish() throws IllegalStateException;
+
+        /**
+         * Rollbacks a commit.
+         * 
+         * @return
+         * @throws IllegalStateException
+         *             If the method is invoked after {@link #finish()}
+         */
+        RpcResult<Void> rollback() throws IllegalStateException;
+    }
+}
index 5c5423d80f40fea969c68f8ff22e51edb34d1de4..32035ea489f985997dfcb99b66d729edc11f14b7 100644 (file)
@@ -1,78 +1,78 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.data;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-\r
-public interface DataProviderService extends DataBrokerService {\r
-\r
-    /**\r
-     * Adds {@link DataValidator} for specified Data Store\r
-     * \r
-     * @param store\r
-     *            Data Store\r
-     * @param validator\r
-     *            Validator\r
-     */\r
-    public void addValidator(DataStoreIdentifier store, DataValidator validator);\r
-\r
-    /**\r
-     * Removes {@link DataValidator} from specified Data Store\r
-     * \r
-     * @param store\r
-     * @param validator\r
-     *            Validator\r
-     */\r
-    public void removeValidator(DataStoreIdentifier store,\r
-            DataValidator validator);\r
-\r
-    /**\r
-     * Adds {@link DataCommitHandler} for specified data store\r
-     * \r
-     * @param store\r
-     * @param provider\r
-     */\r
-    void addCommitHandler(DataStoreIdentifier store, DataCommitHandler provider);\r
-\r
-    /**\r
-     * Removes {@link DataCommitHandler} from specified data store\r
-     * \r
-     * @param store\r
-     * @param provider\r
-     */\r
-    void removeCommitHandler(DataStoreIdentifier store,\r
-            DataCommitHandler provider);\r
-\r
-    /**\r
-     * Adds {@link DataRefresher} for specified data store\r
-     * \r
-     * @param store\r
-     * @param refresher\r
-     */\r
-    void addRefresher(DataStoreIdentifier store, DataRefresher refresher);\r
-\r
-    /**\r
-     * Removes {@link DataRefresher} from specified data store\r
-     * \r
-     * @param store\r
-     * @param refresher\r
-     */\r
-    void removeRefresher(DataStoreIdentifier store, DataRefresher refresher);\r
-\r
-    public interface DataRefresher extends Provider.ProviderFunctionality {\r
-\r
-        /**\r
-         * Fired when some component explicitly requested the data refresh.\r
-         * \r
-         * The provider which exposed the {@link DataRefresher} should republish\r
-         * its provided data by editing the data in all affected data stores.\r
-         */\r
-        void refreshData();\r
-    }\r
-}\r
+/*
+ * 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();
+    }
+}
index a2105b41d7a1ba5e4297c818ea0e770ca7f1d427..2bcb84be34f375486f4791dab794ff58d168c4d7 100644 (file)
@@ -1,57 +1,57 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.data;\r
-\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.common.DataStoreIdentifier;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.yang.common.RpcResult;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-\r
-\r
-/**\r
- * {@link Provider}-supplied Validator of the data.\r
- * \r
- * <p>\r
- * The registration could be done by :\r
- * <ul>\r
- * <li>returning an instance of implementation in the return value of\r
- * {@link Provider#getProviderFunctionality()}\r
- * <li>passing an instance of implementation and {@link DataStoreIdentifier} rpc\r
- * as arguments to the\r
- * {@link DataProviderService#addValidator(DataStoreIdentifier, DataValidator)}\r
- * </ul>\r
- * \r
- **/\r
-public interface DataValidator extends Provider.ProviderFunctionality {\r
-\r
-    /**\r
-     * A set of Data Stores supported by implementation.\r
-     * \r
-     * The set of {@link DataStoreIdentifier}s which identifies target data\r
-     * stores which are supported by this implementation. This set is used, when\r
-     * {@link Provider} is registered to the SAL, to register and expose the\r
-     * validation functionality to affected data stores.\r
-     * \r
-     * @return Set of Data Store identifiers\r
-     */\r
-    Set<DataStoreIdentifier> getSupportedDataStores();\r
-\r
-    /**\r
-     * Performs validation on supplied data.\r
-     * \r
-     * @param toValidate\r
-     *            Data to validate\r
-     * @return Validation result. The\r
-     *         <code>{@link RpcResult#isSuccessful()} == true</code> if the data\r
-     *         passed validation, otherwise contains list of errors.\r
-     */\r
-    RpcResult<Void> validate(CompositeNode toValidate);\r
-\r
-}\r
+/*
+ * 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.
+ * 
+ * <p>
+ * The registration could be done by :
+ * <ul>
+ * <li>returning an instance of implementation in the return value of
+ * {@link Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link DataStoreIdentifier} rpc
+ * as arguments to the
+ * {@link DataProviderService#addValidator(DataStoreIdentifier, DataValidator)}
+ * </ul>
+ * 
+ **/
+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<DataStoreIdentifier> getSupportedDataStores();
+
+    /**
+     * Performs validation on supplied data.
+     * 
+     * @param toValidate
+     *            Data to validate
+     * @return Validation result. The
+     *         <code>{@link RpcResult#isSuccessful()} == true</code> if the data
+     *         passed validation, otherwise contains list of errors.
+     */
+    RpcResult<Void> validate(CompositeNode toValidate);
+
+}
index b58659a7267e4aacfb1cbbca10cc9a8ff87469a3..17911962ff35566229ecf5d2b4eec0b560aa8521 100644 (file)
@@ -1,8 +1,8 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
+/*
+ * 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
index 22abdc2a004245758e155e3f0e1a89d98ee18317..52f60b3cc28728a7dce4a2435bfe1e97bb6a2e0c 100644 (file)
@@ -1,42 +1,42 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.model;\r
-\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.yang.model.api.Module;\r
-import org.opendaylight.controller.yang.model.api.SchemaContext;\r
-\r
-public interface SchemaService extends BrokerService {\r
-\r
-    /**\r
-     * Registers a YANG module to session and global context \r
-     * \r
-     * @param module\r
-     */\r
-    void addModule(Module module);\r
-    \r
-    /**\r
-     * Unregisters a YANG module from session context\r
-     * \r
-     * @param module\r
-     */\r
-    void removeModule(Module module);\r
-    \r
-    /**\r
-     * Returns session specific YANG schema context\r
-     * @return\r
-     */\r
-    SchemaContext getSessionContext();\r
-    \r
-    /**\r
-     * Returns global schema context\r
-     * \r
-     * @return\r
-     */\r
-    SchemaContext getGlobalContext();\r
-}\r
+/*
+ * 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();
+}
index 5f72c628051ad339fa0423e50501d8ba186bb579..5b0c992a006aedfd0fd99cfe87f30bf48323e56b 100644 (file)
@@ -1,42 +1,42 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.notify;\r
-\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.core.api.Consumer;\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-\r
-\r
-/**\r
- * Notification listener for SAL notifications.\r
- */\r
-public interface NotificationListener extends Consumer.ConsumerFunctionality {\r
-    /**\r
-     * A set of notification types supported by listeners.\r
-     * \r
-     * The set of notification {@link QName}s which are supported by this\r
-     * listener. This set is used, when {@link Consumer} is registered to the\r
-     * SAL, to automatically register the listener.\r
-     * \r
-     * @return Set of QNames identifying supported notifications.\r
-     */\r
-    Set<QName> getSupportedNotifications();\r
-\r
-    /**\r
-     * Fired when the notification occurs.\r
-     * \r
-     * The type of the notification could be learned by\r
-     * <code>QName type = notification.getNodeType();</code>\r
-     * \r
-     * @param notification\r
-     *            Notification content\r
-     */\r
-    void onNotification(CompositeNode notification);\r
-}\r
+/*
+ * 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<QName> getSupportedNotifications();
+
+    /**
+     * Fired when the notification occurs.
+     * 
+     * The type of the notification could be learned by
+     * <code>QName type = notification.getNodeType();</code>
+     * 
+     * @param notification
+     *            Notification content
+     */
+    void onNotification(CompositeNode notification);
+}
index 6f7e740cdf6fd5300179b84091e3fddcb57d1c20..51871a770be06eb8e33c061d7e792f06339398fa 100644 (file)
@@ -1,46 +1,46 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.notify;\r
-\r
-import org.opendaylight.controller.sal.core.api.Broker;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.yang.data.api.CompositeNode;\r
-\r
-\r
-/**\r
- * Notification Publishing Service\r
- * \r
- * The simplified process of the notification publishing is following:\r
- * \r
- * <ol>\r
- * <li> {@link Provider} invokes {@link #sendNotification(CompositeNode)}\r
- * <li> {@link Broker} finds {@link NotificationListener}s which subscribed for\r
- * the notification type.\r
- * \r
- * <li>For each subscriber {@link Broker} invokes\r
- * {@link NotificationListener#onNotification(CompositeNode)}\r
- * </ol>\r
- * \r
- * \r
- * \r
- */\r
-public interface NotificationProviderService extends NotificationService {\r
-\r
-    /**\r
-     * Publishes a notification.\r
-     * \r
-     * Notification type is determined by the\r
-     * {@link CompositeNode#getNodeType()} of the\r
-     * <code>notification<code> parameter.\r
-     * \r
-     * @param notification\r
-     *            Notification to publish\r
-     */\r
-    void sendNotification(CompositeNode notification);\r
-\r
-}\r
+/*
+ * 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:
+ * 
+ * <ol>
+ * <li> {@link Provider} invokes {@link #sendNotification(CompositeNode)}
+ * <li> {@link Broker} finds {@link NotificationListener}s which subscribed for
+ * the notification type.
+ * 
+ * <li>For each subscriber {@link Broker} invokes
+ * {@link NotificationListener#onNotification(CompositeNode)}
+ * </ol>
+ * 
+ * 
+ * 
+ */
+public interface NotificationProviderService extends NotificationService {
+
+    /**
+     * Publishes a notification.
+     * 
+     * Notification type is determined by the
+     * {@link CompositeNode#getNodeType()} of the
+     * <code>notification<code> parameter.
+     * 
+     * @param notification
+     *            Notification to publish
+     */
+    void sendNotification(CompositeNode notification);
+
+}
index 98a4925afb0ef21089b4a0bfd1e076924056bfac..3bf10546e50fc70331e943514defbad6999189a5 100644 (file)
@@ -1,54 +1,54 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.core.api.notify;\r
-\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-import org.opendaylight.controller.sal.core.api.Provider;\r
-import org.opendaylight.controller.sal.core.api.RpcImplementation;\r
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
-import org.opendaylight.controller.yang.common.QName;\r
-\r
-\r
-/**\r
- * NotificationService provides access to the notification functionality of the\r
- * SAL.\r
- * \r
- * NotificationService allows for consumption of notifications by registering\r
- * implementations of NotificationListener.\r
- * \r
- * The registration of notification listeners could be done by:\r
- * <ul>\r
- * <li>returning an instance of implementation in the return value of\r
- * {@link Provider#getProviderFunctionality()}\r
- * <li>passing an instance of implementation and {@link QName} of rpc as an\r
- * arguments to the\r
- * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}\r
- * </ul>\r
- * \r
- * \r
- */\r
-public interface NotificationService extends BrokerService {\r
-\r
-    /**\r
-     * Registers a notification listener for supplied notification type.\r
-     * \r
-     * @param notification\r
-     * @param listener\r
-     */\r
-    void addNotificationListener(QName notification,\r
-            NotificationListener listener);\r
-\r
-    /**\r
-     * Removes a notification listener for supplied notification type.\r
-     * \r
-     * @param notification\r
-     * @param listener\r
-     */\r
-    void removeNotificationListener(QName notification,\r
-            NotificationListener listener);\r
-}\r
+/*
+ * 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:
+ * <ul>
+ * <li>returning an instance of implementation in the return value of
+ * {@link Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link QName} of rpc as an
+ * arguments to the
+ * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
+ * </ul>
+ * 
+ * 
+ */
+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);
+}
index b6868340bb45ea551e056e0787ab2089428039dd..61426a3fd8cdee6a26b41976432302d70c450db0 100644 (file)
@@ -1,11 +1,11 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-/**\r
- * SAL Notification functionality\r
- */\r
+/*
+ * 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
index a058df363df0f8339e2791d9032532bfff47ffd0..395c09a40fc386db9750fc2807a3d3f5b6fc9e61 100644 (file)
@@ -1,11 +1,11 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-/**\r
- * Core binding-independent SAL contracts and components\r
- */\r
-package org.opendaylight.controller.sal.core.api;\r
+/*
+ * 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;
index 96af32bc7ae394ba385f54b95fd8c3cbd38decfa..1162b0d99a7f5edcdf9f9c413a28088435ef6a7a 100644 (file)
@@ -3,7 +3,7 @@
        <modelVersion>4.0.0</modelVersion>\r
        <parent>\r
                <groupId>org.opendaylight.controller</groupId>\r
-               <artifactId>sal</artifactId>\r
+               <artifactId>sal-parent</artifactId>\r
                <version>1.0-SNAPSHOT</version>\r
        </parent>\r
        <artifactId>sal-core-demo</artifactId>\r
@@ -54,5 +54,5 @@
 \r
                </plugins>\r
 \r
-       </build>
+       </build>\r
 </project>
\ No newline at end of file
index 3378a36fbc0c3ee55f8bea577aa3b9f8127a197d..aab58123f47eeab6610a1f94aa149f278791d968 100644 (file)
@@ -2,7 +2,7 @@
   <modelVersion>4.0.0</modelVersion>\r
   <parent>\r
     <groupId>org.opendaylight.controller</groupId>\r
-    <artifactId>sal</artifactId>\r
+    <artifactId>sal-parent</artifactId>\r
     <version>1.0-SNAPSHOT</version>\r
   </parent>\r
    <artifactId>sal-core-spi</artifactId>\r
index 74230e5f7c38230ce9cb34a677b904a4aa68ba42..eeea2920d55d74ef2ace39955f4b2e6b82858e12 100644 (file)
@@ -2,7 +2,7 @@
   <modelVersion>4.0.0</modelVersion>\r
   <parent>\r
     <groupId>org.opendaylight.controller</groupId>\r
-    <artifactId>sal</artifactId>\r
+    <artifactId>sal-parent</artifactId>\r
     <version>1.0-SNAPSHOT</version>\r
   </parent>\r
    <artifactId>sal-data-api</artifactId>\r
index b67529ac35938b2c5b6e8d706e37c2a03dc22acc..b5c42ed74a2931069ad1648d482c4b824fe01995 100644 (file)
@@ -2,7 +2,7 @@
   <modelVersion>4.0.0</modelVersion>\r
   <parent>\r
     <groupId>org.opendaylight.controller</groupId>\r
-    <artifactId>sal</artifactId>\r
+    <artifactId>sal-parent</artifactId>\r
     <version>1.0-SNAPSHOT</version>\r
   </parent>\r
   <artifactId>sal-schema-repository-api</artifactId>\r
diff --git a/opendaylight/sal/yang-prototype/sal/samples/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/pom.xml
new file mode 100644 (file)
index 0000000..dc06185
--- /dev/null
@@ -0,0 +1,18 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+               <groupId>org.opendaylight.controller</groupId>
+       </parent>
+       <packaging>pom</packaging>
+       <artifactId>sal-samples</artifactId>
+       <modules>
+               <module>toaster</module>
+               <module>toaster-consumer</module>
+               <module>toaster-it</module>
+               <module>toaster-provider</module>
+       </modules>
+       <groupId>org.opendaylight.controller.samples</groupId>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/pom.xml
new file mode 100644 (file)
index 0000000..914accd
--- /dev/null
@@ -0,0 +1,40 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-consumer</artifactId>
+       <packaging>bundle</packaging>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                               <Export-Package>org.opendaylight.controller.sample.toaster.provider.api</Export-Package>
+                                               <Private-Package>org.opendaylight.controller.sample.toaster.provider.impl</Private-Package>
+                                               <Bundle-Activator>org.opendaylight.controller.sample.toaster.provider.impl.ToastConsumerImpl</Bundle-Activator>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/api/ToastConsumer.java
new file mode 100644 (file)
index 0000000..b236c0e
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * 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.sample.toaster.provider.api;
+
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastType;
+
+public interface ToastConsumer {
+       
+       boolean createToast(Class<? extends ToastType> type,int doneness);
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java
new file mode 100644 (file)
index 0000000..71ef68d
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * 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.sample.toaster.provider.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.controller.sal.binding.api.NotificationService;
+import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.MakeToastInputBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDone;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastType;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ToastConsumerImpl implements BundleActivator, BindingAwareConsumer, ToastConsumer,
+        NotificationListener<ToastDone> {
+
+    private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class);
+
+    private ToasterService toaster;
+
+    private ConsumerContext session;
+
+    @Override
+    public boolean createToast(Class<? extends ToastType> type, int doneness) {
+        MakeToastInputBuilder toastInput = new MakeToastInputBuilder();
+        toastInput.setToasterDoneness((long) doneness);
+        toastInput.setToasterToastType(type);
+
+        try {
+            RpcResult<Void> result = getToastService().makeToast(toastInput.build()).get();
+
+            if (result.isSuccessful()) {
+                log.info("Toast was successfuly finished");
+            } else {
+                log.info("Toast was not successfuly finished");
+            }
+            return result.isSuccessful();
+        } catch (InterruptedException | ExecutionException e) {
+            log.info("Error occured during toast creation");
+        }
+        return false;
+
+    }
+
+    @Override
+    public void onSessionInitialized(ConsumerContext session) {
+        this.session = session;
+        NotificationService notificationService = session.getSALService(NotificationService.class);
+        notificationService.addNotificationListener(ToastDone.class, this);
+
+    }
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
+        BindingAwareBroker broker = context.getService(brokerRef);
+        broker.registerConsumer(this, context);
+        Dictionary<String, String> properties = new Hashtable<>();
+        context.registerService(ToastConsumer.class, this, properties);
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onNotification(ToastDone notification) {
+        log.info("ToastDone Notification Received: {} ",notification.getToastStatus());
+
+    }
+
+    private ToasterService getToastService() {
+        if (toaster == null) {
+            toaster = session.getRpcService(ToasterService.class);
+        }
+        return toaster;
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/pom.xml
new file mode 100644 (file)
index 0000000..edce9a0
--- /dev/null
@@ -0,0 +1,132 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-it</artifactId>
+
+       <properties>
+               <exam.version>3.0.0</exam.version>
+               <url.version>1.5.0</url.version>
+       </properties>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.ops4j.pax.exam</groupId>
+                               <artifactId>maven-paxexam-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>generate-config</id>
+                                               <goals>
+                                                       <goal>generate-depends-file</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+               <pluginManagement>
+                       <plugins>
+                               <!--This plugin's configuration is used to store Eclipse m2e settings 
+                                       only. It has no influence on the Maven build itself. -->
+                               <plugin>
+                                       <groupId>org.eclipse.m2e</groupId>
+                                       <artifactId>lifecycle-mapping</artifactId>
+                                       <version>1.0.0</version>
+                                       <configuration>
+                                               <lifecycleMappingMetadata>
+                                                       <pluginExecutions>
+                                                               <pluginExecution>
+                                                                       <pluginExecutionFilter>
+                                                                               <groupId>
+                                                                                       org.ops4j.pax.exam
+                                                                               </groupId>
+                                                                               <artifactId>
+                                                                                       maven-paxexam-plugin
+                                                                               </artifactId>
+                                                                               <versionRange>
+                                                                                       [1.2.4,)
+                                                                               </versionRange>
+                                                                               <goals>
+                                                                                       <goal>
+                                                                                               generate-depends-file
+                                                                                       </goal>
+                                                                               </goals>
+                                                                       </pluginExecutionFilter>
+                                                                       <action>
+                                                                               <ignore></ignore>
+                                                                       </action>
+                                                               </pluginExecution>
+                                                       </pluginExecutions>
+                                               </lifecycleMappingMetadata>
+                                       </configuration>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster-consumer</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller.samples</groupId>
+                       <artifactId>sample-toaster-provider</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-broker-impl</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-container-native</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-junit4</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.ops4j.pax.exam</groupId>
+                       <artifactId>pax-exam-link-mvn</artifactId>
+                       <version>${exam.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>equinoxSDK381</groupId>
+                       <artifactId>org.eclipse.osgi</artifactId>
+                       <version>3.8.1.v20120830-144521</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>log4j-over-slf4j</artifactId>
+                       <version>1.7.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>ch.qos.logback</groupId>
+                       <artifactId>logback-core</artifactId>
+                       <version>1.0.9</version>
+               </dependency>
+               <dependency>
+                       <groupId>ch.qos.logback</groupId>
+                       <artifactId>logback-classic</artifactId>
+                       <version>1.0.9</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java
new file mode 100644 (file)
index 0000000..663e81a
--- /dev/null
@@ -0,0 +1,84 @@
+package org.opendaylight.controller.sample.toaster.it;
+
+import static org.junit.Assert.*;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemPackages;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+
+import java.util.Collection;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sample.toaster.provider.ToasterProvider;
+import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.WhiteBread;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+@RunWith(PaxExam.class)
+public class ToasterTest {
+
+       public static final String ODL = "org.opendaylight.controller";
+       public static final String YANG = "org.opendaylight.yangtools";
+       public static final String SAMPLE = "org.opendaylight.controller.samples";
+
+       @Test
+       public void properInitialized() throws Exception {
+
+               Collection<ServiceReference<ToasterService>> references = ctx
+                               .getServiceReferences(ToasterService.class, null);
+               assertEquals(2, references.size());
+               
+               consumer.createToast(WhiteBread.class, 5);
+               
+       }
+
+       @Inject
+       BindingAwareBroker broker;
+
+       @Inject
+       ToastConsumer consumer;
+
+       @Inject
+       BundleContext ctx;
+
+       @Configuration
+       public Option[] config() {
+               return options(systemProperty("osgi.console").value("2401"),
+                               mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
+                               mavenBundle("org.slf4j", "log4j-over-slf4j")
+                                               .versionAsInProject(),
+                               mavenBundle("ch.qos.logback", "logback-core")
+                                               .versionAsInProject(),
+                               mavenBundle("ch.qos.logback", "logback-classic")
+                                               .versionAsInProject(),
+                               mavenBundle(ODL, "sal-binding-api").versionAsInProject(),
+                               mavenBundle(ODL, "sal-binding-broker-impl")
+                                               .versionAsInProject(), mavenBundle(ODL, "sal-common")
+                                               .versionAsInProject(),
+                               mavenBundle(ODL, "sal-common-util").versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster").versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster-consumer")
+                                               .versionAsInProject(),
+                               mavenBundle(SAMPLE, "sample-toaster-provider")
+                                               .versionAsInProject(),
+                               mavenBundle(YANG, "yang-binding").versionAsInProject(),
+                               mavenBundle(YANG, "yang-common").versionAsInProject(),
+                               mavenBundle("com.google.guava", "guava").versionAsInProject(),
+                               junitBundles(), mavenBundle("org.javassist", "javassist")
+                                               .versionAsInProject());
+       }
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/pom.xml
new file mode 100644 (file)
index 0000000..49d142c
--- /dev/null
@@ -0,0 +1,44 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>sal-samples</artifactId>
+               <groupId>org.opendaylight.controller.samples</groupId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>sample-toaster-provider</artifactId>
+       <packaging>bundle</packaging>
+
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                       <Bundle-Activator>org.opendaylight.controller.sample.toaster.provider.ToasterProvider</Bundle-Activator>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>sample-toaster</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-binding-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.opendaylight.controller</groupId>
+                       <artifactId>sal-common-util</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/OpendaylightToaster.java
new file mode 100644 (file)
index 0000000..404734b
--- /dev/null
@@ -0,0 +1,118 @@
+package org.opendaylight.controller.sample.toaster.provider;
+
+import java.util.Collections;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.common.util.Futures;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.DisplayString;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.MakeToastInput;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDone.ToastStatus;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDoneBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.Toaster;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.Toaster.ToasterStatus;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterBuilder;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterData;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpendaylightToaster implements ToasterData, ToasterService {
+
+    private static final Logger log = LoggerFactory.getLogger(OpendaylightToaster.class);
+
+    private static final DisplayString toasterManufacturer = new DisplayString("Opendaylight");
+    private static final DisplayString toasterModelNumber = new DisplayString("Model 1 - Binding Aware");
+    private ToasterStatus toasterStatus;
+
+    private NotificationProviderService notificationProvider;
+    private final ExecutorService executor;
+
+    private Future<RpcResult<Void>> currentTask;
+
+    public OpendaylightToaster() {
+        toasterStatus = ToasterStatus.Down;
+        executor = Executors.newFixedThreadPool(1);
+    }
+
+    @Override
+    public Toaster getToaster() {
+        ToasterBuilder tb = new ToasterBuilder();
+        tb //
+        .setToasterManufacturer(toasterManufacturer) //
+                .setToasterModelNumber(toasterModelNumber) //
+                .setToasterStatus(toasterStatus);
+
+        return tb.build();
+    }
+
+    @Override
+    public Future<RpcResult<Void>> cancelToast() {
+        if (currentTask != null) {
+            cancelToastImpl();
+        }
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> makeToast(MakeToastInput input) {
+        // TODO Auto-generated method stub
+        log.info("makeToast - Received input for toast");
+        logToastInput(input);
+        if (currentTask != null) {
+            return inProgressError();
+        }
+        currentTask = executor.submit(new MakeToastTask(input));
+        return currentTask;
+    }
+
+    private Future<RpcResult<Void>> inProgressError() {
+        RpcResult<Void> result = Rpcs.<Void> getRpcResult(false, null, Collections.<RpcError> emptySet());
+        return Futures.immediateFuture(result);
+    }
+
+    private void cancelToastImpl() {
+        currentTask.cancel(true);
+        ToastDoneBuilder toastDone = new ToastDoneBuilder();
+        toastDone.setToastStatus(ToastStatus.Cancelled);
+        notificationProvider.notify(toastDone.build());
+    }
+
+    public void setNotificationProvider(NotificationProviderService salService) {
+        this.notificationProvider = salService;
+    }
+
+    private void logToastInput(MakeToastInput input) {
+        String toastType = input.getToasterToastType().getName();
+        String toastDoneness = input.getToasterDoneness().toString();
+        log.info("Toast: {} doneness: {}", toastType, toastDoneness);
+    }
+
+    private class MakeToastTask implements Callable<RpcResult<Void>> {
+
+        final MakeToastInput toastRequest;
+
+        public MakeToastTask(MakeToastInput toast) {
+            toastRequest = toast;
+        }
+
+        @Override
+        public RpcResult<Void> call() throws Exception {
+            Thread.sleep(1000);
+
+            ToastDoneBuilder notifyBuilder = new ToastDoneBuilder();
+            notifyBuilder.setToastStatus(ToastStatus.Done);
+            notificationProvider.notify(notifyBuilder.build());
+            log.info("Toast Done");
+            logToastInput(toastRequest);
+            return Rpcs.<Void> getRpcResult(true, null, Collections.<RpcError> emptySet());
+        }
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterActivator.java
new file mode 100644 (file)
index 0000000..010023a
--- /dev/null
@@ -0,0 +1,5 @@
+package org.opendaylight.controller.sample.toaster.provider;
+
+public class ToasterActivator {
+
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java
new file mode 100644 (file)
index 0000000..08ac149
--- /dev/null
@@ -0,0 +1,71 @@
+package org.opendaylight.controller.sample.toaster.provider;
+import java.util.Collection;
+import java.util.Collections;
+
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ToasterProvider implements BindingAwareProvider, BundleActivator {
+    private static final Logger log = LoggerFactory.getLogger(ToasterProvider.class);
+
+       private ConsumerContext consumerContext;
+       private ProviderContext providerContext;
+       private OpendaylightToaster toaster;
+       
+       
+       public ToasterProvider() {
+               toaster = new OpendaylightToaster();
+       }
+       
+       @Override
+       public void onSessionInitialized(ConsumerContext session) {
+               log.info("Consumer Session initialized");
+               this.consumerContext = session;
+
+       }
+
+       @Override
+       public void onSessionInitiated(ProviderContext session) {
+               log.info("Provider Session initialized");
+               
+               this.providerContext = session;
+               toaster.setNotificationProvider(session.getSALService(NotificationProviderService.class));
+               providerContext.addRpcImplementation(ToasterService.class, toaster);
+       }       
+       
+       
+       @Override
+       public Collection<? extends RpcService> getImplementations() {
+               return Collections.emptySet();
+       }
+
+       @Override
+       public Collection<? extends ProviderFunctionality> getFunctionality() {
+               return Collections.emptySet();
+       }
+
+       @Override
+       public void start(BundleContext context) throws Exception {
+               ServiceReference<BindingAwareBroker> brokerRef = context.getServiceReference(BindingAwareBroker.class);
+               BindingAwareBroker broker = context.getService(brokerRef);
+               broker.registerProvider(this, context);
+       }
+
+       @Override
+       public void stop(BundleContext context) throws Exception {
+               
+               
+       }
+}
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml b/opendaylight/sal/yang-prototype/sal/samples/toaster/pom.xml
new file mode 100644 (file)
index 0000000..d434275
--- /dev/null
@@ -0,0 +1,117 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>sal-samples</artifactId>
+        <groupId>org.opendaylight.controller.samples</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>sample-toaster</artifactId>
+    <packaging>bundle</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>0.5.7-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>
+                                        target/generated-sources/sal
+                                    </outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>false</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>0.5.7-SNAPSHOT</version>
+                        <type>jar</type>
+                    </dependency>
+                </dependencies>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.7</version>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/sal</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <!--This plugin's configuration is used to store Eclipse 
+                    m2e settings only. It has no influence on the Maven build itself. -->
+                <plugin>
+                    <groupId>org.eclipse.m2e</groupId>
+                    <artifactId>lifecycle-mapping</artifactId>
+                    <version>1.0.0</version>
+                    <configuration>
+                        <lifecycleMappingMetadata>
+                            <pluginExecutions>
+                                <pluginExecution>
+                                    <pluginExecutionFilter>
+                                        <groupId>
+                                            org.opendaylight.yangtools
+                                        </groupId>
+                                        <artifactId>
+                                            yang-maven-plugin
+                                        </artifactId>
+                                        <versionRange>
+                                            [0.5,)
+                                        </versionRange>
+                                        <goals>
+                                            <goal>
+                                                generate-sources
+                                            </goal>
+                                        </goals>
+                                    </pluginExecutionFilter>
+                                    <action>
+                                        <ignore></ignore>
+                                    </action>
+                                </pluginExecution>
+                            </pluginExecutions>
+                        </lifecycleMappingMetadata>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang b/opendaylight/sal/yang-prototype/sal/samples/toaster/src/main/yang/toaster.yang
new file mode 100644 (file)
index 0000000..fc9b665
--- /dev/null
@@ -0,0 +1,187 @@
+module toaster {
+
+    yang-version 1;
+
+    namespace
+      "http://netconfcentral.org/ns/toaster";
+
+    prefix toast;
+
+    organization "Netconf Central";
+
+    contact
+      "Andy Bierman <andy@netconfcentral.org>";
+
+    description
+      "YANG version of the TOASTER-MIB.";
+
+    revision "2009-11-20" {
+      description
+        "Toaster module in progress.";
+    }
+
+
+    identity toast-type {
+      description
+          "Base for all bread types supported by the toaster.
+           New bread types not listed here nay be added in the 
+           future.";
+    }
+
+    identity white-bread {
+      base toast:toast-type;
+      description "White bread.";
+    }
+
+    identity wheat-bread {
+      base toast-type;
+      description "Wheat bread.";
+    }
+
+    identity wonder-bread {
+      base toast-type;
+      description "Wonder bread.";
+    }
+
+    identity frozen-waffle {
+      base toast-type;
+      description "Frozen waffle.";
+    }
+
+    identity frozen-bagel {
+      base toast-type;
+      description "Frozen bagel.";
+    }
+
+    identity hash-brown {
+      base toast-type;
+      description "Hash browned potatos.";
+    }
+
+    typedef DisplayString {
+      type string;
+      description
+        "YANG version of the SMIv2 DisplayString TEXTUAL-CONVENTION.";
+      reference
+        "RFC 2579, section 2.";
+
+    }
+
+    container toaster {
+      presence
+        "Indicates the toaster service is available";
+      description
+        "Top-level container for all toaster database objects.";
+      leaf toasterManufacturer {
+        type DisplayString;
+        config false;
+        mandatory true;
+        description
+          "The name of the toaster's manufacturer. For instance, 
+                Microsoft Toaster.";
+      }
+
+      leaf toasterModelNumber {
+        type DisplayString;
+        config false;
+        mandatory true;
+        description
+          "The name of the toaster's model. For instance,
+               Radiant Automatic.";
+      }
+
+      leaf toasterStatus {
+        type enumeration {
+          enum "up" {
+            value 1;
+            description
+              "The toaster knob position is up.
+                      No toast is being made now.";
+          }
+          enum "down" {
+            value 2;
+            description
+              "The toaster knob position is down.
+                      Toast is being made now.";
+          }
+        }
+        config false;
+        mandatory true;
+        description
+          "This variable indicates the current state of 
+               the toaster.";
+      }
+    }  // container toaster
+
+    rpc make-toast {
+      description
+        "Make some toast.
+           The toastDone notification will be sent when 
+           the toast is finished.
+           An 'in-use' error will be returned if toast
+           is already being made.
+           A 'resource-denied' error will be returned 
+           if the toaster service is disabled.";
+      input {
+        leaf toasterDoneness {
+          type uint32 {
+            range "1 .. 10";
+          }
+          default '5';
+          description
+            "This variable controls how well-done is the 
+                   ensuing toast. It should be on a scale of 1 to 10.
+                   Toast made at 10 generally is considered unfit 
+                   for human consumption; toast made at 1 is warmed 
+                   lightly.";
+        }
+
+        leaf toasterToastType {
+          type identityref {
+            base toast:toast-type;
+          }
+          default 'wheat-bread';
+          description
+            "This variable informs the toaster of the type of 
+                   material that is being toasted. The toaster 
+                   uses this information, combined with 
+                   toasterDoneness, to compute for how 
+                   long the material must be toasted to achieve 
+                   the required doneness.";
+        }
+      }
+    }  // rpc make-toast
+
+    rpc cancel-toast {
+      description
+        "Stop making toast, if any is being made.
+           A 'resource-denied' error will be returned 
+           if the toaster service is disabled.";
+    }  // rpc cancel-toast
+
+    notification toastDone {
+      description
+        "Indicates that the toast in progress has completed.";
+      leaf toastStatus {
+        type enumeration {
+          enum "done" {
+            value 0;
+            description "The toast is done.";
+          }
+          enum "cancelled" {
+            value 1;
+            description
+              "The toast was cancelled.";
+          }
+          enum "error" {
+            value 2;
+            description
+              "The toaster service was disabled or
+                     the toaster is broken.";
+          }
+        }
+        description
+          "Indicates the final toast status";
+      }
+    }  // notification toastDone
+  }  // module toaster