Remove unnecessary memory copy from values() call in Netty mesaging service.
Change-Id: If673adeef3839e51154ac9d7f94967fbdc2712dc
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/InternalMessage.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/InternalMessage.java
index 7e79da0..8b96c2a 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/InternalMessage.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/InternalMessage.java
@@ -31,29 +31,64 @@
* Message status.
*/
public enum Status {
+
+ // NOTE: For backwards compatibility enum constant IDs should not be changed.
+
/**
* All ok.
*/
- OK,
+ OK(0),
/**
* Response status signifying no registered handler.
*/
- ERROR_NO_HANDLER,
+ ERROR_NO_HANDLER(1),
/**
* Response status signifying an exception handling the message.
*/
- ERROR_HANDLER_EXCEPTION,
+ ERROR_HANDLER_EXCEPTION(2),
/**
- * Reponse status signifying invalid message structure.
+ * Response status signifying invalid message structure.
*/
- PROTOCOL_EXCEPTION
+ PROTOCOL_EXCEPTION(3);
- // NOTE: For backwards compatibility it important that new enum constants
- // be appended.
- // FIXME: We should remove this restriction in the future.
+ private final int id;
+
+ Status(int id) {
+ this.id = id;
+ }
+
+ /**
+ * Returns the unique status ID.
+ *
+ * @return the unique status ID.
+ */
+ public int id() {
+ return id;
+ }
+
+ /**
+ * Returns the status enum associated with the given ID.
+ *
+ * @param id the status ID.
+ * @return the status enum for the given ID.
+ */
+ public static Status forId(int id) {
+ switch (id) {
+ case 0:
+ return OK;
+ case 1:
+ return ERROR_NO_HANDLER;
+ case 2:
+ return ERROR_HANDLER_EXCEPTION;
+ case 3:
+ return PROTOCOL_EXCEPTION;
+ default:
+ throw new IllegalArgumentException("Unknown status ID " + id);
+ }
+ }
}
private final int preamble;