23ad2165058d5c3a470429854bf43b4f996dff3e
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / SalAsyncConfigServiceImpl.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowplugin.impl.services.sal;
10
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.Objects;
14 import java.util.concurrent.Future;
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.singlelayer.SingleLayerGetAsyncConfigService;
18 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerSetAsyncConfigService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SalAsyncConfigService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
26
27 public class SalAsyncConfigServiceImpl implements SalAsyncConfigService {
28
29     private final SingleLayerSetAsyncConfigService setAsyncConfigService;
30     private final SingleLayerGetAsyncConfigService getAsyncConfigService;
31
32     public SalAsyncConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
33         setAsyncConfigService = new SingleLayerSetAsyncConfigService(requestContextStack, deviceContext);
34         getAsyncConfigService = new SingleLayerGetAsyncConfigService(requestContextStack, deviceContext);
35     }
36
37     @Override
38     public Future<RpcResult<Void>> setAsync(SetAsyncInput input) {
39         return setAsyncConfigService.handleServiceCall(input);
40     }
41
42     @Override
43     public Future<RpcResult<GetAsyncOutput>> getAsync(GetAsyncInput input) {
44         return Futures.transform(getAsyncConfigService.handleServiceCall(input), result ->
45                 Objects.nonNull(result) && result.isSuccessful()
46                         ? RpcResultBuilder.success(new GetAsyncOutputBuilder(result.getResult())).build()
47                         : RpcResultBuilder.<GetAsyncOutput>failed().build(),
48                 MoreExecutors.directExecutor());
49     }
50 }