X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Futils%2FStatus.java;h=a7a44456cc3011ec6e1957395f65dbcf2fccd9af;hp=503e08e714568bc00118d5ad7626fd1ce396b2b7;hb=c97615f9dcd902079b828eebaafb420a0de61193;hpb=4a5b8b61c06c7091a7de5ed9df7456fa325dd909;ds=sidebyside diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java index 503e08e714..a7a44456cc 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/Status.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,21 +8,24 @@ package org.opendaylight.controller.sal.utils; +import java.io.Serializable; + /** * Represents the return object of the osgi service interfaces function calls. * It contains a code {@code StatusCode} representing the result of the call and * a string which describes a failure reason (if any) in human readable form. */ -public class Status { - StatusCode code; - String description; +public class Status implements Serializable { + private StatusCode code; + private String description; + private long requestId; /** * Generates an instance of the Status class. This is used as return code * for internal API2 function calls. This constructor allows to specify, * beside the Status Code, a custom human readable description to add more * information about the status. - * + * * @param errorCode * The status code. If passed as null, code will be stored as * {@code StatusCode.UNDEFINED} @@ -34,13 +37,14 @@ public class Status { this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED; this.description = (description != null) ? description : this.code .toString(); + this.requestId = 0; } /** * Generates an instance of the Status class based on the passed StatusCode * only. The description field of the Status object will be inferred by the * status code. - * + * * @param errorCode * The status code. If passed as null, code will be stored as * {@code StatusCode.UNDEFINED} @@ -49,11 +53,32 @@ public class Status { this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED; this.description = (description != null) ? description : this.code .toString(); + this.requestId = 0; + } + + /** + * Generates an instance of the Status class to be used in case of + * asynchronous call. It is supposed to be created by the underlying + * infrastructure only when it was successful in allocating the asynchronous + * request id, hence caller should expect StatusCode to be successful. + * + * @param errorCode + * The status code. If passed as null, code will be stored as + * {@code StatusCode.UNDEFINED} + * @param requestId + * The request id set by underlying infrastructure for this + * request + */ + public Status(StatusCode errorCode, long requestId) { + this.code = (errorCode != null) ? errorCode : StatusCode.UNDEFINED; + this.description = (description != null) ? description : this.code + .toString(); + this.requestId = requestId; } /** * Returns the status code - * + * * @return the {@code StatusCode} representing the status code */ public StatusCode getCode() { @@ -62,7 +87,7 @@ public class Status { /** * Returns a human readable description of the failure if any - * + * * @return a string representing the reason of failure */ public String getDescription() { @@ -71,16 +96,27 @@ public class Status { /** * Tells whether the status is successful - * + * * @return true if the Status code is {@code StatusCode.SUCCESS} */ public boolean isSuccess() { return code == StatusCode.SUCCESS; } + /** + * Return the request id assigned by underlying infrastructure in case of + * asynchronous request. In case of synchronous requests, the returned id + * is expected to be 0 + * + * @return The request id assigned for this asynchronous request + */ + public long getRequestId() { + return requestId; + } + @Override public String toString() { - return code + ": " + description; + return code + ": " + description + " (" + requestId + ")"; } @Override