Wrap service handlers to method handleServiceCall.
[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.base.Function;
11
12 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import java.math.BigInteger;
22 import java.util.concurrent.Future;
23
24 public class SalPortServiceImpl extends CommonService implements SalPortService {
25     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalPortServiceImpl.class);
26
27     @Override
28     public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
29         return this.<UpdatePortOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
30                 new Function<BigInteger, Future<RpcResult<Void>>>() {
31                     @Override
32                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
33                         final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
34                         final PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
35                         final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
36                         mdInput.setXid(deviceContext.getNextXid().getValue());
37                         return provideConnectionAdapter(IDConnection).portMod(mdInput.build());
38                     }
39                 });
40     }
41
42 }