2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
10 import java.util.concurrent.Callable;
11 import java.util.concurrent.TimeUnit;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
15 import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService;
16 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
18 import com.google.common.util.concurrent.Futures;
19 import com.google.common.util.concurrent.ListenableFuture;
22 * @param <T> input type
23 * @param <K> future output type
25 public abstract class OFRpcTask<T, K> implements Callable<ListenableFuture<K>> {
27 private OFRpcTaskContext taskContext;
29 private SwitchConnectionDistinguisher cookie;
36 public OFRpcTask(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, T input) {
37 this.taskContext = taskContext;
45 public SwitchConnectionDistinguisher getCookie() {
50 * @param cookie the cookie to set
52 public void setCookie(SwitchConnectionDistinguisher cookie) {
64 * @param input the input to set
66 public void setInput(T input) {
71 * @return the rpcNotificationProviderService
73 public NotificationProviderService getRpcNotificationProviderService() {
74 return taskContext.getRpcNotificationProviderService();
78 * @return message service
79 * @see org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskContext#getMessageService()
81 public IMessageDispatchService getMessageService() {
82 return taskContext.getMessageService();
87 * @see org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskContext#getSession()
89 public SessionContext getSession() {
90 return taskContext.getSession();
95 * @see org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskContext#getMaxTimeout()
97 public long getMaxTimeout() {
98 return taskContext.getMaxTimeout();
102 * @return time unit for max timeout
103 * @see org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskContext#getMaxTimeoutUnit()
105 public TimeUnit getMaxTimeoutUnit() {
106 return taskContext.getMaxTimeoutUnit();
110 * @return protocol version
112 public Short getVersion() {
113 return taskContext.getSession().getFeatures().getVersion();
118 * @return the taskContext
120 public OFRpcTaskContext getTaskContext() {
125 * submit task into rpc worker pool
126 * @return future result of task
128 public ListenableFuture<K> submit() {
129 ListenableFuture<ListenableFuture<K>> compoundResult = getTaskContext().getRpcPool().submit(this);
130 return Futures.dereference(compoundResult);