2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.sal.core.impl;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Collection;
\r
12 import java.util.Collections;
\r
13 import java.util.List;
\r
14 import java.util.concurrent.Callable;
\r
16 import org.opendaylight.controller.sal.core.api.RpcImplementation;
\r
17 import org.opendaylight.controller.yang.common.QName;
\r
18 import org.opendaylight.controller.yang.common.RpcError;
\r
19 import org.opendaylight.controller.yang.common.RpcResult;
\r
20 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
23 public class RpcUtils {
\r
25 Callable<RpcResult<CompositeNode>> callableFor(
\r
26 final RpcImplementation implemenation, final QName rpc,
\r
27 final CompositeNode input) {
\r
29 return new Callable<RpcResult<CompositeNode>>() {
\r
32 public RpcResult<CompositeNode> call() throws Exception {
\r
33 return implemenation.invokeRpc(rpc, input);
\r
38 public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
\r
39 List<RpcError> errors) {
\r
40 RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
\r
44 private static class RpcResultTO<T> implements RpcResult<T> {
\r
46 private final Collection<RpcError> errors;
\r
47 private final T result;
\r
48 private final boolean successful;
\r
50 public RpcResultTO(boolean successful, T result, List<RpcError> errors) {
\r
51 this.successful = successful;
\r
52 this.result = result;
\r
53 this.errors = Collections.unmodifiableList(new ArrayList<RpcError>(
\r
58 public boolean isSuccessful() {
\r
63 public T getResult() {
\r
68 public Collection<RpcError> getErrors() {
\r