5af5880f10fe6e77867516a4235af977abde6872
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / rpc / RequestContextImpl.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.rpc;
9
10 import com.google.common.util.concurrent.SettableFuture;
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15
16 /**
17  * @author joe
18  */
19 public class RequestContextImpl<T> implements RequestContext<T> {
20
21     private final RequestContextStack requestContextStack;
22     private SettableFuture<RpcResult<T>> rpcResultFuture;
23     private long waitTimeout;
24     private Xid xid;
25
26     public RequestContextImpl(RequestContextStack requestContextStack) {
27         this.requestContextStack = requestContextStack;
28     }
29
30     @Override
31     public void close() {
32         requestContextStack.forgetRequestContext(this);
33     }
34
35     @Override
36     public SettableFuture<RpcResult<T>> getFuture() {
37         if (null == rpcResultFuture) {
38             rpcResultFuture = SettableFuture.create();
39         }
40         return rpcResultFuture;
41     }
42
43     @Override
44     public Xid getXid() {
45         return xid;
46     }
47
48     @Override
49     public void setXid(Xid xid) {
50         this.xid = xid;
51     }
52
53     @Override
54     public long getWaitTimeout() {
55         return waitTimeout;
56     }
57
58     @Override
59     public void setWaitTimeout(long waitTimeout) {
60         this.waitTimeout = waitTimeout;
61     }
62 }