CVS update: JGroups/src/org/jgroups/protocols STOMP.java
"Bela Ban" <[email protected]> Thu, 21 Oct 2010 13:55:25 +0000
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/10/21 13:55:25
Modified: src/org/jgroups/protocols STOMP.java
Log:
ns
Revision Changes Path
1.4 +26 -9 JGroups/src/org/jgroups/protocols/STOMP.java
Index: STOMP.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/protocols/STOMP.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- STOMP.java 21 Oct 2010 13:29:22 -0000 1.3
+++ STOMP.java 21 Oct 2010 13:55:25 -0000 1.4
@@ -21,7 +21,7 @@
* Protocol which provides STOMP support. Very simple implementation, with a 1 thread / connection model. Use for
* a few hundred clients max.
* @author Bela Ban
- * @version $Id: STOMP.java,v 1.3 2010/10/21 13:29:22 belaban Exp $
+ * @version $Id: STOMP.java,v 1.4 2010/10/21 13:55:25 belaban Exp $
* @since 2.11
*/
@MBean
@@ -45,6 +45,9 @@
+ public static enum ClientVerb {CONNECT, SUBSCRIBE, UNSUBSCRIBE, BEGIN, COMMIT, ABORT, ACK, DISCONNECT};
+ public static enum ServerVerb {MESSAGE, RECEIPT, ERROR}
+ public static enum ServerResponse {CONNECTED}
public STOMP() {
@@ -93,9 +96,6 @@
Socket client_sock;
while(acceptor != null && srv_sock != null) {
try {
- if(log.isTraceEnabled()) // +++ remove
- log.trace("waiting for client connections on " + srv_sock.getInetAddress() + ":" +
- srv_sock.getLocalPort());
client_sock=srv_sock.accept();
if(log.isTraceEnabled()) // +++ remove
log.trace("accepted connection from " + client_sock.getInetAddress() + ':' + client_sock.getPort());
@@ -131,6 +131,8 @@
}
public void stop() {
+ if(log.isTraceEnabled())
+ log.trace("closing connection to " + sock.getRemoteSocketAddress());
Util.close(in);
Util.close(out);
Util.close(sock);
@@ -155,16 +157,29 @@
log.error("failure reading frame", ex);
stop();
}
+ catch(Throwable t) {
+ log.error("failure reading frame", t);
+ }
}
}
private Frame readFrame(DataInputStream in) throws IOException {
- String verb=Util.readLine(in);
- if(verb == null)
+ String tmp_verb=Util.readLine(in);
+ if(tmp_verb == null)
throw new EOFException("reading verb");
- if(verb.length() == 0)
+ if(tmp_verb.length() == 0)
+ return null;
+
+ ClientVerb verb;
+
+ try {
+ verb=ClientVerb.valueOf(tmp_verb);
+ }
+ catch(IllegalArgumentException illegal_ex) {
+ log.error("verb " + tmp_verb + " unknown");
return null;
+ }
Map<String,String> headers=new HashMap<String,String>();
byte[] body=null;
@@ -224,11 +239,11 @@
}
protected static class Frame {
- final String verb;
+ final ClientVerb verb;
final Map<String,String> headers;
final byte[] body;
- public Frame(String verb, Map<String, String> headers, byte[] body) {
+ public Frame(ClientVerb verb, Map<String, String> headers, byte[] body) {
this.verb=verb;
this.headers=headers;
this.body=body;
@@ -243,6 +258,8 @@
}
if(body != null && body.length > 0) {
sb.append("body: ").append(body.length).append(" bytes");
+ if(body.length < 50)
+ sb.append(": " + new String(body));
}
return sb.toString();
}
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev