OFJResult2RequestCtxFuture uses listenable future
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalPortServiceImpl.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;
9
10 import com.google.common.util.concurrent.JdkFutureAdapters;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
13
14 import com.google.common.base.Function;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.slf4j.Logger;
24 import java.util.concurrent.Future;
25
26 public class SalPortServiceImpl extends CommonService implements SalPortService {
27     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalPortServiceImpl.class);
28
29     @Override
30     public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
31         return this.<UpdatePortOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
32                 new Function<DataCrate<UpdatePortOutput>, ListenableFuture<RpcResult<Void>>>() {
33                     @Override
34                     public ListenableFuture<RpcResult<Void>> apply(final DataCrate<UpdatePortOutput> data) {
35                         final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
36                         final PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
37                         final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
38                         Xid xid = deviceContext.getNextXid();
39                         mdInput.setXid(xid.getValue());
40                         data.getRequestContext().setXid(xid);
41                         return JdkFutureAdapters.listenInPoolThread(provideConnectionAdapter(data.getiDConnection()).portMod(mdInput.build()));
42                     }
43                 });
44     }
45
46 }