Merge "BUG-1291 Fix executor for netconf-connector rejecting tasks."
[controller.git] / opendaylight / md-sal / sal-common-util / src / main / java / org / opendaylight / controller / sal / common / util / Rpcs.java
1 /*
2  * Copyright (c) 2013 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.controller.sal.common.util;
9
10 import java.io.Serializable;
11 import java.util.Collection;
12
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.RpcError;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16
17 import com.google.common.collect.ImmutableList;
18
19 /**
20  * @deprecated Use {@link org.opendaylight.yangtools.yang.common.RpcResultBuilder}
21  */
22 @Deprecated
23 public class Rpcs {
24
25     public static <T> RpcResult<T> getRpcResult(boolean successful) {
26         RpcResult<T> ret = new RpcResultTO<T>(successful, null, ImmutableList.<RpcError>of());
27         return ret;
28     }
29
30     public static <T> RpcResult<T> getRpcResult(boolean successful, T result,
31             Collection<RpcError> errors) {
32         RpcResult<T> ret = new RpcResultTO<T>(successful, result, errors);
33         return ret;
34     }
35
36     public static <T> RpcResult<T> getRpcResult(boolean successful, Collection<RpcError> errors) {
37         return new RpcResultTO<T>(successful, null, errors);
38     }
39
40     private static class RpcResultTO<T> implements RpcResult<T>, Serializable, Immutable {
41         private static final long serialVersionUID = 1L;
42         private final Collection<RpcError> errors;
43         private final T result;
44         private final boolean successful;
45
46         public RpcResultTO(boolean successful, T result,
47                 Collection<RpcError> errors) {
48             this.successful = successful;
49             this.result = result;
50             this.errors = ImmutableList.copyOf(errors);
51         }
52
53         @Override
54         public boolean isSuccessful() {
55             return successful;
56         }
57
58         @Override
59         public T getResult() {
60             return result;
61         }
62
63         @Override
64         public Collection<RpcError> getErrors() {
65             return errors;
66         }
67
68     }
69 }