From 4ffe8b84071babe544086f94c66431380d301d59 Mon Sep 17 00:00:00 2001 From: jestin Date: Sat, 12 May 2012 14:26:08 +0000 Subject: - minor code cleanup - adds a separate file (Protocol.java) containing the Enum values in a proper pattern - resolved a synchronization bug on Ivy.stop() --- src/Protocol.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Protocol.java (limited to 'src/Protocol.java') 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 http://www.tls.cena.fr/products/ivy/ + * + * 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"); + } + +} -- cgit v1.1