001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.protocol;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 /**
024 * Enumerates message types.
025 */
026 public enum MessageEnum {
027
028 REQUEST (1),
029 RESPONSE (2),
030
031 END_OF_DATA (10),
032 END_OF_REQUEST (20),
033 END_OF_SNAPSHOT (30);
034
035 public final int code;
036 private MessageEnum(int code) {
037 this.code = code;
038 }
039
040 public final static Map<Integer,MessageEnum> decoder
041 = new HashMap<Integer,MessageEnum>();
042 static {
043 MessageEnum[] v = MessageEnum.values();
044
045 for(int i = 0; i < v.length; i++) {
046 if(decoder.put(v[i].code, v[i]) != null) {
047 throw new AssertionError("duplicate code in: " + v[i]);
048 }
049 }
050 }
051 }