Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SendEchoImpl.java
similarity index 68%
rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImpl.java
rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SendEchoImpl.java
index a857d4f5bc96e3144930e944c612a0be46a540dc..9482519f26c0f2596ccdfc376d97fa3fabf4e491 100644 (file)
@@ -5,7 +5,7 @@
  * 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.openflowplugin.impl.services.sal;
+package org.opendaylight.openflowplugin.impl.services;
 
 import static java.util.Objects.requireNonNull;
 
@@ -14,33 +14,25 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.impl.services.EchoService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEcho;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
-public final class SalEchoServiceImpl implements SalEchoService {
-    private final EchoService echoService;
-
-    public SalEchoServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
-        echoService = new EchoService(requestContextStack, deviceContext);
+public final class SendEchoImpl extends AbstractSimpleService<EchoInputBuilder, EchoOutput> implements SendEcho {
+    public SendEchoImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext, EchoOutput.class);
     }
 
     @Override
-    public ListenableFuture<RpcResult<SendEchoOutput>> sendEcho(final SendEchoInput sendEchoInput) {
-        final EchoInputBuilder echoInputBld = new EchoInputBuilder()
-                .setData(sendEchoInput.getData());
-        return transform(echoService.handleServiceCall(echoInputBld));
-    }
-
-    private static ListenableFuture<RpcResult<SendEchoOutput>>
-            transform(final ListenableFuture<RpcResult<EchoOutput>> rpcResultListenableFuture) {
-        return Futures.transform(rpcResultListenableFuture, input -> {
+    public ListenableFuture<RpcResult<SendEchoOutput>> invoke(final SendEchoInput sendEchoInput) {
+        return Futures.transform(handleServiceCall(new EchoInputBuilder().setData(sendEchoInput.getData())), input -> {
             requireNonNull(input, "echoOutput value is never expected to be NULL");
             final RpcResult<SendEchoOutput> rpcOutput;
             if (input.isSuccessful()) {
@@ -56,4 +48,12 @@ public final class SalEchoServiceImpl implements SalEchoService {
             return rpcOutput;
         }, MoreExecutors.directExecutor());
     }
+
+    @Override
+    protected OfHeader buildRequest(final Xid xid, final EchoInputBuilder input) {
+        return input
+                .setXid(xid.getValue())
+                .setVersion(getVersion())
+                .build();
+    }
 }