df01952f494207dd55c6616498bb506e24cbc06c
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / util / TaskUtil.java
1 /**
2  * Copyright (c) 2014 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.openflow.md.util;
9
10 import com.google.common.util.concurrent.JdkFutureAdapters;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.Future;
13 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
15 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
16 import org.opendaylight.openflowplugin.openflow.md.core.MessageFactory;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20
21 /**
22  *
23  */
24 public final class TaskUtil {
25
26     private TaskUtil() {
27         throw new AssertionError("TaskUtil is not expected to be instantiated.");
28     }
29
30     /**
31      * @param session
32      * @param cookie
33      * @param messageService
34      * @return barrier response
35      */
36     public static RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrier(SessionContext session,
37                                                                                                             SwitchConnectionDistinguisher cookie, IMessageDispatchService messageService) {
38         BarrierInput barrierInput = MessageFactory.createBarrier(
39                 session.getFeatures().getVersion(), session.getNextXid());
40         Future<RpcResult<BarrierOutput>> barrierResult = messageService.barrier(barrierInput, cookie);
41         ListenableFuture<RpcResult<BarrierOutput>> output = JdkFutureAdapters.listenInPoolThread(barrierResult);
42
43         return new RpcInputOutputTuple<>(barrierInput, output);
44     }
45
46
47 }