diff options
author | jestin | 2012-05-12 14:26:08 +0000 |
---|---|---|
committer | jestin | 2012-05-12 14:26:08 +0000 |
commit | 4ffe8b84071babe544086f94c66431380d301d59 (patch) | |
tree | 12c9c3a4d6f00c071d8cd298f041dc383e887ff7 /src/Protocol.java | |
parent | 6fbefad24ec7e8783365db61b03357d50ee0dd56 (diff) | |
download | ivy-java-4ffe8b84071babe544086f94c66431380d301d59.zip ivy-java-4ffe8b84071babe544086f94c66431380d301d59.tar.gz ivy-java-4ffe8b84071babe544086f94c66431380d301d59.tar.bz2 ivy-java-4ffe8b84071babe544086f94c66431380d301d59.tar.xz |
- minor code cleanup
- adds a separate file (Protocol.java) containing the Enum values in a proper
pattern
- resolved a synchronization bug on Ivy.stop()
Diffstat (limited to 'src/Protocol.java')
-rw-r--r-- | src/Protocol.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Protocol.java b/src/Protocol.java new file mode 100644 index 0000000..a643e39 --- /dev/null +++ b/src/Protocol.java @@ -0,0 +1,54 @@ +/** + * the Protocol magic numbers and chars + * @author Yannick Jestin + * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a> + * + * CHANGELOG: + * 1.2.16 + * introduced to remove the int enum pattern + */ + +package fr.dgac.ivy; + +enum Protocol { + + BYE(0), /* end of the peer */ + ADDREGEXP(1), /* the peer adds a regexp */ + MSG(2), /* the peer sends a message */ + ERROR(3), /* error message */ + DELREGEXP(4), /* the peer removes one of his regex */ + ENDREGEXP(5), /* no more regexp in the handshake */ + SCHIZOTOKEN(6), /* avoid race condition in concurrent connexions, aka BeginRegexp in other implementations */ + DIRECTMSG(7), /* the peer sends a direct message */ + DIE(8), /* the peer wants us to quit */ + PING(9), + PONG(10); + + final static char STARTARG = '\u0002';/* begin of arguments */ + final static char ENDARG = '\u0003'; /* end of arguments */ + final static char ESCAPE = '\u001A'; + final static char NEWLINE = '\n'; + final static int PROTOCOLVERSION = 3 ; + final static int PROTOCOLMINIMUM = 3 ; + final static int MI = 3 ; + + private int value = -1; + private Protocol(int v) {this.value = v;} + + int value() {return value;} + + static Protocol fromString(String s) throws IvyException { + try { + return fromInt(Integer.parseInt(s)); + } catch (NumberFormatException nfe) { + throw new IvyException("protocol problem: "+s+" is not a valid integer"); + } + } + + static Protocol fromInt(int i) throws IvyException { + for (Protocol p : Protocol.values()) + if (p.value() == i) return p; + throw new IvyException("protocol magic number "+i+" not known"); + } + +} |