Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / rpc / AbstractRequestContext.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.ListenableFuture;
11 import com.google.common.util.concurrent.SettableFuture;
12 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16
17 public abstract class AbstractRequestContext<T> implements RequestContext<T> {
18     private final SettableFuture<RpcResult<T>> rpcResultFuture = SettableFuture.create();
19     private final Xid xid;
20     private long waitTimeout;
21
22     protected AbstractRequestContext(final Uint32 xid) {
23         this.xid = xid == null ? null : new Xid(xid);
24     }
25
26     @Deprecated
27     protected AbstractRequestContext(final Long xid) {
28         this.xid = xid == null ? null : new Xid(Uint32.valueOf(xid));
29     }
30
31     @Override
32     public final ListenableFuture<RpcResult<T>> getFuture() {
33         return rpcResultFuture;
34     }
35
36     @Override
37     public final void setResult(final RpcResult<T> result) {
38         rpcResultFuture.set(result);
39     }
40
41     @Override
42     public final Xid getXid() {
43         return xid;
44     }
45
46     @Override
47     public final long getWaitTimeout() {
48         return waitTimeout;
49     }
50
51     @Override
52     public final void setWaitTimeout(final long waitTimeout) {
53         this.waitTimeout = waitTimeout;
54     }
55 }