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;
11 import java.io.Serializable;
14 * Represents the return object of the osgi service interfaces function calls.
15 * It contains a code {@code StatusCode} representing the result of the call and
16 * a string which describes a failure reason (if any) in human readable form.
18 public class Status implements Serializable {
19 private StatusCode code;
20 private String description;
21 private long requestId;
24 * Generates an instance of the Status class. This is used as return code
25 * for internal API2 function calls. This constructor allows to specify,
26 * beside the Status Code, a custom human readable description to add more
27 * information about the status.
30 * The status code. If passed as null, code will be stored as
31 * {@code StatusCode.UNDEFINED}
33 * The human readable description of the status. If passed as
34 * null, description will be inferred by the code
36 public Status(StatusCode errorCode, String description) {
37 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
38 this.description = (description != null) ? description : this.code
44 * Generates an instance of the Status class based on the passed StatusCode
45 * only. The description field of the Status object will be inferred by the
49 * The status code. If passed as null, code will be stored as
50 * {@code StatusCode.UNDEFINED}
52 public Status(StatusCode errorCode) {
53 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
54 this.description = (description != null) ? description : this.code
60 * Generates an instance of the Status class to be used in case of
61 * asynchronous call. It is supposed to be created by the underlying
62 * infrastructure only when it was successful in allocating the asynchronous
63 * request id, hence caller should expect StatusCode to be successful.
66 * The status code. If passed as null, code will be stored as
67 * {@code StatusCode.UNDEFINED}
69 * The request id set by underlying infrastructure for this
72 public Status(StatusCode errorCode, long requestId) {
73 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
74 this.description = (description != null) ? description : this.code
76 this.requestId = requestId;
80 * Returns the status code
82 * @return the {@code StatusCode} representing the status code
84 public StatusCode getCode() {
89 * Returns a human readable description of the failure if any
91 * @return a string representing the reason of failure
93 public String getDescription() {
98 * Tells whether the status is successful
100 * @return true if the Status code is {@code StatusCode.SUCCESS}
102 public boolean isSuccess() {
103 return code == StatusCode.SUCCESS;
107 * Return the request id assigned by underlying infrastructure in case of
108 * asynchronous request. In case of synchronous requests, the returned id
109 * is expected to be 0
111 * @return The request id assigned for this asynchronous request
113 public long getRequestId() {
118 public String toString() {
119 return code + ": " + description + " (" + requestId + ")";
123 public int hashCode() {
124 final int prime = 31;
126 result = prime * result + ((code == null) ? 0 : code.calculateConsistentHashCode());
131 public boolean equals(Object obj) {
136 if (getClass() != obj.getClass())
138 Status other = (Status) obj;
139 if (code != other.code)