Added support for binding-independent RPCs 12/112/1
authorTony Tkacik <ttkacik@cisco.com>
Fri, 5 Apr 2013 11:11:04 +0000 (13:11 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 5 Apr 2013 11:11:04 +0000 (13:11 +0200)
Implemented the support for binding-independent RPCs directly into BrokerImpl,
and removed unused placeholders for functionality.

Cleanup:
  - Moved Session Implementations directly into BrokerImpl as private inner
    classes, because they are BrokerImpl specific.
  - Removed unnecessary packages.
  - Extracted RPC utils from sal-broker-impl to sal-common-utils to be reusable
    for other components without introducing dependency on sal-broker-impl.

Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
18 files changed:
opendaylight/sal/yang-prototype/sal/pom.xml
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/BrokerServiceImpl.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/DataBrokerModule.java [moved from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/DataBrokerModule.java with 86% similarity]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/NotificationModule.java [moved from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/NotificationModule.java with 86% similarity]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java [deleted file]
opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java [moved from opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/RpcUtils.java with 60% similarity]
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/data/DataBrokerService.java
opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/sal/sal-core-demo/src/main/java/org/opendaylight/controller/sal/demo/SALDemo.java

index 1b633b4..9f77613 100644 (file)
@@ -7,15 +7,15 @@
        <packaging>pom</packaging>\r
 \r
        <modules>\r
+               <module>sal-common</module>\r
+               <module>sal-common-util</module>\r
                <module>sal-core-api</module>\r
                <module>sal-data-api</module>\r
                <module>sal-binding-api</module>\r
                <module>sal-binding-spi</module>\r
                <module>sal-binding-broker-impl</module>\r
                <module>sal-schema-repository-api</module>\r
-               <module>sal-common</module>\r
                <module>sal-core-spi</module>\r
-               <module>../yang</module>\r
                <module>sal-broker-impl</module>\r
                <module>sal-core-demo</module>\r
        </modules>\r
                                <artifactId>slf4j-api</artifactId>\r
                                <version>1.7.2</version>\r
                        </dependency>\r
+                       <dependency>\r
+                               <groupId>junit</groupId>\r
+                               <artifactId>junit</artifactId>\r
+                               <version>4.10</version>\r
+                       </dependency>\r
                </dependencies>\r
        </dependencyManagement>\r
 \r
@@ -40,7 +45,6 @@
                <dependency>\r
                        <groupId>junit</groupId>\r
                        <artifactId>junit</artifactId>\r
-                       <version>4.10</version>\r
                        <scope>test</scope>\r
                        <optional>true</optional>\r
                </dependency>\r
index d81c6ac..c195fe4 100644 (file)
                        <artifactId>sal-core-api</artifactId>\r
                        <version>1.0-SNAPSHOT</version>\r
                </dependency>\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-core-spi</artifactId>\r
index 84bc056..b8a0b97 100644 (file)
@@ -1,4 +1,3 @@
-
 /*\r
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
  *\r
@@ -8,46 +7,55 @@
  */\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
-\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;
-import org.opendaylight.controller.yang.common.RpcResult;
-import org.opendaylight.controller.yang.data.api.CompositeNode;
+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
-\r
 public class BrokerImpl implements Broker {\r
     private static Logger log = LoggerFactory.getLogger(BrokerImpl.class);\r
 \r
-    private Set<ConsumerSessionImpl> sessions = new HashSet<ConsumerSessionImpl>();\r
-    private Set<ProviderSessionImpl> providerSessions = new HashSet<ProviderSessionImpl>();\r
-    // private ExecutorService executor;\r
-    private Set<BrokerModule> modules = new HashSet<BrokerModule>();\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
-    private Map<Class<? extends BrokerService>, BrokerModule> serviceProviders = new HashMap<Class<? extends BrokerService>, BrokerModule>();\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
-\r
         ConsumerSessionImpl session = newSessionFor(consumer);\r
         consumer.onSessionInitiated(session);\r
-\r
         sessions.add(session);\r
-\r
         return session;\r
-\r
     }\r
 \r
     @Override\r
@@ -56,11 +64,26 @@ public class BrokerImpl implements Broker {
 \r
         ProviderSessionImpl session = newSessionFor(provider);\r
         provider.onSessionInitiated(session);\r
-\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
@@ -71,11 +94,43 @@ public class BrokerImpl implements Broker {
         return prov.getServiceForSession(service, session);\r
     }\r
 \r
-    public Future<RpcResult<CompositeNode>> invokeRpc(QName rpc,\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
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\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
@@ -96,34 +151,130 @@ public class BrokerImpl implements Broker {
         }\r
     }\r
 \r
+    // Private Factory methods\r
+    \r
     private ConsumerSessionImpl newSessionFor(Consumer cons) {\r
-        return new ConsumerSessionImpl(this, cons);\r
+        return new ConsumerSessionImpl(cons);\r
     }\r
 \r
     private ProviderSessionImpl newSessionFor(Provider provider) {\r
-        return new ProviderSessionImpl(this, provider);\r
+        return new ProviderSessionImpl(provider);\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
+    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
-        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
+        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
-    public void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) {\r
-        sessions.remove(consumerSessionImpl);\r
-        providerSessions.remove(consumerSessionImpl);\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
-
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerServiceImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/BrokerServiceImpl.java
deleted file mode 100644 (file)
index 4f25443..0000000
+++ /dev/null
@@ -1,16 +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.core.impl;\r
-\r
-import org.opendaylight.controller.sal.core.api.BrokerService;\r
-\r
-abstract public class BrokerServiceImpl implements BrokerService {\r
-\r
-    ConsumerSessionImpl session;\r
-}\r
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java
deleted file mode 100644 (file)
index 032dd22..0000000
+++ /dev/null
@@ -1,75 +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.core.impl;\r
-\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.concurrent.Future;\r
-\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.Broker.ConsumerSession;\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
-public class ConsumerSessionImpl implements ConsumerSession {\r
-\r
-    private final BrokerImpl broker;\r
-    private final Consumer consumer;\r
-\r
-    private Map<Class<? extends BrokerService>, BrokerService> instantiatedServices = new HashMap<Class<? extends BrokerService>, BrokerService>();\r
-    private boolean closed = false;\r
-\r
-    public Consumer getConsumer() {\r
-        return consumer;\r
-    }\r
-\r
-    public ConsumerSessionImpl(BrokerImpl broker, Consumer consumer) {\r
-        this.broker = broker;\r
-        this.consumer = consumer;\r
-    }\r
-\r
-    @Override\r
-    public Future<RpcResult<CompositeNode>> rpc(QName rpc, CompositeNode input) {\r
-        return broker.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 = this.broker.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
-        broker.consumerSessionClosed(this);\r
-    }\r
-\r
-    @Override\r
-    public boolean isClosed() {\r
-        return closed;\r
-    }\r
-\r
-}
@@ -5,7 +5,7 @@
  * 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.data;\r
+package org.opendaylight.controller.sal.core.impl;\r
 \r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
@@ -13,9 +13,11 @@ import java.util.HashSet;
 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
@@ -27,7 +29,6 @@ import org.opendaylight.controller.sal.core.api.data.DataProviderService;
 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.impl.RpcUtils;\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
@@ -36,33 +37,40 @@ import org.opendaylight.controller.yang.data.api.CompositeNodeModification;
 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
-        // FIXME: Refactor\r
-        Set<Class<? extends BrokerService>> ret = new HashSet<Class<? extends BrokerService>>();\r
-        ret.add(DataBrokerService.class);\r
-        ret.add(DataProviderService.class);\r
-        return ret;\r
+        return PROVIDED_SESSION_SERVICES;\r
     }\r
 \r
     @Override\r
     public Set<Class<? extends ProviderFunctionality>> getSupportedProviderFunctionality() {\r
-        // FIXME Refactor\r
-        Set<Class<? extends ProviderFunctionality>> ret = new HashSet<Class<? extends ProviderFunctionality>>();\r
-        ret.add(DataValidator.class);\r
-        ret.add(DataCommitHandler.class);\r
-        ret.add(DataRefresher.class);\r
-        return ret;\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
@@ -85,25 +93,24 @@ public class DataBrokerModule implements BrokerModule {
     }\r
 \r
     private DataProviderService newDataProviderService(ConsumerSession session) {\r
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\r
+        return new DataProviderSession();\r
     }\r
 \r
     private DataBrokerService newDataConsumerService(ConsumerSession session) {\r
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\r
+        return new DataConsumerSession();\r
     }\r
 \r
-    @Override\r
-    public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {\r
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\r
+    private StoreContext context(DataStoreIdentifier store) {\r
+        return storeContext.get(store);\r
     }\r
 \r
     private static class StoreContext {\r
-        private Set<DataCommitHandler> commitHandlers = new HashSet<DataCommitHandler>();\r
-        private Set<DataValidator> validators = new HashSet<DataValidator>();\r
-        private Set<DataRefresher> refreshers = new HashSet<DataRefresher>();\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
@@ -153,10 +160,12 @@ public class DataBrokerModule implements BrokerModule {
             throw new UnsupportedOperationException("Not implemented");\r
         }\r
 \r
-    }\r
+        @Override\r
+        public Set<DataStoreIdentifier> getDataStores() {\r
+            // TODO Auto-generated method stub\r
+            return null;\r
+        }\r
 \r
-    private StoreContext context(DataStoreIdentifier store) {\r
-        return storeContext.get(store);\r
     }\r
 \r
     private class DataProviderSession extends DataConsumerSession implements\r
@@ -265,7 +274,7 @@ public class DataBrokerModule implements BrokerModule {
             }\r
             CommitTransaction transaction = new SequentialCommitTransaction(\r
                     store, transactions);\r
-            return RpcUtils.getRpcResult(successful, transaction, errors);\r
+            return Rpcs.getRpcResult(successful, transaction, errors);\r
         }\r
 \r
         @Override\r
@@ -306,7 +315,7 @@ public class DataBrokerModule implements BrokerModule {
                     break;\r
             }\r
 \r
-            return RpcUtils.getRpcResult(successful, null, errors);\r
+            return Rpcs.getRpcResult(successful, null, errors);\r
         }\r
 \r
         @Override\r
@@ -330,7 +339,7 @@ public class DataBrokerModule implements BrokerModule {
                     break;\r
             }\r
 \r
-            return RpcUtils.getRpcResult(successful, null, errors);\r
+            return Rpcs.getRpcResult(successful, null, errors);\r
         }\r
 \r
         @Override\r
@@ -374,7 +383,7 @@ public class DataBrokerModule implements BrokerModule {
                     break;\r
             }\r
 \r
-            return RpcUtils.getRpcResult(successful, null, errors);\r
+            return Rpcs.getRpcResult(successful, null, errors);\r
         }\r
 \r
         @Override\r
@@ -408,4 +417,3 @@ public class DataBrokerModule implements BrokerModule {
         }\r
     }\r
 }\r
-
@@ -22,7 +22,6 @@ import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality;
 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.impl.BrokerServiceImpl;\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
@@ -40,21 +39,25 @@ public class NotificationModule implements BrokerModule {
     private Multimap<QName, NotificationListener> listeners = HashMultimap\r
             .create();\r
 \r
-    private static final Set<Class<? extends BrokerService>> providedServices = ImmutableSet\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 providedServices;\r
+        return PROVIDED_SERVICE_TYPE;\r
     }\r
 \r
     @Override\r
     public Set<Class<? extends ConsumerFunctionality>> getSupportedConsumerFunctionality() {\r
-        // FIXME Refactor\r
-        Set<Class<? extends ConsumerFunctionality>> ret = new HashSet<Class<? extends ConsumerFunctionality>>();\r
-        ret.add(NotificationListener.class);\r
-        return ret;\r
+        return SUPPORTED_CONSUMER_FUNCTIONALITY;\r
     }\r
 \r
     @Override\r
@@ -107,8 +110,8 @@ public class NotificationModule implements BrokerModule {
         return new NotificationProviderSessionImpl();\r
     }\r
 \r
-    private class NotificationConsumerSessionImpl extends BrokerServiceImpl\r
-            implements NotificationService {\r
+    private class NotificationConsumerSessionImpl implements\r
+            NotificationService {\r
 \r
         private Multimap<QName, NotificationListener> consumerListeners = HashMultimap\r
                 .create();\r
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ProviderSessionImpl.java
deleted file mode 100644 (file)
index e87b8bb..0000000
+++ /dev/null
@@ -1,48 +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.core.impl;\r
-\r
-import java.util.Set;\r
-\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
-public class ProviderSessionImpl extends ConsumerSessionImpl implements\r
-        ProviderSession {\r
-\r
-    private Provider provider;\r
-\r
-    public ProviderSessionImpl(BrokerImpl broker, Provider provider) {\r
-        super(broker, null);\r
-        this.provider = provider;\r
-    }\r
-\r
-    @Override\r
-    public void addRpcImplementation(QName rpcType,\r
-            RpcImplementation implementation) throws IllegalArgumentException {\r
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\r
-    }\r
-\r
-    @Override\r
-    public void removeRpcImplementation(QName rpcType,\r
-            RpcImplementation implementation) throws IllegalArgumentException {\r
-        // TODO Implement this method\r
-        throw new UnsupportedOperationException("Not implemented");\r
-    }\r
-\r
-    public Provider getProvider() {\r
-        return this.provider;\r
-    }\r
-\r
-}\r
-
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/data/package-info.java
deleted file mode 100644 (file)
index 34fa5e4..0000000
+++ /dev/null
@@ -1,10 +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.core.impl.data;
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/notify/package-info.java
deleted file mode 100644 (file)
index c068196..0000000
+++ /dev/null
@@ -1,9 +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.core.impl.notify;
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java
deleted file mode 100644 (file)
index 58ceb5f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.opendaylight.controller.sal.core.impl.rpc;\r
-\r
-public interface RpcModule {\r
-\r
-}\r
diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/package-info.java
deleted file mode 100644 (file)
index 41e9bcb..0000000
+++ /dev/null
@@ -1,8 +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.core.impl.rpc;
\ No newline at end of file
diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-common-util/pom.xml
new file mode 100644 (file)
index 0000000..b8be514
--- /dev/null
@@ -0,0 +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
+                       <version>1.0</version>\r
+               </dependency>\r
+               <dependency>\r
+                       <groupId>org.opendaylight.controller</groupId>\r
+                       <artifactId>sal-common</artifactId>\r
+                       <version>1.0-SNAPSHOT</version>\r
+               </dependency>\r
+       </dependencies>
+
+</project>
\ No newline at end of file
@@ -5,38 +5,17 @@
  * 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
+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 java.util.List;\r
-import java.util.concurrent.Callable;\r
-\r
-import org.opendaylight.controller.sal.core.api.RpcImplementation;\r
-import org.opendaylight.controller.yang.common.QName;\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
-\r
-\r
-public class RpcUtils {\r
-\r
-    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
+public class Rpcs {\r
     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,\r
-            List<RpcError> errors) {\r
+            Collection<RpcError> errors) {\r
         RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);\r
         return ret;\r
     }\r
@@ -47,7 +26,8 @@ public class RpcUtils {
         private final T result;\r
         private final boolean successful;\r
 \r
-        public RpcResultTO(boolean successful, T result, List<RpcError> errors) {\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
@@ -71,4 +51,3 @@ public class RpcUtils {
 \r
     }\r
 }\r
-
index abdd3ad..7ced174 100644 (file)
@@ -1,27 +1,29 @@
-<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">\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-core-api</artifactId>\r
-   \r
-   <dependencies>\r
-               <dependency>\r
-               <groupId>org.opendaylight.controller</groupId>\r
-               <artifactId>sal-common</artifactId>\r
-               <version>1.0-SNAPSHOT</version>\r
-       </dependency>\r
-       <dependency>\r
-               <groupId>org.opendaylight.controller</groupId>\r
-               <artifactId>yang-data-api</artifactId>\r
-               <version>1.0</version>\r
-       </dependency>\r
-       <dependency>\r
-               <groupId>org.opendaylight.controller</groupId>\r
-               <artifactId>yang-model-api</artifactId>\r
-               <version>1.0</version>\r
-       </dependency>\r
-   </dependencies>
+<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-core-api</artifactId>\r
+\r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>org.opendaylight.controller</groupId>\r
+                       <artifactId>sal-common</artifactId>\r
+                       <version>1.0-SNAPSHOT</version>\r
+               </dependency>\r
+\r
+               <dependency>\r
+                       <groupId>org.opendaylight.controller</groupId>\r
+                       <artifactId>yang-data-api</artifactId>\r
+                       <version>1.0</version>\r
+               </dependency>\r
+               <dependency>\r
+                       <groupId>org.opendaylight.controller</groupId>\r
+                       <artifactId>yang-model-api</artifactId>\r
+                       <version>1.0</version>\r
+               </dependency>\r
+       </dependencies>
 </project>
\ No newline at end of file
index f5f3938..d74a7d1 100644 (file)
@@ -7,6 +7,7 @@
  */\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
@@ -29,6 +30,9 @@ import org.opendaylight.controller.yang.data.api.Node;
  */\r
 public interface DataBrokerService extends BrokerService {\r
 \r
+    \r
+    Set<DataStoreIdentifier> getDataStores();\r
+    \r
     /**\r
      * Returns a data from specified Data Store.\r
      * \r
diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/model/SchemaService.java
new file mode 100644 (file)
index 0000000..22abdc2
--- /dev/null
@@ -0,0 +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
index b582349..fa0ea39 100644 (file)
@@ -12,7 +12,7 @@ import java.io.IOException;
 import java.io.InputStreamReader;\r
 \r
 import org.opendaylight.controller.sal.core.impl.BrokerImpl;\r
-import org.opendaylight.controller.sal.core.impl.notify.NotificationModule;\r
+import org.opendaylight.controller.sal.core.impl.NotificationModule;\r
 \r
 \r
 public class SALDemo {\r