Remove unused routedRpcRegistration
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / SalEchoServiceImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.services.sal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.impl.services.EchoService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
26
27 public final class SalEchoServiceImpl implements SalEchoService {
28     private final EchoService echoService;
29
30     public SalEchoServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
31         echoService = new EchoService(requestContextStack, deviceContext);
32     }
33
34     @Override
35     public ListenableFuture<RpcResult<SendEchoOutput>> sendEcho(final SendEchoInput sendEchoInput) {
36         final EchoInputBuilder echoInputBld = new EchoInputBuilder()
37                 .setData(sendEchoInput.getData());
38         return transform(echoService.handleServiceCall(echoInputBld));
39     }
40
41     private static ListenableFuture<RpcResult<SendEchoOutput>>
42             transform(final ListenableFuture<RpcResult<EchoOutput>> rpcResultListenableFuture) {
43         return Futures.transform(rpcResultListenableFuture, input -> {
44             requireNonNull(input, "echoOutput value is never expected to be NULL");
45             final RpcResult<SendEchoOutput> rpcOutput;
46             if (input.isSuccessful()) {
47                 final SendEchoOutput sendEchoOutput = new SendEchoOutputBuilder()
48                         .setData(input.getResult().getData())
49                         .build();
50                 rpcOutput = RpcResultBuilder.success(sendEchoOutput).build();
51             } else {
52                 rpcOutput = RpcResultBuilder.<SendEchoOutput>failed()
53                         .withRpcErrors(input.getErrors())
54                         .build();
55             }
56             return rpcOutput;
57         }, MoreExecutors.directExecutor());
58     }
59 }