Wrap service handlers to method handleServiceCall.
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalGroupServiceImpl.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.GroupConvertor;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.slf4j.Logger;
24 import java.math.BigInteger;
25 import java.util.concurrent.Future;
26
27 public class SalGroupServiceImpl extends CommonService implements SalGroupService {
28
29     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalGroupServiceImpl.class);
30
31     @Override
32     public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
33         return this.<AddGroupOutput, Void> handleServiceCall( PRIMARY_CONNECTION,
34                  new Function<BigInteger,Future<RpcResult<Void>>>() {
35
36                     @Override
37                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
38                         return convertAndSend(input, IDConnection);
39                     }
40                 });
41     }
42
43     @Override
44     public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
45         return this.<UpdateGroupOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
46                 new Function<BigInteger, Future<RpcResult<Void>>>() {
47
48                     @Override
49                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
50                         return convertAndSend(input.getUpdatedGroup(), IDConnection);
51                     }
52                 });
53     }
54
55     @Override
56     public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
57         return this.<RemoveGroupOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
58                 new Function<BigInteger, Future<RpcResult<Void>>>() {
59
60                     @Override
61                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
62                         return convertAndSend(input, IDConnection);
63                     }
64                 });
65     }
66
67     Future<RpcResult<Void>> convertAndSend(final Group iputGroup, final BigInteger IDConnection) {
68         final GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(iputGroup, version, datapathId);
69         ofGroupModInput.setXid(deviceContext.getNextXid().getValue());
70         return provideConnectionAdapter(IDConnection).groupMod(ofGroupModInput.build());
71     }
72 }