[ONOS-7278] Fix for Rpc.
- use qualified name for handlerRegistry key
- stop creating executor on every rpc call
- removed unused method
Change-Id: I2637b8443629e3fbae354d1e6af8639c6047ef8a
diff --git a/apps/config/src/main/java/org/onosproject/config/ResourceIdParser.java b/apps/config/src/main/java/org/onosproject/config/ResourceIdParser.java
index 6dee677..50e807a 100644
--- a/apps/config/src/main/java/org/onosproject/config/ResourceIdParser.java
+++ b/apps/config/src/main/java/org/onosproject/config/ResourceIdParser.java
@@ -231,17 +231,6 @@
return bldr.toString();
}
- public static String[] getService(ResourceId path) {
- String[] res = new String[2];
- if (path == null) {
- return res;
- }
- int last = path.nodeKeys().size() - 1;
- res[0] = path.nodeKeys().get(last - 1).schemaId().name();
- res[1] = path.nodeKeys().get(last).schemaId().name();
- return res;
- }
-
private static void parseLeafList(LeafListKey key, StringBuilder bldr) {
bldr.append(key.schemaId().name());
bldr.append(NM_SEP);
diff --git a/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java b/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
index d90a938..d976a40 100644
--- a/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
+++ b/apps/config/src/main/java/org/onosproject/config/impl/DynamicConfigManager.java
@@ -21,7 +21,6 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
-import org.onosproject.config.ResourceIdParser;
import org.onosproject.config.RpcExecutor;
import org.onosproject.config.RpcMessageId;
import org.onosproject.d.config.DeviceResourceIds;
@@ -40,15 +39,16 @@
import org.onosproject.yang.model.DataNode.Type;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.RpcContext;
import org.onosproject.yang.model.RpcRegistry;
import org.onosproject.yang.model.RpcService;
+import org.onosproject.yang.model.SchemaContextProvider;
+
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
-
import org.slf4j.Logger;
import static org.onosproject.d.config.DeviceResourceIds.DCS_NAMESPACE;
@@ -69,6 +69,11 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DynamicConfigStore store;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected SchemaContextProvider contextProvider;
+
+ // FIXME is it OK this is not using the Store?
private ConcurrentHashMap<String, RpcService> handlerRegistry = new ConcurrentHashMap<>();
@Activate
@@ -153,14 +158,14 @@
@Override
public RpcService getRpcService(Class<? extends RpcService> intfc) {
- return handlerRegistry.get(intfc.getSimpleName());
+ return handlerRegistry.get(intfc.getName());
}
@Override
public void registerRpcService(RpcService handler) {
for (Class<?> intfc : handler.getClass().getInterfaces()) {
if (RpcService.class.isAssignableFrom(intfc)) {
- handlerRegistry.put(intfc.getSimpleName(), handler);
+ handlerRegistry.put(intfc.getName(), handler);
}
}
}
@@ -169,7 +174,7 @@
public void unregisterRpcService(RpcService handler) {
for (Class<?> intfc : handler.getClass().getInterfaces()) {
if (RpcService.class.isAssignableFrom(intfc)) {
- String key = intfc.getSimpleName();
+ String key = intfc.getName();
if (handlerRegistry.get(key) == null) {
throw new FailedException("No registered handler found, cannot unregister");
}
@@ -181,7 +186,7 @@
private int getSvcId(RpcService handler, String srvc) {
Class<?>[] intfcs = handler.getClass().getInterfaces();
for (int i = 0; i < intfcs.length; i++) {
- if (intfcs[i].getSimpleName().compareTo(srvc) == 0) {
+ if (intfcs[i].getName().compareTo(srvc) == 0) {
return i;
}
}
@@ -190,14 +195,15 @@
@Override
public CompletableFuture<RpcOutput> invokeRpc(ResourceId id, RpcInput input) {
- String[] ctxt = ResourceIdParser.getService(id);
- RpcService handler = handlerRegistry.get(ctxt[0]);
+ RpcContext context = contextProvider.getRpcContext(id);
+ String srvcIntf = context.serviceIntf().getName();
+ RpcService handler = handlerRegistry.get(srvcIntf);
if (handler == null) {
throw new FailedException("No registered handler found, cannot invoke");
}
return CompletableFuture.supplyAsync(
- new RpcExecutor(handler, getSvcId(handler, ctxt[0]), ctxt[1], RpcMessageId.generate(), input),
- Executors.newSingleThreadExecutor());
+ new RpcExecutor(handler, getSvcId(handler, srvcIntf),
+ context.rpcName(), RpcMessageId.generate(), input));
}
/**