Wrap service handlers to method handleServiceCall.
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / OpendaylightFlowTableStatisticsServiceImpl.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 import java.math.BigInteger;
12 import com.google.common.util.concurrent.JdkFutureAdapters;
13 import java.util.concurrent.Future;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23
24 /**
25  * @author joe
26  */
27 public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements
28         OpendaylightFlowTableStatisticsService {
29
30     @Override
31     public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
32             final GetFlowTablesStatisticsInput input) {
33         return this.<GetFlowTablesStatisticsOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
34                 new Function<BigInteger, Future<RpcResult<Void>>>() {
35
36                     @Override
37                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
38                         final Xid xid = deviceContext.getNextXid();
39
40                         // Create multipart request body for fetch all the group stats
41                         final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
42                         final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
43                         multipartRequestTableBuilder.setEmpty(true);
44                         multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
45
46                         // Set request body to main multipart request
47                         final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
48                                 MultipartType.OFPMPFLOW, xid.getValue(), version);
49
50                         mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
51                         final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
52                                 .getConnectionAdapter().multipartRequest(mprInput.build());
53
54                         return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
55                     }
56                 });
57     }
58
59 }