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
9 package org.opendaylight.controller.sal.utils;
12 * Represents the return object of the osgi service interfaces function calls.
13 * It contains a code {@code StatusCode} representing the result of the call and
14 * a string which describes a failure reason (if any) in human readable form.
17 private StatusCode code;
18 private String description;
19 private long requestId;
22 * Generates an instance of the Status class. This is used as return code
23 * for internal API2 function calls. This constructor allows to specify,
24 * beside the Status Code, a custom human readable description to add more
25 * information about the status.
28 * The status code. If passed as null, code will be stored as
29 * {@code StatusCode.UNDEFINED}
31 * The human readable description of the status. If passed as
32 * null, description will be inferred by the code
34 public Status(StatusCode errorCode, String description) {
35 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
36 this.description = (description != null) ? description : this.code
42 * Generates an instance of the Status class based on the passed StatusCode
43 * only. The description field of the Status object will be inferred by the
47 * The status code. If passed as null, code will be stored as
48 * {@code StatusCode.UNDEFINED}
50 public Status(StatusCode errorCode) {
51 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
52 this.description = (description != null) ? description : this.code
58 * Generates an instance of the Status class to be used in case of
59 * asynchronous call. It is supposed to be created by the underlying
60 * infrastructure only when it was successful in allocating the asynchronous
61 * request id, hence caller should expect StatusCode to be successful.
64 * The status code. If passed as null, code will be stored as
65 * {@code StatusCode.UNDEFINED}
67 * The request id set by underlying infrastructure for this
70 public Status(StatusCode errorCode, long requestId) {
71 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
72 this.description = (description != null) ? description : this.code
74 this.requestId = requestId;
78 * Returns the status code
80 * @return the {@code StatusCode} representing the status code
82 public StatusCode getCode() {
87 * Returns a human readable description of the failure if any
89 * @return a string representing the reason of failure
91 public String getDescription() {
96 * Tells whether the status is successful
98 * @return true if the Status code is {@code StatusCode.SUCCESS}
100 public boolean isSuccess() {
101 return code == StatusCode.SUCCESS;
105 * Return the request id assigned by underlying infrastructure in case of
106 * asynchronous request. In case of synchronous requests, the returned id
107 * is expected to be 0
109 * @return The request id assigned for this asynchronous request
111 public long getRequestId() {
116 public String toString() {
117 return code + ": " + description + " (" + requestId + ")";
121 public int hashCode() {
122 final int prime = 31;
124 result = prime * result + ((code == null) ? 0 : code.hashCode());
129 public boolean equals(Object obj) {
134 if (getClass() != obj.getClass())
136 Status other = (Status) obj;
137 if (code != other.code)