2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.services;
10 import com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.Future;
15 import javax.annotation.Nullable;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
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;
27 public final class SalEchoServiceImpl implements SalEchoService {
29 private final EchoService echoService;
31 public SalEchoServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
32 echoService = new EchoService(requestContextStack, deviceContext);
36 public Future<RpcResult<SendEchoOutput>> sendEcho(final SendEchoInput sendEchoInput) {
37 final EchoInputBuilder echoInputBld = new EchoInputBuilder()
38 .setData(sendEchoInput.getData());
39 return transform(echoService.handleServiceCall(echoInputBld));
42 private Future<RpcResult<SendEchoOutput>> transform(final ListenableFuture<RpcResult<EchoOutput>> rpcResultListenableFuture) {
43 return Futures.transform(rpcResultListenableFuture, new Function<RpcResult<EchoOutput>, RpcResult<SendEchoOutput>>() {
46 public RpcResult<SendEchoOutput> apply(@Nullable final RpcResult<EchoOutput> input) {
47 Preconditions.checkNotNull(input, "echoOutput value is never expected to be NULL");
48 final RpcResult<SendEchoOutput> rpcOutput;
49 if (input.isSuccessful()) {
50 final SendEchoOutput sendEchoOutput = new SendEchoOutputBuilder()
51 .setData(input.getResult().getData())
53 rpcOutput = RpcResultBuilder.success(sendEchoOutput).build();
55 rpcOutput = RpcResultBuilder.<SendEchoOutput>failed()
56 .withRpcErrors(input.getErrors())