Merge "Returning of future from request context - PacketProcessingService."
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / StatisticsServiceUtil.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.util;
10
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20
21 /**
22  * Created by Martin Bobak <mbobak@cisco.com> on 18.5.2015.
23  */
24 public class StatisticsServiceUtil {
25
26     private StatisticsServiceUtil() {
27         throw new IllegalStateException("This class should not be instantiated");
28     }
29
30     public static <T> ListenableFuture<RpcResult<T>> getRpcResultListenableFuture(final Xid xid,
31                                                                                  final MultipartRequestInput multipartRequestInput,
32                                                                                  final DeviceContext deviceContext) {
33         final SettableFuture<RpcResult<T>> settableFuture = SettableFuture.create();
34         final OutboundQueue outboundQueue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
35         outboundQueue.commitEntry(xid.getValue(), multipartRequestInput, new FutureCallback<OfHeader>() {
36             @Override
37             public void onSuccess(final OfHeader ofHeader) {
38             }
39
40             @Override
41             public void onFailure(final Throwable throwable) {
42             }
43         });
44         return settableFuture;
45     }
46
47 }