2 * Copyright (c) 2014 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.util;
10 import com.google.common.util.concurrent.SettableFuture;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.openflowplugin.api.ConnectionException;
14 import org.opendaylight.openflowplugin.api.OFConstants;
15 import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
16 import org.opendaylight.yangtools.yang.common.RpcError;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 public final class RpcResultUtil {
25 private RpcResultUtil() {
26 throw new UnsupportedOperationException("RpcResultUtil is not expected to be instantiated.");
30 * @param e connection exception
31 * @param <T> rpc result return type
32 * @return error wrapped inside {@link RpcResult} which is wrapped inside future
34 public static <T> SettableFuture<RpcResult<T>> getRpcErrorFuture(ConnectionException e) {
35 List<RpcError> rpcErrorList = wrapConnectionErrorIntoRpcErrors(e);
36 SettableFuture<RpcResult<T>> futureWithError = SettableFuture.create();
37 futureWithError.set(RpcResultBuilder.<T>failed().withRpcErrors(rpcErrorList).build());
38 return futureWithError;
41 private static List<RpcError> wrapConnectionErrorIntoRpcErrors(ConnectionException e) {
42 List<RpcError> rpcErrorList = new ArrayList<>();
43 rpcErrorList.add(RpcResultBuilder.newError(
44 RpcError.ErrorType.TRANSPORT,
45 OFConstants.ERROR_TAG_TIMEOUT,
47 OFConstants.APPLICATION_TAG,
48 IMessageDispatchService.CONNECTION_ERROR_MESSAGE,