OFJResult2RequestCtxFuture uses listenable future
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / MeterStatisticsService.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 org.opendaylight.openflowjava.protocol.api.util.BinContent;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
19 import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
20 import org.opendaylight.openflowplugin.impl.services.CommonService;
21 import org.opendaylight.openflowplugin.impl.services.DataCrate;
22 import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import java.util.List;
31 import java.util.concurrent.Future;
32
33 /**
34  * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015.
35  */
36 public class MeterStatisticsService extends CommonService {
37
38     public MeterStatisticsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
39         super(requestContextStack, deviceContext);
40     }
41
42     public Future<RpcResult<List<MultipartReply>>> getAllMeterStatistics(final MultiMsgCollector multiMsgCollector) {
43         return handleServiceCall(
44                 PRIMARY_CONNECTION, new Function<DataCrate<List<MultipartReply>>, ListenableFuture<RpcResult<Void>>>() {
45                     @Override
46                     public ListenableFuture<RpcResult<Void>> apply(final DataCrate<List<MultipartReply>> data) {
47
48                         final Xid xid = deviceContext.getNextXid();
49                         data.getRequestContext().setXid(xid);
50                         multiMsgCollector.registerMultipartXid(xid.getValue());
51
52                         final Future<RpcResult<Void>> resultFromOFLib = deviceContext.getPrimaryConnectionContext()
53                                 .getConnectionAdapter().multipartRequest(
54                                         MultipartRequestInputFactory.makeMultipartRequestInput(
55                                                 xid.getValue(),
56                                                 version,
57                                                 MultipartType.OFPMPMETER));
58                         return JdkFutureAdapters.listenInPoolThread(resultFromOFLib);
59                     }
60                 }
61         );
62
63     }
64
65 }