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;
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageDecoder.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageDecoder.java
index 2c91587..4c88d4b 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageDecoder.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageDecoder.java
@@ -96,7 +96,7 @@
             messageType = new String(messageTypeBytes, Charsets.UTF_8);
             checkpoint(DecoderState.READ_MESSAGE_STATUS);
         case READ_MESSAGE_STATUS:
-            status = Status.values()[buffer.readInt()];
+            status = Status.forId(buffer.readInt());
             checkpoint(DecoderState.READ_CONTENT_LENGTH);
         case READ_CONTENT_LENGTH:
             contentLength = buffer.readInt();
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageEncoder.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageEncoder.java
index 4b40108..1fcc5cc 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageEncoder.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/MessageEncoder.java
@@ -85,7 +85,7 @@
         out.writeBytes(messageTypeBytes);
 
         // write message status value
-        out.writeInt(message.status().ordinal());
+        out.writeInt(message.status().id());
 
         byte[] payload = message.payload();