ONOS-6645 RPC abstractions

Change-Id: Ia6fd6a3f0683e463586bb488e2d005170dfca317
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcHandler.java b/model/src/main/java/org/onosproject/yang/model/RegisterException.java
similarity index 60%
rename from model/src/main/java/org/onosproject/yang/model/RpcHandler.java
rename to model/src/main/java/org/onosproject/yang/model/RegisterException.java
index c1d92cd..5665445 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcHandler.java
+++ b/model/src/main/java/org/onosproject/yang/model/RegisterException.java
@@ -13,23 +13,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
 /**
- * Service for entities that would execute RPC methods invoked through
- * Dynamic Config RPC brokerage.
+ * Exceptions for use by the {@code DynamicConfigService}.
  */
-@Beta
-public interface RpcHandler {
-    /*
-     * Executes the RPC.
-     *
-     * @param msgId of the RPC message to be executed
-     * @param cmd to be executed
-     * @param input data to the RPC command
+public class RegisterException extends RuntimeException {
+    /**
+     * Constructs a new runtime exception with no error message.
      */
-    void executeRpc(Integer msgId, RpcCommand cmd, RpcInput input);
+    public RegisterException() {
+        super();
+    }
+
+    /**
+     * Constructs a new runtime exception with the given error message.
+     *
+     * @param message error message
+     */
+    public RegisterException(String message) {
+        super(message);
+    }
 }
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcCaller.java b/model/src/main/java/org/onosproject/yang/model/RpcCaller.java
deleted file mode 100644
index 7039fc8..0000000
--- a/model/src/main/java/org/onosproject/yang/model/RpcCaller.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Service for entities that would invoke RPCs and receive RPC responses,
- * through the Dynamic Config brokerage.
- */
-@Beta
-public interface RpcCaller {
-    /*
-     * Receives an RPC response.
-     *
-     * @param msgId of a previously invoked RPC
-     * @param output from the RPC execution
-     */
-    void receiveResponse(Integer msgId, RpcOutput output);
-}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcCommand.java b/model/src/main/java/org/onosproject/yang/model/RpcCommand.java
deleted file mode 100644
index 3aeb562..0000000
--- a/model/src/main/java/org/onosproject/yang/model/RpcCommand.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Abstract implementation of an RPC command.
- */
-@Beta
-public abstract class RpcCommand {
-    /**
-     * Identifier of an RPC command.
-     */
-    ResourceId cmdId;
-
-    /**
-     * Creates an instance of RpcCommand.
-     *
-     * @param cmdId of RPC command
-     */
-    public RpcCommand(ResourceId cmdId) {
-        this.cmdId = cmdId;
-    }
-
-    /**
-     * Returns the RPC command id.
-     *
-     * @return cmdId
-     */
-    public ResourceId cmdId() {
-        return this.cmdId;
-    }
-
-    /**
-     * Executes the RPC command.
-     *
-     * @param input input data to the RPC command.
-     */
-    public abstract void execute(RpcInput input);
-}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcInput.java b/model/src/main/java/org/onosproject/yang/model/RpcInput.java
index 08e54bb..27f75e6 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcInput.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcInput.java
@@ -16,17 +16,14 @@
 
 package org.onosproject.yang.model;
 
-import com.google.common.annotations.Beta;
-
 /**
  * Abstraction for RPC input.
  */
-@Beta
 public class RpcInput {
     /**
      * Input data to the RPC execution.
      */
-    DataNode input;
+    private DataNode data;
 
     /**
      * TODO
@@ -39,18 +36,18 @@
     /**
      * Creates an instance of RpcInput.
      *
-     * @param input to RPC execution
+     * @param data input for thr Rpc execution
      */
-    public RpcInput(DataNode input) {
-        this.input = input;
+    public RpcInput(DataNode data) {
+        this.data = data;
     }
 
     /**
-     * Returns RPC input.
+     * Returns the data specified in this input.
      *
-     * @return DataNode
+     * @return data specified in this input
      */
-    public DataNode input() {
-        return this.input;
+    public DataNode data() {
+        return this.data;
     }
 }
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcOutput.java b/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
index 8e6b255..dd13ada 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcOutput.java
@@ -16,12 +16,9 @@
 
 package org.onosproject.yang.model;
 
-import com.google.common.annotations.Beta;
-
 /**
  * Abstraction for RPC output.
  */
-@Beta
 public class RpcOutput {
     public enum Status {
         /**
@@ -41,7 +38,10 @@
          */
         RPC_TIMEOUT,
     }
-
+    /**
+     * Message id of the Rpc request.
+     */
+    String messageId;
     /**
      * Status of RPC execution.
      */
@@ -49,23 +49,45 @@
     /**
      * Output data from the RPC execution.
      */
-    DataNode output;
+    DataNode data;
 
     /**
      * Creates an instance of RpcOutput.
      *
      * @param status of RPC execution
-     * @param output of RPC execution
+     * @param data of RPC execution
      */
-    public RpcOutput(Status status, DataNode output) {
+    public RpcOutput(Status status, DataNode data) {
         this.status = status;
-        this.output = output;
+        this.data = data;
+    }
+
+    /**
+     * Creates an instance of RpcOutput.
+     *
+     * @param messageId of the Rpc request
+     * @param status of RPC execution
+     * @param data of RPC execution
+     */
+    public RpcOutput(String messageId, Status status, DataNode data) {
+        this.messageId = messageId;
+        this.status = status;
+        this.data = data;
+    }
+
+    /**
+     * Returns messageId of the Rpc request.
+     *
+     * @return messageId
+     */
+    public String messageId() {
+        return this.messageId;
     }
 
     /**
      * Returns RPC status.
      *
-     * @return Status
+     * @return status
      */
     public RpcOutput.Status status() {
         return this.status;
@@ -74,9 +96,17 @@
     /**
      * Returns RPC output.
      *
-     * @return DataNode
+     * @return output data
      */
-    public DataNode output() {
-        return this.output;
+    public DataNode data() {
+        return this.data;
+    }
+
+    /**
+     * Sets the messageId in the Rpc output.
+     * @param msgId the msgId to be set in the Rpc output
+     */
+    public void messageId(String msgId) {
+        this.messageId = msgId;
     }
 }
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java b/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java
new file mode 100644
index 0000000..0f554f4
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/RpcRegistry.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.model;
+
+import com.google.common.annotations.Beta;
+
+import java.util.Set;
+
+/**
+ * Entity capable of tracking RPC service end-points.
+ */
+@Beta
+public interface RpcRegistry {
+    /**
+     * Returns the set of all registered service implementations.
+     *
+     * @return set of service implementations
+     */
+    Set<RpcService> getRpcServices();
+
+    /**
+     * Returns the RPC service implementation registered with the specified
+     * RPC service interface.
+     *
+     * @param serviceInterface RPC service interface
+     * @return RPC service implementation
+     */
+    RpcService getRpcService(Class<? extends RpcService> serviceInterface);
+
+    /**
+     * Registers the specified RPC service.
+     *
+     * @param service service implementation to be registered
+     * @throws RegisterException if register failed
+     */
+    void registerRpcService(RpcService service);
+
+    /**
+     * Registers the specified RPC service.
+     *
+     * @param service service implementation to be registered
+     * @throws RegisterException if unregister failed
+     */
+    void unregisterRpcService(RpcService service);
+}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/RpcService.java b/model/src/main/java/org/onosproject/yang/model/RpcService.java
index 2f19b5f..5e4fabd 100644
--- a/model/src/main/java/org/onosproject/yang/model/RpcService.java
+++ b/model/src/main/java/org/onosproject/yang/model/RpcService.java
@@ -18,8 +18,8 @@
 
 /**
  * Token representation of a YANG RPC end-point.
- * <p>
+ *
  * All generated RPC interfaces will extend this interface.
  */
 public interface RpcService {
-}
+}
\ No newline at end of file
diff --git a/model/src/main/java/org/onosproject/yang/model/YangRpcService.java b/model/src/main/java/org/onosproject/yang/model/YangRpcService.java
deleted file mode 100644
index c9d28f2..0000000
--- a/model/src/main/java/org/onosproject/yang/model/YangRpcService.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yang.model;
-
-/**
- * Representation of an entity that provides YANG RPC service.
- */
-public interface YangRpcService {
-
-    /**
-     * Registers an RPC handler.
-     *
-     * @param handler RPC handler
-     * @param command RPC command
-     */
-    void registerHandler(RpcHandler handler, RpcCommand command);
-
-    /**
-     * Unregisters an RPC receiver.
-     *
-     * @param handler RPC handler
-     * @param command RPC command
-     */
-    void unRegisterHandler(RpcHandler handler, RpcCommand command);
-
-    /**
-     * Invokes an RPC.
-     *
-     * @param caller  of the of the RPC
-     * @param msgId   RPC message id
-     * @param command RPC command
-     * @param input   RPC input
-     */
-    void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command,
-                   RpcInput input);
-
-    /**
-     * Provides response to a a previously invoked RPC.
-     *
-     * @param msgId  of a previously invoked RPC
-     * @param output data from the RPC execution
-     */
-    void rpcResponse(Integer msgId, RpcOutput output);
-}