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.ovsdb.openstack.netvirt.api;
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 static final long serialVersionUID = 0L;
20 private StatusCode code;
21 private String description;
22 private long requestId;
25 * Generates an instance of the Status class. This is used as return code
26 * for internal API2 function calls. This constructor allows to specify,
27 * beside the Status Code, a custom human readable description to add more
28 * information about the status.
31 * The status code. If passed as null, code will be stored as
32 * {@code StatusCode.UNDEFINED}
34 * The human readable description of the status. If passed as
35 * null, description will be inferred by the code
37 public Status(StatusCode errorCode, String description) {
38 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
39 this.description = (description != null) ? description : this.code
45 * Generates an instance of the Status class based on the passed StatusCode
46 * only. The description field of the Status object will be inferred by the
50 * The status code. If passed as null, code will be stored as
51 * {@code StatusCode.UNDEFINED}
53 public Status(StatusCode errorCode) {
54 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
55 this.description = (description != null) ? description : this.code
61 * Generates an instance of the Status class to be used in case of
62 * asynchronous call. It is supposed to be created by the underlying
63 * infrastructure only when it was successful in allocating the asynchronous
64 * request id, hence caller should expect StatusCode to be successful.
67 * The status code. If passed as null, code will be stored as
68 * {@code StatusCode.UNDEFINED}
70 * The request id set by underlying infrastructure for this
73 public Status(StatusCode errorCode, long requestId) {
74 this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED;
75 this.description = (description != null) ? description : this.code
77 this.requestId = requestId;
81 * Returns the status code
83 * @return the {@code StatusCode} representing the status code
85 public StatusCode getCode() {
90 * Returns a human readable description of the failure if any
92 * @return a string representing the reason of failure
94 public String getDescription() {
99 * Tells whether the status is successful
101 * @return true if the Status code is {@code StatusCode.SUCCESS}
103 public boolean isSuccess() {
104 return code == StatusCode.SUCCESS || code == StatusCode.CREATED;
108 * Return the request id assigned by underlying infrastructure in case of
109 * asynchronous request. In case of synchronous requests, the returned id
110 * is expected to be 0
112 * @return The request id assigned for this asynchronous request
114 public long getRequestId() {
119 public String toString() {
120 return code + ": " + description + " (" + requestId + ")";
124 public int hashCode() {
125 final int prime = 31;
127 result = prime * result + ((code == null) ? 0 : code.calculateConsistentHashCode());
132 public boolean equals(Object obj) {
139 if (getClass() != obj.getClass()) {
142 Status other = (Status) obj;
143 if (code != other.code) {