CVS update: JGroups/src/org/jgroups/demos StompDraw.java
"Bela Ban" <[email protected]> Wed, 27 Oct 2010 09:24:59 +0000
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/10/27 09:24:59
Modified: src/org/jgroups/demos StompDraw.java
Log:
ns
Revision Changes Path
1.4 +53 -3 JGroups/src/org/jgroups/demos/StompDraw.java
Index: StompDraw.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/demos/StompDraw.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StompDraw.java 27 Oct 2010 07:43:19 -0000 1.3
+++ StompDraw.java 27 Oct 2010 09:24:59 -0000 1.4
@@ -1,4 +1,4 @@
-// $Id: StompDraw.java,v 1.3 2010/10/27 07:43:19 belaban Exp $
+// $Id: StompDraw.java,v 1.4 2010/10/27 09:24:59 belaban Exp $
package org.jgroups.demos;
@@ -130,9 +130,13 @@
setTitle();
String session_id=stomp_client.getSessionId();
- if(session_id != null) {
+ if(session_id != null)
stomp_client.send(clients_dest, null, 0, 0, "client-joined", session_id);
- }
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ StompDraw.this.stop();
+ }
+ });
}
@@ -148,6 +152,20 @@
}
}
+ String getAllClients() {
+ StringBuilder sb=new StringBuilder();
+ boolean first=true;
+ for(String client: clients) {
+ if(first)
+ first=false;
+ else
+ sb.append(",");
+ sb.append(client);
+ }
+
+ return sb.toString();
+ }
+
public void onInfo(Map<String, String> information) {
String view=information.get("view");
Collection<String> list;
@@ -189,7 +207,33 @@
setTitle();
}
}
+
+ stomp_client.send(clients_dest, null, 0, 0, "clients", getAllClients());
+ }
+
+ String left_client=headers.get("client-left");
+ if(left_client != null) {
+ synchronized(clients) {
+ if(clients.remove(left_client)) {
+ num_clients=clients.size();
+ setTitle();
+ }
+ }
}
+
+ String all_clients=headers.get("clients");
+ if(all_clients != null) {
+ List<String> list=Util.parseCommaDelimitedStrings(all_clients);
+ if(list != null) {
+ synchronized(clients) {
+ if(clients.addAll(list)) {
+ num_clients=clients.size();
+ setTitle();
+ }
+ }
+ }
+ }
+
return;
}
@@ -252,6 +296,12 @@
public void stop() {
+ if(!stomp_client.isConnected())
+ return;
+ String session_id=stomp_client.getSessionId();
+ if(session_id != null) {
+ stomp_client.send(clients_dest, null, 0, 0, "client-left", session_id);
+ }
stomp_client.disconnect();
mainFrame.setVisible(false);
mainFrame.dispose();
------------------------------------------------------------------------------
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