Bump MRI upstreams
[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 package org.opendaylight.openflowplugin.impl.services.sal;
9
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGetAsyncConfigService;
16 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerSetAsyncConfigService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SalAsyncConfigService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncOutput;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
25
26 public class SalAsyncConfigServiceImpl implements SalAsyncConfigService {
27
28     private final SingleLayerSetAsyncConfigService setAsyncConfigService;
29     private final SingleLayerGetAsyncConfigService getAsyncConfigService;
30
31     public SalAsyncConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
32         setAsyncConfigService = new SingleLayerSetAsyncConfigService(requestContextStack, deviceContext);
33         getAsyncConfigService = new SingleLayerGetAsyncConfigService(requestContextStack, deviceContext);
34     }
35
36     @Override
37     public ListenableFuture<RpcResult<SetAsyncOutput>> setAsync(final SetAsyncInput input) {
38         return setAsyncConfigService.handleServiceCall(input);
39     }
40
41     @Override
42     public ListenableFuture<RpcResult<GetAsyncOutput>> getAsync(final GetAsyncInput input) {
43         return Futures.transform(getAsyncConfigService.handleServiceCall(input), result ->
44                 result != null && result.isSuccessful()
45                         ? RpcResultBuilder.success(new GetAsyncOutputBuilder(result.getResult()).build()).build()
46                         : RpcResultBuilder.<GetAsyncOutput>failed().build(),
47                 MoreExecutors.directExecutor());
48     }
49 }