OFJResult2RequestCtxFuture uses listenable future
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / FlowStatisticsService.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
9 package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
10
11 import com.google.common.base.Function;
12 import com.google.common.util.concurrent.JdkFutureAdapters;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.List;
15 import java.util.concurrent.Future;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
18 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
19 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
20 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
21 import org.opendaylight.openflowplugin.impl.services.CommonService;
22 import org.opendaylight.openflowplugin.impl.services.DataCrate;
23 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28
29 /**
30  * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
31  */
32 public class FlowStatisticsService extends CommonService {
33     public FlowStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
34         super(requestContextStack, deviceContext);
35     }
36
37     public Future<RpcResult<List<MultipartReply>>> getAllFlowsStatisticsFromAllFlowTables(final MultiMsgCollector multiMsgCollector) {
38         return handleServiceCall(
39                 PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, ListenableFuture<RpcResult<Void>>>() {
40                     @Override
41                     public ListenableFuture<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
42
43                         final Xid xid = deviceContext.getNextXid();
44                         data.getRequestContext().setXid(xid);
45                         multiMsgCollector.registerMultipartXid(xid.getValue());
46
47                         final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
48                                 .getConnectionAdapter().multipartRequest(MultipartRequestInputFactory.makeMultipartRequestInput(xid.getValue(), version, MultipartType.OFPMPFLOW));
49                         return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
50                     }
51                 }
52
53         );
54     }
55
56 }