Migrate restconf to MD-SAL APIs
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfInvokeOperationsServiceImpl.java
index 71c6c6c3b0a19cb48db3922ccc41534dd3732879..deb3fd160fb7c421ecc95b91d92d50d50e2afa99 100644 (file)
@@ -8,9 +8,10 @@
 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
 import java.net.URI;
+import javax.ws.rs.Path;
 import javax.ws.rs.core.UriInfo;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -31,10 +32,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  * Implementation of {@link RestconfInvokeOperationsService}.
  *
  */
+@Path("/")
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
 
-    private final RpcServiceHandler rpcServiceHandler;
-    private final SchemaContextHandler schemaContextHandler;
+    private volatile RpcServiceHandler rpcServiceHandler;
+    private volatile SchemaContextHandler schemaContextHandler;
 
     public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
             final SchemaContextHandler schemaContextHandler) {
@@ -42,6 +44,17 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         this.schemaContextHandler = schemaContextHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof RpcServiceHandler) {
+                rpcServiceHandler = (RpcServiceHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
                                            final UriInfo uriInfo) {
@@ -74,11 +87,12 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response);
 
         RpcDefinition resultNodeSchema = null;
-        final NormalizedNode<?, ?> resultData = result.getResult();
-        if ((result != null) && (result.getResult() != null)) {
+        NormalizedNode<?, ?> resultData = null;
+        if (result != null && result.getResult() != null) {
+            resultData = result.getResult();
             resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
         }
-        return new NormalizedNodeContext(new InstanceIdentifierContext<RpcDefinition>(null, resultNodeSchema,
+        return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema,
                 mountPoint, schemaContextRef.get()), resultData);
     }
 }